summaryrefslogtreecommitdiff
path: root/website
diff options
context:
space:
mode:
authorJayaram Pai2014-04-19 17:55:25 +0530
committerJayaram Pai2014-04-19 17:55:25 +0530
commit2fbf3ecf6cae63691380ec8cc9df2c4beff29dae (patch)
tree11212c19678c33f4546987079b05f037406ea9b1 /website
parent83063012ac3eac51983c83d3b1681595aa59eb1d (diff)
downloadFOSSEE-Forum-2fbf3ecf6cae63691380ec8cc9df2c4beff29dae.tar.gz
FOSSEE-Forum-2fbf3ecf6cae63691380ec8cc9df2c4beff29dae.tar.bz2
FOSSEE-Forum-2fbf3ecf6cae63691380ec8cc9df2c4beff29dae.zip
basic email and notification added, new frontpage interface
Diffstat (limited to 'website')
-rw-r--r--website/models.py11
-rw-r--r--website/templatetags/count_tags.py12
-rw-r--r--website/templatetags/notify.py3
-rw-r--r--website/views.py102
4 files changed, 117 insertions, 11 deletions
diff --git a/website/models.py b/website/models.py
index 7157ee5..c280d2d 100644
--- a/website/models.py
+++ b/website/models.py
@@ -16,7 +16,7 @@ class Question(models.Model):
date_created = models.DateTimeField(auto_now_add=True)
date_modified = models.DateTimeField(auto_now=True)
views = models.IntegerField(default=1)
- votes = models.IntegerField(default=0)
+ # votes = models.IntegerField(default=0)
def user(self):
user = User.objects.get(id=self.uid)
@@ -39,7 +39,7 @@ class Answer(models.Model):
body = models.TextField()
date_created = models.DateTimeField(auto_now_add=True)
date_modified = models.DateTimeField(auto_now=True)
- votes = models.IntegerField(default=0)
+ # votes = models.IntegerField(default=0)
def user(self):
user = User.objects.get(id=self.uid)
@@ -64,8 +64,13 @@ class Notification(models.Model):
uid = models.IntegerField()
pid = models.IntegerField()
qid = models.IntegerField()
- rid = models.IntegerField()
+ aid = models.IntegerField(default=0)
+ cid = models.IntegerField(default=0)
date_created = models.DateTimeField(auto_now_add=True)
+
+ def poster(self):
+ user = User.objects.get(id=self.pid)
+ return user.username
# CDEEP database created using inspectdb arg of manage.py
class TutorialDetails(models.Model):
diff --git a/website/templatetags/count_tags.py b/website/templatetags/count_tags.py
index 48ba020..735675a 100644
--- a/website/templatetags/count_tags.py
+++ b/website/templatetags/count_tags.py
@@ -59,3 +59,15 @@ register.filter('mul', mul)
def div(value, arg=1):
return value / int(arg)
register.filter('div', div)
+
+# retriving total number of questions
+def total_question_count():
+ count = Question.objects.all().count()
+ return count
+register.simple_tag(total_question_count)
+
+# retriving total number of answers
+def total_answer_count():
+ count = Answer.objects.all().count()
+ return count
+register.simple_tag(total_answer_count)
diff --git a/website/templatetags/notify.py b/website/templatetags/notify.py
index 4c1e655..44465ea 100644
--- a/website/templatetags/notify.py
+++ b/website/templatetags/notify.py
@@ -7,7 +7,7 @@ register = template.Library()
def get_notification(nid):
notification = Notification.objects.get(pk=nid)
question = Question.objects.get(pk=notification.qid);
- answer = Answer.objects.get(pk=notification.rid)
+ answer = Answer.objects.get(pk=notification.aid)
context = {
'notification': notification,
'question': question,
@@ -20,4 +20,3 @@ def notification_count(user_id):
count = Notification.objects.filter(uid=user_id).count()
return count
register.simple_tag(notification_count)
-
diff --git a/website/views.py b/website/views.py
index e368feb..7e7e813 100644
--- a/website/views.py
+++ b/website/views.py
@@ -35,8 +35,10 @@ categories = (
)
def home(request):
+ questions = Question.objects.all().order_by('date_created').reverse()[:10]
context = {
- 'categories': categories
+ 'categories': categories,
+ 'questions': questions
}
return render(request, "website/templates/index.html", context)
@@ -91,10 +93,33 @@ def question_answer(request):
notification.qid = qid
notification.aid = answer.id
notification.save()
- #CONTINUE continue
- # foo = User.objects.get(pk=)
- return HttpResponse(foo)
- return HttpResponseRedirect('/question/'+str(qid))
+
+ user = User.objects.get(id=question.uid)
+ # Sending email when an answer is posted
+ subject = 'Question has been answered'
+ message = """
+ Dear {0}<br><br>
+ Your question titled <b>"{1}"</b> has been answered.<br>
+ Link: {2}<br><br>
+ Regards,<br>
+ Spoken Tutorial Forums
+ """.format(
+ user.username,
+ question.title,
+ 'http://forums.spoken-tutorial.org/question/' + str(question.id) + "#answer" + str(answer.id)
+ )
+
+ email = EmailMultiAlternatives(
+ subject,'', 'forums',
+ [user.email],
+ headers={"Content-type":"text/html;charset=iso-8859-1"}
+ )
+
+ email.attach_alternative(message, "text/html")
+ email.send(fail_silently=True)
+ # End of email send
+
+ return HttpResponseRedirect('/question/'+str(qid) + "#answer" + str(answer.id))
@login_required
def answer_comment(request):
@@ -107,7 +132,60 @@ def answer_comment(request):
comment.answer = answer
comment.body = body
comment.save()
- return HttpResponseRedirect("/question/" + str(answer.question.id) + "#")
+
+ # notifying the answer owner
+ if answer.uid != request.user.id:
+ notification = Notification()
+ notification.uid = answer.uid
+ notification.pid = request.user.id
+ notification.qid = answer.question.id
+ notification.aid = answer.id
+ notification.cid = comment.id
+ notification.save()
+
+ user = User.objects.get(id=answer.uid)
+ subject = 'Comment for your answer'
+ message = """
+ Dear {0}<br><br>
+ A comment has been posted on your answer.<br>
+ Link: {1}<br><br>
+ Regards,<br>
+ Spoken Tutorial Forums
+ """.format(
+ user.username,
+ "http://forums.spoken-tutorial.org/question/" + str(answer.question.id) + "#answer" + str(answer.id)
+ )
+ forums_mail(user.email, subject, message)
+
+ # notifying other users in the comment thread
+ uids = answer.answercomment_set.filter(answer=answer).values_list('uid', flat=True)
+ #getting distinct uids
+ uids = set(uids)
+ uids.remove(request.user.id)
+ for uid in uids:
+ notification = Notification()
+ notification.uid = uid
+ notification.pid = request.user.id
+ notification.qid = answer.question.id
+ notification.aid = answer.id
+ notification.cid = comment.id
+ notification.save()
+
+ user = User.objects.get(id=uid)
+ subject = 'Comment has a reply'
+ message = """
+ Dear {0}<br><br>
+ A reply has been posted on your comment.<br>
+ Link: {1}<br><br>
+ Regards,<br>
+ Spoken Tutorial Forums
+ """.format(
+ user.username,
+ "http://forums.spoken-tutorial.org/question/" + str(answer.question.id) + "#answer" + str(answer.id)
+ )
+ forums_mail(user.email, subject, message)
+ return HttpResponse(message)
+ return HttpResponseRedirect("/question/" + str(answer.question.id) + "#")
def filter(request, category=None, tutorial=None, minute_range=None, second_range=None):
context = {
@@ -423,4 +501,16 @@ def ajax_time_search(request):
@csrf_exempt
def ajax_vote(request):
+ #for future use
pass
+
+def forums_mail(to = '', subject='', message=''):
+ # Start of email send
+ email = EmailMultiAlternatives(
+ subject,'', 'forums',
+ [to],
+ headers={"Content-type":"text/html;charset=iso-8859-1"}
+ )
+ email.attach_alternative(message, "text/html")
+ email.send(fail_silently=True)
+ # End of email send