Пример #1
0
    def POST_happening_now(self, featured_thread, target):
        if featured_thread:
            if not target:
                abort(400)

            NamedGlobals.set(HAPPENING_NOW_KEY, {target: featured_thread._id})
        else:
            NamedGlobals.set(HAPPENING_NOW_KEY, None)

        self.redirect('/admin/happening-now')
Пример #2
0
    def GET_happening_now(self):
        """ Get some basic information about the currently featured live thread.

            Returns an empty 204 response for api requests if no thread is currently featured.

            See also: [/api/live/*thread*/about](#GET_api_live_{thread}_about).
        """

        if not is_api() or not feature.is_enabled('live_happening_now'):
            self.abort404()

        event_id = NamedGlobals.get(HAPPENING_NOW_KEY, None)
        if not event_id:
            response.status_code = 204
            return

        try:
            event = LiveUpdateEvent._byID(event_id)
        except NotFound:
            response.status_code = 204
            return
        else:
            c.liveupdate_event = event
            content = Wrapped(event)
            return pages.LiveUpdateEventPage(content).render()
Пример #3
0
    def GET_happening_now(self):
        """ Get some basic information about the currently featured live thread.

            Returns an empty 204 response for api requests if no thread is currently featured.

            See also: [/api/live/*thread*/about](#GET_api_live_{thread}_about).
        """

        if not is_api() or not feature.is_enabled('live_happening_now'):
            self.abort404()

        event_id = NamedGlobals.get(HAPPENING_NOW_KEY, None)
        if not event_id:
            response.status_code = 204
            return

        try:
            event = LiveUpdateEvent._byID(event_id)
        except NotFound:
            response.status_code = 204
            return
        else:
            c.liveupdate_event = event
            content = Wrapped(event)
            return pages.LiveUpdateEventPage(content).render()
Пример #4
0
 def GET_happening_now(self):
     current_thread_id = NamedGlobals.get(HAPPENING_NOW_KEY, None)
     if current_thread_id:
         current_thread = LiveUpdateEvent._byID(current_thread_id)
     else:
         current_thread = None
     return AdminPage(content=pages.HappeningNowAdmin(current_thread),
                      title='live: happening now',
                      nav_menus=[]).render()
Пример #5
0
    def GET_happening_now(self):
        featured_event_ids = NamedGlobals.get(HAPPENING_NOW_KEY, None) or {}
        featured_events = {}
        for target, event_id in featured_event_ids.iteritems():
            event = LiveUpdateEvent._byID(event_id)
            featured_events[target] = event

        return AdminPage(content=pages.HappeningNowAdmin(featured_events),
                         title='live: happening now',
                         nav_menus=[]).render()
 def GET_happening_now(self):
     current_thread_id = NamedGlobals.get(HAPPENING_NOW_KEY, None)
     if current_thread_id:
         current_thread = LiveUpdateEvent._byID(current_thread_id)
     else:
         current_thread = None
     return AdminPage(
             content=pages.HappeningNowAdmin(current_thread),
             title='live: happening now',
             nav_menus=[]
         ).render()
Пример #7
0
def get_featured_event():
    """Return the currently featured live thread for the given user."""
    featured_events = NamedGlobals.get(HAPPENING_NOW_KEY, None)
    location = geoip.get_request_location(request, c)
    event_id = None
    if featured_events:
        event_id = featured_events.get(location) or featured_events.get("ANY")

    if not event_id:
        return None

    try:
        return LiveUpdateEvent._byID(event_id)
    except NotFound:
        return None
def add_featured_live_thread(controller):
    """If we have a live thread featured, display it on the homepage."""
    if not feature.is_enabled('live_happening_now'):
        return None

    # Not on front page
    if not isinstance(c.site, DefaultSR):
        return None

    # Not on first page of front page
    if getattr(controller, 'listing_obj') and controller.listing_obj.prev:
        return None

    event_id = NamedGlobals.get(HAPPENING_NOW_KEY, None)
    if not event_id:
        return None

    try:
        event = LiveUpdateEvent._byID(event_id)
    except NotFound:
        return None
    else:
        return pages.LiveUpdateHappeningNowBar(event=event)
def add_featured_live_thread(controller):
    """If we have a live thread featured, display it on the homepage."""
    if not feature.is_enabled('live_happening_now'):
        return None

    # Not on front page
    if not isinstance(c.site, DefaultSR):
        return None

    # Not on first page of front page
    if getattr(controller, 'listing_obj') and controller.listing_obj.prev:
        return None

    event_id = NamedGlobals.get(HAPPENING_NOW_KEY, None)
    if not event_id:
        return None

    try:
        event = LiveUpdateEvent._byID(event_id)
    except NotFound:
        return None
    else:
        return pages.LiveUpdateHappeningNowBar(event=event)
Пример #10
0
def get_all_featured_events():
    return NamedGlobals.get(HAPPENING_NOW_KEY, None) or {}
    def POST_happening_now(self, featured_thread):
        NamedGlobals.set(HAPPENING_NOW_KEY,
                         getattr(featured_thread, '_id', None))

        self.redirect('/admin/happening-now')
    def POST_happening_now(self, featured_thread):
        NamedGlobals.set(HAPPENING_NOW_KEY,
                         getattr(featured_thread, '_id', None))

        self.redirect('/admin/happening-now')