Changeset 247:fa2184a41e21
- Timestamp:
- 23.02.2010 16:19:20 (2 years ago)
- Branch:
- default
- Location:
- djangobb/djangobb_forum
- Files:
-
- 7 edited
-
admin.py (modified) (1 diff)
-
forms.py (modified) (2 diffs)
-
models.py (modified) (1 diff)
-
templates/forum/reputation.html (modified) (2 diffs)
-
templates/forum/reputation_form.html (modified) (3 diffs)
-
templates/forum/topic.html (modified) (1 diff)
-
views.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
djangobb/djangobb_forum/admin.py
r242 r247 30 30 31 31 class ReputationAdmin(admin.ModelAdmin): 32 list_display = ['from_user', 'to_user', ' topic', 'sign', 'time', 'reason']33 raw_id_fields = ['from_user', 'to_user', ' topic']32 list_display = ['from_user', 'to_user', 'post', 'sign', 'time', 'reason'] 33 raw_id_fields = ['from_user', 'to_user', 'post'] 34 34 35 35 class ReportAdmin(admin.ModelAdmin): -
djangobb/djangobb_forum/forms.py
r245 r247 294 294 class Meta: 295 295 model = Reputation 296 fields = ['reason', ' topic', 'sign']296 fields = ['reason', 'post', 'sign'] 297 297 298 298 def __init__(self, *args, **kwargs): 299 299 self.from_user = kwargs.pop('from_user', None) 300 300 self.to_user = kwargs.pop('to_user', None) 301 self. topic = kwargs.pop('topic', None)301 self.post = kwargs.pop('post', None) 302 302 self.sign = kwargs.pop('sign', None) 303 303 super(ReputationForm, self).__init__(*args, **kwargs) 304 self.fields[' topic'].widget = forms.HiddenInput()304 self.fields['post'].widget = forms.HiddenInput() 305 305 self.fields['sign'].widget = forms.HiddenInput() 306 306 self.fields['reason'].widget = forms.Textarea(attrs={'class':'bbcode'}) … … 315 315 return user 316 316 317 def clean(self): 318 try: 319 Reputation.objects.get(from_user=self.from_user, post=self.cleaned_data['post']) 320 except Reputation.DoesNotExist: 321 pass 322 else: 323 raise forms.ValidationError(_('You already voted for this post')) 324 317 325 def save(self, commit=True): 318 326 reputation = super(ReputationForm, self).save(commit=False) 319 327 reputation.from_user = self.from_user 320 328 reputation.to_user = self.to_user 321 reputation.time = datetime.now()322 329 if commit: 323 330 reputation.save() -
djangobb/djangobb_forum/models.py
r242 r247 245 245 from_user = models.ForeignKey(User, related_name='reputations_from', verbose_name=_('From')) 246 246 to_user = models.ForeignKey(User, related_name='reputations_to', verbose_name=_('To')) 247 topic = models.ForeignKey(Topic, related_name='topic', verbose_name=_('Topic'))248 time = models.DateTimeField(_('Time'), blank=True)247 post = models.ForeignKey(Post, related_name='post', verbose_name=_('Post')) 248 time = models.DateTimeField(_('Time'), auto_now_add=True) 249 249 sign = models.IntegerField(_('Sign'), choices=SIGN_CHOICES, default=0) 250 reason = models.TextField(_('Reason'), blank=True, default='',max_length=1000)250 reason = models.TextField(_('Reason'), max_length=1000) 251 251 252 252 class Meta: 253 253 verbose_name = _('Reputation') 254 254 verbose_name_plural = _('Reputations') 255 256 def __unicode__(self): 257 return u'T[%d], FU[%d], TU[%d]: %s' % (self.topic.id, self.from_user.id, self.to_user.id, unicode(self.time)) 255 unique_together = (('from_user', 'post'),) 256 257 def __unicode__(self): 258 return u'T[%d], FU[%d], TU[%d]: %s' % (self.post.id, self.from_user.id, self.to_user.id, unicode(self.time)) 258 259 259 260 -
djangobb/djangobb_forum/templates/forum/reputation.html
r211 r247 20 20 <tr> 21 21 <th class="tc3" style="width: 15%;">{% trans "From user" %}</th> 22 <th class="tc3" style="width: 15%;">{% trans "For topic" %}</th>22 <th class="tc3" style="width: 15%;">{% trans "For post in topic" %}</th> 23 23 <th class="tc3" style="width: 35%;">{% trans "Reason" %}</th> 24 24 <th class="tc3" style="width: 10%; text-align: center;">{% trans "Estimation" %}</th> … … 33 33 <tr> 34 34 <td><a href="{% url djangobb:reputation reputation.from_user %}">{{ reputation.from_user }}</a></td> 35 <td> {% link reputation.topic %}</td>35 <td><a href="{{ reputation.post.get_absolute_url }}">{{ reputation.post.topic }}</a></td> 36 36 <td>{{ reputation.reason }}</td> 37 37 <td style="text-align: center;"> -
djangobb/djangobb_forum/templates/forum/reputation_form.html
r211 r247 10 10 <form action="{% url djangobb:reputation form.to_user %}" method="post"> 11 11 <table cellspacing="0"> 12 {{ form.topic }} 12 {{ form.errors.as_ul }} 13 {{ form.post }} 13 14 {{ form.sign }} 14 15 <tbody><tr> … … 19 20 <td class="tc4" width="30%">{% trans "To whom we change a reputation:" %}</td> 20 21 <td class="tc4" width="70%">{{ form.to_user }}</td> 21 22 22 </tr> 23 23 <tr> 24 <td class="tc4" width="30%"> {% trans "The reason of change of reputation:" %}</td>24 <td class="tc4" width="30%"></td> 25 25 <td class="tc4" width="70%">{{ form.reason }}</td> 26 26 </tr> … … 34 34 {% endifequal %} 35 35 </td> 36 37 36 </tr> 38 37 </tbody></table> -
djangobb/djangobb_forum/templates/forum/topic.html
r243 r247 55 55 {% endif %} 56 56 {% if forum_settings.REPUTATION_SUPPORT %} 57 {% ifnotequal request.user post.user.username %} 58 <dd><a href="{% url djangobb:reputation post.user %}">{% trans "Reputation" %}</a> : <a href="{% url djangobb:reputation post.user %}?action=plus&topic_id={{ post.topic.id }}"><img src="{{ MEDIA_URL }}forum/img/reputation/warn_add.gif" alt="+" border="0"></a> <strong>{{ post.user.forum_profile.reply_total }} </strong><a href="{% url djangobb:reputation post.user %}?action=minus&topic_id={{ post.topic.id }}"><img src="{{ MEDIA_URL }}forum/img/reputation/warn_minus.gif" alt="-" border="0"></a></dd> 57 <dd><a href="{% url djangobb:reputation post.user %}">{% trans "Reputation" %}</a> 58 {% ifnotequal request.user post.user %} {# TODO: and user.is_authenticated #} 59 : <a href="{% url djangobb:reputation post.user %}?action=plus&post_id={{ post.id }}"><img src="{{ MEDIA_URL }}forum/img/reputation/warn_add.gif" alt="+" border="0"></a> <strong>{{ post.user.forum_profile.reply_total }} </strong><a href="{% url djangobb:reputation post.user %}?action=minus&post_id={{ post.id }}"><img src="{{ MEDIA_URL }}forum/img/reputation/warn_minus.gif" alt="-" border="0"></a></dd> 59 60 {% endifnotequal %} 60 61 {% endif %} -
djangobb/djangobb_forum/views.py
r246 r247 496 496 497 497 if 'action' in request.GET: 498 if 'topic_id' in request.GET: 498 if request.user == user: 499 return HttpResponseForbidden(u'You can not change the reputation of yourself') 500 501 if 'post_id' in request.GET: 499 502 sign = 0 500 topic_id = request.GET['topic_id'] 501 form.fields['topic'].initial = topic_id 503 post_id = request.GET['post_id'] 504 form.fields['post'].initial = post_id 505 print form.fields['post'] 502 506 if request.GET['action'] == 'plus': 503 507 form.fields['sign'].initial = 1 … … 511 515 512 516 elif request.method == 'POST': 513 if 'del_reputation' in request.POST :517 if 'del_reputation' in request.POST and request.user.is_superuser: 514 518 reputation_list = request.POST.getlist('reputation_id') 515 519 for reputation_id in reputation_list: … … 519 523 elif form.is_valid(): 520 524 form.save() 521 topic_id = request.POST['topic']522 topic = get_object_or_404(Topic, id=topic_id)523 return HttpResponseRedirect( topic.get_absolute_url())525 post_id = request.POST['post'] 526 post = get_object_or_404(Post, id=post_id) 527 return HttpResponseRedirect(post.get_absolute_url()) 524 528 else: 525 raise Http404 529 return {'form': form, 530 'TEMPLATE': 'forum/reputation_form.html' 531 } 526 532 else: 527 533 reputations = Reputation.objects.filter(to_user=user).order_by('-time').select_related()
Note: See TracChangeset
for help on using the changeset viewer.
