Example #1
0
def handle_settings(self, request, form):
    """ Handles the GET and POST login requests. """

    layout = DefaultLayout(self, request)
    layout.include_editor()

    request.include('check_contrast')

    if form.submitted(request):
        with request.app.update_town() as town:
            town.name = form.name.data
            town.logo_url = form.logo_url.data
            town.theme_options = form.theme_options
            town.meta = {
                'contact': form.contact.data,
                'contact_html': linkify(
                    form.contact.data).replace('\n', '<br>'),
                'contact_url': form.contact_url.data,
                'opening_hours': form.opening_hours.data,
                'opening_hours_html': linkify(
                    form.opening_hours.data).replace('\n', '<br>'),
                'opening_hours_url': form.opening_hours_url.data,
                'reply_to': form.reply_to.data,
                'facebook_url': form.facebook_url.data,
                'twitter_url': form.twitter_url.data,
                'analytics_code': form.analytics_code.data,
                'online_counter_label': form.online_counter_label.data,
                'reservations_label': form.reservations_label.data,
                'sbb_daypass_label': form.sbb_daypass_label.data,
            }

        request.success(_("Your changes were saved"))
    else:
        form.name.data = self.name
        form.logo_url.data = self.logo_url
        form.theme_options = self.theme_options
        form.contact.data = self.meta.get('contact')
        form.contact_url.data = self.meta.get('contact_url')
        form.opening_hours.data = self.meta.get('opening_hours')
        form.opening_hours_url.data = self.meta.get('opening_hours_url')
        form.reply_to.data = self.meta.get('reply_to')
        form.facebook_url.data = self.meta.get('facebook_url')
        form.twitter_url.data = self.meta.get('twitter_url')
        form.analytics_code.data = self.meta.get('analytics_code')
        form.online_counter_label.data = self.meta.get('online_counter_label')
        form.reservations_label.data = self.meta.get('reservations_label')
        form.sbb_daypass_label.data = self.meta.get('sbb_daypass_label')

    layout.breadcrumbs = [
        Link(_("Homepage"), layout.homepage_url),
        Link(_("Settings"), request.link(self))
    ]

    return {
        'layout': layout,
        'title': _('Settings'),
        'form': form,
        'form_width': 'large'
    }
Example #2
0
    def contact(self, value):
        self.content['contact'] = value

        if value:
            self.content['contact_html'] = '<ul><li>{}</li></ul>'.format(
                '</li><li>'.join(linkify(value).splitlines())
            )
        else:
            self.content['contact_html'] = ""
Example #3
0
    def contact_html(self):
        """ Returns the contacts html, but instead of breaking it into multiple
        lines (like on the site footer), this version puts it all on one line.

        """

        lines = (l.strip() for l in self.town.meta['contact'].splitlines())
        lines = (l for l in lines if l)

        return linkify(', '.join(lines))
Example #4
0
def view_get_occurrence(self, request):
    """ View a single occurrence of an event. """

    layout = OccurrenceLayout(self, request)
    today = replace_timezone(as_datetime(date.today()), self.timezone)
    occurrences = self.event.occurrence_dates(localize=True)
    occurrences = list(filter(lambda x: x >= today, occurrences))
    description = linkify(self.event.description).replace('\n', '<br>')
    session = request.app.session()
    ticket = TicketCollection(session).by_handler_id(self.event.id.hex)

    return {
        'description': description,
        'layout': layout,
        'occurrence': self,
        'occurrences': occurrences,
        'ticket': ticket,
        'title': self.title,
    }
Example #5
0
    def portrait_html(self):
        """ Returns the portrait as HTML. """

        return '<p>{}</p>'.format(linkify(self.portrait).replace('\n', '<br>'))
Example #6
0
 def contact(self, value):
     self.content["contact"] = value
     self.content["contact_html"] = linkify(value)
Example #7
0
 def linkify(self, text):
     return linkify(text)