# HG changeset patch # User cavaliet # Date 1361897564 -3600 # Node ID 14c40542dfbbf366c1a9a3edcdeffed391b90adc # Parent 6b49096afdc2726c3f621b27569ccd7688e5e764 modify segment. export xml corrected. diff -r 6b49096afdc2 -r 14c40542dfbb src/egonomy/locale/en/LC_MESSAGES/django.mo Binary file src/egonomy/locale/en/LC_MESSAGES/django.mo has changed diff -r 6b49096afdc2 -r 14c40542dfbb src/egonomy/locale/en/LC_MESSAGES/django.po --- a/src/egonomy/locale/en/LC_MESSAGES/django.po Tue Feb 26 11:01:21 2013 +0100 +++ b/src/egonomy/locale/en/LC_MESSAGES/django.po Tue Feb 26 17:52:44 2013 +0100 @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-02-26 03:55-0600\n" +"POT-Creation-Date: 2013-02-26 09:32-0600\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -25,6 +25,10 @@ msgid "English" msgstr "" +#: views.py:68 views.py:87 +msgid "You are not allowed to modify this fragment." +msgstr "" + #: templates/egonomy_all_fragments.html:7 #: templates/egonomy_all_fragments.html:18 #: templates/egonomy_all_fragments.html:21 @@ -49,7 +53,7 @@ #: templates/egonomy_all_fragments.html:59 #: templates/egonomy_annotate_picture.html:123 #: templates/egonomy_create_fragment.html:184 templates/egonomy_home.html:81 -#: templates/egonomy_view_fragment.html:100 +#: templates/egonomy_view_fragment.html:102 msgid "Annotated by" msgstr "" @@ -116,7 +120,6 @@ msgstr "" #: templates/egonomy_annotate_picture.html:76 -#: templates/egonomy_view_fragment.html:53 msgid "Save keywords" msgstr "" @@ -125,18 +128,18 @@ msgstr "" #: templates/egonomy_annotate_picture.html:80 templates/egonomy_base.html:36 -#: templates/egonomy_view_fragment.html:57 +#: templates/egonomy_view_fragment.html:53 msgid "by" msgstr "" #: templates/egonomy_annotate_picture.html:85 -#: templates/egonomy_view_fragment.html:62 +#: templates/egonomy_view_fragment.html:64 msgid "Create a fragment" msgstr "" #: templates/egonomy_annotate_picture.html:91 #: templates/egonomy_create_fragment.html:152 -#: templates/egonomy_view_fragment.html:68 +#: templates/egonomy_view_fragment.html:70 msgid "Fragments from this picture" msgstr "" @@ -156,15 +159,15 @@ msgid "Create or edit a fragment" msgstr "" +#: templates/egonomy_create_fragment.html:69 +msgid "Erase the drawing" +msgstr "" + #: templates/egonomy_create_fragment.html:70 -msgid "Erase the drawing" +msgid "Back to the original drawing" msgstr "" #: templates/egonomy_create_fragment.html:71 -msgid "Back to the original drawing" -msgstr "" - -#: templates/egonomy_create_fragment.html:72 msgid "New fragment" msgstr "" @@ -228,10 +231,14 @@ msgid "View a fragment" msgstr "" -#: templates/egonomy_view_fragment.html:56 +#: templates/egonomy_view_fragment.html:52 msgid "Last modification" msgstr "" +#: templates/egonomy_view_fragment.html:58 +msgid "Modify this fragment" +msgstr "" + #: templates/registration/login.html:5 msgid "Login" msgstr "" diff -r 6b49096afdc2 -r 14c40542dfbb src/egonomy/locale/fr/LC_MESSAGES/django.mo Binary file src/egonomy/locale/fr/LC_MESSAGES/django.mo has changed diff -r 6b49096afdc2 -r 14c40542dfbb src/egonomy/locale/fr/LC_MESSAGES/django.po --- a/src/egonomy/locale/fr/LC_MESSAGES/django.po Tue Feb 26 11:01:21 2013 +0100 +++ b/src/egonomy/locale/fr/LC_MESSAGES/django.po Tue Feb 26 17:52:44 2013 +0100 @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-02-26 03:56-0600\n" +"POT-Creation-Date: 2013-02-26 09:34-0600\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -26,6 +26,11 @@ msgid "English" msgstr "Anglais" +#: views.py:68 +#: views.py:87 +msgid "You are not allowed to modify this fragment." +msgstr "Vous n'être pas autorisé à modifier ce fragment." + #: templates/egonomy_all_fragments.html:7 #: templates/egonomy_all_fragments.html:18 #: templates/egonomy_all_fragments.html:21 @@ -52,7 +57,7 @@ #: templates/egonomy_annotate_picture.html:123 #: templates/egonomy_create_fragment.html:184 #: templates/egonomy_home.html:81 -#: templates/egonomy_view_fragment.html:100 +#: templates/egonomy_view_fragment.html:102 msgid "Annotated by" msgstr "Annoté par" @@ -124,7 +129,6 @@ msgstr "Thésaurus Pertimm" #: templates/egonomy_annotate_picture.html:76 -#: templates/egonomy_view_fragment.html:53 msgid "Save keywords" msgstr "Enregistrer les mots-clés" @@ -134,18 +138,18 @@ #: templates/egonomy_annotate_picture.html:80 #: templates/egonomy_base.html:36 -#: templates/egonomy_view_fragment.html:57 +#: templates/egonomy_view_fragment.html:53 msgid "by" msgstr "par" #: templates/egonomy_annotate_picture.html:85 -#: templates/egonomy_view_fragment.html:62 +#: templates/egonomy_view_fragment.html:64 msgid "Create a fragment" msgstr "Créer un fragment" #: templates/egonomy_annotate_picture.html:91 #: templates/egonomy_create_fragment.html:152 -#: templates/egonomy_view_fragment.html:68 +#: templates/egonomy_view_fragment.html:70 msgid "Fragments from this picture" msgstr "Fragments issus de cette image" @@ -165,15 +169,15 @@ msgid "Create or edit a fragment" msgstr "Créer ou modifier un fragment" -#: templates/egonomy_create_fragment.html:70 +#: templates/egonomy_create_fragment.html:69 msgid "Erase the drawing" msgstr "Effacer le tracé" -#: templates/egonomy_create_fragment.html:71 +#: templates/egonomy_create_fragment.html:70 msgid "Back to the original drawing" msgstr "Revenir au tracé d'origine" -#: templates/egonomy_create_fragment.html:72 +#: templates/egonomy_create_fragment.html:71 msgid "New fragment" msgstr "Nouveau fragment" @@ -237,10 +241,14 @@ msgid "View a fragment" msgstr "Voir un fragment" -#: templates/egonomy_view_fragment.html:56 +#: templates/egonomy_view_fragment.html:52 msgid "Last modification" msgstr "Dernière modification" +#: templates/egonomy_view_fragment.html:58 +msgid "Modify this fragment" +msgstr "Modifier ce fragment" + #: templates/registration/login.html:5 msgid "Login" msgstr "Se connecter" diff -r 6b49096afdc2 -r 14c40542dfbb src/egonomy/management/commands/export_to_xml.py --- a/src/egonomy/management/commands/export_to_xml.py Tue Feb 26 11:01:21 2013 +0100 +++ b/src/egonomy/management/commands/export_to_xml.py Tue Feb 26 17:52:44 2013 +0100 @@ -87,15 +87,15 @@ if img.info and img.info.image_file: file_array = img.info.image_file.name.split("/") file_folder = path + file_array[-2] - file_name = file_array[-1].split(".")[0] + ".xml" + file_name = "content-" + file_array[-1].split(".")[0] + ".xml" if not os.path.isdir(file_folder): os.makedirs(file_folder) file_path = file_folder + os.sep + file_name else: # If image_file is none, the xml file is put in path folder - file_path = path + img.id + ".xml" - errors.append(img.id + ".xml") - + file_path = path + "content-" + img.id + ".xml" + errors.append("content-" + img.id + ".xml") + if os.path.exists(file_path): os.remove(file_path) @@ -109,22 +109,22 @@ for t in tags: xml_str += u"\t" + t.strip() + u"\n" # metadatas - xml_str += u"\t\n\t\tcliche\n\t\t" + (img.metadata.cliche if img.metadata.cliche else "") + u"\n\t\n" - xml_str += u"\t\n\t\tinventaire\n\t\t" + (img.metadata.inventaire if img.metadata.inventaire else "") + u"\n\t\n" - xml_str += u"\t\n\t\tdate\n\t\t" + str((img.metadata.date if img.metadata.date else "")) + u"\n\t\n" - xml_str += u"\t\n\t\tlongueur\n\t\t" + str((img.metadata.longueur if img.metadata.longueur else "")) + u"\n\t\n" - xml_str += u"\t\n\t\thauteur\n\t\t" + str((img.metadata.hauteur if img.metadata.hauteur else "")) + u"\n\t\n" - xml_str += u"\t\n\t\tprofondeur\n\t\t" + str((img.metadata.profondeur if img.metadata.profondeur else "")) + u"\n\t\n" - xml_str += u"\t\n\t\tdiametre\n\t\t" + str((img.metadata.diametre if img.metadata.diametre else "")) + u"\n\t\n" - xml_str += u"\t\n\t\tphotographe\n\t\t" + (img.metadata.photographe if img.metadata.photographe else "") + u"\n\t\n" - xml_str += u"\t\n\t\tauteur\n\t\t" + (img.metadata.auteur if img.metadata.auteur else "") + u"\n\t\n" - xml_str += u"\t\n\t\tdroits\n\t\t" + (img.metadata.droits if img.metadata.droits else "") + u"\n\t\n" - xml_str += u"\t\n\t\tmentions\n\t\t" + (img.metadata.mentions if img.metadata.mentions else "") + u"\n\t\n" - xml_str += u"\t\n\t\tperiode\n\t\t" + (img.metadata.periode if img.metadata.periode else "") + u"\n\t\n" - xml_str += u"\t\n\t\ttechnique\n\t\t" + (img.metadata.technique if img.metadata.technique else "") + u"\n\t\n" - xml_str += u"\t\n\t\tsite\n\t\t" + (img.metadata.site if img.metadata.site else "") + u"\n\t\n" - xml_str += u"\t\n\t\tlieu\n\t\t" + (img.metadata.lieu if img.metadata.lieu else "") + u"\n\t\n" - xml_str += u"\t\n\t\tlocalisation\n\t\t" + (img.metadata.localisation if img.metadata.localisation else "") + u"\n\t\n" + xml_str += u"\t\n\t\tcliche\n\t\t" + (img.metadata.cliche if img.metadata.cliche else "") + u"\n\t\n" + xml_str += u"\t\n\t\tinventaire\n\t\t" + (img.metadata.inventaire if img.metadata.inventaire else "") + u"\n\t\n" + xml_str += u"\t\n\t\tdate\n\t\t" + str((img.metadata.date if img.metadata.date else "")) + u"\n\t\n" + xml_str += u"\t\n\t\tlongueur\n\t\t" + str((img.metadata.longueur if img.metadata.longueur else "")) + u"\n\t\n" + xml_str += u"\t\n\t\thauteur\n\t\t" + str((img.metadata.hauteur if img.metadata.hauteur else "")) + u"\n\t\n" + xml_str += u"\t\n\t\tprofondeur\n\t\t" + str((img.metadata.profondeur if img.metadata.profondeur else "")) + u"\n\t\n" + xml_str += u"\t\n\t\tdiametre\n\t\t" + str((img.metadata.diametre if img.metadata.diametre else "")) + u"\n\t\n" + xml_str += u"\t\n\t\tphotographe\n\t\t" + (img.metadata.photographe if img.metadata.photographe else "") + u"\n\t\n" + xml_str += u"\t\n\t\tauteur\n\t\t" + (img.metadata.auteur if img.metadata.auteur else "") + u"\n\t\n" + xml_str += u"\t\n\t\tdroits\n\t\t" + (img.metadata.droits if img.metadata.droits else "") + u"\n\t\n" + xml_str += u"\t\n\t\tmentions\n\t\t" + (img.metadata.mentions if img.metadata.mentions else "") + u"\n\t\n" + xml_str += u"\t\n\t\tperiode\n\t\t" + (img.metadata.periode if img.metadata.periode else "") + u"\n\t\n" + xml_str += u"\t\n\t\ttechnique\n\t\t" + (img.metadata.technique if img.metadata.technique else "") + u"\n\t\n" + xml_str += u"\t\n\t\tsite\n\t\t" + (img.metadata.site if img.metadata.site else "") + u"\n\t\n" + xml_str += u"\t\n\t\tlieu\n\t\t" + (img.metadata.lieu if img.metadata.lieu else "") + u"\n\t\n" + xml_str += u"\t\n\t\tlocalisation\n\t\t" + (img.metadata.localisation if img.metadata.localisation else "") + u"\n\t\n" xml_str += u"" # Write xml string os.write(fd, xml_str.encode('utf8')) diff -r 6b49096afdc2 -r 14c40542dfbb src/egonomy/templates/egonomy_create_fragment.html --- a/src/egonomy/templates/egonomy_create_fragment.html Tue Feb 26 11:01:21 2013 +0100 +++ b/src/egonomy/templates/egonomy_create_fragment.html Tue Feb 26 17:52:44 2013 +0100 @@ -68,7 +68,7 @@
× -

{% trans 'New fragment' %} :

+

{% if frg_to_modify %}{{ frg_to_modify.title }}{% else %}{% trans 'New fragment' %}{% endif %} :

{% with img.info.image_file as image %} @@ -89,9 +89,10 @@
- + - {% csrf_token %} + {% if frg_to_modify %}{% endif %} + {% csrf_token %}
@@ -101,15 +102,15 @@ - + - + - + {% if img.metadata.mots_cles %} diff -r 6b49096afdc2 -r 14c40542dfbb src/egonomy/templates/egonomy_view_fragment.html --- a/src/egonomy/templates/egonomy_view_fragment.html Tue Feb 26 11:01:21 2013 +0100 +++ b/src/egonomy/templates/egonomy_view_fragment.html Tue Feb 26 17:52:44 2013 +0100 @@ -48,14 +48,16 @@ - - + + {% ifequal user fragment.author %} + + + + + {% endifequal %}
diff -r 6b49096afdc2 -r 14c40542dfbb src/egonomy/urls.py --- a/src/egonomy/urls.py Tue Feb 26 11:01:21 2013 +0100 +++ b/src/egonomy/urls.py Tue Feb 26 17:52:44 2013 +0100 @@ -11,7 +11,8 @@ url(r'^$', 'egonomy.views.home', name='home'), url(r'^annotate/(?P.*)/$', 'egonomy.views.annotate_picture', name='annotate_picture'), url(r'^viewfragment/(?P.*)/$', 'egonomy.views.view_fragment', name='view_fragment'), - url(r'^createfragment/(?P.*)/$', 'egonomy.views.create_fragment', name='create_fragment'), + url(r'^createfragment/(?P.*)/(?P.*)/$', 'egonomy.views.create_fragment', name='create_fragment'), + url(r'^createfragment/(?P.*)/', 'egonomy.views.create_fragment', name='create_fragment'), url(r'^savefragment/$', 'egonomy.views.save_fragment', name='save_fragment'), url(r'^allpictures/$', 'egonomy.views.all_pictures', name='all_pictures'), url(r'^allfragments/$', 'egonomy.views.all_fragments', name='all_fragments'), diff -r 6b49096afdc2 -r 14c40542dfbb src/egonomy/views.py --- a/src/egonomy/views.py Tue Feb 26 11:01:21 2013 +0100 +++ b/src/egonomy/views.py Tue Feb 26 17:52:44 2013 +0100 @@ -1,17 +1,19 @@ from django.conf import settings from django.contrib.auth.decorators import login_required +from django.contrib.auth.models import User from django.core.paginator import Paginator, InvalidPage, EmptyPage from django.core.urlresolvers import reverse from django.db.models.aggregates import Max +from django.http.response import HttpResponseForbidden from django.shortcuts import get_object_or_404, render_to_response, redirect from django.template import RequestContext +from django.utils.translation import ugettext as _ from egonomy.models import ImageMetadata, Image, Fragment from egonomy.search_indexes import QueryParser from egonomy.search_indexes.paginator import SearchPaginator from egonomy.search_indexes.query import ModelRelatedSearchQuerySet from haystack.query import RelatedSearchQuerySet import logging -from django.contrib.auth.models import User logger = logging.getLogger(__name__) @@ -54,13 +56,19 @@ context_instance=RequestContext(request)) @login_required -def create_fragment(request, image_id): +def create_fragment(request, image_id, fragment_pk=None): img = get_object_or_404(Image.objects.select_related('info', 'metadata'), id=image_id) frg_list = Fragment.objects.filter(image=img).order_by('-date_saved').select_related('image', 'image__info', 'image__metadata','author') + frg_to_modify = None + if fragment_pk: + frg_to_modify = get_object_or_404(Fragment.objects.select_related('author'), pk=fragment_pk) + # We check if the current user is the fragment's author + if frg_to_modify.author != request.user: + return HttpResponseForbidden(_("You are not allowed to modify this fragment.")) return render_to_response("egonomy_create_fragment.html", - {'img': img, 'fragment_list': frg_list}, + {'img': img, 'frg_to_modify': frg_to_modify, 'fragment_list': frg_list}, context_instance=RequestContext(request)) @login_required @@ -71,16 +79,22 @@ frg_kw = request.POST["user_keywords"] frg_path = request.POST["fragment_path"] frg_image_id = request.POST["image_id"] - img = get_object_or_404(Image, id=frg_image_id) + if "fragment_pk" in request.POST: + frg_pk = request.POST["fragment_pk"] + frg = get_object_or_404(Fragment.objects.select_related('author'), pk=frg_pk) + # We check if the current user is the fragment's author + if frg.author != request.user: + return HttpResponseForbidden(_("You are not allowed to modify this fragment.")) + else : + img = get_object_or_404(Image, id=frg_image_id) + frg = Fragment() + frg.image = img + frg.author = request.user - frg = Fragment() - frg.image = img frg.coordinates = frg_path frg.title = frg_title frg.description = frg_desc frg.tags = frg_kw - frg.author = request.user - frg.save() return redirect("view_fragment", fragment_pk=frg.pk)