]> git.parisson.com Git - mezzo.git/commitdiff
Project : add dynamic content
authorEmilie <zawadzki@ircam.fr>
Fri, 4 Nov 2016 17:58:32 +0000 (18:58 +0100)
committerEmilie <zawadzki@ircam.fr>
Fri, 4 Nov 2016 17:58:32 +0000 (18:58 +0100)
12 files changed:
app/organization/agenda/forms.py
app/organization/agenda/views.py
app/organization/projects/admin.py
app/organization/projects/forms.py [new file with mode: 0644]
app/organization/projects/migrations/0026_dynamiccontentproject.py [new file with mode: 0644]
app/organization/projects/migrations/0027_auto_20161104_1849.py [new file with mode: 0644]
app/organization/projects/migrations/0028_auto_20161104_1855.py [new file with mode: 0644]
app/organization/projects/models.py
app/organization/projects/translation.py
app/organization/projects/urls.py
app/organization/projects/views.py
app/templates/projects/project_detail.html

index 96f6020740f978725ae1a34828da9305ffabc508..af8b12bff4c686a68e25eb4bfcd52197c67f8c79 100644 (file)
@@ -11,16 +11,14 @@ from organization.magazine.models import Article, Topic, Brief
 from organization.pages.models import CustomPage
 from organization.agenda.models import Event, DynamicContentEvent
 from organization.media.models import Playlist
-from organization.network.models import TeamPage
-from organization.projects.models import Project
-
 
 class DynamicContentEventForm(autocomplete.FutureModelForm):
 
     content_object = dal_queryset_sequence.fields.QuerySetSequenceModelField(
         queryset=autocomplete.QuerySetSequence(
             Article.objects.all(),
-            CustomPage.objects.all()
+            CustomPage.objects.all(),
+            Event.objects.all()
         ),
         required=False,
         widget=dal_select2_queryset_sequence.widgets.QuerySetSequenceSelect2('dynamic-content-event'),
index 03d85d5ebaf1843888275054814186c453dc701d..acaddea1b412f3e3908600a4be673e5f3cf596f2 100644 (file)
@@ -2,8 +2,6 @@ from django.views.generic.base import TemplateView
 from mezzanine.conf import settings
 from dal import autocomplete
 from dal_select2_queryset_sequence.views import Select2QuerySetSequenceView
-from organization.network.models import TeamPage
-from organization.projects.models import Project
 from organization.magazine.models import Article
 from organization.pages.models import CustomPage
 from mezzanine_agenda.models import Event
@@ -34,11 +32,8 @@ class DynamicContentEventView(Select2QuerySetSequenceView):
         qs = autocomplete.QuerySetSequence(articles, custompage, events,)
 
         if self.q:
-            # This would apply the filter on all the querysets
             qs = qs.filter(title__icontains=self.q)
 
-        # This will limit each queryset so that they show an equal number
-        # of results.
         qs = self.mixup_querysets(qs)
 
         return qs
index 9396727a0b60486695db5b3bc0bada5418509aff..daed65c2e91ef1304004483592435ae3376ef6ff 100644 (file)
@@ -5,11 +5,12 @@ from django.utils.translation import ugettext_lazy as _
 
 from mezzanine.core.admin import *
 from mezzanine.pages.admin import PageAdmin
-
+from modeltranslation.admin import TranslationTabularInline
 from organization.projects.models import *
 from organization.pages.models import *
 from organization.media.models import Playlist
 from organization.pages.admin import PageImageInline
+from organization.projects.forms import DynamicContentProjectForm
 
 
 class ProjectLinkInline(StackedDynamicInlineAdmin):
@@ -53,6 +54,22 @@ class ProjectAdmin(admin.ModelAdmin):
     model = Project
 
 
+class ProjectRelatedTitleAdmin(TranslationTabularInline):
+
+    model = ProjectRelatedTitle
+
+
+class DynamicContentProjectInline(TabularDynamicInlineAdmin):
+
+    model = DynamicContentProject
+    form = DynamicContentProjectForm
+
+    class Media:
+        js = (
+            static("mezzanine/js/admin/dynamic_inline.js"),
+        )
+
+
 class ProjectAdminDisplayable(DisplayableAdmin):
 
     fieldsets = deepcopy(ProjectAdmin.fieldsets)
@@ -60,7 +77,9 @@ class ProjectAdminDisplayable(DisplayableAdmin):
                 ProjectImageInline,
                 ProjectPlaylistInline,
                 ProjectLinkInline,
-                ProjectFileInline,]
+                ProjectFileInline,
+                ProjectRelatedTitleAdmin,
+                DynamicContentProjectInline]
     filter_horizontal = ['teams', 'organizations']
     list_filter = ['type', 'program', 'program_type', ]
 
diff --git a/app/organization/projects/forms.py b/app/organization/projects/forms.py
new file mode 100644 (file)
index 0000000..afe0c2d
--- /dev/null
@@ -0,0 +1,31 @@
+from dal import autocomplete
+
+import dal_queryset_sequence
+import dal_select2_queryset_sequence
+
+from django import forms
+from django.forms.widgets import HiddenInput
+from django.forms import ModelForm
+from mezzanine.core.models import Orderable
+from organization.magazine.models import Article, Topic, Brief
+from organization.pages.models import CustomPage
+from organization.agenda.models import Event, DynamicContentEvent
+from organization.media.models import Playlist
+from organization.projects.models import DynamicContentProject
+
+
+class DynamicContentProjectForm(autocomplete.FutureModelForm):
+
+    content_object = dal_queryset_sequence.fields.QuerySetSequenceModelField(
+        queryset=autocomplete.QuerySetSequence(
+            Article.objects.all(),
+            CustomPage.objects.all(),
+            Event.objects.all()
+        ),
+        required=False,
+        widget=dal_select2_queryset_sequence.widgets.QuerySetSequenceSelect2('dynamic-content-project'),
+    )
+
+    class Meta:
+        model = DynamicContentProject
+        fields = ('content_object',)
diff --git a/app/organization/projects/migrations/0026_dynamiccontentproject.py b/app/organization/projects/migrations/0026_dynamiccontentproject.py
new file mode 100644 (file)
index 0000000..e18669b
--- /dev/null
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.10 on 2016-11-04 17:33
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import mezzanine.core.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('contenttypes', '0002_remove_content_type_name'),
+        ('organization-projects', '0025_auto_20161103_1825'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='DynamicContentProject',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('_order', mezzanine.core.fields.OrderField(null=True, verbose_name='Order')),
+                ('object_id', models.PositiveIntegerField(editable=False, null=True, verbose_name='related object')),
+                ('content_type', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType', verbose_name='content type')),
+                ('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dynamic_content_project', to='organization-projects.Project', verbose_name='project')),
+            ],
+            options={
+                'verbose_name': 'Dynamic Content Project',
+                'ordering': ('_order',),
+            },
+        ),
+    ]
diff --git a/app/organization/projects/migrations/0027_auto_20161104_1849.py b/app/organization/projects/migrations/0027_auto_20161104_1849.py
new file mode 100644 (file)
index 0000000..efbe8b6
--- /dev/null
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.10 on 2016-11-04 17:49
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organization-projects', '0026_dynamiccontentproject'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='ProjectRelatedTitle',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('title', models.CharField(blank=True, max_length=1024, null=True, verbose_name='title')),
+                ('project', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='related_title', to='organization-projects.Project', verbose_name='project')),
+            ],
+            options={
+                'verbose_name': 'related title',
+            },
+        ),
+        migrations.AlterOrderWithRespectTo(
+            name='projectrelatedtitle',
+            order_with_respect_to='project',
+        ),
+    ]
diff --git a/app/organization/projects/migrations/0028_auto_20161104_1855.py b/app/organization/projects/migrations/0028_auto_20161104_1855.py
new file mode 100644 (file)
index 0000000..30d821c
--- /dev/null
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.10 on 2016-11-04 17:55
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organization-projects', '0027_auto_20161104_1849'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='projectrelatedtitle',
+            name='title_en',
+            field=models.CharField(blank=True, max_length=1024, null=True, verbose_name='title'),
+        ),
+        migrations.AddField(
+            model_name='projectrelatedtitle',
+            name='title_fr',
+            field=models.CharField(blank=True, max_length=1024, null=True, verbose_name='title'),
+        ),
+    ]
index f960eac01b0318dacbdbaa6ded13ea7743b0620a..66356bdbd57a9d6229233c95e60b43a39233bf39 100644 (file)
@@ -196,3 +196,20 @@ class RepositorySystem(Named):
     class Meta:
         verbose_name = _('repository system')
         verbose_name_plural = _("repository systems")
+
+
+class ProjectRelatedTitle(RelatedTitle):
+
+    project = models.OneToOneField(Project, verbose_name=_('project'), related_name='related_title', blank=True, null=True, on_delete=models.SET_NULL)
+
+    class Meta:
+        verbose_name = _("related title")
+        order_with_respect_to = "project"
+
+
+class DynamicContentProject(DynamicContent, Orderable):
+
+    project = models.ForeignKey(Project, verbose_name=_('project'), related_name='dynamic_content_project', blank=True, null=True, on_delete=models.SET_NULL)
+
+    class Meta:
+        verbose_name = 'Dynamic Content Project'
index 8398acd61644ec422c05d6c8a7aad34fffa5a2b4..b7ce47e43674c3d5eb0fcfca5cacec78ba34bdd2 100644 (file)
@@ -67,3 +67,15 @@ class ProjectTopicPageTranslationOptions(TranslationOptions):
 class ProjectDemoTranslationOptions(TranslationOptions):
 
     fields = ('title', 'description',)
+
+
+@register(ProjectRelatedTitle)
+class ProjectRelatedTitleranslationOptions(TranslationOptions):
+
+    fields = ('title',)
+
+
+@register(DynamicContentProject)
+class DynamicContentProjectTranslationOptions(TranslationOptions):
+
+    fields = ()
index 19efbc97d6a2cb6ba4b714421c8f924b35667e93..86bf8853e0ae19a6ce1ffb080064b4ccb78f2ca0 100644 (file)
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
 import django.views.i18n
 from django.conf.urls import patterns, include, url
 from django.conf.urls.i18n import i18n_patterns
-
+from django.contrib.auth.decorators import permission_required
 from mezzanine.core.views import direct_to_template
 from mezzanine.conf import settings
 
@@ -11,4 +11,5 @@ from organization.projects.views import *
 
 urlpatterns = [
     url("^project/detail/(?P<slug>.*)/$", ProjectDetailView.as_view(), name='organization-project-detail'),
+    url("^dynamic-content-project/$",  permission_required('project.can_edit')(DynamicContentProjectView.as_view()), name='dynamic-content-project'),
 ]
index abd8acdba0c4e75311b5fe37f4777ae504d7f2cb..a6bc9154a6729aa636353326be60ba637b861869 100644 (file)
@@ -1,7 +1,11 @@
 from django.shortcuts import render
-
+from dal import autocomplete
+from dal_select2_queryset_sequence.views import Select2QuerySetSequenceView
 from organization.projects.models import *
 from organization.core.views import *
+from organization.magazine.views import Article
+from mezzanine_agenda.models import Event
+from organization.pages.models import CustomPage
 
 
 class ProjectDetailView(SlugMixin, DetailView):
@@ -30,3 +34,26 @@ class ProjectDetailView(SlugMixin, DetailView):
         elif project.topic:
             context['page'] = project.topic.pages.all().first()
         return context
+
+
+class DynamicContentProjectView(Select2QuerySetSequenceView):
+
+    def get_queryset(self):
+
+        articles = Article.objects.all()
+        custompage = CustomPage.objects.all()
+        events = Event.objects.all()
+
+        if self.q:
+            articles = articles.filter(title__icontains=self.q)
+            custompage = custompage.filter(title__icontains=self.q)
+            events = events.filter(title__icontains=self.q)
+
+        qs = autocomplete.QuerySetSequence(articles, custompage, events,)
+
+        if self.q:
+            qs = qs.filter(title__icontains=self.q)
+
+        qs = self.mixup_querysets(qs)
+
+        return qs
index eaa5f064abedf69ef1e80616109baa69361d4b13..ca31accd91aaf4643bd3287d2f694182e0828404 100644 (file)
         </div>
     {% endif %}
 {% endblock %}
+
+{% block page_related_content %}
+    {% with dynamic_content=project.dynamic_content_project.all object=project %}
+        {% include "core/inc/related_content.html" %}
+    {% endwith %}
+{% endblock %}