From: yomguy Date: Thu, 17 Feb 2011 23:59:48 +0000 (+0100) Subject: add forms to Collection and Item, adapt edit views X-Git-Tag: 1.1~438 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=442737df85e7bd183fb7b09b0d9e60505ad6e8b6;p=telemeta.git add forms to Collection and Item, adapt edit views --- diff --git a/telemeta/models/media.py b/telemeta/models/media.py index ea360e64..a78da49c 100644 --- a/telemeta/models/media.py +++ b/telemeta/models/media.py @@ -204,6 +204,10 @@ class MediaCollection(MediaResource): class Meta(MetaCore): db_table = 'media_collections' +class MediaCollectionForm(ModelForm): + class Meta: + model = MediaCollection + class MediaItem(MediaResource): "Describe an item" element_type = 'item' @@ -298,6 +302,10 @@ class MediaItem(MediaResource): return title +class MediaItemForm(ModelForm): + class Meta: + model = MediaItem + class MediaItemKeyword(ModelCore): "Item keyword" item = ForeignKey('MediaItem', verbose_name=_('item'), related_name="keyword_relations") diff --git a/telemeta/templates/telemeta_default/collection_detail_edit.html b/telemeta/templates/telemeta_default/collection_detail_edit.html index d1b369c9..90505e96 100644 --- a/telemeta/templates/telemeta_default/collection_detail_edit.html +++ b/telemeta/templates/telemeta_default/collection_detail_edit.html @@ -1,36 +1,36 @@ -{% extends "telemeta/base.html" %} -{% load telemeta_utils %} -{% load i18n %} - -{% block head_title %}{% trans "Collection" %}{{collection|prepend:': '}} - {{ block.super }}{% endblock %} - -{% block stylesheets %} -{{ block.super }} - - - -{% endblock %} -{% block extra_javascript %} -{% endblock %} - -{% if collection %} - -{% block submenu %} -
Dublin Core
-{% endblock %} - -{% block content %} -

Collection: {{ collection }}

-
-
{% csrf_token %} - - {{ formset }} -
- -
-
-{% endblock %} -{% else %} -

No such collection

-{% endif %} - +{% extends "telemeta/base.html" %} +{% load telemeta_utils %} +{% load i18n %} + +{% block head_title %}{% trans "Collection" %}{{collection|prepend:': '}} - {{ block.super }}{% endblock %} + +{% block stylesheets %} +{{ block.super }} + + + +{% endblock %} +{% block extra_javascript %} +{% endblock %} + +{% if collection %} + +{% block submenu %} +
Dublin Core
+{% endblock %} + +{% block content %} +

Collection: {{ collection }}

+
+
{% csrf_token %} + + {{ form }} +
+ +
+
+{% endblock %} +{% else %} +

No such collection

+{% endif %} + diff --git a/telemeta/templates/telemeta_default/mediaitem_detail_edit.html b/telemeta/templates/telemeta_default/mediaitem_detail_edit.html index c88b2c44..20fe1be0 100644 --- a/telemeta/templates/telemeta_default/mediaitem_detail_edit.html +++ b/telemeta/templates/telemeta_default/mediaitem_detail_edit.html @@ -1,152 +1,152 @@ -{% extends "telemeta/base.html" %} -{% load telemeta_utils %} -{% load i18n %} - -{% block head_title %}{% trans "Item" %}{{item|prepend:': '}} - {{ block.super }}{% endblock %} - -{% block stylesheets %} -{{ block.super }} - - - - {% endblock %} - {% block extra_javascript %} - - - - - - - - -{% endblock %} - - -{% if item %} -{% block submenu %} -
- - Dublin Core -
-{% endblock %} - -{% block content %} -

Item : {{ item }}

-
- - {% if item.file %} -
- Minimize -
-
-
-
- Maximize -
-
-
-
-
- - -
-
-
-
-
- -
-
-
-
-
-
- - - -
- -
- - - - - - - {% for analyser in analysers %} - - - - - - {% endfor %} -
PropertyValueUnit
- {{ analyser.name }} - - {{ analyser.value }} - - {{ analyser.unit }} -
-
- -
-
- {% if audio_export_enabled %} -
-

{% trans "Download:" %} - {% for format in export_formats %} - {{ format.name }} - {% endfor %}

-
- {% endif %} - -
- {% endif %} - -
-
{% csrf_token %} - - {{ formset }} -
- -
-
- -
- -{% endblock %} - -{% else %} -

No such item

-{% endif %} +{% extends "telemeta/base.html" %} +{% load telemeta_utils %} +{% load i18n %} + +{% block head_title %}{% trans "Item" %}{{item|prepend:': '}} - {{ block.super }}{% endblock %} + +{% block stylesheets %} +{{ block.super }} + + + + {% endblock %} + {% block extra_javascript %} + + + + + + + + +{% endblock %} + + +{% if item %} +{% block submenu %} +
+ + Dublin Core +
+{% endblock %} + +{% block content %} +

Item : {{ item }}

+
+ + {% if item.file %} +
+ Minimize +
+
+
+
+ Maximize +
+
+
+
+
+ + +
+
+
+
+
+ +
+
+
+
+
+
+ + + +
+ +
+ + + + + + + {% for analyser in analysers %} + + + + + + {% endfor %} +
PropertyValueUnit
+ {{ analyser.name }} + + {{ analyser.value }} + + {{ analyser.unit }} +
+
+ +
+
+ {% if audio_export_enabled %} +
+

{% trans "Download:" %} + {% for format in export_formats %} + {{ format.name }} + {% endfor %}

+
+ {% endif %} + +
+ {% endif %} + +
+
{% csrf_token %} + + {{ form }} +
+ +
+
+ +
+ +{% endblock %} + +{% else %} +

No such item

+{% endif %} diff --git a/telemeta/web/base.py b/telemeta/web/base.py index 62bdee59..ba3beb8b 100644 --- a/telemeta/web/base.py +++ b/telemeta/web/base.py @@ -52,7 +52,7 @@ from django.contrib.auth.decorators import login_required from django.core.context_processors import csrf from django.forms.models import modelformset_factory -from telemeta.models import MediaItem, Location, MediaCollection, EthnicGroup +from telemeta.models import MediaItem, Location, MediaCollection, EthnicGroup, MediaCollectionForm, MediaItemForm from telemeta.models import dublincore, Enumeration, MediaItemMarker import telemeta.interop.oai as oai from telemeta.interop.oaidatasource import TelemetaOAIDataSource @@ -94,7 +94,7 @@ class WebView(object): graphers = timeside.core.processors(timeside.api.IGrapher) decoders = timeside.core.processors(timeside.api.IDecoder) - encoders= timeside.core.processors(timeside.api.IEncoder) + encoders = timeside.core.processors(timeside.api.IEncoder) analyzers = timeside.core.processors(timeside.api.IAnalyzer) cache = TelemetaCache(settings.TELEMETA_DATA_CACHE_DIR) cache_export = TelemetaCache(settings.TELEMETA_EXPORT_CACHE_DIR) @@ -117,14 +117,14 @@ class WebView(object): def collection_detail_edit(self, request, public_id, template='telemeta/collection_detail_edit.html'): collection = MediaCollection.objects.get(public_id=public_id) - MediaCollectionFormSet = modelformset_factory(MediaCollection) if request.method == 'POST': - formset = MediaCollectionFormSet(request.POST, request.FILES, queryset=MediaCollection.objects.filter(code=public_id)) - if formset.is_valid(): - formset.save() + form = MediaCollectionForm(request.POST, request.FILES, instance=collection) + if form.is_valid(): + form.save() else: - formset = MediaCollectionFormSet(queryset=MediaCollection.objects.filter(code=public_id)) - return render(request, template, {'collection': collection, "formset": formset,}) + form = MediaCollectionForm(instance=collection) + + return render(request, template, {'collection': collection, "form": form,}) def item_previous_next(self, item): # Get previous and next items @@ -205,18 +205,17 @@ class WebView(object): previous, next = self.item_previous_next(item) analyzers = self.item_analyze(item) - MediaItemFormSet = modelformset_factory(MediaItem) if request.method == 'POST': - formset = MediaItemFormSet(request.POST, request.FILES, queryset=MediaItem.objects.filter(code=public_id)) - if formset.is_valid(): - formset.save() + form = MediaItemForm(request.POST, request.FILES, instance=item) + if form.is_valid(): + form.save() else: - formset = MediaItemFormSet(queryset=MediaItem.objects.filter(code=public_id)) + form = MediaItemForm(instance=item) return render(request, template, {'item': item, 'export_formats': formats, 'visualizers': graphers, 'visualizer_id': grapher_id,'analysers': analyzers, #FIXME analysers - 'audio_export_enabled': getattr(settings, 'TELEMETA_DOWNLOAD_ENABLED', True), "formset": formset, + 'audio_export_enabled': getattr(settings, 'TELEMETA_DOWNLOAD_ENABLED', True), "form": form, 'previous' : previous, 'next' : next, })