示例#1
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
示例#2
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
示例#3
0
def pp_profile_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_profile_form POST=request.POST object=request.object %}
       Do stuff with {{ pp_profile.form }}.
    {% endpp_profile_form %}
    """

    context.push()
    namespace = get_namespace(context)

    user = kwargs.get("user", None)
    profile = kwargs.get("profile", None)
    POST = kwargs.get("POST", None)

    if POST and POST.get("form_id") == "pp_profile_form":
        if user.is_authenticated:
            if profile is not None and isinstance(profile, Profile):
                form = ProfileForm(POST, instance=profile)
            else:
                form = ProfileForm(POST)
            # new_arg = form.save(commit=False)
            if form.is_valid():
                new_profile = form.save(commit=False)
                new_profile.user = user
                new_profile.about_me = clean_html(new_profile.about_me)
                new_profile.save()
                namespace["complete"] = True
            else:
                namespace["errors"] = form.errors
    else:
        if profile is not None and isinstance(profile, Profile):
            form = ProfileForm(instance=profile)
        else:
            form = ProfileForm()

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

    return output
示例#4
0
def pp_profile_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_profile_form POST=request.POST object=request.object %}
       Do stuff with {{ pp_profile.form }}.
    {% endpp_profile_form %}
    '''

    context.push()
    namespace = get_namespace(context)

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

    if POST and POST.get("form_id") == "pp_profile_form":
        if user.is_authenticated:
            if profile is not None and isinstance(profile, Profile):
                form = ProfileForm(POST, instance=profile)
            else:
                form = ProfileForm(POST)
            #new_arg = form.save(commit=False)
            if form.is_valid():
                new_profile = form.save(commit=False)
                new_profile.user = user
                new_profile.about_me = clean_html(new_profile.about_me)
                new_profile.save()
                namespace['complete'] = True
            else:
                namespace['errors'] = form.errors
    else:
        if profile is not None and isinstance(profile, Profile):
            form = ProfileForm(instance=profile)
        else:
            form = ProfileForm()

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

    return output
示例#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
示例#6
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