def set_notifications_for_feed(request): user = get_user(request) feed_id = request.POST['feed_id'] notification_types = request.POST.getlist('notification_types') notification_filter = request.POST.get('notification_filter') try: notification = MUserFeedNotification.objects.get(user_id=user.pk, feed_id=feed_id) except MUserFeedNotification.DoesNotExist: params = { "user_id": user.pk, "feed_id": feed_id, } notification = MUserFeedNotification.objects.create(**params) web_was_off = not notification.is_web notification.is_focus = bool(notification_filter == "focus") notification.is_email = bool('email' in notification_types) notification.is_ios = bool('ios' in notification_types) notification.is_android = bool('android' in notification_types) notification.is_web = bool('web' in notification_types) notification.save() if (not notification.is_email and not notification.is_ios and not notification.is_android and not notification.is_web): notification.delete() r = redis.Redis(connection_pool=settings.REDIS_PUBSUB_POOL) if web_was_off and notification.is_web: r.publish(user.username, 'notification:setup:%s' % feed_id) notifications_by_feed = MUserFeedNotification.feeds_for_user(user.pk) return {"notifications_by_feed": notifications_by_feed}
def notifications_by_feed(request): user = get_user(request) notifications_by_feed = MUserFeedNotification.feeds_for_user(user.pk) return notifications_by_feed