Show
Ignore:
Files:
3 removed
12 modified

Legend:

Unmodified
Added
Removed
  • .hgignore

    r8 r22  
    1313*.autosave 
    1414static/forum/avatars 
     15secret.txt 
  • apps/forum/models.py

    r18 r29  
    128128 
    129129    class Meta: 
    130         ordering = ['-created'] 
     130        ordering = ['-updated'] 
    131131        verbose_name = _('Topic') 
    132132        verbose_name_plural = _('Topics') 
     
    206206        self.body_html = urlize(self.body_html) 
    207207        self.body_html = smiles(self.body_html) 
    208  
    209208        new = self.id is None 
    210  
    211209        if new: 
     210            #new post created 
     211            super(Post, self).save(*args, **kwargs) 
    212212            self.topic.updated = datetime.now() 
    213             self.topic.post_count += 1 
     213            self.topic.post_count = Post.objects.filter(topic=self.topic).count() 
    214214            self.topic.save() 
    215215            self.topic.forum.updated = self.topic.updated 
    216             self.topic.forum.post_count += 1 
     216            self.topic.forum.post_count = Post.objects.filter(topic__forum=self.topic.forum).count() 
    217217            self.topic.forum.save() 
    218  
    219         super(Post, self).save(*args, **kwargs) 
     218        else: 
     219            #edit post 
     220            super(Post, self).save(*args, **kwargs) 
    220221 
    221222    def get_absolute_url(self): 
     
    226227        head_post_id = self.topic.posts.order_by('created')[0].id 
    227228        super(Post, self).delete(*args, **kwargs) 
    228          
    229         self.topic.post_count -= 1 
     229        self.topic.post_count = Post.objects.filter(topic=self.topic).count() 
    230230        self.topic.save() 
    231         self.topic.forum.post_count -= 1 
     231        self.topic.forum.post_count = Post.objects.filter(topic__forum=self.topic.forum).count() 
    232232        self.topic.forum.save() 
    233          
     233 
    234234        if self_id == head_post_id: 
    235235            self.topic.delete() 
     
    275275        verbose_name = _('Profile') 
    276276        verbose_name_plural = _('Profiles') 
    277          
     277 
    278278    def last_post(self): 
    279279        posts = Post.objects.filter(user=self.user).order_by('-created').select_related() 
  • apps/forum/settings.py

    r17 r26  
    11from django.conf import settings 
     2import re 
    23 
    34def get(key, default): 
     
    4748EMOTION_ROLL = get('EMOTION_ROLL', '<img src="%sforum/img/smilies/roll.png">' % settings.MEDIA_URL) 
    4849EMOTION_COOL = get('EMOTION_COOL', '<img src="%sforum/img/smilies/cool.png">' % settings.MEDIA_URL) 
     50SMILES = ((r'(:|=)\)', EMOTION_SMILE), #:), =) 
     51          (r'(:|=)\|',  EMOTION_NEUTRAL), #:|, =|  
     52          (r'(:|=)\(', EMOTION_SAD), #:(, =( 
     53          (r'(:|=)D', EMOTION_BIG_SMILE), #:D, =D 
     54          (r':o', EMOTION_YIKES), # :o, :O 
     55          (r';\)', EMOTION_WINK), # ;\  
     56          (r':/', EMOTION_HMM), #:/ 
     57          (r':P', EMOTION_TONGUE), # :P 
     58          (r':lol:', EMOTION_LOL), 
     59          (r':mad:', EMOTION_MAD), 
     60          (r':rolleyes:', EMOTION_ROLL), 
     61          (r':cool:', EMOTION_COOL) 
     62         ) 
     63SMILES = get('SMILES', SMILES) 
  • apps/forum/subscription.py

    r17 r25  
    6161 
    6262def notify_pm_recipients(pm): 
    63     from apps.forum.models import PrivateMessage 
    64      
    65     subject = (u'There are new messages') 
    66     to_email = pm.dst_user.email 
    67     text_content = PM_RECIPIENT_TEXT_TEMPLATE % { 
    68         'username': pm.src_user.username, 
    69         'message': pm.body_text, 
    70         'pm_url': absolute_url(pm.get_absolute_url()), 
    71      } 
    72     send_mail([to_email], subject, text_content) 
     63    if not pm.read: 
     64        from apps.forum.models import PrivateMessage  
     65        subject = (u'There are new messages') 
     66        to_email = pm.dst_user.email 
     67        text_content = PM_RECIPIENT_TEXT_TEMPLATE % { 
     68            'username': pm.src_user.username, 
     69            'message': pm.body_text, 
     70            'pm_url': absolute_url(pm.get_absolute_url()), 
     71         } 
     72        send_mail([to_email], subject, text_content) 
  • apps/forum/templates/forum/forum_row.html

    r8 r29  
    11{% load forum_extras %} 
     2{% load i18n %} 
    23 
    34{% if forum.last_post.topic %} 
     
    3031                {% if forum.last_post.topic %} 
    3132                <a href="{{ forum.last_post.get_absolute_url }}">{% forum_time forum.last_post.created %}</a> 
    32                 <span class="byuser">оставил {{ forum.last_post.user }}</span> 
     33                <span class="byuser">{% trans "by" %} {{ forum.last_post.user }}</span> 
    3334                {% endif %} 
    3435                {% endif %} 
  • apps/forum/templates/forum/moderate.html

    r0 r30  
    6969                                        <td class="tc2">{{ topic.reply_count }}</td> 
    7070                                        <td class="tc3">{{ topic.views }}</td> 
    71                                         <td class="tcr"><a href="{{ topic.get_absolute_url }}">{% forum_time topic.updated %}</a> <span class="byuser">оставил {{ topic.last_post.user }}</span></td> 
     71                                        <td class="tcr"><a href="{{ topic.get_absolute_url }}">{% forum_time topic.updated %}</a> <span class="byuser">{% trans "by" %} {{ topic.last_post.user }}</span></td> 
    7272                                        <td class="tcmod"><input type="checkbox" name="topic_id[{{ topic.id }}]" value="1" /></td> 
    7373                                </tr> 
  • apps/forum/templates/forum/topic.html

    r18 r30  
    88                <p class="pagelink conl">{% pagination %}</p> 
    99                {% if not topic.closed and user.is_authenticated %} 
    10                 <p class="postlink conr"><a href="{% url add_post topic.id %}">Ответить</a></p> 
     10                <p class="postlink conr"><a href="{% url add_post topic.id %}">{% trans "Reply" %}</a></p> 
    1111                {% endif %} 
    1212                                <ul><li><a href="{% url index %}">{% trans "Root" %} </a></li><li>&raquo; {% link topic.forum %} </li><li>&raquo; {{ topic }}  
  • apps/forum/templates/forum/user.html

    r18 r30  
    126126                                                <dl> 
    127127                                                        <dt>{% trans "Posts:" %} </dt> 
    128                                                         <dd>{{ profile.forum_profile.post_count }} - <a href="{% url search %}?action=show_user&user_id={{ profile.id }}">Показать все сообщения</a></dd> 
     128                                                        <dd>{{ profile.forum_profile.post_count }} - <a href="{% url search %}?action=show_user&user_id={{ profile.id }}">{% trans "Show all posts" %}</a></dd> 
    129129                                                        <dt>{% trans "Last post:" %} </dt> 
    130130                                                        {% if profile.forum_profile.last_post %} 
  • apps/forum/templatetags/forum_extras.py

    r14 r28  
    198198@register.filter 
    199199def forum_stars(user): 
    200     posts = user.posts.count() 
     200    posts = user.forum_profile.post_count 
    201201    if posts >= forum_settings.FORUM_STAR_5:  
    202202        return mark_safe('<img src="%sforum/img/stars/Star_5.gif" alt="" >' % (settings.MEDIA_URL)) 
  • apps/forum/util.py

    r17 r26  
    1616from apps.forum import settings as forum_settings 
    1717 
    18 def render_to(template_path): 
    19     """ 
    20     Expect the dict from view. Render returned dict with 
    21     RequestContext. 
    22     """ 
    23  
    24     def decorator(func): 
    25         def wrapper(request, *args, **kwargs): 
    26             output = func(request, *args, **kwargs) 
    27             if not isinstance(output, dict): 
    28                 return output 
    29             kwargs = {'context_instance': RequestContext(request)} 
    30             if 'MIME_TYPE' in output: 
    31                 kwargs['mimetype'] = output.pop('MIME_TYPE') 
    32             if 'TEMPLATE' in output: 
    33                 template = output.pop('TEMPLATE') 
    34             else: 
    35                 template = template_path 
    36             return render_to_response(template, output, **kwargs) 
     18#compile smiles regexp 
     19_SMILES = [(re.compile(smile_re), path) for smile_re, path in forum_settings.SMILES] 
     20 
     21def render_to(template): 
     22    """ 
     23    Decorator for Django views that sends returned dict to render_to_response function 
     24    with given template and RequestContext as context instance. 
     25 
     26    If view doesn't return dict then decorator simply returns output. 
     27    Additionally view can return two-tuple, which must contain dict as first 
     28    element and string with template name as second. This string will 
     29    override template name, given as parameter 
     30 
     31    Parameters: 
     32 
     33     - template: template name to use 
     34 
     35    Examples:: 
     36 
     37      @render_to('some/tmpl.html') 
     38      def view(request): 
     39          if smth: 
     40              return {'context': 'dict'} 
     41          else: 
     42              return {'context': 'dict'}, 'other/tmpl.html' 
     43 
     44     2006-2009 Alexander Solovyov, new BSD License 
     45    """ 
     46    def renderer(func): 
     47        def wrapper(request, *args, **kw): 
     48            output = func(request, *args, **kw) 
     49            if isinstance(output, (list, tuple)): 
     50                return render_to_response(output[1], output[0], RequestContext(request)) 
     51            elif isinstance(output, dict): 
     52                return render_to_response(template, output, RequestContext(request)) 
     53            return output 
    3754        return wrapper 
    38  
    39     return decorator 
     55    return renderer 
    4056 
    4157def absolute_url(path): 
     
    140156    return form 
    141157 
    142 def urlize(data): 
    143     """ 
    144     Urlize plain text links in the HTML contents. 
    145     
    146     Do not urlize content of A and CODE tags. 
    147     """ 
    148      
    149     class URLizeHTMLParser(HTMLParser): 
    150      
    151         def __init__(self): 
     158class ExcludeTagsHTMLParser(HTMLParser): 
     159        """ 
     160        Class for html parsing with excluding specified tags. 
     161        """ 
     162 
     163        def __init__(self, func, tags=('a', 'code')): 
    152164            HTMLParser.__init__(self) 
    153             self.is_link = False 
    154             self.urlized_html = [] 
    155              
     165            self.func = func 
     166            self.is_ignored = False 
     167            self.tags = tags 
     168            self.html = [] 
     169 
    156170        def handle_starttag(self, tag, attrs): 
    157             self.urlized_html.append('<%s%s>' % (tag, self.__html_attrs(attrs))) 
    158             if tag in ('a', 'code'): 
    159                 self.is_link = True 
    160      
     171            self.html.append('<%s%s>' % (tag, self.__html_attrs(attrs))) 
     172            if tag in self.tags: 
     173                self.is_ignored = True 
     174 
    161175        def handle_data(self, data): 
    162             if not self.is_link: 
    163                 data = django_urlize(data) 
    164             self.urlized_html.append(data) 
    165      
     176            if not self.is_ignored: 
     177                data = self.func(data) 
     178            self.html.append(data) 
     179 
    166180        def handle_startendtag(self, tag, attrs): 
    167             self.urlized_html.append('<%s%s/>' % (tag, self.__html_attrs(attrs)))  
    168      
     181            self.html.append('<%s%s/>' % (tag, self.__html_attrs(attrs)))  
     182 
    169183        def handle_endtag(self, tag): 
    170             self.is_link = False 
    171             self.urlized_html.append('</%s>' % (tag)) 
    172      
     184            self.is_ignored = False 
     185            self.html.append('</%s>' % (tag)) 
     186 
     187        def handle_entityref(self, name): 
     188            self.html.append('&%s;' % name) 
     189 
     190        def handle_charref(self, name): 
     191            self.html.append('&%s;' % name) 
     192 
    173193        def __html_attrs(self, attrs): 
    174194            _attrs = '' 
     
    176196                _attrs = ' %s' % (' '.join([('%s="%s"' % (k,v)) for k,v in attrs])) 
    177197            return _attrs 
    178      
     198 
    179199        def feed(self, data): 
    180200            HTMLParser.feed(self, data) 
    181             self.urlized_html = ''.join(self.urlized_html) 
    182          
    183     parser = URLizeHTMLParser() 
     201            self.html = ''.join(self.html) 
     202 
     203def urlize(data): 
     204    """ 
     205    Urlize plain text links in the HTML contents. 
     206    
     207    Do not urlize content of A and CODE tags. 
     208    """ 
     209 
     210    parser = ExcludeTagsHTMLParser(django_urlize) 
    184211    parser.feed(data) 
    185     urlized_html = parser.urlized_html 
     212    urlized_html = parser.html 
    186213    parser.close() 
    187214    return urlized_html 
    188215 
     216def _smile_replacer(data): 
     217    for smile, path in _SMILES: 
     218        data = smile.sub(path, data) 
     219    return data 
     220 
    189221def smiles(data): 
    190     # TODO: code refactoring; ignore smiles in tag [code] 
    191     data = re.compile(r':\)').sub(forum_settings.EMOTION_SMILE, data) 
    192     data = re.compile(r'=\)').sub(forum_settings.EMOTION_SMILE, data) 
    193     data = re.compile(r':\|').sub(forum_settings.EMOTION_NEUTRAL, data) 
    194     data = re.compile(r'=\|').sub(forum_settings.EMOTION_NEUTRAL, data) 
    195     data = re.compile(r':\(').sub(forum_settings.EMOTION_SAD, data) 
    196     data = re.compile(r'=\(').sub(forum_settings.EMOTION_SAD, data) 
    197     data = re.compile(r':D').sub(forum_settings.EMOTION_BIG_SMILE, data) 
    198     data = re.compile(r'=D').sub(forum_settings.EMOTION_BIG_SMILE, data) 
    199     data = re.compile(r':o').sub(forum_settings.EMOTION_YIKES, data) 
    200     data = re.compile(r':O').sub(forum_settings.EMOTION_YIKES, data) 
    201     data = re.compile(r';\)').sub(forum_settings.EMOTION_WINK, data) 
    202     data = re.compile(r'(?<!http):/').sub(forum_settings.EMOTION_HMM, data) 
    203     data = re.compile(r':P').sub(forum_settings.EMOTION_TONGUE, data) 
    204     data = re.compile(r':lol:').sub(forum_settings.EMOTION_LOL, data) 
    205     data = re.compile(r':mad:').sub(forum_settings.EMOTION_MAD, data) 
    206     data = re.compile(r':rolleyes:').sub(forum_settings.EMOTION_ROLL, data) 
    207     data = re.compile(r':cool:').sub(forum_settings.EMOTION_COOL, data) 
    208     return data 
    209  
     222    """ 
     223    Replace text smiles. 
     224    """ 
     225 
     226    parser = ExcludeTagsHTMLParser(_smile_replacer) 
     227    parser.feed(data) 
     228    smiled_html = parser.html 
     229    parser.close() 
     230    return smiled_html 
  • apps/forum/views.py

    r18 r25  
    33import datetime 
    44 
    5 from django.shortcuts import get_object_or_404, render_to_response 
    6 from django.template import RequestContext 
     5from django.shortcuts import get_object_or_404 
    76from django.http import Http404, HttpResponse, HttpResponseRedirect 
    87from django.contrib.auth.models import User 
     
    2726        if cache.get(str(user.id)): 
    2827            users_online.append(user) 
    29     guest_count = len(cache._cache) - users_online.__len__() 
     28    guest_count = len(cache._cache) - len(users_online) 
    3029 
    3130    cats = {} 
     
    4645            'users': User.objects.count(), 
    4746            'users_online': users_online, 
    48             'online_count': users_online.__len__(), 
     47            'online_count': len(users_online), 
    4948            'guest_count': guest_count, 
    5049            'last_user': User.objects.order_by('-date_joined')[0], 
    51             } 
     50           } 
    5251 
    5352@render_to('forum/moderate.html') 
     
    6463                    topic_id = topic_match.group(1) 
    6564                    reverse('move_topic', args=[topic_id]) 
    66                          
     65 
    6766            return HttpResponseRedirect(reverse('index')) 
    6867        elif 'delete_topics' in request.POST: 
    6968            for topic in request.POST: 
    7069                topic_match = re.match('topic_id\[(\d+)\]', reputation) 
    71                      
     70 
    7271                if topic_match: 
    7372                    topic_id = topic_match.group(1) 
     
    7978            for topic in request.POST: 
    8079                topic_match = re.match('topic_id\[(\d+)\]', topic) 
    81                      
     80 
    8281                if topic_match: 
    8382                    topic_id = topic_match.group(1) 
    8483                    open_topic(request, topic_id) 
    85                          
     84 
    8685            return HttpResponseRedirect(reverse('index')) 
    8786        elif 'close_topics' in request.POST: 
    8887            for topic in request.POST: 
    8988                topic_match = re.match('topic_id\[(\d+)\]', topic) 
    90                      
     89 
    9190                if topic_match: 
    9291                    topic_id = topic_match.group(1) 
     
    9493                         
    9594            return HttpResponseRedirect(reverse('index')) 
    96      
     95 
    9796        return {'forum': forum, 
    9897                'topics': topics, 
     
    104103        raise Http404 
    105104 
     105@render_to('forum/search_topics.html') 
    106106def search(request): 
    107107    if 'action' in request.GET: 
    108         if 'show_24h' in request.GET['action']: 
     108        action = request.GET['action'] 
     109        if action == 'show_24h': 
    109110            date =  datetime.datetime.today() - datetime.timedelta(1) 
    110111            topics = Topic.objects.filter(created__gte=date).order_by('created') 
    111             return render_to_response('forum/search_topics.html',  
    112                                      {'topics': topics, 
    113                                      }, RequestContext(request)) 
    114         elif 'show_new' in request.GET['action']: 
     112        elif action == 'show_new': 
    115113            topics = Topic.objects.all().order_by('created') 
    116114            topics = [topic for topic in topics if forum_extras.has_unreads(topic, request.user)] 
    117             return render_to_response('forum/search_topics.html',  
    118                                      {'topics': topics, 
    119                                      }, RequestContext(request)) 
    120         elif 'show_unanswered' in request.GET['action']: 
     115        elif action == 'show_unanswered': 
    121116            topics = Topic.objects.filter(post_count=1) 
    122             return render_to_response('forum/search_topics.html',  
    123                                      {'topics': topics, 
    124                                      }, RequestContext(request)) 
    125         elif 'show_subscriptions' in request.GET['action']: 
     117        elif action == 'show_subscriptions': 
    126118            topics = Topic.objects.filter(subscribers=request.user) 
    127             return render_to_response('forum/search_topics.html',  
    128                                      {'topics': topics, 
    129                                      }, RequestContext(request)) 
    130         elif 'show_user' in request.GET['action']: 
     119        elif action == 'show_user': 
    131120            user_id = request.GET['user_id'] 
    132121            posts = Post.objects.filter(user__id=user_id) 
    133122            topics = [post.topic for post in posts] 
    134             return render_to_response('forum/search_topics.html',  
    135                                      {'topics': topics, 
    136                                      }, RequestContext(request)) 
    137         elif 'search' in request.GET['action']: 
     123        elif action == 'search': 
    138124            posts = Post.objects.all() 
    139125            form = PostSearchForm(request.GET) 
    140126            posts = form.filter(posts) 
    141127            topics = [post.topic for post in posts] 
    142             if 'topics' in request.GET['show_as']: 
    143                 return render_to_response('forum/search_topics.html',  
    144                                     {'topics': topics, 
    145                                      }, RequestContext(request)) 
     128            if action == 'topics': 
     129                return {'topics': topics} 
    146130            elif 'posts' in request.GET['show_as']: 
    147                 return render_to_response('forum/search_posts.html',  
    148                                     {'posts': posts, 
    149                                      }, RequestContext(request)) 
    150     else:   
     131                return {'posts': posts}, 'forum/search_posts.html' 
     132        return {'topics': topics} 
     133    else: 
    151134        form = PostSearchForm() 
    152         category = Category.objects.all()[0] 
    153         return render_to_response('forum/search_form.html',  
    154                                 {'categories': Category.objects.all(), 
    155                                 'form': form, 
    156                                 }, RequestContext(request)) 
    157          
    158 @login_required 
     135        return {'categories': Category.objects.all(), 
     136                'form': form, 
     137                }, 'forum/search_form.html' 
     138 
     139@login_required 
     140@render_to('forum/report.html') 
    159141def misc(request): 
    160142    if 'action' in request.GET: 
    161         if 'markread' in request.GET['action']: 
     143        action = request.GET['action'] 
     144        if action =='markread': 
    162145            for category in Category.objects.all(): 
    163146                for topic in category.topics: 
     
    168151            return HttpResponseRedirect(reverse('index')) 
    169152         
    170         elif 'report' in request.GET['action']: 
    171             if request.GET['post_id']: 
     153        elif action == 'report': 
     154            if request.GET.get('post_id', ''): 
    172155                post_id = request.GET['post_id'] 
    173156                post = get_object_or_404(Post, id=post_id) 
    174157                form = build_form(ReportForm, request, reported_by=request.user, post=post_id) 
    175                 if request.POST and form.is_valid(): 
     158                if request.method == 'POST' and form.is_valid(): 
    176159                    form.save() 
    177160                    return HttpResponseRedirect(post.get_absolute_url()) 
    178                 return render_to_response('forum/report.html',  
    179                             {'form':form, 
    180                              }, RequestContext(request)) 
     161                return {'form':form} 
    181162         
    182163    elif 'submit' in request.POST and 'mail_to' in request.GET: 
     
    192173        user = get_object_or_404(User, username=request.GET['mail_to']) 
    193174        form = MailToForm() 
    194         return render_to_response('forum/mail_to.html',  
    195                         {'form':form, 
    196                          'user': user, 
    197                          }, RequestContext(request)) 
     175        return {'form':form, 
     176                'user': user, 
     177               }, 'forum/mail_to.html' 
    198178 
    199179@render_to('forum/forum.html') 
     
    293273            } 
    294274 
    295  
     275@render_to('forum/user.html') 
    296276def user(request, username): 
    297277    user = get_object_or_404(User, username=username) 
     
    308288            #             'reports': reports, 
    309289            #             }, RequestContext(request)) 
    310             if 'privacy' in request.GET['section']: 
     290            section = request.GET['section'] 
     291            if section == 'privacy': 
    311292                form = build_form(PrivacyProfileForm, request, instance=user.forum_profile) 
    312                 if request.POST and form.is_valid(): 
    313                     form.save() 
    314                 return render_to_response('forum/profile/profile_privacy.html',  
    315                         {'active_menu':'privacy', 
    316                          'profile': user, 
    317                          'form': form, 
    318                          }, RequestContext(request)) 
    319             elif 'display' in request.GET['section']: 
     293                if request.method == 'POST' and form.is_valid(): 
     294                    form.save() 
     295                return {'active_menu':'privacy', 
     296                        'profile': user, 
     297                        'form': form, 
     298                       }, 'forum/profile/profile_privacy.html' 
     299            elif section == 'display': 
    320300                form = build_form(DisplayProfileForm, request, instance=user.forum_profile) 
    321                 if request.POST and form.is_valid(): 
    322                     form.save() 
    323                 return render_to_response('forum/profile/profile_display.html',  
    324                         {'active_menu':'display', 
    325                          'profile': user, 
    326                          'form': form, 
    327                          }, RequestContext(request)) 
    328             elif 'personality' in request.GET['section']: 
     301                if request.method == 'POST' and form.is_valid(): 
     302                    form.save() 
     303                return {'active_menu':'display', 
     304                        'profile': user, 
     305                        'form': form, 
     306                       }, 'forum/profile/profile_display.html' 
     307            elif section == 'personality': 
    329308                form = build_form(PersonalityProfileForm, request, instance=user.forum_profile) 
    330                 if request.POST and form.is_valid(): 
    331                     form.save() 
    332                 return render_to_response('forum/profile/profile_personality.html',  
    333                         {'active_menu':'personality', 
    334                          'profile': user, 
    335                          'form': form, 
    336                          }, RequestContext(request)) 
    337             elif 'messaging' in request.GET['section']: 
     309                if request.method == 'POST' and form.is_valid(): 
     310                    form.save() 
     311                return {'active_menu':'personality', 
     312                        'profile': user, 
     313                        'form': form, 
     314                        }, 'forum/profile/profile_personality.html' 
     315            elif section == 'messaging': 
    338316                form = build_form(MessagingProfileForm, request, instance=user.forum_profile) 
    339                 if request.POST and form.is_valid(): 
    340                     form.save() 
    341                 return render_to_response('forum/profile/profile_messaging.html',  
    342                         {'active_menu':'messaging', 
    343                          'profile': user, 
    344                          'form': form, 
    345                          }, RequestContext(request)) 
    346             elif 'personal' in request.GET['section']: 
     317                if request.method == 'POST' and form.is_valid(): 
     318                    form.save() 
     319                return {'active_menu':'messaging', 
     320                        'profile': user, 
     321                        'form': form, 
     322                       }, 'forum/profile/profile_messaging.html' 
     323            elif section == 'personal': 
    347324                form = build_form(PersonalProfileForm, request, instance=user.forum_profile, user=user) 
    348                 if request.POST and form.is_valid(): 
    349                     form.save() 
    350                 return render_to_response('forum/profile/profile_personal.html',  
    351                         {'active_menu':'personal', 
    352                          'profile': user, 
    353                          'form': form, 
    354                          }, RequestContext(request)) 
    355             elif 'essentials' in request.GET['section']: 
     325                if request.method == 'POST' and form.is_valid(): 
     326                    form.save() 
     327                return {'active_menu':'personal', 
     328                        'profile': user, 
     329                        'form': form, 
     330                       }, 'forum/profile/profile_personal.html' 
     331            elif section == 'essentials': 
    356332                form = build_form(EssentialsProfileForm, request, instance=user.forum_profile, user=user) 
    357                 if request.POST and form.is_valid(): 
    358                     form.save() 
    359                 return render_to_response('forum/profile/profile_essentials.html',  
    360                         {'active_menu':'essentials', 
    361                          'profile': user, 
    362                          'form': form, 
    363                          }, RequestContext(request)) 
     333                if request.method == 'POST' and form.is_valid(): 
     334                    form.save() 
     335                return {'active_menu':'essentials', 
     336                        'profile': user, 
     337                        'form': form, 
     338                        }, 'forum/profile/profile_essentials.html' 
    364339                 
    365340        elif 'action' in request.GET: 
    366             if 'upload_avatar' in request.GET['action']: 
     341            action = request.GET['action'] 
     342            if action == 'upload_avatar': 
    367343                form = build_form(UploadAvatarForm, request, instance=user.forum_profile) 
    368                 if request.POST and form.is_valid(): 
     344                if request.method == 'POST' and form.is_valid(): 
    369345                    form.save() 
    370346                    return HttpResponseRedirect(reverse('forum_profile', args=[user.username])) 
    371                 return render_to_response('forum/upload_avatar.html',  
    372                         {'form': form, 
    373                          'avatar_width': forum_settings.FORUM_AVATAR_WIDTH, 
    374                          'avatar_height': forum_settings.FORUM_AVATAR_HEIGHT, 
    375                          }, RequestContext(request)) 
    376             elif 'delete_avatar' in request.GET['action']: 
     347                return {'form': form, 
     348                        'avatar_width': forum_settings.FORUM_AVATAR_WIDTH, 
     349                        'avatar_height': forum_settings.FORUM_AVATAR_HEIGHT, 
     350                       }, 'forum/upload_avatar.html' 
     351            elif action == 'delete_avatar': 
    377352                profile = get_object_or_404(Profile, user=request.user) 
    378353                profile.avatar = None 
     
    382357        else: 
    383358            form = build_form(EssentialsProfileForm, request, instance=user.forum_profile, user=user) 
    384             if request.POST and form.is_valid(): 
     359            if request.method == 'POST' and form.is_valid(): 
    385360                form.save() 
    386             return render_to_response('forum/profile/profile_essentials.html',  
    387                     {'active_menu':'essentials', 
    388                      'profile': user, 
    389                      'form': form, 
    390                      }, RequestContext(request)) 
     361            return {'active_menu':'essentials', 
     362                    'profile': user, 
     363                    'form': form, 
     364                   }, 'forum/profile/profile_essentials.html' 
    391365             
    392366    else: 
    393367        topic_count = Topic.objects.filter(user=user).count() 
    394         return render_to_response('forum/user.html',  
    395                         {'profile': user, 
    396                          'topic_count': topic_count, 
    397                          'reports': reports, 
    398                          }, RequestContext(request)) 
    399      
    400  
     368        return {'profile': user, 
     369                'topic_count': topic_count, 
     370                'reports': reports, 
     371               } 
     372     
     373@render_to('forum/reputation.html') 
    401374def reputation(request, username): 
    402375    user = get_object_or_404(User, username=username) 
     
    413386                form.fields['sign'].initial = -1 
    414387             
    415             return render_to_response('forum/reputation_form.html',  
    416                     {'form': form, 
    417                      }, RequestContext(request)) 
     388            return {'form': form}, 'forum/reputation_form.html' 
    418389        else: 
    419390            raise Http404 
    420          
    421     elif request.POST: 
     391 
     392    elif request.method == 'POST': 
    422393        if 'del_reputation' in request.POST: 
    423394            for reputation in request.POST: 
     
    437408        else: 
    438409            raise Http404 
    439          
     410 
    440411    else: 
    441412        reputations = Reputation.objects.filter(to_user=user).order_by('-time').select_related() 
    442413         
    443         return render_to_response('forum/reputation.html',  
    444                 {'reputations': reputations, 
     414        return {'reputations': reputations, 
    445415                'profile': user.forum_profile, 
    446                 }, RequestContext(request)) 
    447  
     416               } 
    448417 
    449418def show_post(request, post_id): 
     
    453422    url = '%s?page=%d#post-%d' % (reverse('topic', args=[post.topic.id]), page, post.id) 
    454423    return HttpResponseRedirect(url) 
    455     
     424 
    456425@login_required 
    457426@render_to('forum/edit_post.html') 
     
    481450    topic.views += 1 
    482451    topic.save() 
    483      
     452 
    484453    if forum_moderated_by(topic, request.user): 
    485454        deleted = False 
     
    680649        inbox = False 
    681650        post_user = msg.dst_user 
    682     msg.read = True 
    683     msg.save() 
     651    if not msg.read: 
     652        msg.read = True 
     653        msg.save() 
    684654    return {'msg': msg, 
    685655            'inbox': inbox, 
    686656            'post_user': post_user, 
    687657            } 
    688  
    689658 
    690659@login_required 
     
    697666        return HttpResponseRedirect(reverse('edit_profile')) 
    698667 
    699  
    700668@login_required 
    701669def add_subscription(request, topic_id): 
     
    708676    html = '<link type="text/css" rel="stylesheet" href="%sforum/css/hljs_styles/phpbb_blue.css" /><p>' % settings.MEDIA_URL 
    709677    return HttpResponse(html+mypostmarkup.markup(request.POST.get('data', ''), auto_urls=False)) 
    710  
  • settings.py

    r19 r26  
    1313MANAGERS = ADMINS 
    1414 
    15 DATABASE_ENGINE = 'mysql'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 
    16 DATABASE_NAME = 'DjangoBB'             # Or path to database file if using sqlite3. 
    17 DATABASE_USER = 'root'             # Not used with sqlite3. 
     15DATABASE_ENGINE = ''           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 
     16DATABASE_NAME = ''             # Or path to database file if using sqlite3. 
     17DATABASE_USER = ''             # Not used with sqlite3. 
    1818DATABASE_PASSWORD = ''         # Not used with sqlite3. 
    1919DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3. 
     
    2929# Language code for this installation. All choices can be found here: 
    3030# http://www.i18nguy.com/unicode/language-identifiers.html 
    31 LANGUAGE_CODE = 'ru-ru' 
     31LANGUAGE_CODE = 'en-us' 
    3232 
    3333SITE_ID = 1 
     
    5252 
    5353# Make this unique, and don't share it with anybody. 
    54 SECRET_KEY = 'qry+e%=0&2c(k$=+czmsv8sw74ci5*m8t$83cv!#72b9)ge%io' 
     54 
     55if not hasattr(globals(), 'SECRET_KEY'): 
     56    SECRET_FILE = os.path.join(PROJECT_ROOT, 'secret.txt') 
     57    try: 
     58        SECRET_KEY = open(SECRET_FILE).read().strip() 
     59    except IOError: 
     60        try: 
     61            from random import choice 
     62            import string 
     63            symbols = ''.join((string.lowercase, string.digits, string.punctuation )) 
     64            SECRET_KEY = ''.join([choice(symbols) for i in range(50)]) 
     65            secret = file(SECRET_FILE, 'w') 
     66            secret.write(SECRET_KEY) 
     67            secret.close() 
     68        except IOError: 
     69            raise Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE) 
    5570 
    5671# List of callables that know how to import templates from various sources. 
     
    108123ACCOUNT_USERNAME_MIN_LENGTH = 3 
    109124ACCOUNT_PASSWORD_MIN_LENGTH = 2 
    110 LOGIN_URL = '/forum/account/login/' 
     125LOGIN_URL = '/forum/login/' 
    111126ACCOUNT_DOMAIN = '/forum/account/' 
    112127ACCOUNT_AUTH_KEY_TIMEOUT = 60 * 60 * 24