Commit e46a271a authored by sberna's avatar sberna

Added models Reuse and Workshop

parent 6185ef76
......@@ -129,6 +129,14 @@ class EventAdmin(TabbedTranslationAdmin):
form = EventAdminForm
class ReuseAdmin(EventAdmin):
inlines = [FileInline]
class WorkshopAdmin(EventAdmin):
inlines = [FileInline]
class FAQAdmin(TabbedTranslationAdmin):
list_display = ('domanda', 'priorita')
list_editable = ('priorita',)
......@@ -213,6 +221,8 @@ admin.site.register(Pillola, PillolaAdmin)
admin.site.register(News, NewsAdmin)
admin.site.register(PressReview, PressReviewAdmin)
admin.site.register(Event, EventAdmin)
admin.site.register(Reuse, ReuseAdmin)
admin.site.register(Workshop, WorkshopAdmin)
admin.site.register(FAQ, FAQAdmin)
admin.site.register(OpenDataSection, OpenDataSectionAdmin)
admin.site.register(OpenDataFile, OpenDataFileAdmin)
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2020-07-07 09:10
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('opencoesione', '0015_auto_20190929_1642'),
]
operations = [
migrations.CreateModel(
name='Reuse',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255, verbose_name='titolo')),
('title_it', models.CharField(max_length=255, null=True, verbose_name='titolo')),
('title_en', models.CharField(max_length=255, null=True, verbose_name='titolo')),
('body', models.TextField(verbose_name='testo')),
('body_it', models.TextField(null=True, verbose_name='testo')),
('body_en', models.TextField(null=True, verbose_name='testo')),
('priority', models.PositiveSmallIntegerField(default=0, verbose_name='priorità')),
],
options={
'verbose_name': 'esperienza di riuso',
'verbose_name_plural': 'esperienze di riuso',
'ordering': ['priority', '-pk'],
'abstract': False,
},
),
migrations.CreateModel(
name='Workshop',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255, verbose_name='titolo')),
('title_it', models.CharField(max_length=255, null=True, verbose_name='titolo')),
('title_en', models.CharField(max_length=255, null=True, verbose_name='titolo')),
('body', models.TextField(verbose_name='testo')),
('body_it', models.TextField(null=True, verbose_name='testo')),
('body_en', models.TextField(null=True, verbose_name='testo')),
('priority', models.PositiveSmallIntegerField(default=0, verbose_name='priorità')),
],
options={
'verbose_name': 'esperienza di laboratorio',
'verbose_name_plural': 'esperienze di laboratorio',
'ordering': ['priority', '-pk'],
'abstract': False,
},
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2020-07-07 09:44
from __future__ import unicode_literals
from django.db import migrations, models
def create_flatpages(apps, schema_editor):
FlatPage = apps.get_model('flatpages', 'FlatPage')
FlatPage.add_to_class('title_it', models.CharField(max_length=200))
FlatPage.add_to_class('extra_content', models.TextField(blank=True))
Site = apps.get_model('sites', 'Site')
site = Site.objects.get_current()
for url, title in (('/riuso/', 'Riuso'), ('/laboratori_dati/', 'Laboratori sui dati')):
flatpage, created = FlatPage.objects.get_or_create(url=url, defaults={'title': title, 'title_it': title})
if created:
flatpage.sites.add(site)
class Migration(migrations.Migration):
dependencies = [
('opencoesione', '0016_reuse_workshop'),
]
operations = [
migrations.RunPython(create_flatpages),
]
......@@ -159,7 +159,7 @@ class PressReview(models.Model):
ordering = ['-published_at', '-id']
class Event(models.Model):
class BaseItem(models.Model):
title = models.CharField(max_length=255, verbose_name=_('titolo'))
body = models.TextField(verbose_name=_('testo'))
priority = models.PositiveSmallIntegerField(default=0, verbose_name=_('priorità'))
......@@ -168,9 +168,30 @@ class Event(models.Model):
return self.title
class Meta:
abstract = True
ordering = ['priority', '-pk']
class Event(BaseItem):
class Meta(BaseItem.Meta):
verbose_name = _('evento/riunione')
verbose_name_plural = _('eventi/riunioni')
ordering = ['priority', '-pk']
class Reuse(BaseItem):
documents = GenericRelation(File, verbose_name=_('documenti'))
class Meta(BaseItem.Meta):
verbose_name = _('esperienza di riuso')
verbose_name_plural = _('esperienze di riuso')
class Workshop(BaseItem):
documents = GenericRelation(File, verbose_name=_('documenti'))
class Meta(BaseItem.Meta):
verbose_name = _('esperienza di laboratorio')
verbose_name_plural = _('esperienze di laboratorio')
class FAQ(models.Model):
......
# -*- coding: utf-8 -*-
from django.contrib.flatpages.models import FlatPage
from modeltranslation.translator import register, TranslationOptions
from .models import File, Link, MenuItem, CarouselItem, Pillola, News, PressReview, Event, FAQ, OpenDataSection, OpenDataFile
from .models import File, Link, MenuItem, CarouselItem, Pillola, News, PressReview, Event, FAQ, OpenDataSection, \
OpenDataFile, Reuse, Workshop
from ..tagging.models import Tag
......@@ -41,6 +42,8 @@ class PressReviewTranslationOptions(TranslationOptions):
@register(Event)
@register(Reuse)
@register(Workshop)
class EventTranslationOptions(TranslationOptions):
fields = ('title', 'body')
......
......@@ -20,7 +20,7 @@ from urllib.request import urlopen
from honeypot.decorators import check_honeypot
from .forms import ContactMessageForm
from .models import Pillola, News, PressReview, Event, FAQ, OpenDataFile, OpenDataSection
from .models import Pillola, News, PressReview, Event, FAQ, OpenDataFile, OpenDataSection, Reuse, Workshop
from .monitoraggio.models import Programma, TemaSintetico
from ..tagging.views import TagFilterMixin
......@@ -236,6 +236,30 @@ class EventListView(ListView):
return context
class ReuseListView(ListView):
model = Reuse
paginate_by = 20
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['flatpage'] = FlatPage.objects.get(url='/riuso/')
return context
class WorkshopListView(ListView):
model = Workshop
paginate_by = 20
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['flatpage'] = FlatPage.objects.get(url='/laboratori_dati/')
return context
class FAQListView(ListView):
model = FAQ
......
{% extends 'base.html' %}
{% load digg_paginator i18n %}
{% block page_title %}{{ flatpage.title }}{% endblock %}
{% block precontent %}
<div id="top-info">
<h1>{{ flatpage.title }}</h1>
</div>
{% endblock %}
{% block content %}
<div class="container">
<div class="row">
<div class="col-md-8">
{% if flatpage.content %}
<div id="item-list-intro">
{{ flatpage.content|safe }}
</div>
{% endif %}
{% for object in object_list %}
<div class="item" style="margin-top: 40px">
{{ object.body|safe }}
<ul style="list-style: none; margin: 0; padding: 0">
{% for document in object.documents.all %}
<li style="margin-top: 10px"><a class="download" href="{{ document.file.url }}">{% trans 'Scarica il' %} {{ document.file.name|slice:'-3:'|lower }} ({{ document.file.size|filesizeformat }})</a></li>
{% endfor %}
</ul>
</div>
{% endfor %}
{% digg_paginator %}
</div>
<div class="col-md-4">
{{ flatpage.extra_content|safe }}
</div>
</div>
</div>
{% endblock %}
{% extends 'opencoesione/reuse_list.html' %}
......@@ -99,6 +99,12 @@ urlpatterns += i18n_patterns(
# scopri
url(r'^scopri/', EventListView.as_view(), name='event_list'),
# riuso
url(r'^riuso/', ReuseListView.as_view(), name='reuse_list'),
# laboratori sui dati
url(r'^laboratori_dati/', WorkshopListView.as_view(), name='workshop_list'),
# faq
url(r'^faq/$', FAQListView.as_view(), name='faq_list'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment