From d3a862ae2ad8cc4c42580cbd0caebb4de2a9d479 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Mon, 29 Feb 2016 10:35:20 +0100 Subject: [PATCH] update doc, add mixins and view methods --- README.rst | 17 +++++++----- app/festival/admin.py | 13 --------- app/festival/models.py | 27 +++++++++++++++---- .../templates/festival/artist_list.html | 2 +- .../templates/festival/video_list.html | 2 +- app/festival/urls.py | 6 ++--- app/festival/views.py | 13 +++++++-- 7 files changed, 49 insertions(+), 31 deletions(-) diff --git a/README.rst b/README.rst index 87c51dfc..75ad6233 100644 --- a/README.rst +++ b/README.rst @@ -20,15 +20,18 @@ Run these commands in a terminal:: git clone --recursive git://git.forge.ircam.fr/Manifeste.git cd Manifeste - docker-compose up + docker-compose up db + +The last command is needed to init the database. Press CTRL-C to exit. Then fire up the whole composition:: + + docker-compose up To restore the backuped database, in another terminal:: cd Manifeste docker-compose run db /srv/backup/restore_db.sh - docker-compose run pgdb /srv/backup/restore_db_eve.sh -You should be able to browse the site at http://localhost:8010/ +You should be able to browse the site at http://localhost:9000/ MacOS or Windows: @@ -44,13 +47,15 @@ Run these commands in a terminal:: cd Manifeste docker-compose up +The last command is needed to init the database. Press CTRL-C to exit. Then fire up the whole composition:: + + docker-compose up + Then, in another terminal:: eval "$(docker-machine env manifeste)" cd Manifeste - docker-compose run db /srv/backup/restore_db.sh #(MAJ base festival) - docker-compose run pgdb /srv/backup/restore_db_eve.sh #(MAJ base eve) - + docker-compose run db /srv/backup/restore_db.sh `More info `_ about using docker and related tools. The 3rd command should give you the IP of the VM. For example, if IP is 192.168.59.103, you should be able to browse the site at http://192.168.59.103:8010/ diff --git a/app/festival/admin.py b/app/festival/admin.py index 1438053e..e9bd6bf1 100644 --- a/app/festival/admin.py +++ b/app/festival/admin.py @@ -20,9 +20,6 @@ class FestivalEventInline(admin.StackedInline): class FestivalEventAdmin(EventAdmin): - """ - Admin class for events. - """ inlines = [FestivalEventInline, ] @@ -43,20 +40,10 @@ class VideoAdminDisplayable(DisplayableAdmin): class ArtistAdminDisplayable(DisplayableAdmin): - """ - Admin class for artists. - """ fieldsets = deepcopy(ArtistAdmin.fieldsets) - def save_form(self, request, form, change): - """ - Super class ordering is important here - user must get saved first. - """ - return DisplayableAdmin.save_form(self, request, form, change) - - admin.site.unregister(Event) admin.site.register(Event, FestivalEventAdmin) diff --git a/app/festival/models.py b/app/festival/models.py index a39c29c0..ad419e43 100644 --- a/app/festival/models.py +++ b/app/festival/models.py @@ -1,5 +1,6 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ +from django.core.urlresolvers import reverse, reverse_lazy from mezzanine.core.models import RichText, Displayable from mezzanine.core.fields import RichTextField, OrderField, FileField @@ -72,15 +73,20 @@ class Artist(Displayable, RichText, AdminThumbMixin): photo_credits = models.CharField(_('photo credits'), max_length=255, blank=True, null=True) featured = models.BooleanField(_('featured'), default=False) - search_fields = ("name", "bio") - - def __unicode__(self): - return self.name + search_fields = ("title", "bio") class Meta(MetaCore): verbose_name = _('artist') db_table = app_label + '_artists' + def __unicode__(self): + return self.title + + def get_absolute_url(self): + url_name = "festival_artist_detail" + kwargs = {"slug": self.slug} + return reverse(url_name, kwargs=kwargs) + class Video(Displayable, RichText): """Video""" @@ -88,13 +94,24 @@ class Video(Displayable, RichText): event = models.ForeignKey(Event, related_name='videos', verbose_name=_('event'), blank=True, null=True, on_delete=models.SET_NULL) media_id = models.IntegerField(_('media id')) + class Meta(MetaCore): + verbose_name = _('video') + db_table = app_label + '_videos' + def __unicode__(self): - return + return self.title @property def html(self): pass + @models.permalink + def get_absolute_url(self): + url_name = "festival_video_detail" + kwargs = {"slug": self.slug} + return reverse(url_name, kwargs=kwargs) + + class EventCategory(BaseNameModel): """Event Category""" diff --git a/app/festival/templates/festival/artist_list.html b/app/festival/templates/festival/artist_list.html index 59248133..b921ee80 100644 --- a/app/festival/templates/festival/artist_list.html +++ b/app/festival/templates/festival/artist_list.html @@ -7,7 +7,7 @@
diff --git a/app/festival/templates/festival/video_list.html b/app/festival/templates/festival/video_list.html index 33a57d95..7add06cf 100644 --- a/app/festival/templates/festival/video_list.html +++ b/app/festival/templates/festival/video_list.html @@ -7,7 +7,7 @@
diff --git a/app/festival/urls.py b/app/festival/urls.py index 04aa4905..ffed233f 100644 --- a/app/festival/urls.py +++ b/app/festival/urls.py @@ -11,8 +11,8 @@ from festival.views import * urlpatterns = patterns('', url(r'^artists/$', ArtistListView.as_view(), name="festival-artist-list"), - url(r'^artists/(?P.*)/$', ArtistDetailView.as_view(), name="festival-artist-detail"), - url(r'^videos/$', ArtistListView.as_view(), name="festival-video-list"), - url(r'^videos/(?P.*)/$', ArtistDetailView.as_view(), name="festival-video-detail"), + url(r'^artists/(?P.*)/$', ArtistDetailView.as_view(), name="festival-artist-detail"), + url(r'^videos/$', VideoListView.as_view(), name="festival-video-list"), + url(r'^videos/(?P.*)/$', VideoDetailView.as_view(), name="festival-video-detail"), ) diff --git a/app/festival/views.py b/app/festival/views.py index defac746..7abd16b5 100644 --- a/app/festival/views.py +++ b/app/festival/views.py @@ -1,10 +1,18 @@ from django.shortcuts import render from django.views.generic import * from django.views.generic.base import * +from django.shortcuts import get_object_or_404 from festival.models import * +class SlugMixin(object): + + def get_object(self): + objects = self.model.objects.all() + return get_object_or_404(objects, slug=self.kwargs['slug']) + + class ArtistListView(ListView): model = Artist @@ -15,7 +23,7 @@ class ArtistListView(ListView): return context -class ArtistDetailView(DetailView): +class ArtistDetailView(SlugMixin, DetailView): model = Artist template_name='festival/artist_detail.html' @@ -36,7 +44,7 @@ class VideoListView(ListView): return context -class VideoDetailView(DetailView): +class VideoDetailView(SlugMixin, DetailView): model = Video template_name='festival/video_detail.html' @@ -45,3 +53,4 @@ class VideoDetailView(DetailView): def get_context_data(self, **kwargs): context = super(VideoDetailView, self).get_context_data(**kwargs) return context + -- 2.39.5