Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Email notification templates #1891

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

You have one new notification!

Update in '{{group_name}}'.

{{contributor}} has added a {{instance_type}}.

Best,
{{site_name}} Team.
106 changes: 53 additions & 53 deletions gnowsys-ndf/gnowsys_ndf/ndf/views/discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,58 +262,58 @@ def discussion_reply(request, group_id, node_id):
current_group_id=group_id,
active_user_id_or_list=active_user_ids_list)


# if gs_type_node.if_file.mime_type :
# file_creator_id = gs_type_node.created_by
# if file_creator_id != request.user.id :
# counter_obj = Counter.get_counter_obj(request.user.id, ObjectId(group_id))
# # counter_obj.no_comments_on_others_files += 1
# counter_obj['file']['commented_on_others_res'] += 1
# # counter_obj.no_comments_by_user += 1
# counter_obj['total_comments_by_user'] += 1
# # counter_obj.course_score += GSTUDIO_COMMENT_POINTS
# counter_obj['group_points'] += GSTUDIO_COMMENT_POINTS

# counter_obj_creator = Counter.get_counter_obj(file_creator_id, ObjectId(group_id))
# # counter_obj_creator.no_comments_received_on_files += 1
# counter_obj_creator['file']['comments_gained'] += 1
# # counter_obj_creator.no_comments_for_user += 1
# if str(counter_obj.user_id) in counter_obj_creator.file['comments_by_others_on_res'].keys():
# # counter_obj_creator.comments_by_others_on_files[str(counter_obj.user_id)] += 1
# counter_obj_creator['file']['comments_by_others_on_res'][str(counter_obj.user_id)] += 1
# else:
# # counter_obj_creator.comments_by_others_on_files.update({str(counter_obj.user_id):1})
# counter_obj_creator.file['comments_by_others_on_res'].update({str(counter_obj.user_id):1})
# counter_obj.last_update = datetime.now()
# counter_obj_creator.last_update = datetime.now()
# counter_obj.save()
# counter_obj_creator.save()
# else :
# note_creator_id = gs_type_node.created_by
# if note_creator_id != request.user.id :
# counter_obj = Counter.get_counter_obj(request.user.id, ObjectId(group_id))
# # counter_obj.no_comments_by_user += 1
# counter_obj['total_comments_by_user'] += 1
# # counter_obj.no_comments_on_others_notes += 1
# counter_obj['page']['blog']['commented_on_others_res'] += 1
# counter_obj['group_points'] += GSTUDIO_COMMENT_POINTS

# counter_obj_creator = Counter.get_counter_obj(note_creator_id, ObjectId(group_id))
# # counter_obj_creator.no_comments_for_user += 1
# # counter_obj_creator.no_comments_received_on_notes += 1
# counter_obj_creator['page']['blog']['comments_gained'] += 1

# # if str(counter_obj.user_id) in counter_obj_creator.comments_by_others_on_notes.keys():
# if str(counter_obj.user_id) in counter_obj_creator.page.blog['comments_by_others_on_res'].keys():
# # counter_obj_creator.comments_by_others_on_notes[str(counter_obj.user_id)] += 1
# counter_obj_creator['page']['blog']['comments_by_others_on_res'][str(counter_obj.user_id)] += 1
# else:
# counter_obj_creator.page.blog['comments_by_others_on_res'].update({str(counter_obj.user_id):1})
# counter_obj.last_update = datetime.now()
# counter_obj_creator.last_update = datetime.now()
# counter_obj.save()
# counter_obj_creator.save()

'''
if gs_type_node.if_file.mime_type :
file_creator_id = gs_type_node.created_by
if file_creator_id != request.user.id :
counter_obj = Counter.get_counter_obj(request.user.id, ObjectId(group_id))
# counter_obj.no_comments_on_others_files += 1
counter_obj['file']['commented_on_others_res'] += 1
# counter_obj.no_comments_by_user += 1
counter_obj['total_comments_by_user'] += 1
# counter_obj.course_score += GSTUDIO_COMMENT_POINTS
counter_obj['group_points'] += GSTUDIO_COMMENT_POINTS

counter_obj_creator = Counter.get_counter_obj(file_creator_id, ObjectId(group_id))
# counter_obj_creator.no_comments_received_on_files += 1
counter_obj_creator['file']['comments_gained'] += 1
# counter_obj_creator.no_comments_for_user += 1
if str(counter_obj.user_id) in counter_obj_creator.file['comments_by_others_on_res'].keys():
# counter_obj_creator.comments_by_others_on_files[str(counter_obj.user_id)] += 1
counter_obj_creator['file']['comments_by_others_on_res'][str(counter_obj.user_id)] += 1
else:
# counter_obj_creator.comments_by_others_on_files.update({str(counter_obj.user_id):1})
counter_obj_creator.file['comments_by_others_on_res'].update({str(counter_obj.user_id):1})
counter_obj.last_update = datetime.now()
counter_obj_creator.last_update = datetime.now()
counter_obj.save()
counter_obj_creator.save()
else :
note_creator_id = gs_type_node.created_by
if note_creator_id != request.user.id :
counter_obj = Counter.get_counter_obj(request.user.id, ObjectId(group_id))
# counter_obj.no_comments_by_user += 1
counter_obj['total_comments_by_user'] += 1
# counter_obj.no_comments_on_others_notes += 1
counter_obj['page']['blog']['commented_on_others_res'] += 1
counter_obj['group_points'] += GSTUDIO_COMMENT_POINTS

counter_obj_creator = Counter.get_counter_obj(note_creator_id, ObjectId(group_id))
# counter_obj_creator.no_comments_for_user += 1
# counter_obj_creator.no_comments_received_on_notes += 1
counter_obj_creator['page']['blog']['comments_gained'] += 1

# if str(counter_obj.user_id) in counter_obj_creator.comments_by_others_on_notes.keys():
if str(counter_obj.user_id) in counter_obj_creator.page.blog['comments_by_others_on_res'].keys():
# counter_obj_creator.comments_by_others_on_notes[str(counter_obj.user_id)] += 1
counter_obj_creator['page']['blog']['comments_by_others_on_res'][str(counter_obj.user_id)] += 1
else:
counter_obj_creator.page.blog['comments_by_others_on_res'].update({str(counter_obj.user_id):1})
counter_obj.last_update = datetime.now()
counter_obj_creator.last_update = datetime.now()
counter_obj.save()
counter_obj_creator.save()
'''
formated_time = reply_obj.created_at.strftime("%B %d, %Y, %I:%M %p")

files = []
Expand Down Expand Up @@ -479,4 +479,4 @@ def get_user_replies(request, group_id, user_name_or_id):
},
context_instance=RequestContext(request))
except Exception as no_user:
return HttpResponse('No such User found')
return HttpResponse('No such User found')
28 changes: 25 additions & 3 deletions gnowsys-ndf/gnowsys_ndf/ndf/views/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

from gnowsys_ndf.ndf.views.methods import get_execution_time, staff_required
from gnowsys_ndf.ndf.views.methods import get_language_tuple, create_gattribute, create_thread_for_node
from gnowsys_ndf.ndf.views.notify import activity_notification


''' -- common db queries -- '''

Expand All @@ -38,18 +40,26 @@ def node_create_edit(request,
# check for POST method to node update operation
if request.method == "POST":

object_type = "Object"
creation_flag = False
# put validations
if node_type not in node_collection.db.connection._registered_documents.keys():
raise ValueError('Improper node_type passed')

kwargs={}
group_name, group_id = Group.get_group_name_id(group_id)
kwargs = {}
group_obj = Group.get_group_name_id(group_id, get_obj=True)
group_name = group_altname = group_obj.name
if group_obj.altnames:
group_altname = group_obj.altnames
group_id = group_obj._id

member_of_name, member_of_id = GSystemType.get_gst_name_id(member_of)

if node_id: # existing node object
node_obj = Node.get_node_by_id(node_id)

else: # create new
creation_flag = True
kwargs={
'group_set': group_id,
'member_of': member_of_id
Expand All @@ -63,14 +73,16 @@ def node_create_edit(request,
node_obj.save(group_id=group_id)
node_id = node_obj['_id']

# Consider for Blog page creation
if member_of_name == "Page":
blog_page_gst_name, blog_page_gst_id = GSystemType.get_gst_name_id("Blog page")
# Consider for Blog page creation
if blog_page_gst_id in node_obj.type_of:
object_type = "Note"
discussion_enable_at = node_collection.one({"_type": "AttributeType", "name": "discussion_enable"})
create_gattribute(node_obj._id, discussion_enable_at, True)
return_status = create_thread_for_node(request,group_id, node_obj)

# Update Counter objects
active_user_ids_list = [request.user.id]
if GSTUDIO_BUDDY_LOGIN:
active_user_ids_list += Buddy.get_buddy_userids_list_within_datetime(request.user.id, datetime.datetime.now())
Expand All @@ -83,6 +95,16 @@ def node_create_edit(request,
each_counter_obj.last_update = datetime.datetime.now()
each_counter_obj.save()

if creation_flag:
object_type = member_of_name
# Send email notifications
try:
activity_notification(from_user_id=request.user.id,
group_name=group_altname, instance_type=object_type, to_user_id=group_obj.author_set)
except Exception as notification_err:
print "\n!!!Error while sending notification. ", notification_err
pass

post_req = request.POST
attrs_to_create_update = [f for f in post_req.keys() if ('attribute' in f)]
attrs_to_create_update = [a.split('_')[1] for a in attrs_to_create_update]
Expand Down
6 changes: 5 additions & 1 deletion gnowsys-ndf/gnowsys_ndf/ndf/views/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from gnowsys_ndf.ndf.models import node_collection, triple_collection
from gnowsys_ndf.ndf.templatetags.ndf_tags import get_all_user_groups
from gnowsys_ndf.ndf.views.methods import get_execution_time, get_all_subscribed_users, get_group_name_id
from gnowsys_ndf.ndf.views.tasks import task_set_notify_val
from gnowsys_ndf.ndf.views.tasks import task_set_notify_val, activity_notify_queue
import json

try:
Expand Down Expand Up @@ -275,3 +275,7 @@ def invite_admins(request,group_id):
except Exception as e:
print "Exception in invite_admins in notify view "+str(e)
return HttpResponse("Failure")

@get_execution_time
def activity_notification(from_user_id, group_name, instance_type, to_user_id):
return activity_notify_queue(from_user_id, group_name, instance_type, to_user_id)
29 changes: 28 additions & 1 deletion gnowsys-ndf/gnowsys_ndf/ndf/views/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from gnowsys_ndf.notification import models as notification
from gnowsys_ndf.ndf.models import Node
from gnowsys_ndf.ndf.models import node_collection, triple_collection, filehive_collection, benchmark_collection
from gnowsys_ndf.settings import MEDIA_ROOT
from gnowsys_ndf.settings import MEDIA_ROOT, GSTUDIO_SITE_NAME, GSTUDIO_SITE_LOGO

try:
from bson import ObjectId
Expand Down Expand Up @@ -61,6 +61,33 @@ def task_set_notify_val(request_user_id, group_id, msg, activ, to_user):
return False


@task
def activity_notify_queue(from_user_id, group_name, instance_type, to_user):
'''
Attach notification mail to celery task
'''
from_user = User.objects.get(id=from_user_id)
to_user = list(User.objects.filter(pk__in=to_user))
try:
rendered_msg = render_to_string(
"notification/activity_notification.html",
{
'contributor': from_user.username,
'site_logo': GSTUDIO_SITE_LOGO,
'site_name': GSTUDIO_SITE_NAME,
'group_name': group_name,
'instance_type': instance_type,
# 'instance_url': instance_url,
}
)
notification.create_notice_type("activity_notification", "Activity Notification" , "notification")
notification.send(users=to_user, extra_context=rendered_msg, label= "activity_notification")
return True
except Exception as e:
print "Error in sending notification- "+str(e)
return False


@task
def convertVideo(userid, file_id, filename):
"""
Expand Down
3 changes: 1 addition & 2 deletions gnowsys-ndf/gnowsys_ndf/notification/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class LanguageStoreNotAvailable(Exception):
def create_notice_type(label, display, description, **kwargs):
NoticeType.create(label, display, description, **kwargs)


class NoticeType(models.Model):

label = models.CharField(_("label"), max_length=40)
Expand Down Expand Up @@ -55,7 +54,7 @@ def create(cls, label, display, description, default=2, verbosity=1):
This is intended to be used by other apps as a post_syncdb manangement step.
"""
try:
notice_type = cls._default_manager.get(label=label)
notice_type = cls.objects.get(label=label)
updated = False
if display != notice_type.display:
notice_type.display = display
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

You have one new notification!

Update in '{{group_name}}'.

{{contributor}} has added a {{instance_type}}.

Best,
{{site_name}} Team.