Esempio n. 1
0
 def remove_bulletin(self,bulletin_id,user_id):
     query = Bulletin.select().where(Bulletin.id == bulletin_id , Bulletin.fk_user == user_id)
     if query.count() > 0 : 
         BulletinFilter.delete().where(BulletinFilter.fk_bulletin == bulletin_id).execute()
         query = (Bulletin.delete().where(Bulletin.id== bulletin_id).execute())
         return True
     return False    
Esempio n. 2
0
 def remove_bulletin(self, bulletin_id, user_id):
     query = Bulletin.select().where(Bulletin.id == bulletin_id,
                                     Bulletin.fk_user == user_id)
     if query.count() > 0:
         BulletinFilter.delete().where(
             BulletinFilter.fk_bulletin == bulletin_id).execute()
         query = (Bulletin.delete().where(
             Bulletin.id == bulletin_id).execute())
         return True
     return False
Esempio n. 3
0
    def get_user_bulletin(self, user_id):

        query = (Bulletin.select(
            Bulletin.id, BulletinFilter.query_text,
            Source.title.alias('source'),
            BulletinFilter.scan_period, BulletinFilter.starred,
            Source.id.alias('source_id')).join(BulletinFilter).join(
                Source,
                JOIN_LEFT_OUTER).naive().where(Bulletin.fk_user == user_id))
        ll = []

        if query.count() > 0:
            query = query.execute()
            for index, ft in enumerate(query):
                ll.append({
                    'index': index + 1,
                    'query_text': ft.query_text,
                    'source': ft.source,
                    'id': ft.id,
                    'source_id': ft.source_id,
                    'scan_period': ft.scan_period,
                    'starred': ft.starred
                })
        return ll
        '''
Esempio n. 4
0
 def remove_bulletin_filter(self, filter_id, user_id):
     query = Bulletin.select().join(BulletinFilter).where(
         BulletinFilter.id == filter_id, Bulletin.fk_user == user_id)
     if query.count() > 0:
         query = (BulletinFilter.delete().where(
             BulletinFilter.id == filter_id).execute())
         return True
     return False
Esempio n. 5
0
 def get_bulletin_filter(self,bulletin_id,user_id):
     query = (Bulletin.select(Bulletin.id,fn.isnull(BulletinFilter.query_text,"").alias('query_text'),
                              fn.isnull(Source.title,SQL("'همه منابع'")).alias('source') )
              .join(BulletinFilter).join(Source).naive().where(Bulletin.id==bulletin_id , Bulletin.fk_user== user_id ).execute())
     
     ll = []
     for index,ft  in enumerate( query):
         ll.append({'index':index+1,'query_text':ft.query_text if ft.query_text != None else '' ,
                    'source':ft.source ,'id':ft.id,'source_id':ft.source_id})
     return ll
Esempio n. 6
0
 def add_bulletin(self,user_id,query_text,scan_period,source,starred,bulletin_id):
     b = Bulletin()
     if   bulletin_id >= 0 :
         b = Bulletin.get(Bulletin.id == bulletin_id)
     
     b.fk_user = user_id
     b.save()
     
     bf = BulletinFilter()
     if bulletin_id >= 0 :
         tmp = BulletinFilter.select().where(BulletinFilter.fk_bulletin == b.id )
         for tt in tmp :
             bf = tt
             break
     
     bf.fk_bulletin = b.id
     bf.fk_source = source if source >=0 else None
     bf.query_text = query_text        
     bf.scan_period = scan_period if scan_period >=0 else None  
     bf.starred = 0 if starred == 'false' else 1
     
     bf.save()
Esempio n. 7
0
 def get_user_bulletin(self, user_id):
     
     query = (Bulletin.select(Bulletin.id, BulletinFilter.query_text, Source.title.alias('source'),
                              BulletinFilter.scan_period, BulletinFilter.starred, Source.id.alias('source_id'))
             .join(BulletinFilter).join(Source,JOIN_LEFT_OUTER).naive().where(Bulletin.fk_user == user_id))
     ll = []
     
     if query.count() > 0 :
         query = query.execute()
         for index, ft  in enumerate(query):
             ll.append({'index':index + 1, 'query_text':ft.query_text, 'source':ft.source, 'id':ft.id, 'source_id':ft.source_id,
                        'scan_period':ft.scan_period, 'starred':ft.starred})
     return ll
     
     '''
Esempio n. 8
0
    def get_bulletin_filter(self, bulletin_id, user_id):
        query = (Bulletin.select(
            Bulletin.id,
            fn.isnull(BulletinFilter.query_text, "").alias('query_text'),
            fn.isnull(Source.title, SQL("'همه منابع'")).alias('source')).join(
                BulletinFilter).join(Source).naive().where(
                    Bulletin.id == bulletin_id,
                    Bulletin.fk_user == user_id).execute())

        ll = []
        for index, ft in enumerate(query):
            ll.append({
                'index':
                index + 1,
                'query_text':
                ft.query_text if ft.query_text != None else '',
                'source':
                ft.source,
                'id':
                ft.id,
                'source_id':
                ft.source_id
            })
        return ll
Esempio n. 9
0
    def add_bulletin(self, user_id, query_text, scan_period, source, starred,
                     bulletin_id):
        b = Bulletin()
        if bulletin_id >= 0:
            b = Bulletin.get(Bulletin.id == bulletin_id)

        b.fk_user = user_id
        b.save()

        bf = BulletinFilter()
        if bulletin_id >= 0:
            tmp = BulletinFilter.select().where(
                BulletinFilter.fk_bulletin == b.id)
            for tt in tmp:
                bf = tt
                break

        bf.fk_bulletin = b.id
        bf.fk_source = source if source >= 0 else None
        bf.query_text = query_text
        bf.scan_period = scan_period if scan_period >= 0 else None
        bf.starred = 0 if starred == 'false' else 1

        bf.save()
Esempio n. 10
0
 def remove_bulletin_filter(self,filter_id,user_id):
     query = Bulletin.select().join(BulletinFilter).where(BulletinFilter.id == filter_id , Bulletin.fk_user == user_id)
     if query.count() > 0 :
         query = (BulletinFilter.delete().where(BulletinFilter.id== filter_id).execute())
         return True
     return False