]> git.parisson.com Git - mezzo.git/commitdiff
Add login for blocks, add project block template with login option
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 3 Jan 2017 15:59:31 +0000 (16:59 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 3 Jan 2017 15:59:31 +0000 (16:59 +0100)
15 files changed:
app/organization/agenda/migrations/0021_eventblock_login_required.py [new file with mode: 0644]
app/organization/core/models.py
app/organization/core/views.py
app/organization/media/views.py
app/organization/network/migrations/0077_auto_20170103_1220.py [new file with mode: 0644]
app/organization/pages/migrations/0017_pageblock_login_required.py [new file with mode: 0644]
app/organization/projects/migrations/0035_projectblock_login_required.py [new file with mode: 0644]
app/organization/projects/migrations/0036_auto_20170103_1227.py [new file with mode: 0644]
app/organization/projects/models.py
app/organization/projects/translation.py
app/organization/projects/views.py
app/templates/accounts/account_login.html
app/templates/core/inc/block.html
app/templates/projects/inc/project_block.html [new file with mode: 0644]
app/templates/projects/project_detail.html

diff --git a/app/organization/agenda/migrations/0021_eventblock_login_required.py b/app/organization/agenda/migrations/0021_eventblock_login_required.py
new file mode 100644 (file)
index 0000000..b74c3ca
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.11 on 2017-01-03 11:20
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organization-agenda', '0020_auto_20161205_1536'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='eventblock',
+            name='login_required',
+            field=models.BooleanField(default=False, verbose_name='login required'),
+        ),
+    ]
index 50c1343e6c2769746d89c0f2e6b9e05a9d8a51a9..529849d6f1ecda83f2ed7edd69c2efa6b93929c5 100644 (file)
@@ -100,6 +100,7 @@ class Block(RichText, Titled, Orderable):
 
     with_separator = models.BooleanField(default=False)
     background_color = models.CharField(_('background color'), max_length=32, choices=COLOR_CHOICES, blank=True)
+    login_required = models.BooleanField(_('login required'), default=False)
 
     class Meta:
         abstract = True
index 954d9123fb65d1de386aa0be13b3b3967671e935..bb386a77af9609eeb9728d20b14e135f4a5507c0 100644 (file)
@@ -22,7 +22,7 @@
 from django.shortcuts import render, get_object_or_404
 from django.http import Http404
 from django.views.generic.base import View
-from django.views.generic import DetailView, ListView, TemplateView
+from django.views.generic import DetailView, ListView, TemplateView, UpdateView
 from django.apps import apps
 from django.utils import six, timezone, formats
 from django.utils.translation import ugettext_lazy as _
index 851549e763766a9cb3153d5b94550cd8fa83511f..d5c16d4aaf6247387bdf7ee45b4841b814ab527e 100644 (file)
@@ -73,6 +73,7 @@ class PlaylistListView(ListView):
     model = Playlist
     template_name='media/playlist_list.html'
     context_object_name = 'playlists'
+
     def get_queryset(self):
         self.qs = Playlist.objects.all()
         self.current_type = None
@@ -80,6 +81,7 @@ class PlaylistListView(ListView):
             self.qs = self.qs.filter(type=self.kwargs['type'])
             self.current_type = self.kwargs['type']
         return self.qs
+
     def get_context_data(self, **kwargs):
         context = super(PlaylistListView, self).get_context_data(**kwargs)
 
diff --git a/app/organization/network/migrations/0077_auto_20170103_1220.py b/app/organization/network/migrations/0077_auto_20170103_1220.py
new file mode 100644 (file)
index 0000000..58fdf79
--- /dev/null
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.11 on 2017-01-03 11:20
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organization-network', '0076_auto_20161230_1839'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='organizationblock',
+            name='login_required',
+            field=models.BooleanField(default=False, verbose_name='login required'),
+        ),
+        migrations.AddField(
+            model_name='personblock',
+            name='login_required',
+            field=models.BooleanField(default=False, verbose_name='login required'),
+        ),
+    ]
diff --git a/app/organization/pages/migrations/0017_pageblock_login_required.py b/app/organization/pages/migrations/0017_pageblock_login_required.py
new file mode 100644 (file)
index 0000000..5c2866d
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.11 on 2017-01-03 11:20
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organization-pages', '0016_auto_20161205_1536'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='pageblock',
+            name='login_required',
+            field=models.BooleanField(default=False, verbose_name='login required'),
+        ),
+    ]
diff --git a/app/organization/projects/migrations/0035_projectblock_login_required.py b/app/organization/projects/migrations/0035_projectblock_login_required.py
new file mode 100644 (file)
index 0000000..12a37d7
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.11 on 2017-01-03 11:20
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organization-projects', '0034_auto_20161230_1839'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='projectblock',
+            name='login_required',
+            field=models.BooleanField(default=False, verbose_name='login required'),
+        ),
+    ]
diff --git a/app/organization/projects/migrations/0036_auto_20170103_1227.py b/app/organization/projects/migrations/0036_auto_20170103_1227.py
new file mode 100644 (file)
index 0000000..02072f6
--- /dev/null
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.11 on 2017-01-03 11:27
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import mezzanine.core.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organization-projects', '0035_projectblock_login_required'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='projectblock',
+            name='content_en',
+            field=mezzanine.core.fields.RichTextField(null=True, verbose_name='Content'),
+        ),
+        migrations.AddField(
+            model_name='projectblock',
+            name='content_fr',
+            field=mezzanine.core.fields.RichTextField(null=True, verbose_name='Content'),
+        ),
+        migrations.AddField(
+            model_name='projectblock',
+            name='description_en',
+            field=models.TextField(blank=True, null=True, verbose_name='description'),
+        ),
+        migrations.AddField(
+            model_name='projectblock',
+            name='description_fr',
+            field=models.TextField(blank=True, null=True, verbose_name='description'),
+        ),
+        migrations.AddField(
+            model_name='projectblock',
+            name='title_en',
+            field=models.CharField(max_length=1024, null=True, verbose_name='title'),
+        ),
+        migrations.AddField(
+            model_name='projectblock',
+            name='title_fr',
+            field=models.CharField(max_length=1024, null=True, verbose_name='title'),
+        ),
+    ]
index af207b34b312003fe34ee1c0f98c844ee6020d5c..d5c85d675bf0e2507f5627f2bb4bb247feae94bb 100644 (file)
@@ -149,7 +149,6 @@ class ProjectFile(File):
 
 class ProjectBlock(Block):
 
-
     project = models.ForeignKey(Project, verbose_name=_('project'), related_name='blocks', blank=True, null=True, on_delete=models.SET_NULL)
 
 
index 2b3a87a0de87f1daffd2418dca991e21bcd12e8b..3ce5a108c91a842ff764f1e9a1062b0e5c1ad2fd 100644 (file)
@@ -51,7 +51,7 @@ class ProjectFileTranslationOptions(TranslationOptions):
 @register(ProjectBlock)
 class ProjectBlockTranslationOptions(TranslationOptions):
 
-    pass
+    fields = ('title', 'description', 'content')
 
 
 @register(ProjectLink)
index c3870f2532d6774c13667bd0e46589c2e5458ae5..cdb02a88ecdf3581af19955580c45d123ad4dfe7 100644 (file)
@@ -29,31 +29,41 @@ from organization.core.views import *
 from organization.magazine.views import Article
 from organization.pages.models import CustomPage
 
-class ProjectDetailView(SlugMixin, DetailView):
 
-    model = Project
-    template_name='projects/project_detail.html'
-    context_object_name = 'project'
+class ProjectMixin(object):
 
-    def get_context_data(self, **kwargs):
-        context = super(ProjectDetailView, self).get_context_data(**kwargs)
-        project = self.get_object()
+    def get_context_data_mixin(self, context):
         department = None
 
-        if project.lead_team:
-            if project.lead_team.department:
-                department = project.lead_team.department
+        if self.project.lead_team:
+            if self.project.lead_team.department:
+                department = self.project.lead_team.department
         else:
-            for team in project.teams.all():
+            for team in self.project.teams.all():
                 if team.department:
                     department = team.department
                     break
 
         context['department'] = department
-        if project.topic and project.topic.parent:
-            context['page'] = project.topic.parent.pages.all().first()
-        elif project.topic:
-            context['page'] = project.topic.pages.all().first()
+        if self.project.topic and self.project.topic.parent:
+            context['page'] = self.project.topic.parent.pages.all().first()
+        elif self.project.topic:
+            context['page'] = self.project.topic.pages.all().first()
+
+        return context
+
+
+class ProjectDetailView(SlugMixin, ProjectMixin, DetailView):
+
+    model = Project
+    template_name='projects/project_detail.html'
+    context_object_name = 'project'
+
+    def get_context_data(self, **kwargs):
+        context = super(ProjectDetailView, self).get_context_data(**kwargs)
+        self.project = self.get_object()
+        self.get_context_data_mixin(context)
+        context['next'] = reverse_lazy('organization-project-detail', kwargs={'slug': self.project.slug})
         return context
 
 
@@ -86,7 +96,7 @@ class DynamicContentProjectView(Select2QuerySetSequenceView):
         return results
 
 
-class ProjectDemoDetailView(SlugMixin, DetailView):
+class ProjectDemoDetailView(SlugMixin, ProjectMixin, DetailView):
 
     model = ProjectDemo
     template_name='projects/project_demo_detail.html'
@@ -96,22 +106,5 @@ class ProjectDemoDetailView(SlugMixin, DetailView):
         context = super(ProjectDemoDetailView, self).get_context_data(**kwargs)
         demo = self.get_object()
         project = demo.project
-        department = None
-
-        if project:
-            if project.lead_team:
-                if project.lead_team.department:
-                    department = project.lead_team.department
-            else:
-                for team in project.teams.all():
-                    if team.department:
-                        department = team.department
-                        break
-
-            context['department'] = department
-            if project.topic and project.topic.parent:
-                context['page'] = project.topic.parent.pages.all().first()
-            elif project.topic:
-                context['page'] = project.topic.pages.all().first()
-
+        self.get_context_data_mixin(context)
         return context
index 9bd1a40264db74d6c6d265e086e7453757f8e474..4fbbbaf57771e3b428a026bbe3d5da83f28f1543 100644 (file)
@@ -20,7 +20,6 @@
 {% else %}
     {% include 'accounts/account_form.html'%}
     {% url "signup" as signup_url %}
-    <p>{% blocktrans with request.GET.next as next %}If you don't have an account you can <a href="{{ signup_url }}?next={{ next }}">sign up</a> for one now.{% endblocktrans %}</p>
     {% url "mezzanine_password_reset" as password_reset_url %}
     {% url "profile_update" as profile_update_url %}
     {% blocktrans %}<p>You can also <a href="{{ password_reset_url }}?next={{ profile_update_url }}">reset your password</a> if you've forgotten it.</p>{% endblocktrans %}</p>
index 8524a17529c6960516490a92b4b5c7781927f7ca..bdc2f697effdd287c9c83889ba436e03647cf42d 100644 (file)
@@ -1,7 +1,7 @@
 {% load i18n mezzanine_tags keyword_tags pages_tags organization_tags %}
 {% if blocks %}
     <div class="white-bg pb2">
-        {% if blocks.first.content %}
+        {% if blocks.first %}
         <hr class="mt0" />
         {% endif %}
         {% for block in blocks %}
diff --git a/app/templates/projects/inc/project_block.html b/app/templates/projects/inc/project_block.html
new file mode 100644 (file)
index 0000000..162e577
--- /dev/null
@@ -0,0 +1,45 @@
+{% load i18n mezzanine_tags keyword_tags pages_tags organization_tags %}
+{% if blocks %}
+    <div class="white-bg pb2">
+        {% for block in blocks %}
+            {% if block.content %}
+                {% if not forloop.first and block.with_separator %}
+                    <hr />
+                {% endif %}
+                <div class="page__block{% if block.background_color %} page__block--{{ block.background_color }}{% endif %}">
+                    <div class="container">
+                        <div class="row" data-summary-content>
+                            <div class="col-sm-9 col-sm-push-3 col-lg-8 col-lg-push-2">
+                                {% editable block.title %}
+                                    <h2 class="dotted">{{ block.title }}</h2>
+                                {% endeditable %}
+                                {% if block.description %}
+                                    <div class="chapo">
+                                        {% editable block.description %}
+                                            {{ block.description }}
+                                        {% endeditable %}
+                                    </div>
+                                {% endif %}
+                                {% if block.login_required and not user.is_authenticated %}
+                                    <div class="chapo">
+                                        {% trans "Please login to get links to the data" %}<br><br>
+                                        <a class="button" href="{% url 'login' %}?next={{ next }}#section-0" title="Login">{% trans "Login" %}</a>
+                                    </div>
+                                {% else %}
+                                    {% if block.content %}
+                                        {% editable block.content %}
+                                            {{ block.content|richtext_filters|safe }}
+                                        {% endeditable %}
+                                    {% endif %}
+                                {% endif %}
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            {% endif %}
+        {% endfor %}
+      {% if blocks.last %}
+        <hr class="mt0" />
+      {% endif %}
+    </div>
+{% endif %}
index 07137d544ead3f11e35f6c18668f5f23b9786146..267db9dc75147050c7d6a26c730cba42e974adc2 100644 (file)
     {% endif %}
 
     {% with project.blocks.all as blocks %}
-        {% include "core/inc/block.html" %}
+        {% include "projects/inc/project_block.html" %}
     {% endwith %}
 {% endblock %}