Changeset 247:fa2184a41e21


Ignore:
Timestamp:
23.02.2010 16:19:20 (2 years ago)
Author:
slav0nic <slav0nic0@…>
Branch:
default
Message:

closed #50, #61: Now user can't set reputation to youself and can vote for post only once. WARNING: Reputation model was changed, pls migrate it youself.

Location:
djangobb/djangobb_forum
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • djangobb/djangobb_forum/admin.py

    r242 r247  
    3030 
    3131class 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'] 
    3434 
    3535class ReportAdmin(admin.ModelAdmin): 
  • djangobb/djangobb_forum/forms.py

    r245 r247  
    294294    class Meta: 
    295295        model = Reputation 
    296         fields = ['reason', 'topic', 'sign'] 
     296        fields = ['reason', 'post', 'sign'] 
    297297 
    298298    def __init__(self, *args, **kwargs): 
    299299        self.from_user = kwargs.pop('from_user', None) 
    300300        self.to_user = kwargs.pop('to_user', None) 
    301         self.topic = kwargs.pop('topic', None) 
     301        self.post = kwargs.pop('post', None) 
    302302        self.sign = kwargs.pop('sign', None) 
    303303        super(ReputationForm, self).__init__(*args, **kwargs) 
    304         self.fields['topic'].widget = forms.HiddenInput() 
     304        self.fields['post'].widget = forms.HiddenInput() 
    305305        self.fields['sign'].widget = forms.HiddenInput() 
    306306        self.fields['reason'].widget = forms.Textarea(attrs={'class':'bbcode'}) 
     
    315315            return user 
    316316 
     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 
    317325    def save(self, commit=True): 
    318326        reputation = super(ReputationForm, self).save(commit=False) 
    319327        reputation.from_user = self.from_user 
    320328        reputation.to_user = self.to_user 
    321         reputation.time = datetime.now() 
    322329        if commit: 
    323330            reputation.save() 
  • djangobb/djangobb_forum/models.py

    r242 r247  
    245245    from_user = models.ForeignKey(User, related_name='reputations_from', verbose_name=_('From')) 
    246246    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) 
    249249    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) 
    251251 
    252252    class Meta: 
    253253        verbose_name = _('Reputation') 
    254254        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)) 
    258259 
    259260 
  • djangobb/djangobb_forum/templates/forum/reputation.html

    r211 r247  
    2020                                <tr> 
    2121                                <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> 
    2323                                <th class="tc3" style="width: 35%;">{% trans "Reason" %}</th> 
    2424                                <th class="tc3" style="width: 10%; text-align: center;">{% trans "Estimation" %}</th> 
     
    3333                                        <tr> 
    3434                                                <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> 
    3636                                                <td>{{ reputation.reason }}</td> 
    3737                                                <td style="text-align: center;"> 
  • djangobb/djangobb_forum/templates/forum/reputation_form.html

    r211 r247  
    1010                        <form action="{% url djangobb:reputation form.to_user %}" method="post"> 
    1111                        <table cellspacing="0"> 
    12                                 {{ form.topic }} 
     12                                {{ form.errors.as_ul }} 
     13                                {{ form.post }} 
    1314                                {{ form.sign }} 
    1415                                <tbody><tr> 
     
    1920                                        <td class="tc4" width="30%">{% trans "To whom we change a reputation:" %}</td> 
    2021                                        <td class="tc4" width="70%">{{ form.to_user }}</td> 
    21  
    2222                                </tr> 
    2323                                <tr> 
    24                                         <td class="tc4" width="30%">{% trans "The reason of change of reputation:" %}</td> 
     24                                        <td class="tc4" width="30%"></td> 
    2525                                        <td class="tc4" width="70%">{{ form.reason }}</td> 
    2626                                </tr>                            
     
    3434                                                {% endifequal %} 
    3535                                        </td> 
    36  
    3736                                </tr> 
    3837                        </tbody></table> 
  • djangobb/djangobb_forum/templates/forum/topic.html

    r243 r247  
    5555                                                {% endif %} 
    5656                                                {% 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>&nbsp;&nbsp;<strong>{{ post.user.forum_profile.reply_total }}&nbsp;&nbsp;</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>&nbsp;&nbsp;<strong>{{ post.user.forum_profile.reply_total }}&nbsp;&nbsp;</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> 
    5960                                                        {% endifnotequal %} 
    6061                                                {% endif %} 
  • djangobb/djangobb_forum/views.py

    r246 r247  
    496496 
    497497    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: 
    499502            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'] 
    502506            if request.GET['action'] == 'plus': 
    503507                form.fields['sign'].initial = 1 
     
    511515 
    512516    elif request.method == 'POST': 
    513         if 'del_reputation' in request.POST: 
     517        if 'del_reputation' in request.POST and request.user.is_superuser: 
    514518            reputation_list = request.POST.getlist('reputation_id') 
    515519            for reputation_id in reputation_list: 
     
    519523        elif form.is_valid(): 
    520524            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()) 
    524528        else: 
    525             raise Http404 
     529            return {'form': form, 
     530                    'TEMPLATE': 'forum/reputation_form.html' 
     531                    } 
    526532    else: 
    527533        reputations = Reputation.objects.filter(to_user=user).order_by('-time').select_related() 
Note: See TracChangeset for help on using the changeset viewer.