Example #1
0
def oa_actiontaken_form(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)

    POST = kwargs.get('POST', None)
    obj = kwargs.get('object', None)
    user = kwargs.get('user', None)

    content_type = ContentType.objects.get_for_model(obj)
    path = 'detail.html' + "?_t=" + str(content_type.pk) + "&_o=" + str(obj.pk)

    if POST:
        form = ActionTakenForm(POST)
        if form.is_valid():
            newobj = form.save(commit=False)
            newobj.user = user
            newobj.content_type = content_type
            newobj.object_pk = obj.pk
            newobj.save()
            notification_send.send(sender=newobj, obj=newobj, reply_to=obj)
            relationship_event.send(sender=newobj, obj=newobj, parent=obj)

            #raise HttpRedirectException(HttpResponseRedirect(path))
        else:
            namespace['errors'] = form.errors

    form = ActionTakenForm()

    namespace['form'] = form
    output = nodelist.render(context)
    context.pop()

    return output
Example #2
0
def check_badges(user, model, obj):
    new_badges = []
    ctype = ContentType.objects.get_for_model(model)
    dims = BadgeDimension.objects.filter(content_type=ctype)
    for bd in dims:
        try: b = Badge.objects.get(user=user,dimension=bd)
        except:
            savebadge = test_badge(obj, bd)
            if savebadge:
                b = Badge(user=user,dimension=bd, badge_type_id=bd.badge_type.id)
                b.save()
                notification_send.send(sender=b,obj=b,reply_to=b)
Example #3
0
def check_badges(user, model, obj):
    new_badges = []
    ctype = ContentType.objects.get_for_model(model)
    dims = BadgeDimension.objects.filter(content_type=ctype)
    for bd in dims:
        try:
            b = Badge.objects.get(user=user, dimension=bd)
        except:
            savebadge = test_badge(obj, bd)
            if savebadge:
                b = Badge(user=user,
                          dimension=bd,
                          badge_type_id=bd.badge_type.id)
                b.save()
                notification_send.send(sender=b, obj=b, reply_to=b)
Example #4
0
def pp_message_form(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)

    sender = kwargs.get('sender', None)
    receiver = kwargs.get('receiver', None)
    POST = kwargs.get('POST', None)

    if ContentType.objects.get_for_model(
            receiver) == ContentType.objects.get_for_model(Message):
        namespace['reply'] = receiver.description
        namespace['user'] = receiver.sender
    else:
        namespace['reply'] = None
        namespace['user'] = receiver

    if POST and POST.get("form_id") == "pp_message_form":
        form = MessageForm(POST)
        if form.is_valid():
            mes = form.save(commit=False)
            mes.sender = sender
            mes.receiver = namespace['user']
            mes.read = False
            mes.save()
            #raise HttpRedirectException(HttpResponseRedirect(receiver.get_absolute_url()))
            form = MessageForm()
            namespace['complete'] = True
            notification_send.send(sender=mes.sender,
                                   obj=mes,
                                   reply_to=namespace['reply'])

    else:
        form = MessageForm()

    namespace['form'] = form
    namespace['errors'] = form.errors

    output = nodelist.render(context)
    context.pop()

    return output
Example #5
0
def pp_message_form(context, nodelist, *args, **kwargs):

    context.push()
    namespace = get_namespace(context)

    sender = kwargs.get('sender', None)
    receiver = kwargs.get('receiver', None)
    POST = kwargs.get('POST', None)

    if ContentType.objects.get_for_model(receiver) == ContentType.objects.get_for_model(Message):
        namespace['reply'] = receiver.description
        namespace['user'] = receiver.sender
    else:
        namespace['reply'] = None
        namespace['user'] = receiver

    if POST and POST.get("form_id") == "pp_message_form":
        form = MessageForm(POST)
        if form.is_valid():
            mes = form.save(commit=False)
            mes.sender = sender
            mes.receiver = namespace['user']
            mes.read = False
            mes.save()
            #raise HttpRedirectException(HttpResponseRedirect(receiver.get_absolute_url()))
            form = MessageForm()
            namespace['complete'] = True
            notification_send.send(sender=mes.sender, obj=mes, reply_to=namespace['reply'])

    else:
        form = MessageForm()

    namespace['form'] = form
    namespace['errors'] = form.errors

    output = nodelist.render(context)
    context.pop()

    return output
Example #6
0
def oa_ver_form(context, nodelist, *args, **kwargs):
    '''form_id = forms.CharField(widget=forms.HiddenInput(), initial="pp_arpv_form")
    This block tag creates instances of anonymous photo verification tags, and makes sure
    that the users exist, they are not the same, and
    Usage is as follows:

    {% pp_arpv_form POST=request.POST user=request.user%}
       Do stuff with {{ pp_arpv.form }}.
    {% endpp_arpv_form%}
    '''
    context.push()
    namespace = get_namespace(context)

    user = kwargs.get('user', None)
    POST = kwargs.get('POST', None)
    FILE = kwargs.get('FILE', None)

    ctype = ContentType.objects.get_for_model(user)
    if POST:
        form = arpvForm(POST, FILE)
        if form.is_valid():
            try:
                userobj1 = User.objects.get(username=form.cleaned_data.get('user1'))
                test1 = True
            except:
                test1 = False
            try:
                userobj2 = User.objects.get(username=form.cleaned_data.get('user2'))
                test2 = True
            except:
                test2 = False
            if userobj1 == userobj2:
                namespace['errors'] = 'The users are the same'
            elif not test1:
                namespace['errors'] = 'User1 does not Exist'
            elif not test2:
                namespace['errors'] = 'User2 does not Exist'
            elif not test1 and not test2:
                namespace['errors'] = 'Neither User Exists'
            else:
                photo = form.cleaned_data['photo']
                temp = arpv(user1=userobj1, user2=userobj2, photo=photo)
                temp.submit_user = user
                #if the submit user is one of the photo users, this should be normal
                if temp.submit_user == userobj1:
                    temp.user1Confirm = True
                elif temp.submit_user == userobj2:
                    temp.user2Confirm = True
                temp.created_dt = datetime.datetime.now()
                temp.save()
                #now that we have saved the arpv, send out notifications for confirmation
                if not temp.user1Confirm:
                    link = temp.get_absolute_url()
                    text = 'Click Here to Confirm a Photo of You from ' + str(user.username)
                    notification_send.send(sender=temp, obj=user, reply_to=userobj1, link=link, text=text)
                if not temp.user2Confirm:
                    link = temp.get_absolute_url()
                    text = 'Click Here to Confirm a Photo of You from ' + str(user.username)
                    notification_send.send(sender=temp, obj=user, reply_to=userobj2, link=link, text=text)
                #raise HttpRedirectException(HttpResponseRedirect(returnurl))
                form = arpvForm()
                if user is not None:
                    arpvs = arpv.objects.filter(submit_user=user)
                namespace['photo_ids'] = [i.photo.pk for i in arpvs]
                form.fields['photo'].queryset = IMGSource.objects.filter(object_pk=user.pk, content_type=ctype)
                namespace['arpvs'] = arpvs
            namespace['form'] = form
        else:
            namespace['errors'] = 'Invalid Entry. Make Sure You Have Selected a Photo and 2 Users'
            form = arpvForm()
            form.fields['photo'].queryset = IMGSource.objects.filter(object_pk=user.pk, content_type=ctype)
    else:
        #if user is not None:
        form = arpvForm()
        form.fields['photo'].queryset = IMGSource.objects.filter(object_pk=user.pk, content_type=ctype)
    namespace['form'] = form
    output = nodelist.render(context)
    context.pop()

    return output
Example #7
0
def pp_comment_form(context, nodelist, *args, **kwargs):
    '''
    This block tag can create or process forms either to create or to modify issues.
    Usage is as follows:

    {% pp_comment_form POST=request.POST object=request.object user=request.user %}
       Do stuff with {{ pp-comment.form }}.
    {% endpp_comment_form %}
    '''

    context.push()
    namespace = get_namespace(context)

    POST = kwargs.get('POST', None)
    reply_to = kwargs.get('object', None)
    user = kwargs.get('user', None)
    comment = kwargs.get('edit', None)

    if comment is not None:
        if POST and POST.get("form_id") == "pp_edit_form":
            form = CommentForm(POST, instance=comment)
            if form.is_valid():
                comment.text = clean_html(form.cleaned_data['text'])
                comment.save()
        else:
            form = CommentForm(instance=comment)

        namespace['object_pk'] = comment.pk
        namespace['content_type'] = ContentType.objects.get_for_model(comment).pk

    elif POST and POST.get("form_id") == "pp_comment_form":
        form = CommentForm(POST) if comment is None else CommentForm(POST, instance=comment)
        if form.is_valid():
                newcomment = form.save(commit=False)
                newcomment.user = user
                c_type = ContentType.objects.get_for_model(reply_to.__class__)
                newcomment.content_type = c_type
                newcomment.object_pk = reply_to.pk
                newcomment.text = clean_html(newcomment.text)
                newcomment.reply_to = None
                newcomment.is_leaf = True
                newcomment.submit_date = datetime.datetime.now()
                newcomment.is_root = True
                newcomment.save()
                namespace['object_pk'] = newcomment.pk
                namespace['content_type'] = ContentType.objects.get_for_model(newcomment).pk
                cvt = ContentType.objects.get_for_model(UpDownVote)
                #cons, is_new = Consensus.objects.get_or_create(content_type=c_type,
                #                    object_pk=newcomment.pk,
                #                    vote_type=cvt,
                #                    parent_pk=reply_to.pk)
                notification_send.send(sender=newcomment, obj=newcomment, reply_to=newcomment.content_object)
                relationship_event.send(sender=newcomment, obj=newcomment, parent=newcomment.content_object)
                aso_rep_event.send(sender=newcomment.user, event_score=1, user=newcomment.content_object.user,
                    initiator=newcomment.user, dimension=ReputationDimension.objects.get("comment"), related_object=newcomment)
            #raise HttpRedirectException(HttpResponseRedirect(newcomment.get_absolute_url()))
                form = CommentForm()
        else:
            namespace['errors'] = form.errors

    elif POST and POST.get("form_id") == "pp_reply_form":
        form = ReplyForm(POST) if comment is None else ReplyForm(POST, instance=comment)
        if form.is_valid():
            newcomment = form.save(commit=False)
            newcomment.user = user
            newcomment.content_type = reply_to.content_type
            newcomment.object_pk = reply_to.object_pk
            newcomment.reply_to = Comment.objects.get(pk=reply_to.pk)
            newcomment.reply_to.is_leaf = False
            newcomment.reply_to.save()
            newcomment.text = clean_html(newcomment.text)
            newcomment.is_leaf = True
            newcomment.is_root = False
            newcomment.submit_date = datetime.datetime.now()
            newcomment.save()
            namespace['object_pk'] = newcomment.pk
            namespace['content_type'] = ContentType.objects.get_for_model(newcomment).pk
            cvt = ContentType.objects.get_for_model(UpDownVote)
            #cons, is_new = Consensus.objects.get_or_create(content_type=reply_to.content_type,
            #                        object_pk=newcomment.pk,
            #                        vote_type=cvt,
            #                        parent_pk=reply_to.object_pk)
            if comment is None:
                #if comment is new and not editted
                notification_send.send(sender=newcomment, obj=newcomment, reply_to=newcomment.reply_to)
                relationship_event.send(sender=newcomment, obj=newcomment, parent=newcomment.reply_to)
                aso_rep_event.send(sender=newcomment.user, event_score=1, user=newcomment.reply_to.user,
                    initiator=newcomment.user, dimension=ReputationDimension.objects.get("comment"), related_object=newcomment)
        #raise HttpRedirectException(HttpResponseRedirect(newcomment.get_absolute_url()))
        form = CommentForm()
    else:
        form = CommentForm() if comment is None else CommentForm(instance=comment)

    namespace['form'] = form
    output = nodelist.render(context)
    context.pop()

    return output
Example #8
0
def pp_argument_form(context, nodelist, *args, **kwargs):
    '''
    This block tag can create or process forms either to create or to modify arguments.
    Usage is as follows:

    {% pp_argument_form POST=request.POST path=request.path object=pp-issue.issue arg = pp_argumentation.argument%}
       Do stuff with {{ pp_argumentation.form }}.
    {% endpp_argument_form %}
    '''

    context.push()
    namespace = get_namespace(context)

    POST = kwargs.get('POST', None)
    obj = kwargs.get('object', None)
    arg_type = kwargs.get('dimension', None)
    user = kwargs.get('user', None)

    #arg_type = ARG_TYPES_DICT[arg_type]
    #stance, created = Stance.objects.get_or_create(arg=arg_type)

    if isinstance(obj, Argument):
        arg = obj
        parent = arg.parent
    else:
        arg, parent = (None, obj)
    form = None
    if POST and user != None:
        if POST.get("form_id") == "pp_argument_form_nay":
            stance, created = Stance.objects.get_or_create(arg='nay')
            form = NayArgumentForm(POST)
        if POST.get("form_id") == "pp_argument_form_yea":
            stance, created = Stance.objects.get_or_create(arg='yea')
            form = YeaArgumentForm(POST)
        if POST.get("form_id") == "pp_argument_form_yea" or POST.get("form_id") == "pp_argument_form_nay":
            if form.is_valid():
                new_arg = form.save(commit=False)
                new_arg.stance = stance
                new_arg.user = user
                #new_arg.description = urlize(new_arg.description, trim_url_limit=30, nofollow=True)
                new_arg.parent_type = ContentType.objects.get_for_model(parent)
                new_arg.parent_pk = parent.id
                new_arg.save()
                namespace['object_pk'] = new_arg.pk
                namespace['content_type'] = ContentType.objects.get_for_model(new_arg).pk
                cons, is_new = Consensus.objects.get_or_create(content_type=ContentType.objects.get_for_model(Argument),
                                                               object_pk=new_arg.pk, parent_pk=new_arg.parent_pk)

                if is_new:
                    cons.intiate_vote_distributions()
                    #if this is a new issue/consensus, send signal for reputation
                    aso_rep_event.send(sender=new_arg, event_score=4, user=new_arg.user, initiator=new_arg.user, dimension=ReputationDimension.objects.get('Argument'), related_object=new_arg)
                    notification_send.send(sender=new_arg.user, obj=new_arg, reply_to=parent)
                    relationship_event.send(sender=new_arg.user, obj=new_arg, parent=parent)

                #raise HttpRedirectException(HttpResponseRedirect(new_arg.get_absolute_url()))
                if arg_type == 'n':
                    form = NayArgumentForm()
                if arg_type == 'y':
                    form = YeaArgumentForm()
            else:
                namespace['errors'] = form.errors
    else:
        if arg_type == 'n':
            form = NayArgumentForm()
        if arg_type == 'y':
            form = YeaArgumentForm()

    namespace['help_text'] = 'Supply a ' + str(arg_type) + ' Argument for your position.'
    namespace['form'] = form
    output = nodelist.render(context)
    context.pop()
    return output
Example #9
0
def pp_comment_form(context, nodelist, *args, **kwargs):
    '''
    This block tag can create or process forms either to create or to modify issues.
    Usage is as follows:

    {% pp_comment_form POST=request.POST object=request.object user=request.user %}
       Do stuff with {{ pp-comment.form }}.
    {% endpp_comment_form %}
    '''

    context.push()
    namespace = get_namespace(context)

    POST = kwargs.get('POST', None)
    reply_to = kwargs.get('object', None)
    user = kwargs.get('user', None)
    comment = kwargs.get('edit', None)

    if comment is not None:
        if POST and POST.get("form_id") == "pp_edit_form":
            form = CommentForm(POST, instance=comment)
            if form.is_valid():
                comment.text = clean_html(form.cleaned_data['text'])
                comment.save()
        else:
            form = CommentForm(instance=comment)

        namespace['object_pk'] = comment.pk
        namespace['content_type'] = ContentType.objects.get_for_model(comment).pk

    elif POST and POST.get("form_id") == "pp_comment_form":
        form = CommentForm(POST) if comment is None else CommentForm(POST, instance=comment)
        if form.is_valid():
                newcomment = form.save(commit=False)
                newcomment.user = user
                c_type = ContentType.objects.get_for_model(reply_to.__class__)
                newcomment.content_type = c_type
                newcomment.object_pk = reply_to.pk
                newcomment.text = clean_html(newcomment.text)
                newcomment.reply_to = None
                newcomment.is_leaf = True
                newcomment.submit_date = datetime.datetime.now()
                newcomment.is_root = True
                newcomment.save()
                namespace['object_pk'] = newcomment.pk
                namespace['content_type'] = ContentType.objects.get_for_model(newcomment).pk
                cvt = ContentType.objects.get_for_model(UpDownVote)
                #cons, is_new = Consensus.objects.get_or_create(content_type=c_type,
                #                    object_pk=newcomment.pk,
                #                    vote_type=cvt,
                #                    parent_pk=reply_to.pk)
                notification_send.send(sender=newcomment, obj=newcomment, reply_to=newcomment.content_object)
                relationship_event.send(sender=newcomment, obj=newcomment, parent=newcomment.content_object)
                aso_rep_event.send(sender=newcomment.user, event_score=1, user=newcomment.content_object.user,
                    initiator=newcomment.user, dimension=ReputationDimension.objects.get("comment"), related_object=newcomment)
            #raise HttpRedirectException(HttpResponseRedirect(newcomment.get_absolute_url()))
                form = CommentForm()
        else:
            namespace['errors'] = form.errors

    elif POST and POST.get("form_id") == "pp_reply_form":
        form = ReplyForm(POST) if comment is None else ReplyForm(POST, instance=comment)
        if form.is_valid():
            newcomment = form.save(commit=False)
            newcomment.user = user
            newcomment.content_type = reply_to.content_type
            newcomment.object_pk = reply_to.object_pk
            newcomment.reply_to = Comment.objects.get(pk=reply_to.pk)
            newcomment.reply_to.is_leaf = False
            newcomment.reply_to.save()
            newcomment.text = clean_html(newcomment.text)
            newcomment.is_leaf = True
            newcomment.is_root = False
            newcomment.submit_date = datetime.datetime.now()
            newcomment.save()
            namespace['object_pk'] = newcomment.pk
            namespace['content_type'] = ContentType.objects.get_for_model(newcomment).pk
            cvt = ContentType.objects.get_for_model(UpDownVote)
            #cons, is_new = Consensus.objects.get_or_create(content_type=reply_to.content_type,
            #                        object_pk=newcomment.pk,
            #                        vote_type=cvt,
            #                        parent_pk=reply_to.object_pk)
            if comment is None:
                #if comment is new and not editted
                notification_send.send(sender=newcomment, obj=newcomment, reply_to=newcomment.reply_to)
                relationship_event.send(sender=newcomment, obj=newcomment, parent=newcomment.reply_to)
                aso_rep_event.send(sender=newcomment.user, event_score=1, user=newcomment.reply_to.user,
                    initiator=newcomment.user, dimension=ReputationDimension.objects.get("comment"), related_object=newcomment)
        #raise HttpRedirectException(HttpResponseRedirect(newcomment.get_absolute_url()))
        form = CommentForm()
    else:
        form = CommentForm() if comment is None else CommentForm(instance=comment)

    namespace['form'] = form
    output = nodelist.render(context)
    context.pop()

    return output