Skip to content
Snippets Groups Projects
Commit e1bf8b31 authored by jan.bednarik's avatar jan.bednarik
Browse files

shared: Remove outdated shared Person model

parent e8d8b9d2
No related branches found
No related tags found
2 merge requests!418Release,!414district and region modules
Pipeline #6699 passed
# Generated by Django 3.2.8 on 2022-01-14 14:27
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("wagtailimages", "0023_add_choose_permissions"),
("district", "0030_alter_districtelectionpage_content"),
]
operations = [
migrations.RemoveField(
model_name="districtpersonpage",
name="person",
),
migrations.AlterField(
model_name="districtpersonpage",
name="background_photo",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="wagtailimages.image",
verbose_name="obrázek do záhlaví",
),
),
migrations.AlterField(
model_name="districtpersonpage",
name="profile_photo",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="wagtailimages.image",
verbose_name="profilová fotka",
),
),
]
...@@ -20,7 +20,7 @@ from wagtail.images.edit_handlers import ImageChooserPanel ...@@ -20,7 +20,7 @@ from wagtail.images.edit_handlers import ImageChooserPanel
from wagtailmetadata.models import MetadataPageMixin from wagtailmetadata.models import MetadataPageMixin
from calendar_utils.models import CalendarMixin from calendar_utils.models import CalendarMixin
from shared.models import ArticleMixin, Person, SubpageMixin from shared.models import ArticleMixin, SubpageMixin
from uniweb.constants import RICH_TEXT_FEATURES from uniweb.constants import RICH_TEXT_FEATURES
from .blocks import ( from .blocks import (
...@@ -430,6 +430,7 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -430,6 +430,7 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page):
blank=True, blank=True,
null=True, null=True,
related_name="+", related_name="+",
verbose_name="obrázek do záhlaví",
) )
profile_photo = models.ForeignKey( profile_photo = models.ForeignKey(
"wagtailimages.Image", "wagtailimages.Image",
...@@ -437,11 +438,10 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -437,11 +438,10 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page):
blank=True, blank=True,
null=True, null=True,
related_name="+", related_name="+",
verbose_name="profilová fotka",
) )
person = models.ForeignKey(Person, on_delete=models.PROTECT, null=True)
text = RichTextField("text", blank=True, features=RICH_TEXT_FEATURES) text = RichTextField("text", blank=True, features=RICH_TEXT_FEATURES)
# Fallbackové hodnoty pro data získávana z API (viz Person model)
email = models.EmailField("Email", blank=True, null=True) email = models.EmailField("Email", blank=True, null=True)
phone = models.CharField("Telefon", max_length=16, blank=True, null=True) phone = models.CharField("Telefon", max_length=16, blank=True, null=True)
city = models.CharField("Město/obec", max_length=64, blank=True, null=True) city = models.CharField("Město/obec", max_length=64, blank=True, null=True)
...@@ -457,16 +457,22 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -457,16 +457,22 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page):
### PANELS ### PANELS
content_panels = Page.content_panels + [ content_panels = Page.content_panels + [
FieldPanel("person"), MultiFieldPanel(
[
FieldPanel("job"), FieldPanel("job"),
FieldPanel("job_function"), FieldPanel("job_function"),
ImageChooserPanel("background_photo"), ],
"Základní údaje",
),
MultiFieldPanel(
[
ImageChooserPanel("profile_photo"), ImageChooserPanel("profile_photo"),
ImageChooserPanel("background_photo"),
],
"Fotky",
),
FieldPanel("perex"), FieldPanel("perex"),
FieldPanel("text"), FieldPanel("text"),
]
settings_panels = [
MultiFieldPanel( MultiFieldPanel(
[ [
FieldPanel("email"), FieldPanel("email"),
...@@ -489,6 +495,8 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -489,6 +495,8 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page):
), ),
] ]
settings_panels = []
### RELATIONS ### RELATIONS
parent_page_types = ["district.DistrictPeoplePage"] parent_page_types = ["district.DistrictPeoplePage"]
...@@ -520,20 +528,6 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -520,20 +528,6 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page):
context["random_people"] = context["random_people"][:3] context["random_people"] = context["random_people"][:3]
return context return context
def get_email(self):
return self.person.email if self.person.email else self.email
def get_phone(self):
return self.person.phone if self.person.phone else self.phone
@property
def pageperex(self):
"""
Vraci perex Pirata nejblizzsi lokalnimu kontextu. Zamerne jiny nazev, aby
v template bylo na vyber z x.perex, x.person.perex a x.pageperex
"""
return self.perex or self.person.perex
class DistrictPeoplePage(SubpageMixin, MetadataPageMixin, Page): class DistrictPeoplePage(SubpageMixin, MetadataPageMixin, Page):
### FIELDS ### FIELDS
......
# Generated by Django 3.2.8 on 2022-01-14 14:27
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("wagtailimages", "0023_add_choose_permissions"),
("region", "0007_alter_regionelectionpage_content"),
]
operations = [
migrations.RemoveField(
model_name="regionpersonpage",
name="person",
),
migrations.AlterField(
model_name="regionpersonpage",
name="background_photo",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="wagtailimages.image",
verbose_name="obrázek do záhlaví",
),
),
migrations.AlterField(
model_name="regionpersonpage",
name="profile_photo",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="wagtailimages.image",
verbose_name="profilová fotka",
),
),
]
...@@ -20,7 +20,7 @@ from wagtail.images.edit_handlers import ImageChooserPanel ...@@ -20,7 +20,7 @@ from wagtail.images.edit_handlers import ImageChooserPanel
from wagtailmetadata.models import MetadataPageMixin from wagtailmetadata.models import MetadataPageMixin
from calendar_utils.models import CalendarMixin from calendar_utils.models import CalendarMixin
from shared.models import ArticleMixin, Person, SubpageMixin from shared.models import ArticleMixin, SubpageMixin
from uniweb.constants import RICH_TEXT_FEATURES from uniweb.constants import RICH_TEXT_FEATURES
from .blocks import ( from .blocks import (
...@@ -426,6 +426,7 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -426,6 +426,7 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page):
blank=True, blank=True,
null=True, null=True,
related_name="+", related_name="+",
verbose_name="obrázek do záhlaví",
) )
profile_photo = models.ForeignKey( profile_photo = models.ForeignKey(
"wagtailimages.Image", "wagtailimages.Image",
...@@ -433,11 +434,10 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -433,11 +434,10 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page):
blank=True, blank=True,
null=True, null=True,
related_name="+", related_name="+",
verbose_name="profilová fotka",
) )
person = models.ForeignKey(Person, on_delete=models.PROTECT, null=True)
text = RichTextField("text", blank=True, features=RICH_TEXT_FEATURES) text = RichTextField("text", blank=True, features=RICH_TEXT_FEATURES)
# Fallbackové hodnoty pro data získávana z API (viz Person model)
email = models.EmailField("Email", blank=True, null=True) email = models.EmailField("Email", blank=True, null=True)
phone = models.CharField("Telefon", max_length=16, blank=True, null=True) phone = models.CharField("Telefon", max_length=16, blank=True, null=True)
city = models.CharField("Město/obec", max_length=64, blank=True, null=True) city = models.CharField("Město/obec", max_length=64, blank=True, null=True)
...@@ -453,16 +453,22 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -453,16 +453,22 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page):
### PANELS ### PANELS
content_panels = Page.content_panels + [ content_panels = Page.content_panels + [
FieldPanel("person"), MultiFieldPanel(
[
FieldPanel("job"), FieldPanel("job"),
FieldPanel("job_function"), FieldPanel("job_function"),
ImageChooserPanel("background_photo"), ],
"Základní údaje",
),
MultiFieldPanel(
[
ImageChooserPanel("profile_photo"), ImageChooserPanel("profile_photo"),
ImageChooserPanel("background_photo"),
],
"Fotky",
),
FieldPanel("perex"), FieldPanel("perex"),
FieldPanel("text"), FieldPanel("text"),
]
settings_panels = [
MultiFieldPanel( MultiFieldPanel(
[ [
FieldPanel("email"), FieldPanel("email"),
...@@ -485,6 +491,8 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -485,6 +491,8 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page):
), ),
] ]
settings_panels = []
### RELATIONS ### RELATIONS
parent_page_types = ["region.RegionPeoplePage"] parent_page_types = ["region.RegionPeoplePage"]
...@@ -516,20 +524,6 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -516,20 +524,6 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page):
context["random_people"] = context["random_people"][:3] context["random_people"] = context["random_people"][:3]
return context return context
def get_email(self):
return self.person.email if self.person.email else self.email
def get_phone(self):
return self.person.phone if self.person.phone else self.phone
@property
def pageperex(self):
"""
Vraci perex Pirata nejblizzsi lokalnimu kontextu. Zamerne jiny nazev, aby
v template bylo na vyber z x.perex, x.person.perex a x.pageperex
"""
return self.perex or self.person.perex
class RegionPeoplePage(SubpageMixin, MetadataPageMixin, Page): class RegionPeoplePage(SubpageMixin, MetadataPageMixin, Page):
### FIELDS ### FIELDS
......
# Generated by Django 3.2.8 on 2022-01-14 14:27
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("region", "0008_auto_20220114_1527"),
("district", "0031_auto_20220114_1527"),
("shared", "0001_initial"),
]
operations = [
migrations.DeleteModel(
name="Person",
),
]
...@@ -82,78 +82,3 @@ class ArticleMixin(models.Model): ...@@ -82,78 +82,3 @@ class ArticleMixin(models.Model):
def tag_filter_page(self): def tag_filter_page(self):
"""Page used for filtering by tags in url like `?tag=foo`.""" """Page used for filtering by tags in url like `?tag=foo`."""
return self.get_parent() return self.get_parent()
class Person(models.Model):
"""Informace o Piratovi. Slouzi prevazne jako cache informaci o osobe pro
uziti v ramci Majaku. Snaha je zadavat tady minimum informaci o osobe a
zbytek vytahovat via API z jinych zdroju, neb nechceme dalsi databazi lidi.
"""
# ve formatu iapi: https://iapi.pirati.cz/v1/user?username=john.doe
username = models.TextField("Uživatelské jméno osoby", blank=False)
profile_id = models.IntegerField(
"Číslo medailonku (0..2) z lide.pirati.cz",
blank=True,
default=0,
validators=[MinValueValidator(0), MaxValueValidator(2)],
)
perex = models.TextField("Defaultni perex osoby", blank=True)
panels = [
FieldPanel("username"),
FieldPanel("profile_id"),
FieldPanel("perex"),
]
def _iapi(self):
"""Vrati data o osobe z piratskeho IAPI jako json. Cached via django cache"""
key = f"profile_{self.username}"
profile = cache.get(key)
if profile is None:
profile = requests.get(
f"https://iapi.pirati.cz/v1/user?username={self.username}"
).json()
cache.set(key, profile, 3600)
return profile
@property
def name(self):
return self._iapi().get("displayname")
@property
def email(self):
try:
return self._iapi()["profiles"][self.profile_id]["email"]
except (IndexError, KeyError):
return None
@property
def phone(self):
try:
return self._iapi()["profiles"][self.profile_id]["phone"]
except (IndexError, KeyError):
return None
@property
def longtext(self): # medailonek
return "" # TODO
@property
def portrait(self): # profilova fotka
try:
return self._iapi()["profiles"][self.profile_id]["photo"]
except (IndexError, KeyError):
return None
@property
def facebook(self):
return None # TODO
def __str__(self):
return self.username
class Meta:
verbose_name_plural = "Piráti"
verbose_name = "Pirát"
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
<div class="badge badge--condensed"> <div class="badge badge--condensed">
<a href="{{ person_page.url }}" class="avatar badge__avatar avatar--sm"> <a href="{{ person_page.url }}" class="avatar badge__avatar avatar--sm">
{% image person_page.profile_photo max-80x80 as profile_img %} {% image person_page.profile_photo max-80x80 as profile_img %}
<img src="{% firstof person_page.person.portrait profile_img.url %}" alt="{{ person_page.person.name }}"/> <img src="{{ profile_img.url }}" alt="{{ person_page.title }}"/>
</a> </a>
<div class="badge__body"> <div class="badge__body">
<span class="head-heavy-2xs badge__title"> <span class="head-heavy-2xs badge__title">
<a href="{{ person_page.url }}" title="{{ person_page.person.name }}" class="content-block--nostyle"> <a href="{{ person_page.url }}" title="{{ person_page.title }}" class="content-block--nostyle">
{{ person_page.person.name }} {{ person_page.title }}
</a> </a>
</span> </span>
<span class="badge__occupation"> <span class="badge__occupation">
...@@ -20,17 +20,17 @@ ...@@ -20,17 +20,17 @@
{% endif %} {% endif %}
</span> </span>
{% if not skipcontacts %} {% if not skipcontacts %}
{% if person_page.get_phone %} {% if person_page.phone %}
<a href="tel:{{ person_page.get_phone }}" <a href="tel:{{ person_page.phone }}"
class="contact-line icon-link content-block--nostyle contact-line--responsive badge__link"> class="contact-line icon-link content-block--nostyle contact-line--responsive badge__link">
<i class="ico--phone"></i> <i class="ico--phone"></i>
<span>{{ person_page.get_phone }}</span> <span>{{ person_page.phone }}</span>
</a> </a>
{% endif %} {% endif %}
{% if person_page.get_email %} {% if person_page.email %}
<a href="mailto:{{ person_page.get_email }}" <a href="mailto:{{ person_page.email }}"
class="contact-line icon-link content-block--nostyle contact-line--responsive badge__link"> class="contact-line icon-link content-block--nostyle contact-line--responsive badge__link">
<i class="ico--envelope"></i><span>{{ person_page.get_email }}</span> <i class="ico--envelope"></i><span>{{ person_page.email }}</span>
</a> </a>
{% endif %} {% endif %}
{% endif %} {% endif %}
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
<div class="badge w-full"> <div class="badge w-full">
<div class="avatar avatar--md badge__avatar"> <div class="avatar avatar--md badge__avatar">
{% image person_page.profile_photo max-100x100 as profile_img %} {% image person_page.profile_photo max-100x100 as profile_img %}
<img src="{% firstof person_page.person.portrait profile_img.url %}" alt="{{ person_page.person.name }}"/> <img src="{{ profile_img.url }}" alt="{{ person_page.title }}"/>
</div> </div>
<div class="badge__body"> <div class="badge__body">
<a href="{{ person_page.url }}" class="head-heavy-xs"> <a href="{{ person_page.url }}" class="head-heavy-xs">
{{ person_page.person.name }} {{ person_page.title }}
</a> </a>
<p class="badge__occupation"> <p class="badge__occupation">
{% if title %} {% if title %}
...@@ -17,16 +17,16 @@ ...@@ -17,16 +17,16 @@
{{ person_page.job_function|default_if_none:"" }} {{ person_page.job_function|default_if_none:"" }}
{% endif %} {% endif %}
</p> </p>
{% if person_page.get_phone %} {% if person_page.phone %}
<a href="tel:{{ person_page.get_phone }}" class="contact-line contact-line--responsive icon-link badge__link"> <a href="tel:{{ person_page.phone }}" class="contact-line contact-line--responsive icon-link badge__link">
<i class="ico--phone"></i> <i class="ico--phone"></i>
<span>{{ person_page.get_phone }}</span> <span>{{ person_page.phone }}</span>
</a> </a>
{% endif %} {% endif %}
{% if person_page.get_email %} {% if person_page.email %}
<a href="mailto:{{ person_page.get_email }}" class="contact-line contact-line--responsive icon-link badge__link"> <a href="mailto:{{ person_page.email }}" class="contact-line contact-line--responsive icon-link badge__link">
<i class="ico--envelope"></i> <i class="ico--envelope"></i>
<span>{{ person_page.get_email }}</span> <span>{{ person_page.email }}</span>
</a> </a>
{% endif %} {% endif %}
</div> </div>
......
from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register
from .models import Person
class PersonAdmin(ModelAdmin):
model = Person
menu_label = "Pirati"
menu_icon = "group"
menu_order = 200
add_to_settings_menu = False
exclude_from_explorer = False
list_display = ("username",)
search_fields = ("username",)
modeladmin_register(PersonAdmin)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment