from app.Model.Article import Article
from app.Model.Taglist import Taglist
from app.Model.Taglist import Taglist
from app import dBSession
import re

class TaglistService():
    #tag文章列表
    def getJoinList(self, filters, order, field=(), offset = 0, limit = 15):
        res = {}
        res['count'] =  dBSession.query(Taglist).filter(*filters).join(Taglist.article).count()
        res['list'] = []
        if res['count'] > 0:
            res['list'] = dBSession.query(Taglist).filter(*filters).join(Taglist.article)
            res['list'] = res['list'].order_by(order).offset(offset).limit(limit).all() 
        if not field:
            res['list'] = [c.to_dict() for c in res['list']]
        else:
            res['list'] = [c.to_dict(only=field) for c in res['list']]
        
        return res