def update(request, tag_id): """ Updates a Tag. URL: ^admin/tag/edit/(?P<tag_id>\d+)/$ """ variables = dict() variables['title'] = _('Edit Tag') tag = Tag.objects.get(pk=tag_id) if request.POST: try: tag_form = TagForm(request.POST) if tag_form.is_valid(): name = tag_form.cleaned_data['name'] tag.name = name tag.save() messages.success(request, _('Tag successfully updated.')) UpdateTagFilesTask.delay() return HttpResponseRedirect(reverse(admin_index)) else: messages.warning(request, _('Correct the errors bellow.')) except: messages.error(request, _('There was an error while saving the Tag.')) else: tag_form = TagForm(initial={'name': tag.name}) variables['tag'] = tag variables['tag_form'] = tag_form t = get_template('tag/admin/update.html') html = t.render(RequestContext(request, variables)) return HttpResponse(html)
def create(request): """ Saves a tag. URL: ^admin/tag/create/$ """ variables = dict() variables['title'] = _('Create new Tag') if request.POST: try: tag_form = TagForm(request.POST) if tag_form.is_valid(): name = tag_form.cleaned_data['name'] tag = Tag() tag.name = name tag.save() UpdateTagFilesTask.delay() messages.success(request, _('Tag successfully created.')) return HttpResponseRedirect(reverse(admin_index)) else: messages.warning(request, _('Correct the errors bellow.')) except: messages.error(request, _('There was an error while saving the Tag.')) else: tag_form = TagForm() variables['tag_form'] = tag_form t = get_template('tag/admin/create.html') html = t.render(RequestContext(request, variables)) return HttpResponse(html)