Example #1
0
    def _process_args(self):
        data = request.json
        self.object = None
        if 'categId' in data:
            self.object = Category.get_one(data['categId'])
        elif 'contribId' in data:
            self.object = Contribution.get_one(data['contribId'])
        elif 'sessionId' in data:
            self.object = Session.get_one(data['sessionId'])
        elif 'confId' in data:
            self.object = Event.get_one(data['confId'])

        if self.object is None:
            raise BadRequest
Example #2
0
 def _iter_shorturls(self):
     it = self.zodb_root['shorturl'].iteritems()
     total = len(self.zodb_root['shorturl'])
     it = verbose_iterator(it, total, lambda x: x[1].id, lambda x: '')
     for shorturl, conf in it:
         try:
             event = Event.get_one(conf.id)
         except NoResultFound:
             self.print_warning(cformat(
                 '%{yellow!}Ignoring shorturl %{reset}%{yellow}{}%{yellow!} (event deleted)'
             ).format(shorturl),
                                always=False,
                                event_id=conf.id)
             continue
         yield shorturl, conf, event
    def as_event(self):
        """Returns the :class:`.Event` for this object

        :rtype: indico.modules.events.models.events.Event
        """
        from indico.modules.events.models.events import Event
        event_id = int(self.id)
        # this is pretty ugly, but the api sends queries in a loop in
        # some cases and we can't really avoid this for now.  If we
        # already have the event in the identity map we keep using
        # the simple id-based lookup though as lazyloading the acl
        # entries is just one query anyway
        if (has_request_context() and request.blueprint == 'api'
                and request.endpoint != 'api.jsonrpc'
                and (Event, (event_id, )) not in db.session.identity_map):
            acl_user_strategy = joinedload('acl_entries').defaultload('user')
            # remote group membership checks will trigger a load on _all_emails
            # but not all events use this so there's no need to eager-load them
            acl_user_strategy.noload('_primary_email')
            acl_user_strategy.noload('_affiliation')
            return Event.find(id=event_id).options(acl_user_strategy).one()
        else:
            # use get() so sqlalchemy can make use of the identity cache
            return Event.get_one(event_id)