Skip to content

Commit

Permalink
Create usable links for seminar rooms
Browse files Browse the repository at this point in the history
For "events", room specifications like "SR 1" are often used. However,
this is not a valid room numer as expected by the twiki map.

Translate "SR [1234]" to correct room numbers for the link target.
  • Loading branch information
donald committed Aug 13, 2020
1 parent d0e154b commit 2915e07
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions mpicms/base/templatetags/base_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def remove_i18n(url):
# 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]"
Expand All @@ -42,11 +41,27 @@ def remove_i18n(url):
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 '<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(r'<a href="http://twiki.molgen.mpg.de/foswiki/bin/room/\1">\1</a>', rooms))
return mark_safe(ROOM_PATTERN.sub(room_match_to_link, rooms))

0 comments on commit 2915e07

Please sign in to comment.