Skip to content

Commit

Permalink
unrolling spam detect
Browse files Browse the repository at this point in the history
  • Loading branch information
DuP-491 committed Feb 5, 2022
1 parent 1d1df4a commit 0f4f8f1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 52 deletions.
3 changes: 1 addition & 2 deletions news/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.1.5 on 2022-02-05 11:58
# Generated by Django 3.1.5 on 2022-02-05 15:47

from django.db import migrations, models

Expand All @@ -20,7 +20,6 @@ class Migration(migrations.Migration):
('link', models.URLField(blank=True, null=True)),
('date', models.DateField(blank=True)),
('is_open', models.BooleanField(default=False)),
('broadcast', models.DateTimeField(auto_now_add=True)),
],
),
]
17 changes: 0 additions & 17 deletions news/migrations/0002_remove_news_broadcast.py

This file was deleted.

20 changes: 0 additions & 20 deletions news/migrations/0003_news_broadcast.py

This file was deleted.

16 changes: 8 additions & 8 deletions news/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class News(models.Model):
link = models.URLField(blank=True,null=True)
date = models.DateField(blank=True,unique=False)
is_open = models.BooleanField(default=False)
broadcast = models.DateTimeField(auto_now_add=timezone.now(),blank=True)
# broadcast = models.DateTimeField(auto_now_add=timezone.now(),blank=True)

def __str__(self):
return f'{self.title}'
Expand All @@ -22,10 +22,10 @@ def save(self, *args,**kwargs):
super().save(args,kwargs)

def allow_broadcast(self):
# return True
now = datetime.datetime.utcnow().replace(tzinfo=utc)
time_difference = now-self.broadcast
if time_difference.total_seconds() > 300:
return True
else:
return False
return True
# now = datetime.datetime.utcnow().replace(tzinfo=utc)
# time_difference = now-self.broadcast
# if time_difference.total_seconds() > 300:
# return True
# else:
# return False
10 changes: 5 additions & 5 deletions news/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def createNews(request):
def broadCastNews(request,pk):
# news_id=request.POST.get('id')
news = News.objects.get(id=pk)
if not news.allow_broadcast():
messages.success(request, f"Broadcast for this post has been recently done,try again after 5 minutes")
return redirect('news:news_page')
# if not news.allow_broadcast():
# messages.success(request, f"Broadcast for this post has been recently done,try again after 5 minutes")
# return redirect('news:news_page')
mail_subject = news.title
notice_body = render_to_string('news/notice_email.html', context={'body': news.content})
to_users = []
Expand All @@ -67,8 +67,8 @@ def broadCastNews(request,pk):
for i in range(0,len(to_users),100):
EmailThread(mail_subject, notice_body, to_users[i:i+100]).start()
messages.success(request, f'Notice has been broadcast to all users')
news.broadcast=timezone.now()
news.save()
# news.broadcast=timezone.now()
# news.save()
except:
messages.success(request, f'Notice was not broad casted')
return redirect('news:news_page')
Expand Down

0 comments on commit 0f4f8f1

Please sign in to comment.