Si vous constatez la perte de tickets, de commentaires ou de projets, veuillez consulter la page https://status.framasoft.org/incident/626.

...
 
Commits (12)
......@@ -63,8 +63,8 @@ class LinkBlock(blocks.StructBlock):
class PersonBlock(blocks.StructBlock):
"""A person block, linked to a person page"""
person = blocks.PageChooserBlock(
label=_('Person page'),
person_page = blocks.PageChooserBlock(
label=_('Person or author page'),
target_model='wagtailperson.PersonPage',
)
......
......@@ -2,11 +2,15 @@ from django.db import models
from django.utils.translation import gettext as _
from django.utils.text import slugify
from modelcluster.fields import ParentalKey
from wagtail.core.models import Page, Orderable
from wagtail.core.fields import RichTextField, StreamField
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
from taggit.models import TaggedItemBase
from taggit.managers import TaggableManager
from wagtail.snippets.models import register_snippet
from wagtail.snippets.edit_handlers import SnippetChooserPanel
from wagtail.admin.edit_handlers import (
FieldPanel,
InlinePanel,
......@@ -18,13 +22,51 @@ from wagtail.images.blocks import ImageChooserBlock
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.embeds.blocks import EmbedBlock
from wagtailperson.blocks import (
HeaderBlock,
LinkBlock,
)
# Models
class PersonPage(Page):
class PersonTag(TaggedItemBase):
"""A tag, related to a person"""
content_object = ParentalKey(
'Person',
related_name='tagged_items',
on_delete=models.CASCADE,
null=True,
)
class PersonExtrernalLink(Orderable, models.Model):
"""A person's external link"""
person = ParentalKey(
'Person',
on_delete=models.CASCADE,
verbose_name=_('Person'),
related_name='external_links'
)
label = models.CharField(
verbose_name=_('Label'),
max_length=255,
)
url = models.URLField(
verbose_name=_('URL'),
max_length=255,
)
panels = [
FieldPanel('label'),
FieldPanel('url'),
]
class Meta:
verbose_name = _("Person's extrernal link")
verbose_name_plural = _("Person's extrernal links")
def __str__(self):
return self.label
class Person(ClusterableModel):
"""A person"""
picture = models.ForeignKey(
'wagtailimages.Image',
......@@ -38,12 +80,7 @@ class PersonPage(Page):
verbose_name=_('Name'),
max_length=250,
)
custom_titles = models.CharField(
verbose_name=_('Custom titles'),
max_length=250,
blank=True,
help_text=_('Some custom titles, separated by commas'),
)
tags = TaggableManager(through=PersonTag, blank=True)
intro = models.CharField(
verbose_name=_('Introduction'),
max_length=250,
......@@ -54,92 +91,49 @@ class PersonPage(Page):
blank=True,
verbose_name=_('Abstract'),
)
extra_infos = StreamField(
[
('heading', HeaderBlock()),
('link', LinkBlock()),
('paragraph', blocks.RichTextBlock()),
('quote', blocks.BlockQuoteBlock()),
('image', ImageChooserBlock()),
('document', DocumentChooserBlock()),
('embed', EmbedBlock()),
],
blank=True,
verbose_name=_('Extra informations'),
)
# Editor panels configuration
content_panels = [
FieldPanel('name'),
panels = [
ImageChooserPanel('picture'),
InlinePanel('titles', label=_('Titles')),
FieldPanel('custom_titles'),
FieldPanel('name'),
FieldPanel('tags'),
FieldPanel('intro'),
FieldPanel('abstract'),
StreamFieldPanel('extra_infos'),
InlinePanel('external_links', label=_('link')),
]
class Meta:
verbose_name = _('Person')
verbose_name_plural = _('Persons')
verbose_name = _('Person or author')
verbose_name_plural = _('Persons or authors')
ordering = ['name']
def __str__(self):
return self.name
def save(self, *args, **kwargs):
"""Override save to populate title and slug"""
self.title = self.name
if not self.slug:
self.slug = slugify(self.name, allow_unicode=True)
return super(PersonPage, self).save(*args, **kwargs)
def custom_titles_list(self):
"""Get custom titles, in form of a list of strings"""
if not self.custom_titles:
return []
return self.custom_titles.split(',')
@register_snippet
class PersonTitle(models.Model):
"""The title of a person"""
title = models.CharField(
verbose_name=_('Title'),
max_length=250,
)
class Meta:
verbose_name = _('Person title')
verbose_name_plural = _('Person titles')
ordering = ['title']
# Models
def __str__(self):
return self.title
class PersonTitlePage(Orderable):
"""A many-to-many retation between PensonPage and PersonTitle"""
page = ParentalKey(
PersonPage,
related_name='titles',
)
title = models.ForeignKey(
PersonTitle,
on_delete=models.CASCADE,
related_name='+',
class PersonPage(Page):
"""A person"""
person = models.ForeignKey(
Person,
on_delete=models.PROTECT,
verbose_name=_('Person'),
null=True,
)
panels = [
FieldPanel('title'),
# Editor panels configuration
content_panels = Page.content_panels + [
FieldPanel('person'),
]
class Meta:
verbose_name = _('Person Title Page')
verbose_name_plural = _('Person Title Pages')
verbose_name = _('Person or author page')
verbose_name_plural = _('Person or author pages')
ordering = ['title']
def __str__(self):
return self.title.title
return self.title
class PersonIndexPage(Page):
......@@ -156,8 +150,8 @@ class PersonIndexPage(Page):
subpage_types = ['wagtailperson.PersonPage']
class Meta:
verbose_name = _('Person Index Page')
verbose_name_plural = _('Person Index Pages')
verbose_name = _('Persons or authors Index Page')
verbose_name_plural = _('Persons or authors Index Pages')
def __str__(self):
return self.title
......@@ -172,7 +166,7 @@ class PersonIndexPage(Page):
for page
in self.get_children().live()
),
key=lambda person: person.name
key=lambda person_page: person_page.person.name
)
context['person_pages'] = person_pages
return context
......@@ -18,13 +18,13 @@
margin-top: 30px;
}
.person .description ul.titles {
.person .description ul.tags {
list-style-type: none;
padding: 0;
margin-top: 0;
}
.person .description ul.titles li {
.person .description ul.tags li {
font-weight: bold;
}
......
......@@ -4,8 +4,8 @@
<link rel="stylesheet" href="{% static 'wagtailperson/css/person.css' %}" type="text/css"/>
{% with person=value.person %}
<a class="person short_description" href="{% pageurl person %}">
{% with person=value.person_page.person %}
<a class="person short_description" href="{% pageurl value.person_page %}">
<div class="person short_description">
{% if person.picture %}
<div class="picture">
......@@ -14,12 +14,9 @@
{% endif %}
<div class="description">
<h2>{{ person.name }}</h1>
<ul class="titles">
{% for title in person.titles.all %}
<li>{{ title.title }}</li>
{% endfor %}
{% for title in person.custom_titles_list %}
<li>{{ title }}</li>
<ul class="tags">
{% for tag in person.tags.all %}
<li>{{ tag }}</li>
{% endfor %}
</ul>
<p class="intro">
......
......@@ -15,30 +15,29 @@
<div class="intro">{{ page.intro|richtext }}</div>
{% for person in person_pages %}
<a class="person short_description" href="{% pageurl person %}">
<div class="person short_description">
{% if person.picture %}
<div class="picture">
{% image person.picture fill-100x150 %}
{% for person_page in person_pages %}
{% with person=person_page.person %}
<a class="person short_description" href="{% pageurl person_page %}">
<div class="person short_description">
{% if person.picture %}
<div class="picture">
{% image person.picture fill-100x150 %}
</div>
{% endif %}
<div class="description">
<h2>{{ person.name }}</h2>
<ul class="tags">
{% for title in person.tags.all %}
<li>{{ tag }}</li>
{% endfor %}
</ul>
<p class="intro">
{{ person.intro }}
</p>
</div>
{% endif %}
<div class="description">
<h2>{{ person.name }}</h2>
<ul class="titles">
{% for title in person.titles.all %}
<li>{{ title.title }}</li>
{% endfor %}
{% for title in person.custom_titles_list %}
<li>{{ title }}</li>
{% endfor %}
</ul>
<p class="intro">
{{ person.intro }}
</p>
</div>
</div>
</a>
</a>
{% endwith %}
{% endfor %}
{% endblock %}
......@@ -11,28 +11,22 @@
{% block body_class %}template-personpage{% endblock %}
{% block content %}
<h1>{{ page.name }}</h1>
<h1>{{ page.person.name }}</h1>
<div class="person full_description">
{% if page.picture %}
{% if page.person.picture %}
<div class="picture">
{% image page.picture original %}
{% image page.person.picture original %}
</div>
{% endif %}
<div class="description">
<ul class="titles">
{% for title in page.titles.all %}
<li>{{ title.title }}</li>
{% endfor %}
{% for title in page.custom_titles_list %}
<li>{{ title }}</li>
<ul class="tags">
{% for tag in page.person.tags.all %}
<li>{{ tag }}</li>
{% endfor %}
</ul>
<p class="abstract">
{{ page.abstract|richtext }}
{{ page.person.abstract|richtext }}
</p>
<div class="extra_infos">
{% include_block page.extra_infos %}
</div>
</div>
</div>
{% endblock %}
from django.utils.html import format_html_join
from django.conf import settings
from wagtail.core import hooks
from django.utils.translation import gettext as _
from wagtail.contrib.modeladmin.options import (
ModelAdmin,
modeladmin_register,
)
from .models import (
Person,
)
@hooks.register('insert_editor_js')
def editor_js():
"""Insert slof_from_name javascript in admin javascript"""
js_files = [
'wagtailperson/js/slug_from_person_name.js',
]
js_includes = format_html_join(
'\n',
'<script src="{0}{1}"></script>',
(
(settings.STATIC_URL, filename)
for filename
in js_files
),
)
return js_includes
class PersonModelAdmin(ModelAdmin):
"""Define the person model integration to the admin ui"""
model = Person
menu_label = _('Persons or authors')
menu_icon = 'user'
menu_order = 200
list_display = ('name',)
list_filter = ('tags',)
search_field = ('name',)
modeladmin_register(PersonModelAdmin)