Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show number of voters in poll and small enhancement for sub page. #114

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
14 changes: 12 additions & 2 deletions ISS/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def clean(self, value):
posters = []
unfound = []

for username in value.split(','):
for username in value.split('; '):
if not username: continue

norm = Poster.iss_normalize_username(username)
Expand All @@ -79,6 +79,12 @@ def clean(self, value):
else:
posters.append(user)

for poster in posters:
if posters.count(poster) > 1:
raise ValidationError(
'Duplicate users found.',
code='DUPLICATE_USERS')

if unfound:
raise ValidationError(unfound)
else:
Expand All @@ -88,7 +94,7 @@ def widget_attrs(self, widget):
attrs = super(PosterSelectField, self).widget_attrs(widget)

attrs['data-auto-suggest'] = 'true'
attrs['data-auto-suggest-delimiter'] = ','
attrs['data-auto-suggest-delimiter'] = '; '

return attrs

Expand Down Expand Up @@ -540,6 +546,10 @@ def clean_username(self):
raise ValidationError('You may not register that username.',
code='FORBIDDEN_USERNAME')

if ";" in norm_username:
raise ValidationError('You may not register that username.',
code='FORBIDDEN_USERNAME')

if len(norm_username) < 1:
raise ValidationError('Invalid username', code='INVALID_GENERAL')

Expand Down
17 changes: 16 additions & 1 deletion ISS/models/core_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ISS import utils
from ISS.utils import HomoglyphNormalizer
from .polls import Poll
from .polls import PollVote
from .auth_package import AuthPackage, AccessControlList
from .admin_models import Ban

Expand Down Expand Up @@ -221,13 +222,27 @@ def can_auto_anonymize(self):
@transaction.atomic
def merge_into(self, other):
"""
Reassigns all the records that tie to this user to another one and
Reassigns all (<-- lies) the records that tie to this user to another one and
sometimesok marked this conversation as resolved.
Show resolved Hide resolved
disables this user afterwards.
"""

Thread.objects.filter(author=self).update(author=other)

Post.objects.filter(author=self).update(posted_from='127.0.0.1')
Post.objects.filter(author=self).update(author=other)

PostSnapshot.objects.filter(obsolesced_by=self).update(obsolescing_ip='127.0.0.1')
PostSnapshot.objects.filter(obsolesced_by=self).update(obsolesced_by=other)
sometimesok marked this conversation as resolved.
Show resolved Hide resolved

for post in Post.objects.all():
post.content = post.content.replace("author=\"" + self.username + "\"", "author=\"" + str(other) + "\"")
post.save()
Comment on lines +241 to +243
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know people don't like having their usernames hang out in quotes, but we can't do this for two reasons:

  1. On a policy/moral level this edits posts belonging to people other than the person anonymizing themselves. Editing other peoples posts is a right reserved for the tyrant (me)
  2. Iterating over every post in the DB, doing a string substitution, and writing back to the DB is going to clobber the DB. On NiS prod the select query probably won't even finish before we run out of memory.


PrivateMessage.objects.filter(receiver=self).delete()
PrivateMessage.objects.filter(sender=self).delete()
sometimesok marked this conversation as resolved.
Show resolved Hide resolved

PollVote.objects.filter(voter=self).update(voter=other)
sometimesok marked this conversation as resolved.
Show resolved Hide resolved

for thanks in self.thanks_given.all():
try:
with transaction.atomic():
Expand Down
1 change: 1 addition & 0 deletions ISS/templates/thread.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ <h3 class="poll-prompt">
<ul class="voter-list">
{% for vote in opt.votes.all %}
<li>
Votes: {{ opt.votes.count }} -
<a href="{{ vote.voter.get_url }}">{{ vote.voter.username }}</a>
{% if not forloop.last %},{% endif %}
</li>
Expand Down
3 changes: 1 addition & 2 deletions ISS/views/forum.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,7 @@ def usercp(request):
threads = (Thread.objects.all()
.filter(
threadflag__poster_id=request.user.id,
threadflag__subscribed=True,
last_update__gt=F('threadflag__last_read_date'))
threadflag__subscribed=True)
sometimesok marked this conversation as resolved.
Show resolved Hide resolved
.order_by('-last_update'))

threads_per_page = utils.get_config('threads_per_forum_page')
Expand Down