Changeset e634d6b
- Timestamp:
- 05/01/07 16:45:31 (6 years ago)
- Branches:
- master, crem, crem2, dev, diadems, forma, generic, instru_search, lam, nlivemulti, production, release/1.4.4, security, social, storage, test, video
- Children:
- c2aa673
- Parents:
- 4bdb860
- git-author:
- olivier <> (05/01/07 16:45:31)
- git-committer:
- olivier <> (05/01/07 16:45:31)
- Location:
- telemeta
- Files:
-
- 4 added
- 4 edited
-
models.py (modified) (4 diffs)
-
templates/admin.html (added)
-
templates/base.html (modified) (2 diffs)
-
templates/dictionary_edit.html (added)
-
templates/dictionary_edit_value.html (added)
-
templates/dictionary_list.html (added)
-
urls.py (modified) (3 diffs)
-
views/web.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
telemeta/models.py
r77469e8 re634d6b 20 20 return fields_dict 21 21 22 class PhysicalFormat(models.Model): 23 value = models.CharField(maxlength=250) 24 is_dictionary = True 25 def __str__(self): 26 return self.value 27 class Meta: 28 ordering = ['value'] 29 22 30 class MediaCollectionManager(models.Manager): 23 31 def quick_search(self, pattern): … … 26 34 Q(description__icontains=pattern) 27 35 ) 36 28 37 29 38 class MediaCollection(models.Model, MediaCore): … … 43 52 source = models.CharField(maxlength=250, blank=True) 44 53 subject = models.CharField(maxlength=250, blank=True) 54 physical_format = models.ForeignKey(PhysicalFormat, null=True, blank=True) 45 55 46 56 objects = MediaCollectionManager() … … 132 142 pass 133 143 134 -
telemeta/templates/base.html
r75931df re634d6b 1 <html> 2 <link rel="stylesheet" href="/css/style.css" /> 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml" lang="{{ LANGUAGE_CODE }}" xml:lang="{{ LANGUAGE_CODE }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}> 3 <head> 4 <title>Telemeta</title> 5 <link rel="stylesheet" type="text/css" href="/css/telemeta.css" /> 6 {% block extra_style %}{% endblock %} 7 </head> 8 {% load i18n %} 3 9 <body> 4 10 <!-- 11 {% if user.is_authenticated and user.is_staff %} 12 <div id="user-tools">{% trans 'Welcome,' %} <strong>{% if user.first_name %}{{ user.first_name|escape }}{% else %}{{ user.username }}{% endif %}</strong>. {% block userlinks %}<a href="doc/">{% trans 'Documentation' %}</a> / <a href="password_change/">{% trans 'Change password' %}</a> / <a href="logout/">{% trans 'Log out' %}</a>{% endblock %}</div> 13 {% endif %} 14 --> 5 15 <div id="header"> 6 <a href="/"> Telemeta Web Interface</a>16 <a href="/"><img src="/images/logo.png"></a> 7 17 </div> 8 18 … … 20 30 </div> 21 31 32 <div id="content"> 22 33 {% block content %}{% endblock %} 34 </div> 23 35 24 36 </body> -
telemeta/urls.py
r77469e8 re634d6b 1 1 from django.conf.urls.defaults import * 2 2 from telemeta.models import MediaItem, MediaCollection 3 from telemeta.core import ComponentManager 4 from telemeta.views.web import WebView 5 6 comp_mgr = ComponentManager() 7 web_view = WebView(comp_mgr) 3 8 4 9 all_items = { … … 11 16 12 17 urlpatterns = patterns('', 13 (r'^$', 'telemeta.views.web.index'),18 (r'^$', web_view.index), 14 19 (r'^items/$', 'django.views.generic.list_detail.object_list', 15 20 dict(all_items, paginate_by=10, template_name="mediaitem_list.html")), 16 (r'^items/(?P<item_id>[0-9]+)/$', 'telemeta.views.web.item_detail'),21 (r'^items/(?P<item_id>[0-9]+)/$', web_view.item_detail), 17 22 (r'^items/(?P<item_id>[0-9]+)/download/(?P<format>[0-9A-Z]+)/$', 18 'telemeta.views.web.item_export'),23 web_view.item_export), 19 24 #(r'^media_item/(?P<media_item_id>[0-9]+)/$', 'telemeta.views.web.media_item_edit'), 20 25 (r'^media_item/(?P<media_item_id>[0-9]+)/update/$', 'telemeta.views.web.media_item_update'), … … 25 30 'django.views.generic.list_detail.object_detail', 26 31 dict(all_collections, template_name="collection_detail.html")), 32 #(r'^dictionaries/$', web_view.dictionary_list), 33 (r'^admin/$', web_view.admin_index), 34 (r'^admin/dictionaries/(?P<dictionary_id>[0-9a-z]+)/$', web_view.edit_dictionary), 35 (r'^admin/dictionaries/(?P<dictionary_id>[0-9a-z]+)/add/$', web_view.add_to_dictionary), 36 (r'^admin/dictionaries/(?P<dictionary_id>[0-9a-z]+)/update/$', web_view.update_dictionary), 37 (r'^admin/dictionaries/(?P<dictionary_id>[0-9a-z]+)/(?P<value_id>[0-9]+)/$', 38 web_view.edit_dictionary_value), 27 39 28 (r'^search/$', 29 'telemeta.views.web.quick_search'), 40 (r'^admin/dictionaries/(?P<dictionary_id>[0-9a-z]+)/(?P<value_id>[0-9]+)/update/$', 41 web_view.update_dictionary_value), 42 43 (r'^search/$', web_view.quick_search), 30 44 31 45 32 # CSS (FIXME: for developement only) 33 (r'^css/(?P<path>.*)$', 'django.views.static.serve', {'document_root': './telemeta/css'}), 46 # CSS+Images (FIXME: for developement only) 47 (r'^css/(?P<path>.*)$', 'django.views.static.serve', {'document_root': './telemeta/htdocs/css'}), 48 (r'^images/(?P<path>.*)$', 'django.views.static.serve', {'document_root': './telemeta/htdocs/images'}), 34 49 ) 35 50 -
telemeta/views/web.py
r77469e8 re634d6b 9 9 import re 10 10 from telemeta.core import * 11 from telemeta.core import ComponentManager12 11 from telemeta.export import * 13 12 from django.conf import settings 14 13 import os 15 14 16 def index(request):17 "Render the homepage"18 19 media_items = MediaItem.objects.all()20 template = loader.get_template('index.html')21 context = Context({22 'media_items' : media_items,23 })24 return HttpResponse(template.render(context))25 26 15 class WebView(Component): 16 """Provide web UI methods""" 27 17 28 18 exporters = ExtensionPoint(IExporter) 29 19 20 def index(self, request): 21 """Render the homepage""" 22 23 template = loader.get_template('index.html') 24 context = Context({}) 25 return HttpResponse(template.render(context)) 26 30 27 def item_detail(self, request, item_id): 28 """Show the details of a given item""" 31 29 item = MediaItem.objects.get(pk=item_id) 32 30 formats = [] … … 36 34 {'item': item, 'export_formats': formats}) 37 35 38 def file_stream(self, filepath): 36 def __file_stream(self, filepath): 37 """Generator for streaming a file from the disk. 38 39 This method shouldn't be needed anymore when bug #8 get fixed 40 """ 41 39 42 buffer_size = 0xFFFF 40 43 f = open(filepath, 'rb') … … 47 50 48 51 def item_export(self, request, item_id, format): 52 """Export a given media item in the specified format (OGG, FLAC, ...)""" 49 53 for exporter in self.exporters: 50 54 if exporter.get_format() == format: … … 69 73 outfile = exporter.process(item.id, infile, metadata, []) 70 74 71 response = HttpResponse(self. file_stream(outfile), mimetype = mime_type)75 response = HttpResponse(self.__file_stream(outfile), mimetype = mime_type) 72 76 response['Content-Disposition'] = 'attachment; filename="download.' + \ 73 77 exporter.get_file_extension() + '"' … … 75 79 76 80 def quick_search(self, request): 81 """Perform a simple search through collections and items core metadata""" 77 82 pattern = request.REQUEST["pattern"] 78 83 collections = MediaCollection.objects.quick_search(pattern) … … 82 87 'items': items}) 83 88 84 85 86 comp_mgr = ComponentManager() 87 view = WebView(comp_mgr) 88 item_detail = view.item_detail 89 item_export = view.item_export 90 quick_search = view.quick_search 91 89 def __get_dictionary_list(self): 90 from django.db.models import get_models 91 models = get_models(telemeta.models) 92 93 dictionaries = [] 94 for model in models: 95 if getattr(model, "is_dictionary", False): 96 dictionaries.append({"name": model._meta.verbose_name_plural, 97 "id": model._meta.module_name}) 98 return dictionaries 99 100 def __get_admin_context_vars(self): 101 return {"dictionaries": self.__get_dictionary_list()} 102 103 def admin_index(self, request): 104 return render_to_response('admin.html', self. __get_admin_context_vars()) 105 106 def __get_dictionary(self, id): 107 from django.db.models import get_models 108 models = get_models(telemeta.models) 109 for model in models: 110 if model._meta.module_name == id: 111 break 112 113 if model._meta.module_name != id: 114 return None 115 116 return model 117 118 119 def edit_dictionary(self, request, dictionary_id): 120 121 dictionary = self.__get_dictionary(dictionary_id) 122 if dictionary == None: 123 raise Http404 124 125 vars = self.__get_admin_context_vars() 126 vars["dictionary_id"] = dictionary._meta.module_name 127 vars["dictionary_name"] = dictionary._meta.verbose_name 128 vars["dictionary_name_plural"] = dictionary._meta.verbose_name_plural 129 vars["dictionary_values"] = dictionary.objects.all() 130 return render_to_response('dictionary_edit.html', vars) 131 132 def add_to_dictionary(self, request, dictionary_id): 133 134 dictionary = self.__get_dictionary(dictionary_id) 135 if dictionary == None: 136 raise Http404 137 138 dictionary_value = dictionary(value=request.POST['value']) 139 dictionary_value.save() 140 141 return self.edit_dictionary(request, dictionary_id) 142 143 def update_dictionary(self, request, dictionary_id): 144 145 dictionary = self.__get_dictionary(dictionary_id) 146 if dictionary == None: 147 raise Http404 148 149 if request.POST.has_key("remove"): 150 dictionary.objects.filter(id__in=request.POST['sel']).delete() 151 152 return self.edit_dictionary(request, dictionary_id) 153 154 def edit_dictionary_value(self, request, dictionary_id, value_id): 155 156 dictionary = self.__get_dictionary(dictionary_id) 157 if dictionary == None: 158 raise Http404 159 160 vars = self.__get_admin_context_vars() 161 vars["dictionary_id"] = dictionary._meta.module_name 162 vars["dictionary_name"] = dictionary._meta.verbose_name 163 vars["dictionary_name_plural"] = dictionary._meta.verbose_name_plural 164 vars["dictionary_record"] = dictionary.objects.get(id__exact=value_id) 165 return render_to_response('dictionary_edit_value.html', vars) 166 167 def update_dictionary_value(self, request, dictionary_id, value_id): 168 169 if request.POST.has_key("save"): 170 dictionary = self.__get_dictionary(dictionary_id) 171 if dictionary == None: 172 raise Http404 173 174 record = dictionary.objects.get(id__exact=value_id) 175 record.value = request.POST["value"] 176 record.save() 177 178 return self.edit_dictionary(request, dictionary_id) 179 180 92 181 def media_item_edit(request, media_item_id): 93 182 "Provide MediaItem object edition"
Note: See TracChangeset
for help on using the changeset viewer.
