From 0f4f8f11c617926a49e2a5dabe1a2dd0fe162fd9 Mon Sep 17 00:00:00 2001 From: DuP-491 Date: Sat, 5 Feb 2022 21:17:42 +0530 Subject: [PATCH] unrolling spam detect --- news/migrations/0001_initial.py | 3 +-- news/migrations/0002_remove_news_broadcast.py | 17 ---------------- news/migrations/0003_news_broadcast.py | 20 ------------------- news/models.py | 16 +++++++-------- news/views.py | 10 +++++----- 5 files changed, 14 insertions(+), 52 deletions(-) delete mode 100644 news/migrations/0002_remove_news_broadcast.py delete mode 100644 news/migrations/0003_news_broadcast.py diff --git a/news/migrations/0001_initial.py b/news/migrations/0001_initial.py index 714a301b..ad07cf21 100644 --- a/news/migrations/0001_initial.py +++ b/news/migrations/0001_initial.py @@ -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 @@ -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)), ], ), ] diff --git a/news/migrations/0002_remove_news_broadcast.py b/news/migrations/0002_remove_news_broadcast.py deleted file mode 100644 index 58b57b13..00000000 --- a/news/migrations/0002_remove_news_broadcast.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.1.5 on 2022-02-05 15:04 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('news', '0001_initial'), - ] - - operations = [ - migrations.RemoveField( - model_name='news', - name='broadcast', - ), - ] diff --git a/news/migrations/0003_news_broadcast.py b/news/migrations/0003_news_broadcast.py deleted file mode 100644 index c6d1e9a2..00000000 --- a/news/migrations/0003_news_broadcast.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 3.1.5 on 2022-02-05 15:06 - -from django.db import migrations, models -import django.utils.timezone - - -class Migration(migrations.Migration): - - dependencies = [ - ('news', '0002_remove_news_broadcast'), - ] - - operations = [ - migrations.AddField( - model_name='news', - name='broadcast', - field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), - preserve_default=False, - ), - ] diff --git a/news/models.py b/news/models.py index 44cd7173..874eb496 100644 --- a/news/models.py +++ b/news/models.py @@ -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}' @@ -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 diff --git a/news/views.py b/news/views.py index 0107bd29..da588428 100644 --- a/news/views.py +++ b/news/views.py @@ -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 = [] @@ -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')