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.
This commit is contained in:
parent
7ee8d7eff1
commit
3e08a0e613
7 changed files with 40 additions and 26 deletions
|
@ -29,8 +29,8 @@ class ProfileAdmin(admin.ModelAdmin):
|
||||||
raw_id_fields = ['user']
|
raw_id_fields = ['user']
|
||||||
|
|
||||||
class ReputationAdmin(admin.ModelAdmin):
|
class ReputationAdmin(admin.ModelAdmin):
|
||||||
list_display = ['from_user', 'to_user', 'topic', 'sign', 'time', 'reason']
|
list_display = ['from_user', 'to_user', 'post', 'sign', 'time', 'reason']
|
||||||
raw_id_fields = ['from_user', 'to_user', 'topic']
|
raw_id_fields = ['from_user', 'to_user', 'post']
|
||||||
|
|
||||||
class ReportAdmin(admin.ModelAdmin):
|
class ReportAdmin(admin.ModelAdmin):
|
||||||
list_display = ['reported_by', 'post', 'zapped', 'zapped_by', 'created', 'reason']
|
list_display = ['reported_by', 'post', 'zapped', 'zapped_by', 'created', 'reason']
|
||||||
|
|
|
@ -293,15 +293,15 @@ class ReputationForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Reputation
|
model = Reputation
|
||||||
fields = ['reason', 'topic', 'sign']
|
fields = ['reason', 'post', 'sign']
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.from_user = kwargs.pop('from_user', None)
|
self.from_user = kwargs.pop('from_user', None)
|
||||||
self.to_user = kwargs.pop('to_user', None)
|
self.to_user = kwargs.pop('to_user', None)
|
||||||
self.topic = kwargs.pop('topic', None)
|
self.post = kwargs.pop('post', None)
|
||||||
self.sign = kwargs.pop('sign', None)
|
self.sign = kwargs.pop('sign', None)
|
||||||
super(ReputationForm, self).__init__(*args, **kwargs)
|
super(ReputationForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['topic'].widget = forms.HiddenInput()
|
self.fields['post'].widget = forms.HiddenInput()
|
||||||
self.fields['sign'].widget = forms.HiddenInput()
|
self.fields['sign'].widget = forms.HiddenInput()
|
||||||
self.fields['reason'].widget = forms.Textarea(attrs={'class':'bbcode'})
|
self.fields['reason'].widget = forms.Textarea(attrs={'class':'bbcode'})
|
||||||
|
|
||||||
|
@ -314,11 +314,18 @@ class ReputationForm(forms.ModelForm):
|
||||||
else:
|
else:
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
try:
|
||||||
|
Reputation.objects.get(from_user=self.from_user, post=self.cleaned_data['post'])
|
||||||
|
except Reputation.DoesNotExist:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise forms.ValidationError(_('You already voted for this post'))
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
reputation = super(ReputationForm, self).save(commit=False)
|
reputation = super(ReputationForm, self).save(commit=False)
|
||||||
reputation.from_user = self.from_user
|
reputation.from_user = self.from_user
|
||||||
reputation.to_user = self.to_user
|
reputation.to_user = self.to_user
|
||||||
reputation.time = datetime.now()
|
|
||||||
if commit:
|
if commit:
|
||||||
reputation.save()
|
reputation.save()
|
||||||
return reputation
|
return reputation
|
||||||
|
|
|
@ -244,17 +244,18 @@ class Post(models.Model):
|
||||||
class Reputation(models.Model):
|
class Reputation(models.Model):
|
||||||
from_user = models.ForeignKey(User, related_name='reputations_from', verbose_name=_('From'))
|
from_user = models.ForeignKey(User, related_name='reputations_from', verbose_name=_('From'))
|
||||||
to_user = models.ForeignKey(User, related_name='reputations_to', verbose_name=_('To'))
|
to_user = models.ForeignKey(User, related_name='reputations_to', verbose_name=_('To'))
|
||||||
topic = models.ForeignKey(Topic, related_name='topic', verbose_name=_('Topic'))
|
post = models.ForeignKey(Post, related_name='post', verbose_name=_('Post'))
|
||||||
time = models.DateTimeField(_('Time'), blank=True)
|
time = models.DateTimeField(_('Time'), auto_now_add=True)
|
||||||
sign = models.IntegerField(_('Sign'), choices=SIGN_CHOICES, default=0)
|
sign = models.IntegerField(_('Sign'), choices=SIGN_CHOICES, default=0)
|
||||||
reason = models.TextField(_('Reason'), blank=True, default='', max_length=1000)
|
reason = models.TextField(_('Reason'), max_length=1000)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Reputation')
|
verbose_name = _('Reputation')
|
||||||
verbose_name_plural = _('Reputations')
|
verbose_name_plural = _('Reputations')
|
||||||
|
unique_together = (('from_user', 'post'),)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u'T[%d], FU[%d], TU[%d]: %s' % (self.topic.id, self.from_user.id, self.to_user.id, unicode(self.time))
|
return u'T[%d], FU[%d], TU[%d]: %s' % (self.post.id, self.from_user.id, self.to_user.id, unicode(self.time))
|
||||||
|
|
||||||
|
|
||||||
class Profile(models.Model):
|
class Profile(models.Model):
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="tc3" style="width: 15%;">{% trans "From user" %}</th>
|
<th class="tc3" style="width: 15%;">{% trans "From user" %}</th>
|
||||||
<th class="tc3" style="width: 15%;">{% trans "For topic" %}</th>
|
<th class="tc3" style="width: 15%;">{% trans "For post in topic" %}</th>
|
||||||
<th class="tc3" style="width: 35%;">{% trans "Reason" %}</th>
|
<th class="tc3" style="width: 35%;">{% trans "Reason" %}</th>
|
||||||
<th class="tc3" style="width: 10%; text-align: center;">{% trans "Estimation" %}</th>
|
<th class="tc3" style="width: 10%; text-align: center;">{% trans "Estimation" %}</th>
|
||||||
<th class="tc3" style="width: 15%;">{% trans "Date" %}</th>
|
<th class="tc3" style="width: 15%;">{% trans "Date" %}</th>
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
{% for reputation in reputations %}
|
{% for reputation in reputations %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{% url djangobb:reputation reputation.from_user %}">{{ reputation.from_user }}</a></td>
|
<td><a href="{% url djangobb:reputation reputation.from_user %}">{{ reputation.from_user }}</a></td>
|
||||||
<td>{% link reputation.topic %}</td>
|
<td><a href="{{ reputation.post.get_absolute_url }}">{{ reputation.post.topic }}</a></td>
|
||||||
<td>{{ reputation.reason }}</td>
|
<td>{{ reputation.reason }}</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
{% ifequal reputation.sign 1 %}
|
{% ifequal reputation.sign 1 %}
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
<div class="inbox">
|
<div class="inbox">
|
||||||
<form action="{% url djangobb:reputation form.to_user %}" method="post">
|
<form action="{% url djangobb:reputation form.to_user %}" method="post">
|
||||||
<table cellspacing="0">
|
<table cellspacing="0">
|
||||||
{{ form.topic }}
|
{{ form.errors.as_ul }}
|
||||||
|
{{ form.post }}
|
||||||
{{ form.sign }}
|
{{ form.sign }}
|
||||||
<tbody><tr>
|
<tbody><tr>
|
||||||
<td class="tc4" width="30%">{% trans "Your name:" %}</td>
|
<td class="tc4" width="30%">{% trans "Your name:" %}</td>
|
||||||
|
@ -18,10 +19,9 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td class="tc4" width="30%">{% trans "To whom we change a reputation:" %}</td>
|
<td class="tc4" width="30%">{% trans "To whom we change a reputation:" %}</td>
|
||||||
<td class="tc4" width="70%">{{ form.to_user }}</td>
|
<td class="tc4" width="70%">{{ form.to_user }}</td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="tc4" width="30%">{% trans "The reason of change of reputation:" %}</td>
|
<td class="tc4" width="30%"></td>
|
||||||
<td class="tc4" width="70%">{{ form.reason }}</td>
|
<td class="tc4" width="70%">{{ form.reason }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -33,7 +33,6 @@
|
||||||
{% trans "Reduction of a reputation" %}
|
{% trans "Reduction of a reputation" %}
|
||||||
{% endifequal %}
|
{% endifequal %}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody></table>
|
</tbody></table>
|
||||||
<table cellspacing="0">
|
<table cellspacing="0">
|
||||||
|
|
|
@ -54,8 +54,9 @@
|
||||||
<dd>{% trans "IP:" %} {{ post.user_ip }}</dd>
|
<dd>{% trans "IP:" %} {{ post.user_ip }}</dd>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if forum_settings.REPUTATION_SUPPORT %}
|
{% if forum_settings.REPUTATION_SUPPORT %}
|
||||||
{% ifnotequal request.user post.user.username %}
|
<dd><a href="{% url djangobb:reputation post.user %}">{% trans "Reputation" %}</a>
|
||||||
<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>
|
{% ifnotequal request.user post.user %} {# TODO: and user.is_authenticated #}
|
||||||
|
: <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>
|
||||||
{% endifnotequal %}
|
{% endifnotequal %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<dd class="usercontacts"><a href="{% url djangobb:forum_profile post.user %}">{% trans "Profile" %}</a>
|
<dd class="usercontacts"><a href="{% url djangobb:forum_profile post.user %}">{% trans "Profile" %}</a>
|
||||||
|
|
|
@ -495,10 +495,14 @@ def reputation(request, username):
|
||||||
form = build_form(ReputationForm, request, from_user=request.user, to_user=user)
|
form = build_form(ReputationForm, request, from_user=request.user, to_user=user)
|
||||||
|
|
||||||
if 'action' in request.GET:
|
if 'action' in request.GET:
|
||||||
if 'topic_id' in request.GET:
|
if request.user == user:
|
||||||
|
return HttpResponseForbidden(u'You can not change the reputation of yourself')
|
||||||
|
|
||||||
|
if 'post_id' in request.GET:
|
||||||
sign = 0
|
sign = 0
|
||||||
topic_id = request.GET['topic_id']
|
post_id = request.GET['post_id']
|
||||||
form.fields['topic'].initial = topic_id
|
form.fields['post'].initial = post_id
|
||||||
|
print form.fields['post']
|
||||||
if request.GET['action'] == 'plus':
|
if request.GET['action'] == 'plus':
|
||||||
form.fields['sign'].initial = 1
|
form.fields['sign'].initial = 1
|
||||||
elif request.GET['action'] == 'minus':
|
elif request.GET['action'] == 'minus':
|
||||||
|
@ -510,7 +514,7 @@ def reputation(request, username):
|
||||||
raise Http404
|
raise Http404
|
||||||
|
|
||||||
elif request.method == 'POST':
|
elif request.method == 'POST':
|
||||||
if 'del_reputation' in request.POST:
|
if 'del_reputation' in request.POST and request.user.is_superuser:
|
||||||
reputation_list = request.POST.getlist('reputation_id')
|
reputation_list = request.POST.getlist('reputation_id')
|
||||||
for reputation_id in reputation_list:
|
for reputation_id in reputation_list:
|
||||||
reputation = get_object_or_404(Reputation, pk=reputation_id)
|
reputation = get_object_or_404(Reputation, pk=reputation_id)
|
||||||
|
@ -518,11 +522,13 @@ def reputation(request, username):
|
||||||
return HttpResponseRedirect(reverse('djangobb:index'))
|
return HttpResponseRedirect(reverse('djangobb:index'))
|
||||||
elif form.is_valid():
|
elif form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
topic_id = request.POST['topic']
|
post_id = request.POST['post']
|
||||||
topic = get_object_or_404(Topic, id=topic_id)
|
post = get_object_or_404(Post, id=post_id)
|
||||||
return HttpResponseRedirect(topic.get_absolute_url())
|
return HttpResponseRedirect(post.get_absolute_url())
|
||||||
else:
|
else:
|
||||||
raise Http404
|
return {'form': form,
|
||||||
|
'TEMPLATE': 'forum/reputation_form.html'
|
||||||
|
}
|
||||||
else:
|
else:
|
||||||
reputations = Reputation.objects.filter(to_user=user).order_by('-time').select_related()
|
reputations = Reputation.objects.filter(to_user=user).order_by('-time').select_related()
|
||||||
return {'reputations': reputations,
|
return {'reputations': reputations,
|
||||||
|
|
Reference in a new issue