Added tag editing view and listing documents with an specific tag

This commit is contained in:
Roberto Rosario
2011-04-28 21:30:37 -04:00
parent 2532a0a2d8
commit 675bdd6112
13 changed files with 271 additions and 137 deletions

View File

@@ -365,7 +365,7 @@ class MetaDataImageWidget(forms.widgets.Widget):
output.append(u'<div style="white-space:nowrap; overflow: auto;">')
for document in value['group_data']:
tags_template = []
tag_block_template = u'<div style="padding: 1px; border: 1px solid black; background: %s;">%s</div>'
tag_block_template = u'<div style="padding: 0px 5px 0px 5px; border: 1px solid black; background: %s;">%s</div>'
tag_count = document.tags.count()
if tag_count:
tags_template.append(u'<div class="tc">')

View File

@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-04-28 00:37-0400\n"
"POT-Creation-Date: 2011-04-28 21:29-0400\n"
"PO-Revision-Date: 2011-04-28 00:17\n"
"Last-Translator: Roberto Rosario <rosario_r@jp.pr.gov>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -195,11 +195,11 @@ msgstr "Documentos"
msgid "thumbnail"
msgstr "miniatura"
#: __init__.py:136 views.py:295 views.py:852
#: __init__.py:136 views.py:297 views.py:846
msgid "metadata"
msgstr "metadatos"
#: __init__.py:143 __init__.py:149 models.py:65 views.py:76
#: __init__.py:143 __init__.py:149 models.py:65 views.py:74
msgid "documents"
msgstr "documentos"
@@ -268,15 +268,15 @@ msgstr "paso 2 de 2: Metadatos de documento"
msgid "Tags"
msgstr "Etiquetas"
#: forms.py:406 views.py:277
#: forms.py:402 views.py:274
msgid "Pages"
msgstr "Páginas"
#: forms.py:407
#: forms.py:403
msgid "Select"
msgstr "Seleccionar"
#: forms.py:416
#: forms.py:412
msgid "Click on the image for full size view of the first page."
msgstr "Haga clic en la imagen para ver la primera página en tamaño completo"
@@ -309,7 +309,7 @@ msgid "description"
msgstr "descripción"
#: models.py:64 models.py:238 models.py:265 models.py:436 models.py:450
#: views.py:383
#: views.py:373
msgid "document"
msgstr "documento"
@@ -398,7 +398,7 @@ msgstr "índices de metadatos"
msgid "metadata value"
msgstr "datos de metadato"
#: models.py:246 models.py:247 views.py:91
#: models.py:246 models.py:247 views.py:88
msgid "document metadata"
msgstr "metadatos de documento"
@@ -570,15 +570,15 @@ msgstr "artículo de grupo de documentos"
msgid "group items"
msgstr "artículos de grupos de documentos"
#: models.py:411 views.py:668
#: models.py:411 views.py:658
msgid "order"
msgstr "orden"
#: models.py:412 views.py:669 views.py:709
#: models.py:412 views.py:659 views.py:699
msgid "transformation"
msgstr "transformación"
#: models.py:413 views.py:670
#: models.py:413 views.py:660
msgid "arguments"
msgstr "argumentos"
@@ -607,7 +607,7 @@ msgstr "accesado"
msgid "recent document"
msgstr "documento reciente"
#: models.py:447 views.py:1041
#: models.py:447 views.py:1023
msgid "recent documents"
msgstr "documentos recientes"
@@ -659,223 +659,215 @@ msgstr "Páginas de documentos en la base de datos: %d"
msgid "Document statistics"
msgstr "Estadísticas de documentos"
#: views.py:150
#: views.py:147
#, python-format
msgid "Extracted file: %s, uploaded successfully."
msgstr "Archivo extraido: %s, ha subido con éxito."
#: views.py:176
#: views.py:173
msgid "Document uploaded successfully."
msgstr "Documento subido con éxito."
#: views.py:194
#: views.py:191
#, python-format
msgid "Staging file: %s, uploaded successfully."
msgstr "Archivo de ensayo: %s, ha subido con éxito."
#: views.py:198
#: views.py:195
#, python-format
msgid "Staging file: %s, deleted successfully."
msgstr "Archivo de ensayo: %s, eliminado con éxito."
#: views.py:212
#: views.py:209
msgid "upload a local document"
msgstr "subir un documento local"
#: views.py:230
#: views.py:227
msgid "files in staging"
msgstr "archivos de ensayo"
#: views.py:239
#: views.py:236
msgid "upload a document from staging"
msgstr "subir un documento de ensayo"
#: views.py:248
#: views.py:245
msgid "Current metadata"
msgstr "metadatos actuales"
#: views.py:266
#: views.py:263
msgid "Filename"
msgstr "Nombre del archivo"
#: views.py:267
#: views.py:264
msgid "File extension"
msgstr "Extensión de archivo"
#: views.py:268
#: views.py:265
msgid "File mimetype"
msgstr "Tipo MIME del archivo"
#: views.py:269
#: views.py:266
msgid "File mime encoding"
msgstr "Codificación de archivos MIME"
#: views.py:270
#: views.py:267
msgid "File size"
msgstr "Tamaños del archivo"
#: views.py:271
#: views.py:268
msgid "Exists in storage"
msgstr "Existe en el almacenamiento"
#: views.py:272
#: views.py:269
msgid "File path in storage"
msgstr "Ruta de archivos en el almacenamiento"
#: views.py:273
#: views.py:270
msgid "Date added"
msgstr "Fecha en que se agregó"
#: views.py:274
#: views.py:271
msgid "Time added"
msgstr "El tiempo añadido"
#: views.py:275
#: views.py:272
msgid "Checksum"
msgstr "Suma de comprobación"
#: views.py:276
#: views.py:273
msgid "UUID"
msgstr "UUID"
#: views.py:287 views.py:843
#: views.py:284 views.py:833
msgid "document properties"
msgstr "propiedades del documento"
#: views.py:297 views.py:854
#: views.py:299 views.py:848
msgid "value"
msgstr "valor"
#: views.py:305 views.py:862
#: views.py:307 views.py:856
#, python-format
msgid "Document group query error: %s"
msgstr "Drror de consulta de grupo de documentos: %s"
#: views.py:315 views.py:872
#: views.py:317 views.py:866
#, python-format
msgid "document groups (%s)"
msgstr "grupo de documentos (%s)"
#: views.py:328 views.py:888
msgid "tags"
msgstr "etiquetas"
#: views.py:331 views.py:891
msgid "color"
msgstr "color"
#: views.py:340
#: views.py:330
msgid "index links"
msgstr "enlaces de índice"
#: views.py:363 views.py:467 views.py:787
#: views.py:353 views.py:457 views.py:777
msgid "Must provide at least one document."
msgstr "Debe proveer al menos un documento."
#: views.py:374
#: views.py:364
#, python-format
msgid "Document: %s deleted successfully."
msgstr "Documento: %s eliminado con éxito."
#: views.py:376
#: views.py:366
#, python-format
msgid "Document: %(document)s delete error: %(error)s"
msgstr "Documento: %(document)s, error de eliminación: %(error)s "
#: views.py:390
#: views.py:380
#, python-format
msgid "Are you sure you wish to delete the document: %s?"
msgstr "¿Está seguro que desea eliminar el documento: %s?"
#: views.py:392
#: views.py:382
#, python-format
msgid "Are you sure you wish to delete the documents: %s?"
msgstr "¿Está seguro que desea eliminar los documentos: %s?"
#: views.py:431
#: views.py:421
#, python-format
msgid "Document %s edited successfully."
msgstr "Documento %s editado con éxito."
#: views.py:440
#: views.py:430
msgid "Document filesystem links updated successfully."
msgstr "Enlaces del documento actualizados con éxito."
#: views.py:464
#: views.py:454
msgid "All documents must be from the same type."
msgstr "Todos los documentos deben ser del mismo tipo."
#: views.py:499
#: views.py:489
#, python-format
msgid "Error deleting filesystem links for document: %(document)s; %(error)s"
msgstr ""
"Error al eliminar los enlaces del sistema de archivos para el documento: "
"%(document)s; %(error)s "
#: views.py:502
#: views.py:492
#, python-format
msgid "Metadata for document %s edited successfully."
msgstr "Metadatos para documento %s editado con éxito."
#: views.py:511
#: views.py:501
#, python-format
msgid "Filesystem links updated successfully for document: %s."
msgstr ""
"Enlaces del sistema de archivos actualizados con éxito para el documento: %s."
#: views.py:513
#: views.py:503
#, python-format
msgid "Error creating filesystem links for document: %(document)s; %(error)s"
msgstr ""
"Error al crear vínculos de sistema de archivos para el documento: "
"%(document)s; %(error)s "
#: views.py:527
#: views.py:517
#, python-format
msgid "Edit metadata for document: %s"
msgstr "Editar de metadatos para el documento: %s"
#: views.py:529
#: views.py:519
#, python-format
msgid "Edit metadata for documents: %s"
msgstr "Editar metadatos para los documentos: %s"
#: views.py:551
#: views.py:541
#, python-format
msgid "Page transformation error: %s"
msgstr "Error de transformación de página: %s"
#: views.py:612
#: views.py:602
#, python-format
msgid "Staging file transformation error: %(error)s"
msgstr "Error de transformación de archivo de ensayo: %(error)s "
#: views.py:641
#: views.py:631
msgid "Staging file delete successfully."
msgstr "Archivo de ensayo eliminado con éxito."
#: views.py:665
#: views.py:655
#, python-format
msgid "transformations for: %s"
msgstr "transformaciones para: %s"
#: views.py:694
#: views.py:684
#, python-format
msgid "Create new transformation for page: %(page)s of document: %(document)s"
msgstr ""
"Crear nueva transformación de la página: %(page)s del documento: "
"%(document)s "
#: views.py:710
#: views.py:700
#, python-format
msgid "Edit transformation \"%(transformation)s\" for: %(document_page)s"
msgstr "Editar transformación \" %(transformation)s\" para: %(document_page)s"
#: views.py:731 views.py:807
#: views.py:721 views.py:797
msgid "document transformation"
msgstr "transformación de documento"
#: views.py:732
#: views.py:722
#, python-format
msgid ""
"Are you sure you wish to delete transformation \"%(transformation)s\" for: "
@@ -884,17 +876,17 @@ msgstr ""
"¿Está seguro que desea eliminar la transformación \"%(transformation)s\" "
"para: %(document_page)s"
#: views.py:753 views.py:913
#: views.py:743 views.py:895
msgid "On large databases this operation may take some time to execute."
msgstr ""
"En bases de datos de gran tamaño esta operación puede tardar algún tiempo en "
"ejecutarse."
#: views.py:767
#: views.py:757
msgid "duplicated documents"
msgstr "documentos duplicados"
#: views.py:799
#: views.py:789
#, python-format
msgid ""
"All the page transformations for document: %s, have been deleted "
@@ -903,7 +895,7 @@ msgstr ""
"Todas las transformaciones de la página de documento: %s, se han eliminado "
"con éxito."
#: views.py:801
#: views.py:791
#, python-format
msgid ""
"Error deleting the page transformations for document: %(document)s; "
@@ -912,7 +904,7 @@ msgstr ""
"Error al eliminar las transformaciones de página para el documento: "
"%(document)s; %(error)s."
#: views.py:815
#: views.py:805
#, python-format
msgid ""
"Are you sure you wish to clear all the page transformations for document: %s?"
@@ -920,7 +912,7 @@ msgstr ""
"¿Está seguro que desea eliminar todas las transformaciones de página del "
"documento: %s?"
#: views.py:817
#: views.py:807
#, python-format
msgid ""
"Are you sure you wish to clear all the page transformations for documents: "
@@ -929,37 +921,37 @@ msgstr ""
"¿Está seguro que desea eliminar las transformaciones de página de los "
"documentos: %s?"
#: views.py:923
#: views.py:905
msgid "missing documents"
msgstr "documentos perdidos"
#: views.py:939 views.py:958
#: views.py:921 views.py:940
#, python-format
msgid "details for: %s"
msgstr "detalles para: %s"
#: views.py:979
#: views.py:961
msgid "Document page edited successfully."
msgstr "Página del documento se ha editado correctamente."
#: views.py:987
#: views.py:969
#, python-format
msgid "edit: %s"
msgstr "editar: %s"
#: views.py:998
#: views.py:980
msgid "There are no more pages in this document"
msgstr "No hay más páginas en este documento"
#: views.py:1011
#: views.py:993
msgid "You are already at the first page of this document"
msgstr "Usted ya está en la primera página de este documento"
#: views.py:1109
#: views.py:1091
msgid "No action selected."
msgstr "Ninguna acción seleccionada."
#: views.py:1125
#: views.py:1107
#, python-format
msgid "documents in group: %(group)s, for document: %(document)s"
msgstr "grupo de documentos: %(group)s, para el documento: %(document)s "
@@ -968,6 +960,12 @@ msgstr "grupo de documentos: %(group)s, para el documento: %(document)s "
msgid "Rotate [degrees]"
msgstr "Rotar [degrees]"
#~ msgid "tags"
#~ msgstr "etiquetas"
#~ msgid "color"
#~ msgstr "color"
#~ msgid "metadata groups (%s)"
#~ msgstr "grupos de metadatos (%s)"

View File

@@ -66,19 +66,15 @@ PICTURE_UNKNOWN_SMALL = u'1299549572_unknown2.png'
PICTURE_UNKNOWN_MEDIUM = u'1299549805_unknown.png'
def document_list(request):
def document_list(request, object_list=None, title=None):
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW])
return object_list(
request,
queryset=Document.objects.only('file_filename', 'file_extension').all(),
template_name='generic_list.html',
extra_context={
'title': _(u'documents'),
'multi_select_as_buttons': True,
'hide_links': True,
},
)
return render_to_response('generic_list.html', {
'object_list': object_list if object_list else Document.objects.only('file_filename', 'file_extension').all(),
'title': title if title else _(u'documents'),
'multi_select_as_buttons': True,
'hide_links': True,
}, context_instance=RequestContext(request))
def document_create(request, multiple=True):

View File

@@ -130,6 +130,17 @@ def _get_object_navigation_links(context, menu_name=None, links_dict=object_navi
current_view = resolve_to_name(current_path)
context_links = []
try:
"""
Override the navigation links dictionary with the provided
link list
"""
navigation_object_links = Variable('navigation_object_links').resolve(context)
if navigation_object_links:
return navigation_object_links
except VariableDoesNotExist:
pass
try:
object_name = Variable('navigation_object_name').resolve(context)
except VariableDoesNotExist:
@@ -139,12 +150,6 @@ def _get_object_navigation_links(context, menu_name=None, links_dict=object_navi
obj = Variable(object_name).resolve(context)
except VariableDoesNotExist:
obj = None
try:
navigation_object_links = Variable('navigation_object_links').resolve(context)
links_dict = navigation_object_links if navigation_object_links else object_navigation
except VariableDoesNotExist:
pass
try:
links = links_dict[menu_name][current_view]['links']

View File

@@ -24,9 +24,23 @@ register_permissions('tags', [
tag_list = {'text': _('tags'), 'view': 'tag_list', 'famfam': 'tag_blue'}
tag_document_remove = {'text': _('delete'), 'view': 'tag_remove', 'args': ['object.id', 'document.id'], 'famfam': 'tag_blue_delete', 'permissions': {'namespace': 'tags', 'permissions': [PERMISSION_TAG_REMOVE]}}
tag_delete = {'text': _('delete'), 'view': 'tag_delete', 'args': 'object.id', 'famfam': 'tag_blue_delete', 'permissions': {'namespace': 'tags', 'permissions': [PERMISSION_TAG_DELETE]}}
tag_edit = {'text': _('edit'), 'view': 'tag_edit', 'args': 'object.id', 'famfam': 'tag_blue_edit', 'permissions': {'namespace': 'tags', 'permissions': [PERMISSION_TAG_EDIT]}}
tag_tagged_item_list = {'text': _('tagged documents'), 'view': 'tag_tagged_item_list', 'args': 'object.id', 'famfam': 'tag_blue_edit'}
tag_multiple_delete = {'text': _('delete'), 'view': 'tag_multiple_delete', 'famfam': 'tag_blue_delete', 'permissions': {'namespace': 'tags', 'permissions': [PERMISSION_TAG_DELETE]}}
#register_links(Tag, [tag_delete])
register_model_list_columns(Tag, [
{
'name': _(u'color'),
'attribute': lambda x: u'<div style="width: 20px; height: 20px; border: 1px solid black; background: %s;"></div>' %
x.tagproperties_set.get().get_color_code(),
},
{
'name': _(u'color name'),
'attribute': lambda x: x.tagproperties_set.get().get_color_display(),
}
])
register_links(Tag, [tag_tagged_item_list, tag_edit])
register_multi_item_links(['tag_list'], [tag_multiple_delete])
@@ -39,5 +53,4 @@ tags_menu = [
]
},
]
register_menu(tags_menu)

View File

@@ -3,9 +3,4 @@ from django.contrib import admin
from tags.models import TagProperties
#class PermissionAdmin(admin.ModelAdmin):
# inlines = [PermissionHolderInline]
# list_display = ('namespace', 'name', 'label')
# list_display_links = list_display
admin.site.register(TagProperties)

View File

@@ -7,6 +7,18 @@ from models import COLOR_CHOICES
class AddTagForm(forms.Form):
"""
Form to be displayed in the sidebar of a document and allow adding
new or existing tags
"""
new_tag = forms.CharField(required=False, label=_(u'New tag'))
color = forms.ChoiceField(choices=COLOR_CHOICES, required=False, label=_(u'Color'))
existing_tags = forms.ModelChoiceField(required=False, queryset=Tag.objects.all(), label=_(u'Existing tags'))
class TagForm(forms.Form):
"""
Form to edit an existing tag's properties
"""
name = forms.CharField(label=_(u'Name'))
color = forms.ChoiceField(choices=COLOR_CHOICES, label=_(u'Color'))

View File

@@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-04-28 00:14-0400\n"
"PO-Revision-Date: 2011-04-28 00:17\n"
"POT-Creation-Date: 2011-04-28 21:20-0400\n"
"PO-Revision-Date: 2011-04-28 21:23\n"
"Last-Translator: Roberto Rosario <rosario_r@jp.pr.gov>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
@@ -19,22 +19,66 @@ msgstr ""
"X-Translated-Using: django-rosetta 0.5.6\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: __init__.py:10
#: __init__.py:17
msgid "Create new tags"
msgstr "Crear nuevas etiquetas"
#: __init__.py:18
msgid "Attach exising tags"
msgstr "Anejar etiquetas existentes"
#: __init__.py:19
msgid "Remove tags from documents"
msgstr "Quitar etiquetas de los documentos"
#: __init__.py:20
msgid "Delete global tags"
msgstr "Eliminar las etiquetas globales"
#: __init__.py:21
msgid "Edit global tags"
msgstr "Editar etiquetas globales"
#: __init__.py:24 __init__.py:51 utils.py:13 views.py:73
msgid "tags"
msgstr "etiquetas"
#: __init__.py:25 __init__.py:26 __init__.py:29
msgid "delete"
msgstr "eliminar"
#: forms.py:15
#: __init__.py:27
msgid "edit"
msgstr "editar"
#: __init__.py:28
msgid "tagged documents"
msgstr "documentos etiquetados"
#: __init__.py:33 models.py:34
msgid "color"
msgstr "color"
#: __init__.py:38
msgid "color name"
msgstr "nombre del color"
#: forms.py:14
msgid "New tag"
msgstr "Nueva etiqueta"
#: forms.py:16
#: forms.py:15 forms.py:24
msgid "Color"
msgstr "Color"
#: forms.py:17
#: forms.py:16
msgid "Existing tags"
msgstr "Etiquetas existentes"
#: forms.py:23
msgid "Name"
msgstr "Nombre"
#: models.py:14
msgid "Blue"
msgstr "Azul"
@@ -59,14 +103,10 @@ msgstr "Rojo"
msgid "Yellow"
msgstr "Amarillo"
#: models.py:33
#: models.py:33 views.py:108
msgid "tag"
msgstr "etiqueta"
#: models.py:34
msgid "color"
msgstr "color"
#: models.py:37
msgid "tag properties"
msgstr "propiedades de etiqueta"
@@ -75,21 +115,63 @@ msgstr "propiedades de etiqueta"
msgid "tags properties"
msgstr "propiedades de etiquetas"
#: views.py:25
#: views.py:26
#, python-format
msgid "Tag \"%s\" removed successfully."
msgstr "Etiqueta \"%s\" eliminada exitosamente."
#: views.py:52
msgid "Must choose either a new tag or an existing one."
msgstr "Debe elegir una etiqueta nueva o una ya existente."
#: views.py:56
#, python-format
msgid "Document is already tagged as \"%s\""
msgstr "Documento ya está etiquetado como \"%s\""
#: views.py:61
#: views.py:65
#, python-format
msgid "Tag \"%s\" added successfully."
msgstr "Etiqueta \"%s\", agregada exitosamente."
#: views.py:89
msgid "Must provide at least one tag."
msgstr "Debe proveer al menos una etiqueta."
#: views.py:99
#, python-format
msgid "Tag \"%s\" deleted successfully."
msgstr "Etiqueta \"%s\" borrada exitosamente."
#: views.py:101
#, python-format
msgid "Error deleting tag \"%(tag)s\": %(error)s"
msgstr "Error al eliminar la etiqueta \"%(tag)s\": %(error)s"
#: views.py:115
#, python-format
msgid "Are you sure you wish to delete the tag: %s?"
msgstr "¿Está seguro que desea eliminar la etiqueta: %s?"
#: views.py:116 views.py:119
msgid "Will be removed from all documents."
msgstr "Se eliminará de todos los documentos."
#: views.py:118
#, python-format
msgid "Are you sure you wish to delete the tags: %s?"
msgstr "¿Está seguro que desea eliminar de las etiquetas: %s?"
#: views.py:151
#, python-format
msgid "edit tag: %s"
msgstr "editar la etiqueta: %s"
#: views.py:162
#, python-format
msgid "documents with the tag \"%s\""
msgstr "documentos con la etiqueta \"%s\""
#: templatetags/tags_tags.py:17
msgid "Add tag to document"
msgstr "Agregar etiqueta al documento"

View File

@@ -27,7 +27,7 @@ COLOR_CODES = (
(COLOR_YELLOW, u'yellow'),
(COLOR_GREENYELLOW, u'greenyellow '),
)
class TagProperties(models.Model):
tag = models.ForeignKey(Tag, verbose_name=_(u'tag'))

View File

@@ -3,6 +3,8 @@ from django.conf.urls.defaults import patterns, url
urlpatterns = patterns('tags.views',
url(r'^list/$', 'tag_list', (), 'tag_list'),
url(r'^(?P<tag_id>\d+)/delete/$', 'tag_delete', (), 'tag_delete'),
url(r'^(?P<tag_id>\d+)/edit/$', 'tag_edit', (), 'tag_edit'),
url(r'^(?P<tag_id>\d+)/tagged_item/list/$', 'tag_tagged_item_list', (), 'tag_tagged_item_list'),
url(r'^multiple/delete/$', 'tag_multiple_delete', (), 'tag_multiple_delete'),
url(r'^(?P<tag_id>\d+)/remove_from_document/(?P<document_id>\d+)/$', 'tag_remove', (), 'tag_remove'),

View File

@@ -3,17 +3,15 @@ from django.utils.translation import ugettext as _
from tags import tag_document_remove
def get_tags_subtemplate(obj):
def get_tags_subtemplate(obj):
"""
Return all the settings to render a subtemplate containing and
object's tags
"""
return {
'name': 'generic_list_subtemplate.html',
'title': _(u'tags'),
'object_list': obj.tags.all(),
'extra_columns': [
{'name': _(u'color'), 'attribute': lambda x: u'<div style="width: 20px; height: 20px; border: 1px solid black; background: %s;"></div>' % x.tagproperties_set.get().get_color_code()},
],
'hide_link': True,
'navigation_object_links': {None: {
'document_view_simple' : {'links': [tag_document_remove]},
'document_view' : {'links': [tag_document_remove]}
}}
'navigation_object_links': [tag_document_remove],
}

View File

@@ -6,26 +6,25 @@ from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from permissions.api import check_permissions
from taggit.models import Tag
from documents.models import Document
from documents.views import document_list
from tags.forms import AddTagForm
from tags.forms import AddTagForm, TagForm
from tags.models import TagProperties
from tags import PERMISSION_TAG_CREATE, PERMISSION_TAG_ATTACH, \
PERMISSION_TAG_REMOVE, PERMISSION_TAG_DELETE, PERMISSION_TAG_EDIT
def tag_remove(request, tag_id, document_id):
check_permissions(request.user, 'tags', [PERMISSION_TAG_REMOVE])
tag = get_object_or_404(Tag, pk=tag_id)
document = get_object_or_404(Document, pk=document_id)
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', None)))
tag.delete()
messages.success(request, _(u'Tag "%s" removed successfully.') % tag)
return HttpResponseRedirect(previous)
@@ -33,7 +32,7 @@ def tag_add(request, document_id):
document = get_object_or_404(Document, pk=document_id)
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', None)))
if request.method == 'POST':
previous = request.META.get('HTTP_REFERER', '/')
form = AddTagForm(request.POST)
@@ -52,17 +51,17 @@ def tag_add(request, document_id):
else:
messages.error(request, _(u'Must choose either a new tag or an existing one.'))
return HttpResponseRedirect(previous)
if tag_name in document.tags.values_list('name', flat=True):
messages.warning(request, _(u'Document is already tagged as "%s"') % tag_name)
return HttpResponseRedirect(previous)
document.tags.add(tag_name)
if is_new:
tag = Tag.objects.get(name=tag_name)
TagProperties(tag=tag, color=form.cleaned_data['color']).save()
messages.success(request, _(u'Tag "%s" added successfully.') % tag_name)
return HttpResponseRedirect(previous)
@@ -127,3 +126,37 @@ def tag_multiple_delete(request):
return tag_delete(
request, tag_id_list=request.GET.get('id_list', [])
)
def tag_edit(request, tag_id):
check_permissions(request.user, 'tags', [PERMISSION_TAG_EDIT])
tag = get_object_or_404(Tag, pk=tag_id)
if request.method == 'POST':
form = TagForm(request.POST)
if form.is_valid():
tag.name = form.cleaned_data['name']
tag.save()
tag_properties = tag.tagproperties_set.get()
tag_properties.color = form.cleaned_data['color']
tag_properties.save()
return HttpResponseRedirect(reverse('tag_list'))
else:
form = TagForm(initial={
'name': tag.name,
'color': tag.tagproperties_set.get().color
})
return render_to_response('generic_form.html', {
'title': _(u'edit tag: %s') % tag,
'form': form,
'object': tag,
},
context_instance=RequestContext(request))
def tag_tagged_item_list(request, tag_id):
tag = get_object_or_404(Tag, pk=tag_id)
object_list = [tagged_item.content_object for tagged_item in tag.taggit_taggeditem_items.all()]
return document_list(request, object_list=object_list, title=_('documents with the tag "%s"') % tag)