Changeset e634d6b


Ignore:
Timestamp:
May 1, 2007 4:45:31 PM (7 years ago)
Author:
olivier <>
Branches:
master, crem, crem2, dev, dev2, diadems, feature/breadcrumbs, feature/ts-0.5, feature/ts-0.5.4, feature/writecache, forma, generic, instru_search, lam, lam2, mapsv3, merge, nlivemulti, production, release/1.4.4, sabiod, security, server, social, storage, telecaster, test, video
Children:
c2aa673
Parents:
4bdb860
git-author:
olivier <> (01/05/2007 16:45:31)
git-committer:
olivier <> (01/05/2007 16:45:31)
Message:
  • Created new administration interface. BEWARE: update your site urls (in urls.py), telemeta now provides an internal "admin/" url, that may conflict with django's admin.
  • Implemented edition of generic "dictionaries" (or "enumerations"). These are the linked tables that contained various predefined values, used in collections, items and/or parts
  • added "physical format" dictionary (collection field and linked table), see EthnomusDatabase
  • misc cleanup
Location:
telemeta
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • telemeta/models.py

    r77469e8 re634d6b  
    2020        return fields_dict 
    2121 
     22class 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         
    2230class MediaCollectionManager(models.Manager): 
    2331    def quick_search(self, pattern): 
     
    2634            Q(description__icontains=pattern) 
    2735        ) 
     36 
    2837 
    2938class MediaCollection(models.Model, MediaCore): 
     
    4352    source = models.CharField(maxlength=250, blank=True) 
    4453    subject = models.CharField(maxlength=250, blank=True) 
     54    physical_format = models.ForeignKey(PhysicalFormat, null=True, blank=True) 
    4555 
    4656    objects = MediaCollectionManager() 
     
    132142        pass 
    133143 
    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 %} 
    39<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--> 
    515<div id="header"> 
    6 <a href="/">Telemeta Web Interface</a> 
     16<a href="/"><img src="/images/logo.png"></a> 
    717</div> 
    818 
     
    2030</div> 
    2131 
     32<div id="content"> 
    2233{% block content %}{% endblock %} 
     34</div> 
    2335 
    2436</body> 
  • telemeta/urls.py

    r77469e8 re634d6b  
    11from django.conf.urls.defaults import * 
    22from telemeta.models import MediaItem, MediaCollection 
     3from telemeta.core import ComponentManager 
     4from telemeta.views.web import WebView 
     5 
     6comp_mgr = ComponentManager() 
     7web_view = WebView(comp_mgr) 
    38 
    49all_items = { 
     
    1116 
    1217urlpatterns = patterns('', 
    13     (r'^$', 'telemeta.views.web.index'), 
     18    (r'^$', web_view.index), 
    1419    (r'^items/$', 'django.views.generic.list_detail.object_list',  
    1520        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), 
    1722    (r'^items/(?P<item_id>[0-9]+)/download/(?P<format>[0-9A-Z]+)/$',  
    18         'telemeta.views.web.item_export'), 
     23        web_view.item_export), 
    1924    #(r'^media_item/(?P<media_item_id>[0-9]+)/$', 'telemeta.views.web.media_item_edit'), 
    2025    (r'^media_item/(?P<media_item_id>[0-9]+)/update/$', 'telemeta.views.web.media_item_update'), 
     
    2530        'django.views.generic.list_detail.object_detail', 
    2631        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),    
    2739 
    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), 
    3044 
    3145 
    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'}), 
    3449) 
    3550 
  • telemeta/views/web.py

    r77469e8 re634d6b  
    99import re 
    1010from telemeta.core import * 
    11 from telemeta.core import ComponentManager 
    1211from telemeta.export import * 
    1312from django.conf import settings 
    1413import os 
    1514 
    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  
    2615class WebView(Component): 
     16    """Provide web UI methods""" 
    2717 
    2818    exporters = ExtensionPoint(IExporter) 
    2919 
     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 
    3027    def item_detail(self, request, item_id): 
     28        """Show the details of a given item""" 
    3129        item = MediaItem.objects.get(pk=item_id) 
    3230        formats = [] 
     
    3634                    {'item': item, 'export_formats': formats}) 
    3735 
    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 
    3942        buffer_size = 0xFFFF 
    4043        f = open(filepath, 'rb') 
     
    4750 
    4851    def item_export(self, request, item_id, format):                     
     52        """Export a given media item in the specified format (OGG, FLAC, ...)""" 
    4953        for exporter in self.exporters: 
    5054            if exporter.get_format() == format: 
     
    6973        outfile = exporter.process(item.id, infile, metadata, []) 
    7074 
    71         response = HttpResponse(self.file_stream(outfile), mimetype = mime_type) 
     75        response = HttpResponse(self.__file_stream(outfile), mimetype = mime_type) 
    7276        response['Content-Disposition'] = 'attachment; filename="download.' + \ 
    7377                    exporter.get_file_extension() + '"' 
     
    7579 
    7680    def quick_search(self, request): 
     81        """Perform a simple search through collections and items core metadata""" 
    7782        pattern = request.REQUEST["pattern"] 
    7883        collections = MediaCollection.objects.quick_search(pattern) 
     
    8287                     'items': items}) 
    8388 
    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         
    92181def media_item_edit(request, media_item_id): 
    93182    "Provide MediaItem object edition" 
Note: See TracChangeset for help on using the changeset viewer.