Skip to content

Commit

Permalink
Utilise update pour la désinscription (#4172)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume authored and pierre-24 committed Feb 8, 2017
1 parent cb10faf commit 2ee7534
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
40 changes: 13 additions & 27 deletions zds/member/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,37 +369,24 @@ def unregister(request):
current = request.user
# Nota : as of v21 all about content paternity is held by a proper receiver in zds.tutorialv2.models.models_database
# comments likes / dislikes
for vote in CommentVote.objects.filter(user=current):
votes = CommentVote.objects.filter(user=current)
for vote in votes:
if vote.positive:
vote.comment.like -= 1
else:
vote.comment.dislike -= 1
vote.comment.save()
vote.delete()
votes.delete()
# all messages anonymisation (forum, article and tutorial posts)
for message in Comment.objects.filter(author=current):
message.author = anonymous
message.save()
for message in PrivatePost.objects.filter(author=current):
message.author = anonymous
message.save()
Comment.objects.filter(author=current).update(author=anonymous)
PrivatePost.objects.filter(author=current).update(author=anonymous)
# karma notes, alerts and sanctions anonymisation (to keep them)
for note in KarmaNote.objects.filter(moderator=current):
note.moderator = anonymous
note.save()
for ban in Ban.objects.filter(moderator=current):
ban.moderator = anonymous
ban.save()
for alert in Alert.objects.filter(author=current):
alert.author = anonymous
alert.save()
for alert in Alert.objects.filter(moderator=current):
alert.moderator = anonymous
alert.save()
KarmaNote.objects.filter(moderator=current).update(moderator=anonymous)
Ban.objects.filter(moderator=current).update(moderator=anonymous)
Alert.objects.filter(author=current).update(author=anonymous)
Alert.objects.filter(moderator=current).update(moderator=anonymous)
# in case current has been moderator in his old day
for message in Comment.objects.filter(editor=current):
message.editor = anonymous
message.save()
Comment.objects.filter(editor=current).update(editor=anonymous)
for topic in PrivateTopic.objects.filter(author=current):
topic.participants.remove(current)
if topic.participants.count() > 0:
Expand All @@ -411,9 +398,7 @@ def unregister(request):
for topic in PrivateTopic.objects.filter(participants__in=[current]):
topic.participants.remove(current)
topic.save()
for topic in Topic.objects.filter(author=current):
topic.author = anonymous
topic.save()
Topic.objects.filter(author=current).update(author=anonymous)
# Before deleting gallery let's summurize what we deleted
# - unpublished tutorials with only the unregistering member as an author
# - unpublished articles with only the unregistering member as an author
Expand All @@ -424,14 +409,15 @@ def unregister(request):
# - "personnal galleries" with more than one owner
# so we will just delete the unretistering user ownership and give it to anonymous in the only case
# he was alone so that gallery is not lost
galleries = UserGallery.objects.filter(user=current)
for gallery in UserGallery.objects.filter(user=current):
if gallery.gallery.get_linked_users().count() == 1:
anonymous_gallery = UserGallery()
anonymous_gallery.user = external
anonymous_gallery.mode = 'w'
anonymous_gallery.gallery = gallery.gallery
anonymous_gallery.save()
gallery.delete()
galleries.delete()

# remove API access (tokens + applications)
for token in AccessToken.objects.filter(user=current):
Expand Down
6 changes: 1 addition & 5 deletions zds/notification/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ def get_queryset(self):
def mark_notifications_as_read(request):
"""Mark the notifications of the current user as read"""

notifications = Notification.objects.get_unread_notifications_of(request.user)

for notification in notifications:
notification.is_read = True
notification.save()
Notification.objects.get_unread_notifications_of(request.user).update(is_read=True)

messages.success(request, _(u'Vos notifications ont bien été marquées comme lues.'))

Expand Down
20 changes: 20 additions & 0 deletions zds/utils/migrations/0010_auto_20170203_2100.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('utils', '0009_auto_20161113_2328'),
]

operations = [
migrations.AlterField(
model_name='alert',
name='privatetopic',
field=models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, verbose_name='Message priv\xe9', blank=True, to='mp.PrivateTopic', null=True),
),
]
1 change: 1 addition & 0 deletions zds/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class Alert(models.Model):
blank=True)
# PrivateTopic sending the resolve_reason to the alert creator
privatetopic = models.ForeignKey(PrivateTopic,
on_delete=models.SET_NULL,
verbose_name=u'Message privé',
db_index=True,
null=True,
Expand Down

0 comments on commit 2ee7534

Please sign in to comment.