forked from rc/aircox
admin; section.get -> section.render; templates fix; menu are now per view; doc
This commit is contained in:
@ -1,8 +1,25 @@
|
||||
from django.contrib import admin
|
||||
from suit.admin import SortableTabularInline, SortableModelAdmin
|
||||
|
||||
import aircox.programs.models as programs
|
||||
import aircox.cms.admin as cms
|
||||
import aircox.website.models as models
|
||||
|
||||
admin.site.register(models.Program)
|
||||
admin.site.register(models.Diffusion)
|
||||
import aircox.website.forms as forms
|
||||
|
||||
|
||||
class TrackInline (SortableTabularInline):
|
||||
fields = ['artist', 'name', 'tags', 'position']
|
||||
form = forms.TrackForm
|
||||
model = programs.Track
|
||||
sortable = 'position'
|
||||
extra = 10
|
||||
|
||||
|
||||
class DiffusionPostAdmin(cms.RelatedPostAdmin):
|
||||
inlines = [TrackInline]
|
||||
|
||||
|
||||
admin.site.register(models.Program, cms.RelatedPostAdmin)
|
||||
admin.site.register(models.Diffusion, DiffusionPostAdmin)
|
||||
|
||||
|
||||
|
40
website/autocomplete_light_registry.py
Normal file
40
website/autocomplete_light_registry.py
Normal file
@ -0,0 +1,40 @@
|
||||
import autocomplete_light.shortcuts as al
|
||||
import aircox.programs.models as programs
|
||||
|
||||
from taggit.models import Tag
|
||||
al.register(Tag)
|
||||
|
||||
|
||||
class OneFieldAutocomplete(al.AutocompleteModelBase):
|
||||
choice_html_format = u'''
|
||||
<span class="block" data-value="%s">%s</span>
|
||||
'''
|
||||
|
||||
def choice_html (self, choice):
|
||||
value = choice[self.search_fields[0]]
|
||||
return self.choice_html_format % (self.choice_label(choice),
|
||||
self.choice_label(value))
|
||||
|
||||
|
||||
def choices_for_request(self):
|
||||
#if not self.request.user.is_staff:
|
||||
# self.choices = self.choices.filter(private=False)
|
||||
filter_args = { self.search_fields[0] + '__icontains': self.request.GET['q'] }
|
||||
|
||||
self.choices = self.choices.filter(**filter_args)
|
||||
self.choices = self.choices.values(self.search_fields[0]).distinct()
|
||||
return self.choices
|
||||
|
||||
|
||||
class TrackArtistAutocomplete(OneFieldAutocomplete):
|
||||
search_fields = ['artist']
|
||||
model = programs.Track
|
||||
al.register(TrackArtistAutocomplete)
|
||||
|
||||
|
||||
class TrackNameAutocomplete(OneFieldAutocomplete):
|
||||
search_fields = ['name']
|
||||
model = programs.Track
|
||||
al.register(TrackNameAutocomplete)
|
||||
|
||||
|
19
website/forms.py
Normal file
19
website/forms.py
Normal file
@ -0,0 +1,19 @@
|
||||
from django import forms
|
||||
|
||||
import autocomplete_light.shortcuts as al
|
||||
from autocomplete_light.contrib.taggit_field import TaggitWidget
|
||||
|
||||
import aircox.programs.models as programs
|
||||
|
||||
|
||||
class TrackForm (forms.ModelForm):
|
||||
class Meta:
|
||||
model = programs.Track
|
||||
fields = ['artist', 'name', 'tags', 'position']
|
||||
widgets = {
|
||||
'artist': al.TextWidget('TrackArtistAutocomplete'),
|
||||
'name': al.TextWidget('TrackNameAutocomplete'),
|
||||
'tags': TaggitWidget('TagAutocomplete'),
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ class Diffusion (RelatedPost):
|
||||
super().__init__(*args, **kwargs)
|
||||
if self.thread:
|
||||
if not self.title:
|
||||
self.title = _('{name} on {first_diff}').format(
|
||||
self.title = _('{name} // {first_diff}').format(
|
||||
self.related.program.name,
|
||||
self.related.start.strftime('%A %d %B')
|
||||
)
|
||||
|
Reference in New Issue
Block a user