Changes in [20:b3faeb72eb1a:30:648fc619304f]
- Files:
-
- 3 removed
- 12 modified
-
.hgignore (modified) (1 diff)
-
apps/forum/migrations/001_forum_updated.py (deleted)
-
apps/forum/migrations/002_post_count.py (deleted)
-
apps/forum/migrations/__init__.py (deleted)
-
apps/forum/models.py (modified) (4 diffs)
-
apps/forum/settings.py (modified) (2 diffs)
-
apps/forum/subscription.py (modified) (1 diff)
-
apps/forum/templates/forum/forum_row.html (modified) (2 diffs)
-
apps/forum/templates/forum/moderate.html (modified) (1 diff)
-
apps/forum/templates/forum/topic.html (modified) (1 diff)
-
apps/forum/templates/forum/user.html (modified) (1 diff)
-
apps/forum/templatetags/forum_extras.py (modified) (1 diff)
-
apps/forum/util.py (modified) (3 diffs)
-
apps/forum/views.py (modified) (19 diffs)
-
settings.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
.hgignore
r8 r22 13 13 *.autosave 14 14 static/forum/avatars 15 secret.txt -
apps/forum/models.py
r18 r29 128 128 129 129 class Meta: 130 ordering = ['- created']130 ordering = ['-updated'] 131 131 verbose_name = _('Topic') 132 132 verbose_name_plural = _('Topics') … … 206 206 self.body_html = urlize(self.body_html) 207 207 self.body_html = smiles(self.body_html) 208 209 208 new = self.id is None 210 211 209 if new: 210 #new post created 211 super(Post, self).save(*args, **kwargs) 212 212 self.topic.updated = datetime.now() 213 self.topic.post_count += 1213 self.topic.post_count = Post.objects.filter(topic=self.topic).count() 214 214 self.topic.save() 215 215 self.topic.forum.updated = self.topic.updated 216 self.topic.forum.post_count += 1216 self.topic.forum.post_count = Post.objects.filter(topic__forum=self.topic.forum).count() 217 217 self.topic.forum.save() 218 219 super(Post, self).save(*args, **kwargs) 218 else: 219 #edit post 220 super(Post, self).save(*args, **kwargs) 220 221 221 222 def get_absolute_url(self): … … 226 227 head_post_id = self.topic.posts.order_by('created')[0].id 227 228 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() 230 230 self.topic.save() 231 self.topic.forum.post_count -= 1231 self.topic.forum.post_count = Post.objects.filter(topic__forum=self.topic.forum).count() 232 232 self.topic.forum.save() 233 233 234 234 if self_id == head_post_id: 235 235 self.topic.delete() … … 275 275 verbose_name = _('Profile') 276 276 verbose_name_plural = _('Profiles') 277 277 278 278 def last_post(self): 279 279 posts = Post.objects.filter(user=self.user).order_by('-created').select_related() -
apps/forum/settings.py
r17 r26 1 1 from django.conf import settings 2 import re 2 3 3 4 def get(key, default): … … 47 48 EMOTION_ROLL = get('EMOTION_ROLL', '<img src="%sforum/img/smilies/roll.png">' % settings.MEDIA_URL) 48 49 EMOTION_COOL = get('EMOTION_COOL', '<img src="%sforum/img/smilies/cool.png">' % settings.MEDIA_URL) 50 SMILES = ((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 ) 63 SMILES = get('SMILES', SMILES) -
apps/forum/subscription.py
r17 r25 61 61 62 62 def notify_pm_recipients(pm): 63 from apps.forum.models import PrivateMessage64 65 subject = (u'There are new messages')66 to_email = pm.dst_user.email67 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 1 1 {% load forum_extras %} 2 {% load i18n %} 2 3 3 4 {% if forum.last_post.topic %} … … 30 31 {% if forum.last_post.topic %} 31 32 <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> 33 34 {% endif %} 34 35 {% endif %} -
apps/forum/templates/forum/moderate.html
r0 r30 69 69 <td class="tc2">{{ topic.reply_count }}</td> 70 70 <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> 72 72 <td class="tcmod"><input type="checkbox" name="topic_id[{{ topic.id }}]" value="1" /></td> 73 73 </tr> -
apps/forum/templates/forum/topic.html
r18 r30 8 8 <p class="pagelink conl">{% pagination %}</p> 9 9 {% 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> 11 11 {% endif %} 12 12 <ul><li><a href="{% url index %}">{% trans "Root" %} </a></li><li>» {% link topic.forum %} </li><li>» {{ topic }} -
apps/forum/templates/forum/user.html
r18 r30 126 126 <dl> 127 127 <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> 129 129 <dt>{% trans "Last post:" %} </dt> 130 130 {% if profile.forum_profile.last_post %} -
apps/forum/templatetags/forum_extras.py
r14 r28 198 198 @register.filter 199 199 def forum_stars(user): 200 posts = user. posts.count()200 posts = user.forum_profile.post_count 201 201 if posts >= forum_settings.FORUM_STAR_5: 202 202 return mark_safe('<img src="%sforum/img/stars/Star_5.gif" alt="" >' % (settings.MEDIA_URL)) -
apps/forum/util.py
r17 r26 16 16 from apps.forum import settings as forum_settings 17 17 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 21 def 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 37 54 return wrapper 38 39 return decorator 55 return renderer 40 56 41 57 def absolute_url(path): … … 140 156 return form 141 157 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): 158 class ExcludeTagsHTMLParser(HTMLParser): 159 """ 160 Class for html parsing with excluding specified tags. 161 """ 162 163 def __init__(self, func, tags=('a', 'code')): 152 164 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 156 170 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= True160 171 self.html.append('<%s%s>' % (tag, self.__html_attrs(attrs))) 172 if tag in self.tags: 173 self.is_ignored = True 174 161 175 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 166 180 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 169 183 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 173 193 def __html_attrs(self, attrs): 174 194 _attrs = '' … … 176 196 _attrs = ' %s' % (' '.join([('%s="%s"' % (k,v)) for k,v in attrs])) 177 197 return _attrs 178 198 179 199 def feed(self, data): 180 200 HTMLParser.feed(self, data) 181 self.urlized_html = ''.join(self.urlized_html) 182 183 parser = URLizeHTMLParser() 201 self.html = ''.join(self.html) 202 203 def 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) 184 211 parser.feed(data) 185 urlized_html = parser. urlized_html212 urlized_html = parser.html 186 213 parser.close() 187 214 return urlized_html 188 215 216 def _smile_replacer(data): 217 for smile, path in _SMILES: 218 data = smile.sub(path, data) 219 return data 220 189 221 def 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 3 3 import datetime 4 4 5 from django.shortcuts import get_object_or_404, render_to_response 6 from django.template import RequestContext 5 from django.shortcuts import get_object_or_404 7 6 from django.http import Http404, HttpResponse, HttpResponseRedirect 8 7 from django.contrib.auth.models import User … … 27 26 if cache.get(str(user.id)): 28 27 users_online.append(user) 29 guest_count = len(cache._cache) - users_online.__len__()28 guest_count = len(cache._cache) - len(users_online) 30 29 31 30 cats = {} … … 46 45 'users': User.objects.count(), 47 46 'users_online': users_online, 48 'online_count': users_online.__len__(),47 'online_count': len(users_online), 49 48 'guest_count': guest_count, 50 49 'last_user': User.objects.order_by('-date_joined')[0], 51 }50 } 52 51 53 52 @render_to('forum/moderate.html') … … 64 63 topic_id = topic_match.group(1) 65 64 reverse('move_topic', args=[topic_id]) 66 65 67 66 return HttpResponseRedirect(reverse('index')) 68 67 elif 'delete_topics' in request.POST: 69 68 for topic in request.POST: 70 69 topic_match = re.match('topic_id\[(\d+)\]', reputation) 71 70 72 71 if topic_match: 73 72 topic_id = topic_match.group(1) … … 79 78 for topic in request.POST: 80 79 topic_match = re.match('topic_id\[(\d+)\]', topic) 81 80 82 81 if topic_match: 83 82 topic_id = topic_match.group(1) 84 83 open_topic(request, topic_id) 85 84 86 85 return HttpResponseRedirect(reverse('index')) 87 86 elif 'close_topics' in request.POST: 88 87 for topic in request.POST: 89 88 topic_match = re.match('topic_id\[(\d+)\]', topic) 90 89 91 90 if topic_match: 92 91 topic_id = topic_match.group(1) … … 94 93 95 94 return HttpResponseRedirect(reverse('index')) 96 95 97 96 return {'forum': forum, 98 97 'topics': topics, … … 104 103 raise Http404 105 104 105 @render_to('forum/search_topics.html') 106 106 def search(request): 107 107 if 'action' in request.GET: 108 if 'show_24h' in request.GET['action']: 108 action = request.GET['action'] 109 if action == 'show_24h': 109 110 date = datetime.datetime.today() - datetime.timedelta(1) 110 111 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': 115 113 topics = Topic.objects.all().order_by('created') 116 114 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': 121 116 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': 126 118 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': 131 120 user_id = request.GET['user_id'] 132 121 posts = Post.objects.filter(user__id=user_id) 133 122 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': 138 124 posts = Post.objects.all() 139 125 form = PostSearchForm(request.GET) 140 126 posts = form.filter(posts) 141 127 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} 146 130 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: 151 134 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') 159 141 def misc(request): 160 142 if 'action' in request.GET: 161 if 'markread' in request.GET['action']: 143 action = request.GET['action'] 144 if action =='markread': 162 145 for category in Category.objects.all(): 163 146 for topic in category.topics: … … 168 151 return HttpResponseRedirect(reverse('index')) 169 152 170 elif 'report' in request.GET['action']:171 if request.GET ['post_id']:153 elif action == 'report': 154 if request.GET.get('post_id', ''): 172 155 post_id = request.GET['post_id'] 173 156 post = get_object_or_404(Post, id=post_id) 174 157 form = build_form(ReportForm, request, reported_by=request.user, post=post_id) 175 if request. POSTand form.is_valid():158 if request.method == 'POST' and form.is_valid(): 176 159 form.save() 177 160 return HttpResponseRedirect(post.get_absolute_url()) 178 return render_to_response('forum/report.html', 179 {'form':form, 180 }, RequestContext(request)) 161 return {'form':form} 181 162 182 163 elif 'submit' in request.POST and 'mail_to' in request.GET: … … 192 173 user = get_object_or_404(User, username=request.GET['mail_to']) 193 174 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' 198 178 199 179 @render_to('forum/forum.html') … … 293 273 } 294 274 295 275 @render_to('forum/user.html') 296 276 def user(request, username): 297 277 user = get_object_or_404(User, username=username) … … 308 288 # 'reports': reports, 309 289 # }, RequestContext(request)) 310 if 'privacy' in request.GET['section']: 290 section = request.GET['section'] 291 if section == 'privacy': 311 292 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': 320 300 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': 329 308 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': 338 316 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': 347 324 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': 356 332 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' 364 339 365 340 elif 'action' in request.GET: 366 if 'upload_avatar' in request.GET['action']: 341 action = request.GET['action'] 342 if action == 'upload_avatar': 367 343 form = build_form(UploadAvatarForm, request, instance=user.forum_profile) 368 if request. POSTand form.is_valid():344 if request.method == 'POST' and form.is_valid(): 369 345 form.save() 370 346 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': 377 352 profile = get_object_or_404(Profile, user=request.user) 378 353 profile.avatar = None … … 382 357 else: 383 358 form = build_form(EssentialsProfileForm, request, instance=user.forum_profile, user=user) 384 if request. POSTand form.is_valid():359 if request.method == 'POST' and form.is_valid(): 385 360 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' 391 365 392 366 else: 393 367 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') 401 374 def reputation(request, username): 402 375 user = get_object_or_404(User, username=username) … … 413 386 form.fields['sign'].initial = -1 414 387 415 return render_to_response('forum/reputation_form.html', 416 {'form': form, 417 }, RequestContext(request)) 388 return {'form': form}, 'forum/reputation_form.html' 418 389 else: 419 390 raise Http404 420 421 elif request. POST:391 392 elif request.method == 'POST': 422 393 if 'del_reputation' in request.POST: 423 394 for reputation in request.POST: … … 437 408 else: 438 409 raise Http404 439 410 440 411 else: 441 412 reputations = Reputation.objects.filter(to_user=user).order_by('-time').select_related() 442 413 443 return render_to_response('forum/reputation.html', 444 {'reputations': reputations, 414 return {'reputations': reputations, 445 415 'profile': user.forum_profile, 446 }, RequestContext(request)) 447 416 } 448 417 449 418 def show_post(request, post_id): … … 453 422 url = '%s?page=%d#post-%d' % (reverse('topic', args=[post.topic.id]), page, post.id) 454 423 return HttpResponseRedirect(url) 455 424 456 425 @login_required 457 426 @render_to('forum/edit_post.html') … … 481 450 topic.views += 1 482 451 topic.save() 483 452 484 453 if forum_moderated_by(topic, request.user): 485 454 deleted = False … … 680 649 inbox = False 681 650 post_user = msg.dst_user 682 msg.read = True 683 msg.save() 651 if not msg.read: 652 msg.read = True 653 msg.save() 684 654 return {'msg': msg, 685 655 'inbox': inbox, 686 656 'post_user': post_user, 687 657 } 688 689 658 690 659 @login_required … … 697 666 return HttpResponseRedirect(reverse('edit_profile')) 698 667 699 700 668 @login_required 701 669 def add_subscription(request, topic_id): … … 708 676 html = '<link type="text/css" rel="stylesheet" href="%sforum/css/hljs_styles/phpbb_blue.css" /><p>' % settings.MEDIA_URL 709 677 return HttpResponse(html+mypostmarkup.markup(request.POST.get('data', ''), auto_urls=False)) 710 -
settings.py
r19 r26 13 13 MANAGERS = ADMINS 14 14 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.15 DATABASE_ENGINE = '' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 16 DATABASE_NAME = '' # Or path to database file if using sqlite3. 17 DATABASE_USER = '' # Not used with sqlite3. 18 18 DATABASE_PASSWORD = '' # Not used with sqlite3. 19 19 DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. … … 29 29 # Language code for this installation. All choices can be found here: 30 30 # http://www.i18nguy.com/unicode/language-identifiers.html 31 LANGUAGE_CODE = ' ru-ru'31 LANGUAGE_CODE = 'en-us' 32 32 33 33 SITE_ID = 1 … … 52 52 53 53 # 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 55 if 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) 55 70 56 71 # List of callables that know how to import templates from various sources. … … 108 123 ACCOUNT_USERNAME_MIN_LENGTH = 3 109 124 ACCOUNT_PASSWORD_MIN_LENGTH = 2 110 LOGIN_URL = '/forum/ account/login/'125 LOGIN_URL = '/forum/login/' 111 126 ACCOUNT_DOMAIN = '/forum/account/' 112 127 ACCOUNT_AUTH_KEY_TIMEOUT = 60 * 60 * 24
![(please configure the [header_logo] section in trac.ini)](/htdocs/logo.png)