def create_chapter_notification(sender, instance, created, **kwargs): if created: notification = Notification() notification.user_id = instance.member_id notification.type = Notification.JOIN_CHAPTER notification.chapter_id = instance.chapter_id notification.save()
def create_award_notification(sender, instance, created, **kwargs): if created: notification = Notification() notification.user_id = instance.recipient_id notification.creator_id = instance.awarder_id notification.type = Notification.AWARD notification.award_id = instance.award_id notification.save()
def create_rank_notification(sender, instance, created, **kwargs): old_rank = instance.rank_tracker.changed().get('rank') if old_rank: notification = Notification() if old_rank < instance.rank_id: # promotion notification.type = Notification.PROMOTION if old_rank > instance.rank_id: # demotion notification.type = Notification.DEMOTION if instance.rank_id is None: # kicked notification.type = Notification.KICKED notification.user = instance notification.rank_id = instance.rank_id notification.save()
def default_issue_notification(instance, **kw): """ Given an issue see default_issue_notification we need to send a notification """ log("Firing signal: default_notification") users = approved_users() if not users.count(): return notification = Notification() notification.type = "Issue" notification.type_key = str(instance.key()) notification.user = [ str(u.key()) for u in users ] notification.save() # turn this on when its all working #issue_created.connect(default_issue_notification, dispatch_uid="default_issue_notification") #issue_changed.connect(default_issue_notification, dispatch_uid="default_issue_notification")
def default_notification(instance, **kw): """ Given an error see if we need to send a notification """ log("Firing signal: default_notification") users = approved_users() filtered = [] for user in users: profile = get_profile(user) if profile.notification and instance.priority <= profile.notification: filtered.append(user) if not filtered: return notification = Notification() notification.type = "Error" notification.type_key = str(instance.key()) notification.user = [ str(u.key()) for u in filtered ] notification.save()
def default_notification(instance, **kw): """ Given an error see if we need to send a notification """ log("Firing signal: default_notification") users = approved_users() filtered = [] for user in users: profile = get_profile(user) if profile.notification and instance.priority <= profile.notification: filtered.append(user) if not filtered: return notification = Notification() notification.type = "Error" notification.type_key = str(instance.key()) notification.user = [str(u.key()) for u in filtered] notification.save()
def default_issue_notification(instance, **kw): """ Given an issue see default_issue_notification we need to send a notification """ log("Firing signal: default_notification") users = approved_users() if not users.count(): return notification = Notification() notification.type = "Issue" notification.type_key = str(instance.key()) notification.user = [str(u.key()) for u in users] notification.save() # turn this on when its all working #issue_created.connect(default_issue_notification, dispatch_uid="default_issue_notification") #issue_changed.connect(default_issue_notification, dispatch_uid="default_issue_notification")
def notification_create(request): if request.method == 'POST': try: user_pk = request.POST.get('user_pk', None) market_id = request.POST.get('market_id', None) details = request.POST.get('details', None) description = request.POST.get('description', None) comment = request.POST.get('comment', None) kind = request.POST.get('kind', None) notification_type = int(request.POST.get('type', 0)) valid_types = [6, 7, 8, 10] if notification_type not in valid_types: return JsonResponse({'message': 'invalid type'}, status=400) user = request.user role = get_role(user) if role not in ['corporate', 'finance'] or (role in ['corporate', 'finance'] and kind == 'consultant'): receiver = get_user_model().objects.get(pk=user_pk) elif kind == 'market': market = Market.objects.get(pk=market_id, is_active=True) else: return JsonResponse({'message': 'invalid kind'}, status=400) if notification_type == 6: """ Direct notification """ details = "From {}".format(user.person.get_full_name()) user = get_user_model().objects.get(pk=user_pk) mail_context = { 'details': details, 'comment': comment } subject = 'New notification' send_mail_wrapper( subject, 'notifications/emails/new_notification_email.html', mail_context, [user.person.email]) elif notification_type == 7: post_id = request.POST['post_id'] post = Post.objects.get(pk=post_id) details = "From {} about the bulletin {} ".format( user.person.get_full_name(), post.title ) elif notification_type == 8: registration_id = request.POST['registration_id'] registration = Registration.objects.prefetch_related('costumer').get(pk=registration_id) details = "From {} about the {} registration notes".format( user.person.get_full_name(), registration.costumer.get_full_name() ) elif notification_type == 10: details = "From corporate" notification = Notification() notification.creator = request.user notification.type = notification_type notification.description = description notification.details = details notification.comment = comment notification.save() if role not in ['corporate', 'finance'] or (role in ['corporate', 'finance'] and kind == 'consultant'): notification_receiver = NotificationReceiver() notification_receiver.receiver = receiver notification_receiver.notification = notification notification_receiver.save() elif kind == 'market': groups = ['supervisors', 'free agents', 'consultants', 'new markets coordinator'] excluded_groups = Group.objects.exclude(name__in=groups) user_ids = get_user_model().objects.filter( groups__name__in=groups, is_active=True, consultantprofile__market=market ).exclude( groups__in=excluded_groups ).distinct().values_list('id', flat=True) bulk_receiver_creation(notification, user_ids) return JsonResponse({}, status=200) except get_user_model().DoesNotExist: return JsonResponse({'user': '******'}, status=400) except Exception as e: return JsonResponse({}, status=500)