Ejemplo n.º 1
0
 def flushTopicDetailpageDesc(self, strategy_id):
     data_desc2 = DataDesc()
     data_desc2.setSchema(SCHEMA.schema_topic_manage)
     data_desc2.setDataType(
         DATATYPE.data_type_query_topic_media_by_strategy)
     data_desc2.setKey(1, strategy_id)
     data_desc2.setCached(True, 600)
     return data_desc2
 def flush_channel_detailpage(self, channel_id): 
     day_list = self.session.query(distinct(channel_info.date)).\
             filter(channel_info.channel_id == channel_id).all()
     for date in day_list:
         data_desc = DataDesc(SCHEMA.schema_channel_management,
                         DATATYPE.data_type_query_play_bills)
         data_desc.setKey(1, channel_id)
         data_desc.setKey(2, int(date[0]))
         self.add_notify_descriptor(data_desc, "reload")
 def flushTopicDetailpageDesc(self, strategy_id):
     data_desc2 = DataDesc()
     data_desc2.setSchema(SCHEMA.schema_topic_manage)
     data_desc2.setDataType(DATATYPE.data_type_query_topic_media_by_strategy)
     data_desc2.setKey(1, strategy_id)
     data_desc2.setCached(True, 600)
     return data_desc2
    def processUpdate(self):
        #log.debug("category_management_handler process update enter")
        data_type = self.data_desc.getDataType()
        if DATATYPE.data_type_update_by_id == data_type:
            category_id = self.data_desc.getKey(1)
            category_id2 = self.data_desc.getModifier("category_id2")
            filters = self.data_desc.getModifier("filters")
            categories = self.data_desc.getModifier("categories")
            category_name = self.data_desc.getModifier("category_name")
            content = self.packToXML(categories, filters)
            self.session.query(category_manager).\
                         filter(category_manager.category_id==category_id).\
                         update({"name":category_name,
                                 "category_id":category_id2,
                                 "category_info":content})
            self.session.commit()

            data_desc3 = DataDesc(SCHEMA.schema_category_management,
                             DATATYPE.data_type_query_filter)
            data_desc3.setKey(1, category_id)
            self.add_notify_descriptor(data_desc3, "reload")
    def processUpdate(self):
        #log.debug("category_management_handler process update enter")
        data_type = self.data_desc.getDataType()
        if DATATYPE.data_type_update_by_id == data_type:
            category_id = self.data_desc.getKey(1)
            category_id2 = self.data_desc.getModifier("category_id2")
            filters = self.data_desc.getModifier("filters")
            categories = self.data_desc.getModifier("categories")
            category_name = self.data_desc.getModifier("category_name")
            content = self.packToXML(categories, filters)
            self.session.query(category_manager).\
                         filter(category_manager.category_id==category_id).\
                         update({"name":category_name,
                                 "category_id":category_id2,
                                 "category_info":content})
            self.session.commit()

            data_desc3 = DataDesc(SCHEMA.schema_category_management,
                                  DATATYPE.data_type_query_filter)
            data_desc3.setKey(1, category_id)
            self.add_notify_descriptor(data_desc3, "reload")
Ejemplo n.º 6
0
def db_mget(data_descriptor, session=None):
    '''to get multiple record , at the testing stage'''
    cache_time = get_cache_policy(data_descriptor.getSchema(),
                                  data_descriptor.getDataType())
    if cache_time < 0:
        cache_time = None

    cache = Cache_Service() if cache_time is not None else None

    if cache is None and data_descriptor.isCacheOnly():
        return None

    keys = data_descriptor.getmKey()
    if not isinstance(keys, (list, tuple)):
        return False

    cached_keys = [make_cached_key(data_descriptor.getSchema(),
                                   data_descriptor.getDataType(), k) \
                                   for k in keys]
    collection = []
    if cache is not None:
        collection = cache.mget(cached_keys)

    if data_descriptor.isCacheOnly():
        return collection

    keys_index_not_cached = [i for i, item in enumerate(collection) \
                                if item is None]
    keys_to_db = [keys[i] for i in keys_index_not_cached]
    for i in keys_index_not_cached:
        data_desc = DataDesc(data_descriptor.getSchema(),
                             data_descriptor.getDataType())
        data_desc.setKey(i, keys[i])
        ret = db_get(data_desc, session)
        collection[i] = ret

    return collection
Ejemplo n.º 7
0
def db_mget(data_descriptor, session=None):
    '''to get multiple record , at the testing stage'''
    cache_time = get_cache_policy(data_descriptor.getSchema(),
                                  data_descriptor.getDataType())
    if cache_time < 0:
        cache_time = None

    cache = Cache_Service() if cache_time is not None else None

    if cache is None and data_descriptor.isCacheOnly():
        return None
        
    keys = data_descriptor.getmKey()
    if not isinstance(keys, (list, tuple)):
        return False

    cached_keys = [make_cached_key(data_descriptor.getSchema(),
                                   data_descriptor.getDataType(), k) \
                                   for k in keys]
    collection = []
    if cache is not None:
        collection = cache.mget(cached_keys)

    if data_descriptor.isCacheOnly():
        return collection
    
    keys_index_not_cached = [i for i, item in enumerate(collection) \
                                if item is None]
    keys_to_db = [keys[i] for i in keys_index_not_cached ]
    for i in keys_index_not_cached:
        data_desc = DataDesc(data_descriptor.getSchema(),
                             data_descriptor.getDataType())
        data_desc.setKey(i, keys[i])
        ret = db_get(data_desc, session)
        collection[i] = ret

    return collection
Ejemplo n.º 8
0
 def flush_channel_detailpage(self, channel_id):
     day_list = self.session.query(distinct(channel_info.date)).\
             filter(channel_info.channel_id == channel_id).all()
     for date in day_list:
         data_desc = DataDesc(SCHEMA.schema_channel_management,
                              DATATYPE.data_type_query_play_bills)
         data_desc.setKey(1, channel_id)
         data_desc.setKey(2, int(date[0]))
         self.add_notify_descriptor(data_desc, "reload")
Ejemplo n.º 9
0
 def processDelete(self):
     data_type = self.data_desc.getDataType()
     if DATATYPE.data_type_del_by_id == data_type:
         id = self.data_desc.getKey(1)
         model_id = self.data_desc.getKey(2)
         try:
             self.delete_frontpage_strategy(model_id)
             self.delete_category_frontpage_strategy(model_id)
             self.delete_category_navigation(model_id)
             self.delete_model_version(id)
         except NoResultFound:
             return None
         self.session.commit()
         data_desc = DataDesc(SCHEMA.schema_model_version, DATATYPE.data_type_query_all)
         self.add_notify_descriptor(data_desc, "reload")
Ejemplo n.º 10
0
 def processInsert(self):
     data_type = self.data_desc.getDataType()
     
     if DATATYPE.data_type_insert_record==data_type:
         fmodel_id = self.data_desc.getKey(1)
         details = self.data_desc.getModifier("details")
         model_id = details.get('model_id')
         try:
             self.insert_frontpage_strategy(fmodel_id, model_id)
             self.insert_category_frontpage_strategy(fmodel_id, model_id)
             self.insert_category_navigation(fmodel_id, model_id)
             self.insert_model_version(details)
         except NoResultFound:
             return None
         self.session.commit()
         data_desc = DataDesc(SCHEMA.schema_model_version, DATATYPE.data_type_query_all)
         self.add_notify_descriptor(data_desc, "reload")
Ejemplo n.º 11
0
 def flushTopicListDesc(self):
     data_desc2 = DataDesc()
     data_desc2.setSchema(SCHEMA.schema_topic_category)
     data_desc2.setDataType(DATATYPE.data_type_query_all)
     data_desc2.setCached(True, 600)
     return data_desc2
    def processInsert(self):
        data_type = self.data_desc.getDataType()

        if DATATYPE.data_type_create_pic_submit == data_type:
            date = self.data_desc.getKey(1)
            navi = self.data_desc.getKey(2)
            model_id = self.data_desc.getKey(3)

            try:
                strategy = self.getStrategy(navi, date, model_id)
            except NoResultFound:
                strategy = None

            if strategy is not None:
                self.processUpdate()
                return
            
            layout_id = self.data_desc.getModifier("layout_id")
            details = self.data_desc.getModifier("details")
            #strategy_name = self.data_desc.getModifier("strategy_name").decode('utf-8')
            strategy_name = self.data_desc.getModifier("strategy_name")
            deleted = self.data_desc.getModifier("deleted")
            audit_result = self.data_desc.getModifier("audit_result")
            show_vender_log = self.data_desc.getModifier("show_vender_log")
            if isinstance(strategy_name, unicode):
                strategy_name = strategy_name.encode('utf-8')

            strategy = category_frontpage_strategy(date=date,
                                                   convert_date=self.convertDate(int(date)),
                                                   navigation_id=navi,
                                                   name=strategy_name,
                                                   layout=layout_id,
                                                   tiles=details,
                                                   deleted=deleted,
                                                   audit_result=audit_result,
                                                   model_id=model_id,
                                                   show_vender_log=show_vender_log)

            self.session.add(strategy)
            self.session.commit()

            data_desc3 = DataDesc(SCHEMA.schema_category_frontpage,
                             DATATYPE.data_type_initialization)
            data_desc3.setKey(1, navi)
            data_desc3.setKey(2, date)
            data_desc3.setKey(3, model_id)
            self.add_notify_descriptor(data_desc3, "reload")

        elif DATATYPE.data_type_category_navigation_management == data_type:
            ids = self.data_desc.getKey(1)
            names = self.data_desc.getModifier("names")
            sequences = self.data_desc.getModifier("sequences")
            onlines = self.data_desc.getModifier("onlines")
            for i in range(0, len(ids)):
                navi = category_navigation(name=names[i],
                                           sequence=sequences[i],
                                           online=onlines[i])
                self.session.add(navi)
                self.session.commit()
                navi.navigation_id = navi.id
                self.session.merge(navi)
                self.session.commit()
    def processUpdate(self):
        data_type = self.data_desc.getDataType()

        if DATATYPE.data_type_create_pic_submit==data_type:
            date = self.data_desc.getKey(1)
            navi = self.data_desc.getKey(2)
            model_id = self.data_desc.getKey(3)
            layout_id = self.data_desc.getModifier("layout_id")
            details = self.data_desc.getModifier("details")
            strategy_name = self.data_desc.getModifier("strategy_name")
            audit_result = self.data_desc.getModifier("audit_result")
            deleted = self.data_desc.getModifier("deleted")
            show_vender_log = self.data_desc.getModifier("show_vender_log")
            try:
                strategy = self.getStrategy(navi, date, model_id)
            except NoResultFound:
                return None
            if isinstance(strategy_name, unicode):
                strategy_name = strategy_name.encode('utf-8')
            #############for new requirement##########
            self.session.query(category_frontpage_strategy).\
                        filter(category_frontpage_strategy.date == date,
                               category_frontpage_strategy.navigation_id == navi,
                               category_frontpage_strategy.model_id == model_id).\
                        update({"tiles": details,
                                "name": strategy_name,
                                "model_id": model_id,
                                "audit_result": audit_result,
                                "deleted": deleted,
                                "show_vender_log": show_vender_log})
            self.session.commit()

            data_desc2 = DataDesc(SCHEMA.schema_category_frontpage,
                             DATATYPE.data_type_initialization)
            data_desc2.setKey(1, navi)
            data_desc2.setKey(2, date)
            data_desc2.setKey(3, model_id)
            self.add_notify_descriptor(data_desc2, "reload")
        elif DATATYPE.data_type_for_feature_audit_category == data_type:
            date = self.data_desc.getKey(1)
            navi = self.data_desc.getKey(2)
            deleted = self.data_desc.getModifier("deleted")
            audit_result = self.data_desc.getModifier("audit_result")
            model_id = 0
            try:
                strategy = self.getStrategy(navi, date, model_id)
            except NoResultFound:
                return None
            if isinstance(audit_result, unicode):
                audit_result = audit_result.encode('utf-8')
            #############for new requirement##########
            self.session.query(category_frontpage_strategy).\
                        filter(category_frontpage_strategy.date==date,
                               category_frontpage_strategy.navigation_id==navi).\
                        update({"deleted": deleted,
                                "audit_result": audit_result})
            self.session.commit()

            data_desc2 = DataDesc(SCHEMA.schema_category_frontpage,
                             DATATYPE.data_type_initialization)
            data_desc2.setKey(1, navi)
            data_desc2.setKey(2, date)
            data_desc2.setKey(3, model_id)
            self.add_notify_descriptor(data_desc2, "reload")
            
        elif DATATYPE.data_type_upd_squence == data_type:
            # this data_type is obsolate
            queue = self.data_desc.getModifier("queue")
            for sequence, navi_id in enumerate(queue):
                self.session.query(category_navigation).\
                             filter(category_navigation.navigation_id==navi_id).\
                             update({"sequence": sequence})
            self.session.commit()
        elif DATATYPE.data_type_category_navigation_management == data_type:
            ids = self.data_desc.getKey(1)
            names = self.data_desc.getModifier("names")
            sequences = self.data_desc.getModifier("sequences")
            onlines = self.data_desc.getModifier("onlines")
            for i in range(0, len(ids)):
                self.session.query(category_navigation).\
                             filter(category_navigation.navigation_id==ids[i]).\
                             update({"name":names[i],
                                     "sequence": sequences[i],
                                     "online": onlines[i]})
            self.session.commit()
            dsc = DataDesc(SCHEMA.schema_category_navigation, DATATYPE.data_type_query_all)
            self.add_notify_descriptor(dsc, "reload")
        elif DATATYPE.data_type_del_by_navi_date == data_type:
            navi = self.data_desc.getKey(1)
            date = self.data_desc.getKey(2)
            model_id = self.data_desc.getKey(3)
            try:
                strategy = self.getStrategy(navi, date, model_id)
            except NoResultFound:
                return None
            self.session.query(category_frontpage_strategy).\
                        filter(category_frontpage_strategy.date == date,
                               category_frontpage_strategy.navigation_id == navi,
                               category_frontpage_strategy.model_id == model_id).\
                        update({"deleted": 1})
            self.session.commit()

            data_desc4 = DataDesc(SCHEMA.schema_category_frontpage,
                             DATATYPE.data_type_initialization)
            data_desc4.setKey(1, navi)
            data_desc4.setKey(2, date)
            data_desc4.setKey(3, model_id)
            # self.add_notify_descriptor(data_desc4, "reload")
            self.add_notify_descriptor(data_desc4, "flush_cache")
    def processUpdate(self):
        data_type = self.data_desc.getDataType()

        if DATATYPE.data_type_create_pic_submit == data_type:
            date = self.data_desc.getKey(1)
            navi = self.data_desc.getKey(2)
            model_id = self.data_desc.getKey(3)
            layout_id = self.data_desc.getModifier("layout_id")
            details = self.data_desc.getModifier("details")
            strategy_name = self.data_desc.getModifier("strategy_name")
            audit_result = self.data_desc.getModifier("audit_result")
            deleted = self.data_desc.getModifier("deleted")
            show_vender_log = self.data_desc.getModifier("show_vender_log")
            try:
                strategy = self.getStrategy(navi, date, model_id)
            except NoResultFound:
                return None
            if isinstance(strategy_name, unicode):
                strategy_name = strategy_name.encode('utf-8')
            #############for new requirement##########
            self.session.query(category_frontpage_strategy).\
                        filter(category_frontpage_strategy.date == date,
                               category_frontpage_strategy.navigation_id == navi,
                               category_frontpage_strategy.model_id == model_id).\
                        update({"tiles": details,
                                "name": strategy_name,
                                "model_id": model_id,
                                "audit_result": audit_result,
                                "deleted": deleted,
                                "show_vender_log": show_vender_log})
            self.session.commit()

            data_desc2 = DataDesc(SCHEMA.schema_category_frontpage,
                                  DATATYPE.data_type_initialization)
            data_desc2.setKey(1, navi)
            data_desc2.setKey(2, date)
            data_desc2.setKey(3, model_id)
            self.add_notify_descriptor(data_desc2, "reload")
        elif DATATYPE.data_type_for_feature_audit_category == data_type:
            date = self.data_desc.getKey(1)
            navi = self.data_desc.getKey(2)
            deleted = self.data_desc.getModifier("deleted")
            audit_result = self.data_desc.getModifier("audit_result")
            model_id = 0
            try:
                strategy = self.getStrategy(navi, date, model_id)
            except NoResultFound:
                return None
            if isinstance(audit_result, unicode):
                audit_result = audit_result.encode('utf-8')
            #############for new requirement##########
            self.session.query(category_frontpage_strategy).\
                        filter(category_frontpage_strategy.date==date,
                               category_frontpage_strategy.navigation_id==navi).\
                        update({"deleted": deleted,
                                "audit_result": audit_result})
            self.session.commit()

            data_desc2 = DataDesc(SCHEMA.schema_category_frontpage,
                                  DATATYPE.data_type_initialization)
            data_desc2.setKey(1, navi)
            data_desc2.setKey(2, date)
            data_desc2.setKey(3, model_id)
            self.add_notify_descriptor(data_desc2, "reload")

        elif DATATYPE.data_type_upd_squence == data_type:
            # this data_type is obsolate
            queue = self.data_desc.getModifier("queue")
            for sequence, navi_id in enumerate(queue):
                self.session.query(category_navigation).\
                             filter(category_navigation.navigation_id==navi_id).\
                             update({"sequence": sequence})
            self.session.commit()
        elif DATATYPE.data_type_category_navigation_management == data_type:
            ids = self.data_desc.getKey(1)
            names = self.data_desc.getModifier("names")
            sequences = self.data_desc.getModifier("sequences")
            onlines = self.data_desc.getModifier("onlines")
            for i in range(0, len(ids)):
                self.session.query(category_navigation).\
                             filter(category_navigation.navigation_id==ids[i]).\
                             update({"name":names[i],
                                     "sequence": sequences[i],
                                     "online": onlines[i]})
            self.session.commit()
            dsc = DataDesc(SCHEMA.schema_category_navigation,
                           DATATYPE.data_type_query_all)
            self.add_notify_descriptor(dsc, "reload")
        elif DATATYPE.data_type_del_by_navi_date == data_type:
            navi = self.data_desc.getKey(1)
            date = self.data_desc.getKey(2)
            model_id = self.data_desc.getKey(3)
            try:
                strategy = self.getStrategy(navi, date, model_id)
            except NoResultFound:
                return None
            self.session.query(category_frontpage_strategy).\
                        filter(category_frontpage_strategy.date == date,
                               category_frontpage_strategy.navigation_id == navi,
                               category_frontpage_strategy.model_id == model_id).\
                        update({"deleted": 1})
            self.session.commit()

            data_desc4 = DataDesc(SCHEMA.schema_category_frontpage,
                                  DATATYPE.data_type_initialization)
            data_desc4.setKey(1, navi)
            data_desc4.setKey(2, date)
            data_desc4.setKey(3, model_id)
            # self.add_notify_descriptor(data_desc4, "reload")
            self.add_notify_descriptor(data_desc4, "flush_cache")
Ejemplo n.º 15
0
 def flushTopicListDesc(self):
     data_desc2 = DataDesc()
     data_desc2.setSchema(SCHEMA.schema_topic_category)
     data_desc2.setDataType(DATATYPE.data_type_query_all)
     data_desc2.setCached(True, 600)
     return data_desc2
Ejemplo n.º 16
0
 def flush_channel_video(self, program_id, channel_id):
     data_desc = DataDesc(SCHEMA.schema_Basic_Media_model,
                          DATATYPE.get_channel_video_detail)
     data_desc.setKey(1, program_id)
     data_desc.setKey(2, channel_id)
     self.add_notify_descriptor(data_desc, "reload")
Ejemplo n.º 17
0
 def flush_channel_list(self):
     data_desc = DataDesc(SCHEMA.schema_channel,
                          DATATYPE.data_type_query_all)
     self.add_notify_descriptor(data_desc, "reload")
    def processInsert(self):
        data_type = self.data_desc.getDataType()

        if DATATYPE.data_type_create_pic_submit == data_type:
            date = self.data_desc.getKey(1)
            navi = self.data_desc.getKey(2)
            model_id = self.data_desc.getKey(3)

            try:
                strategy = self.getStrategy(navi, date, model_id)
            except NoResultFound:
                strategy = None

            if strategy is not None:
                self.processUpdate()
                return

            layout_id = self.data_desc.getModifier("layout_id")
            details = self.data_desc.getModifier("details")
            #strategy_name = self.data_desc.getModifier("strategy_name").decode('utf-8')
            strategy_name = self.data_desc.getModifier("strategy_name")
            deleted = self.data_desc.getModifier("deleted")
            audit_result = self.data_desc.getModifier("audit_result")
            show_vender_log = self.data_desc.getModifier("show_vender_log")
            if isinstance(strategy_name, unicode):
                strategy_name = strategy_name.encode('utf-8')

            strategy = category_frontpage_strategy(
                date=date,
                convert_date=self.convertDate(int(date)),
                navigation_id=navi,
                name=strategy_name,
                layout=layout_id,
                tiles=details,
                deleted=deleted,
                audit_result=audit_result,
                model_id=model_id,
                show_vender_log=show_vender_log)

            self.session.add(strategy)
            self.session.commit()

            data_desc3 = DataDesc(SCHEMA.schema_category_frontpage,
                                  DATATYPE.data_type_initialization)
            data_desc3.setKey(1, navi)
            data_desc3.setKey(2, date)
            data_desc3.setKey(3, model_id)
            self.add_notify_descriptor(data_desc3, "reload")

        elif DATATYPE.data_type_category_navigation_management == data_type:
            ids = self.data_desc.getKey(1)
            names = self.data_desc.getModifier("names")
            sequences = self.data_desc.getModifier("sequences")
            onlines = self.data_desc.getModifier("onlines")
            for i in range(0, len(ids)):
                navi = category_navigation(name=names[i],
                                           sequence=sequences[i],
                                           online=onlines[i])
                self.session.add(navi)
                self.session.commit()
                navi.navigation_id = navi.id
                self.session.merge(navi)
                self.session.commit()
Ejemplo n.º 19
0
import os

from itertools import permutations
from string import ascii_uppercase

from df import data_function
from df.datamodel.schema import SCHEMA
from df.datamodel.schema import DATATYPE
from df.data_descriptor import DataDesc

x3 = permutations(ascii_uppercase, r=3)
x2 = permutations(ascii_uppercase, r=2)
x1 = permutations(ascii_uppercase, r=1)

data_desc = DataDesc(SCHEMA.schema_search, DATATYPE.data_type_query_all)
data_desc.setCached(True)

for x in x1:
    key = "".join(x)
    params = {"start": '0', "rows": '200', "type": '0', "search_key": key}
    print "processing key ", key
    data_desc.setKey(1, params)
    data_function.db_get(data_desc)

for x in x2:
    key = "".join(x)
    params = {"start": '0', "rows": '200', "type": '0', "search_key": key}
    print "processing key ", key
    data_desc.setKey(1, params)
    data_function.db_get(data_desc)
 def flush_channel_video(self, program_id, channel_id):
     data_desc = DataDesc(SCHEMA.schema_Basic_Media_model,
                      DATATYPE.get_channel_video_detail)
     data_desc.setKey(1, program_id)
     data_desc.setKey(2, channel_id)
     self.add_notify_descriptor(data_desc, "reload")
Ejemplo n.º 21
0
 def getReloadDesc(self, schema, dataType, date, model_id):
     data_desc2 = DataDesc(schema, dataType)
     data_desc2.setKey(1, date)
     data_desc2.setKey(2, model_id)
     return data_desc2
Ejemplo n.º 22
0
import os

from itertools import permutations
from string import ascii_uppercase

from df import data_function
from df.datamodel.schema import SCHEMA
from df.datamodel.schema import DATATYPE
from df.data_descriptor import DataDesc

x3 = permutations(ascii_uppercase, r=3)
x2 = permutations(ascii_uppercase, r=2)
x1 = permutations(ascii_uppercase, r=1)

data_desc = DataDesc(SCHEMA.schema_search,
                     DATATYPE.data_type_query_all)
data_desc.setCached(True)


for x in x1:
    key = "".join(x)
    params = {"start": '0',
          "rows": '200',
          "type": '0',
          "search_key": key}
    print "processing key ", key
    data_desc.setKey(1, params)
    data_function.db_get(data_desc)

for x in x2:
    key = "".join(x)