Пример #1
0
def pp_get_root(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)
    root = kwargs.pop('object', None)
    root = get_root(root)
    namespace['root'] = root
    #except:
    #    namespace['root'] = None
    output = nodelist.render(context)
    context.pop()

    return output
Пример #2
0
def pp_get_root(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)
    root = kwargs.pop('object', None)
    root = get_root(root)
    namespace['root'] = root
    #except:
    #    namespace['root'] = None
    output = nodelist.render(context)
    context.pop()

    return output
Пример #3
0
def create_notice_email(obj_pk, ctype_pk, reply_to, link, text):
    ctype = ContentType.objects.get(pk=ctype_pk)
    obj = ctype.get_object_for_this_type(pk=obj_pk)
    try:
        profile = Profile.objects.get(user=reply_to.user)
        send_email = profile.receive_emails
    except:
        send_email = True
    content_type = ContentType.objects.get_for_model(obj)
    if reply_to is not None:
        rep_type = ContentType.objects.get_for_model(reply_to)
    else:
        rep_type = None
    user_type = ContentType.objects.get_for_model(User)
    if content_type is not user_type and rep_type is not user_type:
        path = obj.get_absolute_url()
        if str(content_type) == 'message':
            if send_email:
                    notification.send([obj.receiver], "message_received", {"from_user": obj.sender, "user_url": settings.DOMAIN + obj.sender.get_absolute_url(),
                    "notice_message": obj.sender.username  + "said<br>" + obj.description,
                    "path": settings.DOMAIN + path})
            redis_client().publish(obj.receiver, json.dumps({'message': obj.sender.username + ' said',
                'object': str(obj.description), 'type': 'message', 'object_pk': str(obj.sender.pk)}))
            text = obj.description
            link = obj.get_absolute_url()
        elif obj.user != reply_to.user:
            #redis_client().publish(cons.content_object.user.username, json.dumps({'message': 'Someone voted on', 'object': str(cons.content_object.summary), 'type': 'vote', 'object_pk': str(cons.content_object.pk)}))
            #if this notification is a comment_reply
            if str(content_type) == 'comment':
                if str(rep_type) == 'comment':
                    summ = str(reply_to.text)
                else:
                    summ = str(reply_to.summary)
                if send_email:
                        print reply_to.user.email
                        notification.send([reply_to.user], "comment_reply", {"from_user": obj.user, "user_url": settings.DOMAIN + obj.user.get_absolute_url(),
                        "notice_message": "New comment received for your " + str(rep_type) + " '" + summ + "':",
                        "reply": str(obj.text), "path": path})
                tt = str(obj.text)
                text = str(obj.user.username) + " replied to your " + str(rep_type) + "<br>" + tt
                link = obj.get_absolute_url()
                redis_client().publish(reply_to.user.username, json.dumps({'message': obj.user.username + " commented on ",
                    'object': str(summ), 'type': 'comment', 'object_pk': str(obj.pk)}))

            #if notification is an action_reply
            elif str(content_type) == 'action taken':
                if send_email:
                        notification.send([reply_to.user], "action_reply", {"from_user": obj.user, "user_url": settings.DOMAIN + obj.user.get_absolute_url(),
                        "notice_message": str(obj.user.username) + " acted on your " + str(rep_type) + " : " + str(reply_to.summary),
                        "path": settings.DOMAIN + path})

                text = str(obj.user.username) + " acted on your " + str(rep_type)
                link = reply_to.get_absolute_url()

            elif str(content_type) == 'argument':
                if send_email:
                        notification.send([reply_to.user], "argument_reply", {"from_user": obj.user, "user_url": settings.DOMAIN + obj.user.get_absolute_url(),
                        "notice_message": "New argument received for your " + str(rep_type) + " " + str(reply_to.summary),
                        "path": settings.DOMAIN + path})
                text = str(obj.user.username) + " created an argument for your " + str(rep_type)
                link = reply_to.get_absolute_url()
                #push to nodejs through redis
                redis_client().publish(reply_to.user.username, json.dumps({'message': obj.user.username + ' made an argument on',
                        'object': str(reply_to.summary), 'type': 'argument', 'object_pk': str(obj.pk)}))

            #if notification is badge_received

        #elif str(content_type) == 'badge':
        #    content_type = ContentType.objects.get_for_model(User)
        #    path = "/index.html#user/t-" + str(content_type.pk) + "/o-" + str(obj.user.pk)
        #    if send_email:
        #            notification.send([reply_to.user], "badge_received", {"from_user": obj.user,
        #        "notice_message": str(obj.user.username) + ", you've received a " + str(rep_type) + " '" + str(reply_to.dimension.name) + "':",
        #        "path": settings.DOMAIN_NAME + path})
        #    text = "you received a " + str(reply_to.dimension.name) + " badge"
        #    link = reply_to.get_absolute_url()

            #if notification is a child_reply

            #if notification is a message_received

            #if notification is support_Created

            #if notification is an argument_reply
  
    if link is not None and text is not None:
        if user_type != rep_type:
            if reply_to is None:

                notif = Notification(receiver=obj.receiver, sender=obj.sender, text=text,
                    link=link, content_type=content_type, object_pk=obj.pk, is_read=False, submit_date=datetime.datetime.now())
            else:
                notif = Notification(receiver=reply_to.user, sender=obj.user, text=text,
                    link=link, content_type=rep_type, object_pk=reply_to.pk, is_read=False, submit_date=datetime.datetime.now())
        else:
            root = get_root(obj)
            notif = Notification(receiver=reply_to, sender=obj, text=text, group=root,
                link=link, content_type=rep_type, object_pk=reply_to.pk, is_read=False, submit_date=datetime.datetime.now())
        notif.save()