Skip to content

Commit

Permalink
notice broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
DuP-491 committed Jan 30, 2022
1 parent d82e636 commit d7f4c2c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions news/templates/news/notice.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ <h5 class="card-title mb-2 mt-1">{{news.title}}</h5>
<a href="{% url 'news:news_delete' pk=news.pk %}">
<button type="button" class="noticebtn">Delete Notice</button>
</a>
<a href="{% url 'news:news_broadcast' pk=news.pk %}">
<button type="button" class="noticebtn">BroadCast Notice</button>
</a>
</div>
{% endif %}
</div>
Expand Down
3 changes: 3 additions & 0 deletions news/templates/news/notice_email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% autoescape off %}
{{ body }}
{% endautoescape %}
1 change: 1 addition & 0 deletions news/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
path('form/',views.createNews,name='news_form'),
path('delete/<int:pk>/',views.deleteNews,name='news_delete'),
path('update/<int:pk>/',views.updateNews,name='news_update'),
path('broadcast/<int:pk>/',views.broadCastNews,name='news_broadcast'),
]
23 changes: 23 additions & 0 deletions news/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
from .models import News
from django.contrib import messages
from RoboClub.decorators import has_role_head_or_coordinator
from django.template.loader import render_to_string
from django.contrib.auth.models import User
from django.core.mail import EmailMessage
from django.http import JsonResponse
# Create your views here.

def news(request):
Expand All @@ -31,6 +35,25 @@ def createNews(request):
context['form']=form
return render(request,'news/notice_form.html',context)

@has_role_head_or_coordinator
def broadCastNews(request,pk):
# news_id=request.POST.get('id')
news = News.objects.get(id=pk)
mail_subject = news.title
message = render_to_string('news/notice_email.html', context={'body': news.content})
to_users = []
for user in User.objects.all():
try:
email = EmailMessage(
subject=mail_subject, body=message,to=[user.email],
)
email.content_subtype = "html"
email.send()
except:
pass
messages.success(request, f'Notice has been broadcasted to all users')
return redirect('news:news_page')

@has_role_head_or_coordinator
def deleteNews(request,pk):
news=News.objects.get(pk=pk)
Expand Down
3 changes: 1 addition & 2 deletions user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def loginUser(request):
elif user is not None:
login(request, user)
print(user.profile.first_name)
if user.profile.first_name is '':
print("Sd")
if user.profile.first_name == '':
messages.info(request,"Please Complete Your Profile")
return redirect('user:profile_page',user=user)
return redirect('home:index')
Expand Down

0 comments on commit d7f4c2c

Please sign in to comment.