예제 #1
0
def yield_sitemap_event(fbl, all_events):
    # Don't really need fbl, but makes everything easier

    for event in all_events:
        if not event.has_content():
            continue

        url_node = etree.Element('url')
        loc_node = etree.Element('loc')
        loc_node.text = urls.dd_event_url(event)
        if event.is_fb_event:
            if 'updated_time' in event.fb_event['info']:
                lastmod_node = etree.Element('lastmod')
                updated = event.fb_event['info']['updated_time']
                updated = updated.replace('+0000', '+00:00')
                lastmod_node.text = updated
                url_node.append(lastmod_node)
            else:
                logging.info('Event %s does not have updated_time: %s' % (event.id, event.fb_event))
        changefreq_node = etree.Element('changefreq')
        priority_node = etree.Element('priority')

        if event.end_time:
            end_time = event.end_time
        else:
            end_time = event.start_time + datetime.timedelta(hours=2)

        start_time_delta = event.start_time - datetime.datetime.now()
        end_time_delta = end_time - datetime.datetime.now()
        event_delta = end_time - event.start_time

        priority_node.text = '0.5'

        # Event is active and not a multi-week event:
        if event_delta.days < 7 and start_time_delta.days <= 1 and end_time_delta.days >= 0:
            changefreq_node.text = 'hourly'

        # If it ended awhile ago
        elif end_time_delta.days < -30:
            changefreq_node.text = 'yearly'
            priority_node.text = '0.1'
        elif end_time_delta.days < -10:
            changefreq_node.text = 'weekly'

        # If it's coming up soon
        elif start_time_delta.days < 30:
            changefreq_node.text = 'daily'

        else:
            changefreq_node.text = 'weekly'

        url_node.append(loc_node)
        url_node.append(changefreq_node)
        url_node.append(priority_node)
        # prints out as one line
        yield '%s\n' % etree.tostring(url_node)
예제 #2
0
 def get(self, event_id):
     source = self.request.get('s', 'empty')
     medium = self.request.get('m', 'dd.events')
     db_event = eventdata.DBEvent.get_by_id(event_id)
     return self.redirect(
         urls.dd_event_url(
             db_event, {
                 'utm_source': source,
                 'utm_medium': medium,
                 'utm_campaign': 'dd.events'
             }))
예제 #3
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 dancedeets.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)
예제 #4
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 dancedeets.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)
예제 #5
0
    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)
            return
        if not event_types.should_show(db_event):
            self.abort(404)
            return
        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)

        fb_event_wall = None
        if db_event.is_fb_event:
            try:
                fb_event_wall = self.fbl.get(fb_api.LookupEventWall, event_id)
            except fb_api.NoFetchedDataException:
                # If there are problems fetching (likely due to super-large walls)
                # let's just ignore it for now and keep going
                pass

        upcoming_events = []
        past_event = db_event.is_past()
        if past_event:
            # Look up new events for organizers!
            admin_ids = [admin['id'] for admin in db_event.admins]
            # Check admin_ids, because if we try to field.IN([]), we get the error: "Cannot convert FalseNode to predicate"
            if admin_ids:
                events = eventdata.DBEvent.query(
                    eventdata.DBEvent.admin_fb_uids.IN(admin_ids),
                    eventdata.DBEvent.search_time_period ==
                    dates.TIME_FUTURE).fetch(1000)
                events = sorted(events, key=lambda x: x.start_time)
                upcoming_events = [
                    api_format.canonicalize_base_event_data(e, version=(2, 0))
                    for e in events
                ]

        canceled_event = db_event.is_canceled()
        # Render React component for inclusion in our template:
        api_event = api_format.canonicalize_event_data(
            db_event, (2, 0), event_wall=fb_event_wall)
        render_amp = bool(self.request.get('amp'))
        props = dict(
            amp=render_amp,
            event=api_event,
            userRsvp=rsvps.get(event_id),
            pastEvent=past_event,
            canceledEvent=canceled_event,
            upcomingEvents=upcoming_events,
        )
        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/amp.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(https://static.dancedeets.com/')
                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')
예제 #6
0
 def get_lookups(cls, object_id):
     return [
         ('comments', cls.url('comments/', ids=urls.dd_event_url(object_id))),
     ]
예제 #7
0
def campaign_url(eid, source):
    return urls.dd_event_url(eid, {'utm_source': source, 'utm_medium': 'share', 'utm_campaign': 'autopost'})