Esempio n. 1
0
def add_tag(request):
    if not request.user.is_authenticated()  or not request.user.is_active:
        #needs to popup registration dialog instead
        return HttpResponse(simplejson.dumps({'FAIL':True}), #need a better non-auth error here, interferes with view
                                mimetype='application/json')

    if request.method == 'POST':
        obj_id = request.POST[u'obj']
        tag = str(request.POST[u'tag'])
        c_type = str(request.POST['c_type'])
        app_type = str(request.POST['app_type'])

        model_type = ContentType.objects.get(app_label=app_type, model=c_type)
        obj = model_type.get_object_for_this_type(pk=obj_id)

        Tag.objects.add_tag(obj, tag)
        add_group_tag.apply_async(args=[obj_id, c_type, tag])

        new_tag = Tag.objects.get(name=tag)
        try:
            relationship_event.send(sender=new_tag, obj=new_tag, parent=obj, initiator=request.user)
        except:
            pass
        results = {'linktaglist': get_link_tag_list(request.user, obj, get_links=True), 'taglist': get_recommended_tag_list(obj, get_links=True), 'FAIL': False}
        return HttpResponse(simplejson.dumps(results),
                    mimetype='application/json')
Esempio n. 2
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
Esempio n. 3
0
def pp_tag_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_tag_form POST=request.POST path=request.path object=pp-issue.issue %}
       Do stuff with {{ pp_tag.form }}.
    {% endpp_tag_form %}
    '''

    context.push()
    namespace = get_namespace(context)

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

    obj_pk = obj.content_object.pk
    ctype_pk = ContentType.objects.get_for_model(obj.content_object).pk

    #obj = Consensus.objects.get(object_pk=content_obj.pk)
    if POST and POST.get("form_id") == "pp_tag_form":

        if tag != None:
            Tag.objects.add_tag(obj, tag.name)
        else:
            form = TagForm(POST)
            #new_arg = form.save(commit=False)
            if form.is_valid():
                tag_list = form.cleaned_data['tag'].split(',')
                for t in tag_list:
                    if len(t) > 0:
                        clean_tag = clean_html(t.replace(' ', '-'))
                        if len(str(clean_tag)) < 32:
                            Tag.objects.add_tag(obj, clean_tag)
                            tag = TaggedItem._default_manager.get(
                                tag_name=clean_tag, object_id=obj.pk)
                            new_tag = tag.tag
                            try:
                                add_group_tag.apply_async(
                                    args=[obj_pk, ctype_pk, clean_tag])
                                relationship_event.send(sender=new_tag,
                                                        obj=new_tag,
                                                        parent=obj,
                                                        initiator=user)
                                form = TagForm()
                            except:
                                namespace[
                                    'errors'] = "You've already used that tag for this object"
                        else:
                            namespace[
                                'errors'] = clean_tag + " invalid.<br>Tags cannot be longer than 32 characters."
        #raise HttpRedirectException(HttpResponseRedirect(obj.content_object.get_absolute_url()))
    else:
        form = TagForm()
    namespace['form'] = form
    output = nodelist.render(context)
    context.pop()
    return output
Esempio n. 4
0
def pp_tag_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_tag_form POST=request.POST path=request.path object=pp-issue.issue %}
       Do stuff with {{ pp_tag.form }}.
    {% endpp_tag_form %}
    '''

    context.push()
    namespace = get_namespace(context)

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

    obj_pk = obj.content_object.pk
    ctype_pk = ContentType.objects.get_for_model(obj.content_object).pk

    #obj = Consensus.objects.get(object_pk=content_obj.pk)
    if POST and POST.get("form_id") == "pp_tag_form":

        if tag != None:
            Tag.objects.add_tag(obj, tag.name)
        else:
            form = TagForm(POST)
            #new_arg = form.save(commit=False)
            if form.is_valid():
                tag_list = form.cleaned_data['tag'].split(',')
                for t in tag_list:
                    if len(t) > 0:
                        clean_tag = clean_html(t.replace(' ', '-'))
                        if len(str(clean_tag)) < 32:
                            Tag.objects.add_tag(obj, clean_tag)
                            tag = TaggedItem._default_manager.get(tag_name=clean_tag, object_id=obj.pk)
                            new_tag = tag.tag
                            try:
                                add_group_tag.apply_async(args=[obj_pk, ctype_pk, clean_tag])
                                relationship_event.send(sender=new_tag, obj=new_tag, parent=obj, initiator=user)
                                form = TagForm()
                            except:
                                namespace['errors'] = "You've already used that tag for this object"
                        else:
                            namespace['errors'] = clean_tag + " invalid.<br>Tags cannot be longer than 32 characters."
        #raise HttpRedirectException(HttpResponseRedirect(obj.content_object.get_absolute_url()))
    else:
        form = TagForm()
    namespace['form'] = form
    output = nodelist.render(context)
    context.pop()
    return output
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 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