Skip to content

Fix languagepicker #95

Merged
merged 9 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
]

WAGTAILMODELTRANSLATION_TRANSLATE_SLUGS = False
WAGTAILMODELTRANSLATION_LOCALE_PICKER_DEFAULT = ('de', 'en')

# WAGTAIL
WAGTAIL_SITE_NAME = 'MPI CMS'
Expand Down
2 changes: 1 addition & 1 deletion mpicms/base/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class BaseAppConfig(AppConfig):
verbose_name = "Base"

def ready(self):
import mpicms.base.signals
import mpicms.base.signals # noqa: F401
6 changes: 3 additions & 3 deletions mpicms/base/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MenuBlock(blocks.StructBlock):
('url', blocks.URLBlock(label=_('URL')))
], label=_('Items'))
)

class Meta:
icon = 'list-ul'
label = _('Menu')
icon = 'list-ul'
label = _('Menu')
3 changes: 3 additions & 0 deletions mpicms/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class Meta: # noqa
verbose_name = _("wiki page")
verbose_name_plural = _("wiki pages")


class PhonelistPage(BasePage):
content_panels = Page.content_panels
promote_panels = Page.promote_panels
Expand All @@ -143,9 +144,11 @@ def serve(self, request, *args, **kwargs):
def serve_preview(self, request, mode_name):
return ContactListView.as_view()(request)


class FormField(AbstractFormField):
page = ParentalKey('FormPage', on_delete=models.CASCADE, related_name='form_fields')


class FormPage(AbstractEmailForm, SideBarMixin, BasePage):
intro = RichTextField(blank=True)
thank_you_text = RichTextField(blank=True)
Expand Down
4 changes: 2 additions & 2 deletions mpicms/base/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def notify_user(sender, instance, action, model, pk_set, **kwargs):
groups = ', '.join([group.__str__() for group in model.objects.filter(pk__in=pk_set)])
send_mail(
f'You have been added to {groups}',
f'An admin has added you to the following group/groups: {groups}. You are now granted all associated permissons.',
f'An admin has added you to the following group/groups: {groups}.'
f' You are now granted all associated permissons.',
settings.DEFAULT_FROM_EMAIL,
[instance.email],
fail_silently=True,
)
logger.debug(f'User {instance} added to {groups}. Email sent out.')

14 changes: 8 additions & 6 deletions mpicms/base/templatetags/base_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def is_subscribed(page, user):
@register.filter
def remove_i18n(url):
if url.startswith('/en') or url.startswith('/de'):
return url[3:]
return url[3:]
return url


Expand All @@ -41,15 +41,16 @@ def remove_i18n(url):
r"|HS\d\d"
r"|GH[01]\d"
r"|[K0123]\.[1234]\.F?\d\d"
r"|SR ?([1234])" )
r"|SR ?([1234])")

SR_MAP= {
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
Expand All @@ -59,9 +60,10 @@ def room_match_to_link(match):
target_room = SR_MAP[sr_number]
return '<a href="http://twiki.molgen.mpg.de/foswiki/bin/room/' + target_room + '">' + room + '</a>'


@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))
if autoescape:
rooms = conditional_escape(rooms)
return mark_safe(ROOM_PATTERN.sub(room_match_to_link, rooms))
1 change: 1 addition & 0 deletions mpicms/base/templatetags/md_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
register = template.Library()
md_processor = None


@register.filter
def markdown(text):
global md_processor
Expand Down
7 changes: 6 additions & 1 deletion mpicms/base/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .models import (
WikiPage, RootPage, HomePage, FeaturedImage, PhonelistPage,
FormPage, FormField,
FormPage,
)


Expand All @@ -20,32 +20,37 @@ class FeaturedImageTR(TranslationOptions):
'text'
)


@register(RootPage)
class RootPageTR(TranslationOptions):
fields = {
'footer_items',
'quick_links'
}


@register(HomePage)
class HomePageTR(TranslationOptions):
fields = (
'body',
'sidebar'
)


@register(WikiPage)
class WikiPageTR(TranslationOptions):
fields = (
'body',
'sidebar'
)


@register(PhonelistPage)
class PhonelistPageTR(TranslationOptions):
fields = (
)


@register(FormPage)
class FormPageTR(TranslationOptions):
fields = (
Expand Down
13 changes: 10 additions & 3 deletions mpicms/base/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,22 @@ def register_h1_feature(features):

@hooks.register('register_admin_menu_item')
def register_site_button():
return MenuItem(_('View website'), '/?', classnames='icon icon-site', order=1) # Without the ? Wagtail applies different CSS
# Without the ? Wagtail applies different CSS
return MenuItem(_('View website'), '/?', classnames='icon icon-site', order=1)


@hooks.register('after_edit_page')
def send_notifications(request, page):
subscribers = [user.email for user in page.subscribers.exclude(id=request.user.id)]

if subscribers:
html_message = f'''<a href="{request.build_absolute_uri(reverse('wagtailadmin_pages:revisions_index', args=[page.id]))}">View changes</a>\n
html_message = f'''\
<a href="{request.build_absolute_uri(reverse('wagtailadmin_pages:revisions_index', args=[page.id]))}">View changes</a>

Edited by {request.user}.
You are receiving this message because you subscribed to updates for page {page.get_admin_display_title()}.
Log in to the admin interface and click <a href="{request.build_absolute_uri(reverse('wagtailadmin_pages_unsubscribe', args=[page.id]))}">here</a> to unsubscribe.'''
Log in to the admin interface and click <a href="{request.build_absolute_uri(reverse('wagtailadmin_pages_unsubscribe',
args=[page.id]))}">here</a> to unsubscribe.'''

send_mail(
f'Page {page.get_admin_display_title()} edited.',
Expand All @@ -58,10 +63,12 @@ def send_notifications(request, page):
fail_silently=True)
logger.debug(f'Send change notification to {subscribers}')


@hooks.register('construct_page_action_menu')
def remove_submit_to_moderator_option(menu_items, request, context):
menu_items[:] = [item for item in menu_items if item.name != 'action-submit']


class FeaturedImageAdmin(ModelAdmin):
model = FeaturedImage
menu_label = _('Featured Images')
Expand Down
2 changes: 1 addition & 1 deletion mpicms/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

def ics_view(request):
index = EventIndex.objects.first()
response = HttpResponse(index.ics, content_type="text/calendar")
response = HttpResponse(index.ics, content_type="text/calendar")
response["Content-disposition"] = "attachment; filename=calendar.ics"
return response
2 changes: 1 addition & 1 deletion mpicms/personal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Contact(index.Indexed, ClusterableModel):
objects = ContactManager()

panels = [
MultiFieldPanel([
MultiFieldPanel([
FieldPanel('title', classname=''),
FieldPanel('first_name'),
FieldPanel('last_name'),
Expand Down
3 changes: 2 additions & 1 deletion mpicms/personal/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def get_groups(self, obj):
get_groups.short_description = _('Groups')

def get_positions(self, obj):
return ", ".join([position.__str__() for position in Position.objects.filter(contacts__in=obj.positions.all()).distinct()])
return ", ".join([position.__str__() for position in
Position.objects.filter(contacts__in=obj.positions.all()).distinct()])
get_groups.short_description = _('Positions')

def get_queryset(self, request):
Expand Down
17 changes: 9 additions & 8 deletions mpicms/users/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from django.urls import re_path
from django.views import defaults as default_views

from wagtail.users.views import users
from django.http import Http404

from .views import edit


app_name = 'wagtailusers_users'
def forbidden_view(request):
raise Http404("disabled")


app_name = 'mpicms_users'

urlpatterns = [
re_path(r'^$', users.index, name='index'),
re_path(r'^add/$', default_views.page_not_found,
kwargs={"exception": Exception("Page not Found")}, name='add'),
re_path(r'^add/$', forbidden_view),
re_path(r'^([^\/]+)/$', edit, name='edit'),
re_path(r'^([^\/]+)/delete/$', default_views.page_not_found, name='delete'),
re_path(r'^([^\/]+)/delete/$', forbidden_view),
]
12 changes: 0 additions & 12 deletions mpicms/users/wagtail_hooks.py

This file was deleted.

2 changes: 1 addition & 1 deletion requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ psycopg2-binary

# Wagtail
wagtail
wagtail-modeltranslation
git+https://github.com/buczek/wagtail-modeltranslation.git@add-toggle-configure

markdown
pygments
Expand Down
16 changes: 8 additions & 8 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ asgiref==3.2.10 # via django
beautifulsoup4==4.8.2 # via wagtail
certifi==2020.6.20 # via requests
chardet==3.0.4 # via requests
django-auth-ldap==2.2.0
django-auth-ldap==2.2.0 # via -r base.in
django-filter==2.3.0 # via wagtail
django-modelcluster==5.0.2 # via wagtail
django-modeltranslation==0.15.1 # via wagtail-modeltranslation
django-taggit==1.3.0 # via wagtail
django-treebeard==4.3.1 # via wagtail
django==3.1
django==3.1 # via -r base.in, django-auth-ldap, django-filter, django-modeltranslation, django-taggit, django-treebeard, djangorestframework, wagtail
djangorestframework==3.11.1 # via wagtail
draftjs-exporter==2.1.7 # via wagtail
et-xmlfile==1.0.1 # via openpyxl
html5lib==1.1 # via wagtail
ics==0.7
ics==0.7 # via -r base.in
idna==2.10 # via requests
importlib-metadata==1.7.0 # via markdown
jdcal==1.4.1 # via openpyxl
l18n==2018.5 # via wagtail
markdown==3.2.2
markdown==3.2.2 # via -r base.in
openpyxl==3.0.4 # via tablib
pillow==7.2.0 # via wagtail
psycopg2-binary==2.8.5
psycopg2-binary==2.8.5 # via -r base.in
pyasn1-modules==0.2.8 # via python-ldap
pyasn1==0.4.8 # via pyasn1-modules, python-ldap
pygments==2.6.1
pygments==2.6.1 # via -r base.in
python-dateutil==2.8.1 # via arrow, ics
python-ldap==3.3.1 # via django-auth-ldap
pytz==2020.1 # via django, django-modelcluster, l18n
Expand All @@ -43,8 +43,8 @@ tablib[xls,xlsx]==2.0.0 # via wagtail
tatsu==4.4.0 # via ics
unidecode==1.1.1 # via wagtail
urllib3==1.25.10 # via requests
wagtail-modeltranslation==0.10.13
wagtail==2.10
git+https://github.com/buczek/wagtail-modeltranslation.git@add-toggle-configure # via -r base.in
wagtail==2.10 # via -r base.in, wagtail-modeltranslation
webencodings==0.5.1 # via html5lib
willow==1.4 # via wagtail
xlrd==1.2.0 # via tablib
Expand Down
Loading