Interfejs do dołączania galerii do dokumentu, jeżeli żadna nie jest dołączona.
authorzuber <marek@stepniowski.com>
Fri, 6 Nov 2009 12:07:07 +0000 (13:07 +0100)
committerzuber <marek@stepniowski.com>
Fri, 6 Nov 2009 12:07:07 +0000 (13:07 +0100)
apps/explorer/admin.py
apps/explorer/forms.py
apps/explorer/views.py
platforma/templates/explorer/editor.html

index c84a5d9..dd765f5 100644 (file)
@@ -1,29 +1,13 @@
 from django.contrib import admin
-from django import forms
-import os
-
-from django.conf import settings
 
 import explorer.models
+from explorer import forms
 
 admin.site.register(explorer.models.EditorSettings)
 admin.site.register(explorer.models.EditorPanel)
 
-
-class GalleryAdminForm(forms.ModelForm):
-    subpath = forms.ChoiceField(choices=())
-    
-    def __init__(self, *args, **kwargs):
-        super(GalleryAdminForm, self).__init__(*args, **kwargs)
-        self.fields['subpath'].choices = [(settings.IMAGE_DIR + '/' + x, x) for x in os.listdir(settings.MEDIA_ROOT + settings.IMAGE_DIR)]
-        
-    class Meta:
-        mode = explorer.models.GalleryForDocument
-        fields = ('document', 'subpath',)
-
-
 class GalleryAdmin(admin.ModelAdmin):
-    form = GalleryAdminForm
+    form = forms.GalleryChoiceForm
     list_display = ('document', 'subpath',)
     search_fields = ('document', 'subpath',)
 
index 6c5c88d..33585bc 100644 (file)
@@ -1,12 +1,14 @@
 # -*- coding: utf-8 -*-
-from django import forms
-
-from lxml import etree
+import os
 from librarian import dcparser
+
+from django import forms
+from django.conf import settings
 import django.utils
 
 from explorer import models
 
+
 class PersonField(forms.CharField):
     def clean(self, value):
         try:
@@ -79,6 +81,17 @@ class SplitForm(forms.Form):
     fulltext = forms.CharField(widget=forms.HiddenInput(), required=False)
     splittext = forms.CharField(widget=forms.HiddenInput(), required=False)
 
+class GalleryChoiceForm(forms.ModelForm):
+    subpath = forms.ChoiceField(choices=())
+
+    def __init__(self, *args, **kwargs):
+        super(GalleryChoiceForm, self).__init__(*args, **kwargs)
+        self.fields['subpath'].choices = [(settings.IMAGE_DIR + '/' + x, x) for x in os.listdir(settings.MEDIA_ROOT + settings.IMAGE_DIR)]
+
+    class Meta:
+        model = models.GalleryForDocument
+        fields = ('document', 'subpath',)
+
 class DublinCoreForm(forms.Form):
     about = forms.URLField(verify_exists=False)
     author = PersonField()
@@ -109,4 +122,5 @@ class DublinCoreForm(forms.Form):
             vdict = info.to_dict()
             for name in self.fields.keys():
                 if vdict.has_key(name):
-                    self.fields[name].initial = vdict[name]
\ No newline at end of file
+                    self.fields[name].initial = vdict[name]
+
index 2c9b17d..5ec452a 100644 (file)
@@ -13,8 +13,10 @@ from django.utils import simplejson as json
 from django.views.generic.simple import direct_to_template
 from django.contrib.auth.decorators import login_required
 
+from explorer import forms
 from api.models import PullRequest
 
+
 def ajax_login_required(view):
     """Similar ro @login_required, but instead of redirect, 
     just return some JSON stuff with error."""
@@ -28,11 +30,12 @@ def ajax_login_required(view):
 @login_required
 def display_editor(request, path):
     user = request.GET.get('user', request.user.username)
-    log.info(user)
+    gallery_form = forms.GalleryChoiceForm()
     
     return direct_to_template(request, 'explorer/editor.html', extra_context={
             'fileid': path,
-            'euser': user
+            'euser': user,
+            'gallery_form': gallery_form,
     })
     
 #
index 7bc9c61..0dcc06b 100755 (executable)
        
        <script type="text/html" charset="utf-8" id="image-gallery-empty-template">
            <div class="image-gallery-empty-template">
-            Galeria jest pusta
+            <div class="empty-gallery-info">Galeria dla tego dokumentu nie istnieje i/lub jest pusta.</div>
+            
+            {% if user.is_superuser %}
+            <div class="choose-gallery">
+                <p>Dołącz galerię do dokumentu:</p>
+                <p>{{ gallery_form.subpath }} <input id="choose-gallery" type="submit" value="Dołącz"></p>
+            </div>
+            {% endif %}
         </div>
        </script>