Beispiel #1
0
    def get_list(self, endpoint=None, page=1, per_page=None,
                 url_args=None, raise_if_empty=True, paginator=Pagination):
        """Return a dict with pagination and topics."""

        if per_page is None:
            per_page = 20

        # send the query
        offset = per_page * (page - 1)
        stickylist = self.filter(Topic.is_sticky==True) \
                        .order_by(db.desc(Topic.modification_date)).all()
        topiclist = self.filter(db.or_(Topic.is_sticky==False,Topic.is_sticky==None)) \
                        .order_by(db.desc(Topic.modification_date)) \
                        .offset(offset).limit(per_page).all()

        # if raising exceptions is wanted, raise i
        if raise_if_empty and (page != 1 and not topiclist):
            raise NotFound()

        pagination = paginator(endpoint, page, per_page,
                                self.count(), url_args=url_args)

        return {
            'stickies':         stickylist,
            'topics':           topiclist,
            'pagination':       pagination,
        }
Beispiel #2
0
    def refresh(self):
        """Refresh our lasttopic/lastpost data"""

        postquery = Post.query.filter(Post.topic_id==self.id)
        self.postcount = postquery.count()

        lastpost = postquery.order_by(db.desc(Post.id)).first()
        self.lastpost_id = lastpost.id
        self.modification_date = lastpost.date
Beispiel #3
0
 def refresh(self):
     topicfilter = Topic.query.filter(Topic.forum_id==self.id)
     topics = topicfilter.order_by(db.desc(Topic.modification_date)).all()
     self.topiccount = topicfilter.count()
     if self.topiccount:
         lasttopic = topics[0]
         self.lasttopic_id = lasttopic.id
         self.lastpost_id = lasttopic.lastpost.id
         postcount = 0
         for topic in topics:
             postcount += topic.postcount
     else:
         self.lasttopic_id = None
         self.lastpost_id = None
         postcount = 0
     self.postcount = postcount
     self.modification_date = datetime.utcnow()
Beispiel #4
0
    def get_list(self, endpoint=None, page=1, per_page=None,
                 url_args=None, raise_if_empty=True, paginator=Pagination):
        """Return a dict with pagination and wars."""

        if per_page is None:
            per_page = 20

        # send the query
        offset = per_page * (page - 1)
        warlist = self.order_by(db.desc(War.date)) \
                         .offset(offset).limit(per_page).all()

        # if raising exceptions is wanted, raise it
        if raise_if_empty and (page != 1 and not warlist):
            raise NotFound()

        pagination = paginator(endpoint, page, per_page,
                                self.count(), url_args=url_args)

        return {
            'wars':             warlist,
            'pagination':       pagination,
            'warstates':        warstates
        }
Beispiel #5
0
    date = None
    result = NullWarResult()


# Lazy people :D
mapper=db.mapper
relation=db.relation
backref=db.backref

mapper(War, wars, properties={
    'id':               wars.c.war_id,
    'by_member':        relation(WarMember,
                        collection_class=db.attribute_mapped_collection('member')),
    'maps':             relation(WarMap, secondary=war_maps),
    'squad':            relation(Squad, uselist=False,
                                 backref=backref('wars', order_by=db.desc(wars.c.date))),
    'members':          relation(User, secondary=warmembers),
    'orgamember':       relation(User, uselist=False, primaryjoin=wars.c.orgamember_id==users.c.user_id),
    'mode':             relation(WarMode, uselist=False),
    'modificationuser': relation(User, uselist=False, primaryjoin=wars.c.modificationuser_id==users.c.user_id)
})
mapper(WarMember, warmembers, properties={
    'war':              relation(War),
    'member':           relation(User)
})
mapper(WarMode, warmodes, properties={
    'id':               warmodes.c.warmode_id,
    'game':             relation(Game, uselist=False)
})
mapper(WarMap, warmaps, properties={
    'id':               warmaps.c.map_id,