diff --git a/config/settings/base.py b/config/settings/base.py index 8b57606..36d0187 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -131,7 +131,6 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'wagtail.core.middleware.SiteMiddleware', 'wagtail.contrib.redirects.middleware.RedirectMiddleware', ] diff --git a/config/settings/local.py b/config/settings/local.py index 56c63a5..203be0d 100644 --- a/config/settings/local.py +++ b/config/settings/local.py @@ -27,9 +27,9 @@ # EMAIL # ------------------------------------------------------------------------------ -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' -EMAIL_HOST = 'localhost' -EMAIL_PORT = 1025 +#EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +#EMAIL_HOST = 'localhost' +#EMAIL_PORT = 1025 # django-debug-toolbar # ------------------------------------------------------------------------------ diff --git a/mpicms/base/api.py b/mpicms/base/api.py index 68b980c..d55a989 100644 --- a/mpicms/base/api.py +++ b/mpicms/base/api.py @@ -1,11 +1,11 @@ -from wagtail.api.v2.endpoints import PagesAPIEndpoint +from wagtail.api.v2.views import PagesAPIViewSet from wagtail.api.v2.router import WagtailAPIRouter -from wagtail.images.api.v2.endpoints import ImagesAPIEndpoint -from wagtail.documents.api.v2.endpoints import DocumentsAPIEndpoint +from wagtail.images.api.v2.views import ImagesAPIViewSet +from wagtail.documents.api.v2.views import DocumentsAPIViewSet api_router = WagtailAPIRouter('wagtailapi') -api_router.register_endpoint('pages', PagesAPIEndpoint) -api_router.register_endpoint('images', ImagesAPIEndpoint) -api_router.register_endpoint('documents', DocumentsAPIEndpoint) +api_router.register_endpoint('pages', PagesAPIViewSet) +api_router.register_endpoint('images', ImagesAPIViewSet) +api_router.register_endpoint('documents', DocumentsAPIViewSet) diff --git a/mpicms/base/migrations/0052_formfield_clean_name.py b/mpicms/base/migrations/0052_formfield_clean_name.py new file mode 100644 index 0000000..f95f09d --- /dev/null +++ b/mpicms/base/migrations/0052_formfield_clean_name.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1 on 2020-08-12 14:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0051_formfield_formpage'), + ] + + operations = [ + migrations.AddField( + model_name='formfield', + name='clean_name', + field=models.CharField(blank=True, default='', help_text='Safe name of the form field, the label converted to ascii_snake_case', max_length=255, verbose_name='name'), + ), + ] diff --git a/mpicms/base/templatetags/base_tags.py b/mpicms/base/templatetags/base_tags.py index 0286963..5df90d4 100644 --- a/mpicms/base/templatetags/base_tags.py +++ b/mpicms/base/templatetags/base_tags.py @@ -1,7 +1,9 @@ -from django import template - -from mpicms.base.utils import get_room_link +import re +from django import template +from django.template.defaultfilters import stringfilter +from django.utils.html import conditional_escape +from django.utils.safestring import mark_safe register = template.Library() @@ -16,13 +18,50 @@ def is_subscribed(page, user): return user in page.subscribers.all() -@register.simple_tag -def room_link(room): - return get_room_link(room) - - @register.filter def remove_i18n(url): if url.startswith('/en') or url.startswith('/de'): return url[3:] return url + + +# The ROOM_PATTERN should be in sync with the twiki plugin setting +# in http://twiki.molgen.mpg.de/foswiki/System/RoomsPlugin + +ROOM_PATTERN = re.compile( + r"R[0-4]\d\d[abc]?" + r"|[012]\.[012][012]\d\.?\d?[ab]?" + r"|B[01]\.[01][0-9]" + r"|KB\.0[01]|E[012]\da?" + r"|K4?\.[012][012]\d?(?:\.\d)?" + r"|K[B123]\.\d\d\d?[abc]?" + r"|W[012]\d[abc]?" + r"|K[TV]1?\.[012]\d[abcdefg]?" + r"|TH[0-5]\d[ab]?" + r"|HS\d\d" + r"|GH[01]\d" + r"|[K0123]\.[1234]\.F?\d\d" + r"|SR ?([1234])" ) + +SR_MAP= { + "1": "0.3.73", + "2": "0.3.05", + "3": "0.3.06", + "4": "0.2.01", +} + +def room_match_to_link(match): + room = match.group(0) + target_room = room + if room.startswith("SR"): + sr_number = match.group(1) + if sr_number in SR_MAP: + target_room = SR_MAP[sr_number] + return '' + room + '' + +@register.filter(needs_autoescape=True) +@stringfilter +def add_room_links(rooms, autoescape=True): + if autoescape: + rooms = conditional_escape(rooms) + return mark_safe(ROOM_PATTERN.sub(room_match_to_link, rooms)) diff --git a/mpicms/base/utils.py b/mpicms/base/utils.py index 37e144f..fee0e50 100644 --- a/mpicms/base/utils.py +++ b/mpicms/base/utils.py @@ -3,8 +3,3 @@ def can_create(request, model): if request.user.is_staff or request.user.is_superuser: return True return not getattr(model, 'creation_limited', False) - - -def get_room_link(room): - if room: - return 'https://twiki.molgen.mpg.de/foswiki/bin/room/' + room.split()[0] diff --git a/mpicms/contrib/sites/migrations/0004_auto_20200812_1604.py b/mpicms/contrib/sites/migrations/0004_auto_20200812_1604.py new file mode 100644 index 0000000..ab5e7fa --- /dev/null +++ b/mpicms/contrib/sites/migrations/0004_auto_20200812_1604.py @@ -0,0 +1,17 @@ +# Generated by Django 3.1 on 2020-08-12 14:04 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('sites', '0003_set_site_domain_and_name'), + ] + + operations = [ + migrations.AlterModelOptions( + name='site', + options={'ordering': ['domain'], 'verbose_name': 'site', 'verbose_name_plural': 'sites'}, + ), + ] diff --git a/mpicms/personal/migrations/0026_auto_20200813_1342.py b/mpicms/personal/migrations/0026_auto_20200813_1342.py new file mode 100644 index 0000000..0f2c326 --- /dev/null +++ b/mpicms/personal/migrations/0026_auto_20200813_1342.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1 on 2020-08-13 11:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('personal', '0025_auto_20190902_1149'), + ] + + operations = [ + migrations.AlterField( + model_name='contact', + name='room', + field=models.CharField(blank=True, max_length=50, verbose_name='room'), + ), + ] diff --git a/mpicms/personal/models.py b/mpicms/personal/models.py index 15c787f..c7c87a4 100644 --- a/mpicms/personal/models.py +++ b/mpicms/personal/models.py @@ -97,7 +97,7 @@ class Contact(index.Indexed, ClusterableModel): last_name = models.CharField(_("last name"), max_length=50, blank=True) email = models.EmailField(_("email"), blank=True) phone = models.CharField(_("phone number"), blank=True, max_length=50) - room = models.CharField(_("room"), max_length=25, blank=True) + room = models.CharField(_("room"), max_length=50, blank=True) is_active = models.BooleanField(_("is active"), default=True) priority = models.PositiveSmallIntegerField( _("priority"), blank=True, default=0, validators=[MaxValueValidator(999)], @@ -126,8 +126,11 @@ class Contact(index.Indexed, ClusterableModel): search_fields = [ index.SearchField('first_name', partial_match=True), + index.AutocompleteField('first_name'), index.SearchField('last_name', partial_match=True), + index.AutocompleteField('last_name'), index.SearchField('email', partial_match=True), + index.AutocompleteField('email'), index.SearchField('phone'), index.SearchField('room'), index.FilterField('is_active') @@ -135,14 +138,8 @@ class Contact(index.Indexed, ClusterableModel): ] def __str__(self): - if self.first_name and self.last_name: - if self.title: - return f'{self.title} {self.first_name} {self.last_name}' - return f'{self.first_name} {self.last_name}' - elif self.first_name: - return self.first_name - elif self.last_name: - return self.last_name + if self.first_name or self.last_name: + return " ".join(filter(None, (self.title, self.first_name, self.last_name))) else: return self.email diff --git a/mpicms/templates/base/blocks/contact_block.html b/mpicms/templates/base/blocks/contact_block.html index e296b2d..3a21a9e 100644 --- a/mpicms/templates/base/blocks/contact_block.html +++ b/mpicms/templates/base/blocks/contact_block.html @@ -25,7 +25,7 @@ {% if value.contact.room %} - {{ value.contact.room }} + {{ value.contact.room | add_room_links }} {% endif %} diff --git a/mpicms/templates/events/event.html b/mpicms/templates/events/event.html index 7f7efc6..73b4f33 100644 --- a/mpicms/templates/events/event.html +++ b/mpicms/templates/events/event.html @@ -38,10 +38,10 @@

{{ page.title }}

{% if page.room %} -
+
- {{ page.room }} - + {{ page.room | add_room_links }} +
{% endif %} @@ -58,4 +58,4 @@

{{ page.title }}

-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/mpicms/templates/footer.html b/mpicms/templates/footer.html index 2bd22ae..be7774e 100644 --- a/mpicms/templates/footer.html +++ b/mpicms/templates/footer.html @@ -1,5 +1,5 @@ -{% load i18n %} - +{% load i18n wagtailcore_tags %} +{% wagtail_site as current_site %} @@ -7,7 +7,7 @@
- {% with request.site.root_page.specific.footer_items as footer_items %} + {% with current_site.root_page.specific.footer_items as footer_items %} {% for menu in footer_items %}