##// END OF EJS Templates
Added django management command to clean old users. Cleaned up failing tests. Fixed error when trying to get a non-existent post
neko259 -
r689:3d81370e 1.8-dev
parent child Browse files
Show More
@@ -0,0 +1,1 b''
1 __author__ = 'vurdalak'
@@ -0,0 +1,1 b''
1 __author__ = 'vurdalak'
@@ -0,0 +1,29 b''
1 from datetime import datetime, timedelta
2 from django.core.management import BaseCommand
3 from django.db import transaction
4 from django.db.models import Count
5 from boards.models import User, Post
6
7 __author__ = 'neko259'
8
9 OLD_USER_AGE_DAYS = 90
10
11
12 class Command(BaseCommand):
13 help = 'Removes empty users (that don\'t have posts or tags'
14
15 @transaction.atomic
16 def handle(self, *args, **options):
17 old_registration_date = datetime.now().date() - timedelta(
18 OLD_USER_AGE_DAYS)
19
20 old_users = User.objects.annotate(tags_count=Count('fav_tags')).filter(
21 tags_count=0).filter(registration_time__lt=old_registration_date)
22 deleted_users = 0
23 for user in old_users:
24 if not Post.objects.filter(user=user).exists():
25 self.stdout.write('Deleting user %s' % user.user_id)
26 user.delete()
27 deleted_users += 1
28
29 self.stdout.write('Deleted %d users' % deleted_users) No newline at end of file
@@ -161,8 +161,7 b' class PagesTest(TestCase):'
161
161
162 response_not_existing = client.get(THREAD_PAGE + str(
162 response_not_existing = client.get(THREAD_PAGE + str(
163 existing_post_id + 1) + '/')
163 existing_post_id + 1) + '/')
164 self.assertEqual(PAGE_404,
164 self.assertEqual(PAGE_404, response_not_existing.templates[0].name,
165 response_not_existing.templates[0].name,
166 u'Not existing thread is opened')
165 u'Not existing thread is opened')
167
166
168 response_existing = client.get(TAG_PAGE + tag_name + '/')
167 response_existing = client.get(TAG_PAGE + tag_name + '/')
@@ -177,7 +176,7 b' class PagesTest(TestCase):'
177
176
178 reply_id = Post.objects.create_post('', TEST_TEXT,
177 reply_id = Post.objects.create_post('', TEST_TEXT,
179 thread=Post.objects.all()[0]
178 thread=Post.objects.all()[0]
180 .thread)
179 .get_thread())
181 response_not_existing = client.get(THREAD_PAGE + str(
180 response_not_existing = client.get(THREAD_PAGE + str(
182 reply_id) + '/')
181 reply_id) + '/')
183 self.assertEqual(PAGE_404,
182 self.assertEqual(PAGE_404,
@@ -37,9 +37,6 b' def api_get_threaddiff(request, thread_i'
37
37
38 thread = get_object_or_404(Post, id=thread_id).get_thread()
38 thread = get_object_or_404(Post, id=thread_id).get_thread()
39
39
40 logger.info('Getting thread #%s diff since %s' % (thread_id,
41 last_update_time))
42
43 filter_time = datetime.fromtimestamp(float(last_update_time) / 1000000,
40 filter_time = datetime.fromtimestamp(float(last_update_time) / 1000000,
44 timezone.get_current_timezone())
41 timezone.get_current_timezone())
45
42
@@ -13,8 +13,6 b' import neboard'
13
13
14 BAN_REASON_SPAM = 'Autoban: spam bot'
14 BAN_REASON_SPAM = 'Autoban: spam bot'
15
15
16 OLD_USER_AGE_DAYS = 90
17
18 PARAMETER_FORM = 'form'
16 PARAMETER_FORM = 'form'
19
17
20
18
@@ -74,9 +72,6 b' class BaseBoardView(View):'
74 user = User.objects.create(user_id=new_id, rank=RANK_USER,
72 user = User.objects.create(user_id=new_id, rank=RANK_USER,
75 registration_time=time_now)
73 registration_time=time_now)
76
74
77 # TODO Move this to manage.py commands
78 #self._delete_old_users()
79
80 session['user_id'] = user.id
75 session['user_id'] = user.id
81 else:
76 else:
82 user = User.objects.select_related('fav_tags').get(
77 user = User.objects.select_related('fav_tags').get(
@@ -97,21 +92,6 b' class BaseBoardView(View):'
97
92
98 return theme
93 return theme
99
94
100 def _delete_old_users(self):
101 """
102 Delete users with no favorite tags and posted messages. These can be spam
103 bots or just old user accounts
104 """
105
106 old_registration_date = datetime.now().date() - timedelta(
107 OLD_USER_AGE_DAYS)
108
109 for user in User.objects.annotate(tags_count=Count('fav_tags')).filter(
110 tags_count=0).filter(
111 registration_time__lt=old_registration_date):
112 if not Post.objects.filter(user=user).exists():
113 user.delete()
114
115 @transaction.atomic
95 @transaction.atomic
116 def _ban_current_user(self, request):
96 def _ban_current_user(self, request):
117 """
97 """
@@ -23,7 +23,10 b" PARAMETER_BUMPABLE = 'bumpable'"
23 class ThreadView(BaseBoardView, PostMixin, FormMixin):
23 class ThreadView(BaseBoardView, PostMixin, FormMixin):
24
24
25 def get(self, request, post_id, mode=MODE_NORMAL, form=None):
25 def get(self, request, post_id, mode=MODE_NORMAL, form=None):
26 opening_post = Post.objects.filter(id=post_id).only('thread_new')[0]
26 try:
27 opening_post = Post.objects.filter(id=post_id).only('thread_new')[0]
28 except IndexError:
29 raise Http404
27
30
28 # If this is not OP, don't show it as it is
31 # If this is not OP, don't show it as it is
29 if not opening_post or not opening_post.is_opening():
32 if not opening_post or not opening_post.is_opening():
General Comments 0
You need to be logged in to leave comments. Login now