def on_map_item_save(sender, instance, created, **kwargs): if instance is None: return follow_key = 'dateaaction.'+str(instance.action.pk) history_key = follow_key+'_dateamapitem.'+str(instance.pk) if created: # create notice on commented object hist_item = DateaHistory( user=instance.user, acting_obj=instance, follow_key = follow_key, history_key = history_key, sender_type = 'map_item', receiver_type = 'action', action = instance.action ) hist_item.generate_extract('dateamapitem', instance) hist_item.save() # create receiver item recv_item = DateaHistoryReceiver( user = instance.action.user, name = instance.action.name, url = instance.get_absolute_url(), content_obj = instance.action, history_item = hist_item, ) recv_item.save() hist_item.send_mail_to_action_owner('content') else: # publish or unpublish all DateaHistoryNotice objects # associated with this mapitem for hitem in DateaHistory.objects.filter(history_key=history_key): hitem.generate_extract('dateamapitem', instance) hitem.check_published() hitem.save() # publish or unpublish all DateaFollow objects associated with this object if instance.published_changed(): DateaFollow.objects.filter(follow_key=follow_key).update(published=instance.published)
def on_follow_save(sender, instance, created, **kwargs): if instance is None: return ctype = ContentType.objects.get(model=instance.object_type.lower()) receiver_obj = ctype.get_object_for_this_type(pk=instance.object_id) follow_key = ctype.model+'.'+str(receiver_obj.pk) history_key = follow_key+'_dateafollow.'+str(instance.pk) # don't create history on following one's own objects if instance.user == receiver_obj.user: return if created: # create notice on commented object recv_type = receiver_obj.get_api_name(mode='base') hist_item = DateaHistory( user=instance.user, acting_obj=instance, follow_key = follow_key, history_key = history_key, sender_type = 'follow', receiver_type = recv_type, ) if hasattr(receiver_obj, 'action'): hist_item.action = receiver_obj.action hist_item.save() # create receiver item if recv_type == 'action': recv_name = receiver_obj.name else: recv_name = receiver_obj.user.username recv_item = DateaHistoryReceiver( user = receiver_obj.user, name = recv_name, url = receiver_obj.get_absolute_url(), content_obj = receiver_obj, history_item = hist_item, ) recv_item.save() hist_item.send_mail_to_receivers('follow') # create notice on the action, if relevant if hasattr(receiver_obj, 'action'): action = getattr(receiver_obj, 'action') action_follow_key = 'dateaaction.'+str(action.pk) # create notice on commented object's action action_hist_item = DateaHistory( user=instance.user, acting_obj=instance, follow_key = action_follow_key, history_key = history_key, sender_type = 'follow', receiver_type = receiver_obj.get_api_name(mode='base'), action = action ) action_hist_item.save() # create receiver item recv_item = DateaHistoryReceiver( user = receiver_obj.user, name = recv_name, url = receiver_obj.get_absolute_url(), content_obj = receiver_obj, history_item = action_hist_item, ) recv_item.save() if action.user != receiver_obj.user: action_hist_item.send_mail_to_action_owner('follow') else: hist_item = DateaHistory.objects.get(history_key=history_key) hist_item.check_published()
def on_map_item_response_save(sender, instance, **kwargs): if instance is None: return map_items = instance.map_items.all() action = map_items[0].action history_key = 'dateaaction.'+str(action.pk)+'_dateamapitemresponse.'+str(instance.pk) # create notice on replied objects for item in map_items: follow_key = 'dateamapitem.'+str(item.pk) hist_item = DateaHistory( user=instance.user, acting_obj=instance, follow_key = follow_key, history_key = history_key, sender_type = 'map_item_response', receiver_type = 'map_item', action = action ) hist_item.generate_extract('dateamapitemresponse', instance) hist_item.save() # create receiver item recv_item = DateaHistoryReceiver( user = item.action.user, name = item.user.username, url = item.get_absolute_url(), content_obj = item, history_item = hist_item, ) recv_item.save() hist_item.send_mail_to_receivers('reply') # create notice on the action action_follow_key = 'dateaaction.'+str(action.pk) # create notice on commented object's action action_hist_item = DateaHistory( user=instance.user, acting_obj=instance, follow_key = action_follow_key, history_key = history_key, sender_type = 'map_item_response', receiver_type = 'map_item', action = action ) action_hist_item.generate_extract('dateamapitemresponse', instance) action_hist_item.save() for item in map_items: # create receiver item recv_item = DateaHistoryReceiver( user = item.action.user, name = item.user.username, url = item.get_absolute_url(), content_obj = item, history_item = action_hist_item, ) recv_item.save()
def on_comment_save(sender, instance, created, **kwargs): if instance is None: return ctype = ContentType.objects.get(model=instance.object_type.lower()) receiver_obj = ctype.get_object_for_this_type(pk=instance.object_id) follow_key = ctype.model+'.'+str(receiver_obj.pk) history_key = follow_key+'_dateacomment.'+str(instance.pk) if created: # create notice on commented object hist_item = DateaHistory( user=instance.user, acting_obj=instance, follow_key = follow_key, history_key = history_key, sender_type = 'comment', receiver_type = receiver_obj.get_api_name(mode='base') ) if hasattr(receiver_obj, 'action'): hist_item.action = receiver_obj.action hist_item.generate_extract('dateacomment', instance) hist_item.save() # create receiver item recv_item = DateaHistoryReceiver( user = receiver_obj.user, name = receiver_obj.user.username, url = receiver_obj.get_absolute_url(), content_obj = receiver_obj, history_item = hist_item, ) recv_item.save() hist_item.send_mail_to_receivers('comment') # create notice on the action, if relevant if hasattr(receiver_obj, 'action'): action = getattr(receiver_obj, 'action') action_follow_key = 'dateaaction.'+str(action.pk) # create notice on commented object's action action_hist_item = DateaHistory( user=instance.user, acting_obj=instance, follow_key = action_follow_key, history_key = history_key, sender_type = 'comment', receiver_type = receiver_obj.get_api_name(mode='base'), action = action ) action_hist_item.generate_extract('dateacomment', instance) action_hist_item.save() # generate receiver item action_recv_item = DateaHistoryReceiver( user = receiver_obj.user, name = receiver_obj.user.username, url = receiver_obj.get_absolute_url(), content_obj = receiver_obj, history_item = action_hist_item, ) action_recv_item.save() if action.user != receiver_obj.user: action_hist_item.send_mail_to_action_owner('comment') else: hist_items = DateaHistory.objects.filter(history_key=history_key) for item in hist_items: item.generate_extract('dateacomment', instance) item.check_published() item.save()