def get(self, event_id):
        self.finish_preload()
        if not event_id:
            self.response.out.write('Need an event_id.')
            return

        # Load the db_event instead of the fb_event, as the db_event is likely to be in cache
        db_event = eventdata.DBEvent.get_by_id(event_id)
        if not db_event:
            self.abort(404)
        if not db_event.has_content():
            self.response.out.write('This event was %s.' % db_event.empty_reason)
            return

        self.display['displayable_event'] = DisplayableEvent(db_event)

        self.display['next'] = self.request.url
        self.display['show_mobile_app_promo'] = True
        self.jinja_env.filters['make_category_link'] = lambda lst: [jinja2.Markup('<a href="/?keywords=%s">%s</a>') % (x, x) for x in lst]

        self.display['canonical_url'] = urls.dd_event_url(db_event)

        self.display['email_suffix'] = '+event-%s' % db_event.id

        rsvps = {}
        if self.fb_uid:
            rsvps = rsvp.get_rsvps(self.fbl)

        # Render React component for inclusion in our template:
        api_event = api.canonicalize_event_data(db_event, None, version=(1, 3))
        render_amp = bool(self.request.get('amp'))
        props = dict(
            amp=render_amp,
            event=api_event,
            userRsvp=rsvps.get(event_id),
        )
        self.setup_react_template('event.js', props, static_html=render_amp)

        if render_amp:
            if self.display['displayable_event']:
                # Because minification interferes with html-validity when producing:
                # <meta name=viewport content=width=device-width,minimum-scale=1,initial-scale=1,maximum-scale=1,user-scalable=no>
                self.allow_minify = False
                try:
                    event_amp_css_filename = os.path.join(os.path.dirname(__file__), '..', 'dist-includes/css/eventAmp.css')
                    event_amp_css = open(event_amp_css_filename).read()
                    event_amp_css = re.sub(r'@-ms-viewport\s*{.*?}', '', event_amp_css)
                    event_amp_css = re.sub(r'!important', '', event_amp_css)
                    event_amp_css = event_amp_css.replace('url(..', 'url(/dist-' + self._get_static_version())
                except IOError as e:
                    logging.exception('Failed to load AMP CSS')
                    event_amp_css = ''
                self.display['event_amp_stylesheet'] = event_amp_css
                self.render_template('event_amp')
            else:
                self.abort(404)
        else:
            self.render_template('event')
Exemple #2
0
    def get(self):
        self.finish_preload()
        form = search_base.SearchForm(
            formdata=self.request.GET,
            data=self.user.dict_for_form() if self.user else None)
        if not form.validate():
            logging.warning("Form errors: %s", form.errors)
            self.write_json_response([])
            return
        search_query = form.build_query(start_end_query=True)
        search_results = search.Search(search_query).get_search_results()

        if 'class' in form.deb.data:
            from classes import class_index
            class_results = class_index.ClassSearch(
                search_query).get_search_results()
            search_results += class_results
            search_results.sort(key=lambda x: x.start_time)

        json_results = []
        for result in search_results:
            start_time = result.start_time
            end_time = result.fake_end_time
            duration = end_time - start_time
            if duration > datetime.timedelta(days=5):
                end_time = start_time
            elif duration <= datetime.timedelta(days=1):
                end_time = start_time
            all_day = False
            title = '@ %s\n\n%s' % (result.actual_city_name, result.name)
            json_results.append(
                dict(
                    id=result.event_id,
                    title=title,
                    start=start_time.strftime('%Y-%m-%dT%H:%M:%SZ'),
                    end=end_time.strftime('%Y-%m-%dT%H:%M:%SZ'),
                    url=urls.dd_event_url(result.event_id),
                    allDay=all_day,
                ))
        self.write_json_response(json_results)
    def get(self):
        self.finish_preload()
        form = search_base.SearchForm(formdata=self.request.GET, data=self.user.dict_for_form() if self.user else None)
        if not form.validate():
            logging.warning("Form errors: %s", form.errors)
            self.write_json_response([])
            return
        search_query = form.build_query(start_end_query=True)
        search_results = search.Search(search_query).get_search_results()

        if 'class' in form.deb.data:
            from classes import class_index
            class_results = class_index.ClassSearch(search_query).get_search_results()
            search_results += class_results
            search_results.sort(key=lambda x: x.start_time)

        json_results = []
        for result in search_results:
            start_time = result.start_time
            end_time = result.fake_end_time
            duration = end_time - start_time
            if duration > datetime.timedelta(days=5):
                end_time = start_time
            elif duration <= datetime.timedelta(days=1):
                end_time = start_time
            all_day = False
            title = '@ %s\n\n%s' % (result.actual_city_name, result.name)
            json_results.append(dict(
                id=result.event_id,
                title=title,
                start=start_time.strftime('%Y-%m-%dT%H:%M:%SZ'),
                end=end_time.strftime('%Y-%m-%dT%H:%M:%SZ'),
                url=urls.dd_event_url(result.event_id),
                allDay=all_day,
            ))
        self.write_json_response(json_results)
def campaign_url(eid, source):
    return urls.dd_event_url(eid, {
        'utm_source': source,
        'utm_medium': 'share',
        'utm_campaign': 'autopost'
    })
 def get(self, event_id):
     return self.redirect(urls.dd_event_url(event_id))
Exemple #6
0
 def get_lookups(cls, object_id):
     return [
         ('comments',
          cls.url('/comments/?ids=%s' % urls.dd_event_url(object_id))),
     ]
def campaign_url(eid, source):
    return urls.dd_event_url(eid, {
        'utm_source': source,
        'utm_medium': 'share',
        'utm_campaign': 'autopost'
    })