Esempio n. 1
0
def add_tag(request, tag_id=False, project_id=False, task_id=False):
    """
    Provides a page where tags can be
    created by the user.
    """
    if request.method == 'POST':
        postData = deepcopy(request.POST)

        if ('public' not in request.POST):
            postData['public'] = 'off'

        form = AddTagForm(postData)

        if form.is_valid():

            if (not tag_id):
                newTag = Tag()
            else:
                newTag = Tag.objects.get(id=tag_id)

            newTag.name = form.cleaned_data['name']
            newTag.description = form.cleaned_data['description']
            newTag.public = form.cleaned_data['public']
            newTag.owner = request.user

            if ('public' not in request.POST):
                newTag.public = False

            newTag.save()

            if (task_id):
                task = ProjectTask.objects.get(id=task_id)
                task.tags.add(newTag)
                task.save()
            if (project_id):
                project = Project.objects.get(id=project_id)
                project.tags.add(newTag)
                project.save()

            if ('returnUrl' in request.session):
                return HttpResponseRedirect(request.session['returnUrl'])
            else:
                return HttpResponseRedirect('/tags/' + str(newTag.id))

        else:

            pageData = {}
            pageData['form'] = form
            pageData['postTo'] = request.get_full_path()
            messages.warning(request, "Please check your inputs.")
            return render_to_response('tag_create.html', RequestContext(request, pageData))

    else:
        form = AddTagForm()
        args = {}
        args['form'] = form
        args['postTo'] = request.get_full_path()
        return render_to_response('tag_create.html', RequestContext(request, args))
Esempio n. 2
0
def list_tag(request, name, **kwargs):
    try:
        tag = Tag.objects.get(name=name)
    except:
        tag = Tag()
        tag.name = name
    queryset = SoftwareCollection.tagged.with_all(tag).filter(has_content=True)
    dictionary = {'tag': tag}
    return _list(request, 'scls/list_tag.html', queryset, dictionary, **kwargs)
Esempio n. 3
0
def list_tag(request, name, **kwargs):
    try:
        tag = Tag.objects.get(name=name)
    except:
        tag = Tag()
        tag.name = name
    queryset = SoftwareCollection.tagged.with_all(tag)
    dictionary = {'tag': tag}
    return _list(request, 'scls/list_tag.html', queryset, dictionary, **kwargs)
Esempio n. 4
0
def TagsView(request, template_name="news/tags_list.html"):

    if request.method == 'POST':

        for field in request.POST:

            region_field = field.split('_')
            tag_name = request.POST[field]

            if region_field[0] == 'tag' and tag_name != 'None':

                # What region are we dealing with?
                if region_field[1] == '0':
                    region = None  # 0 = All
                else:
                    region = Region.objects.get(id=region_field[1])

                # Get region tag if available
                if region is not None:
                    tag = list(Tag.objects.get_for_object(region))
                else:
                    tag = [
                        get_redmap_tag(),
                    ]

                if not tag:

                    # create tag if not exists
                    tag = Tag()
                    tag.name = tag_name
                    tag.save()

                elif tag[0].name != tag_name:

                    # update tag if different
                    tag[0].name = tag_name
                    tag[0].save()

                    # TODO: If we update a tag, we will need to update zinnia
                    #       entries with updated tags because the app stores
                    #       tags in a plain-text string rather than by model
                    #       association

                if region is not None:
                    # attach tag to region
                    Tag.objects.update_tags(region, tag_name + ',')

        return HttpResponseRedirect(reverse('news_tags_list'))

    return render(request, template_name)