示例#1
0
    def update_from_json(cls, data):
        PROPNAME_MAPPING = EntityProp.map_name_id()
        eid = None
        PROP_MAPPING = {
            'image':
                lambda s, _eid, _id, _val: [PropMedia.delete(_eid, _id, False),
                                            PropMedia(_eid, _id,
                                                      cls.convert_media_value_to_media_item('image', _eid, _val)).
                                            add_or_update(session=s, no_commit=True)],
            'priority':
                lambda s, _eid, _id, _val: PropInt(eid, _id, _val).add_or_update(session=s, no_commit=True)
        }

        if 'id' in data:
            with DBConnection() as session:
                eid = data['id']
                entity = session.db.query(EntityNews).filter_by(eid=eid).all()
                fields = ['title', 'desc', 'text']
                if len(entity):
                    for _ in entity:
                        for l in cls.locales:
                            for f in fields:
                                if f in data and l in data[f]:
                                    setattr(_, '%s_%s' % (f, l), data[f][l])
                        session.db.commit()

                        if 'prop' in data:
                            for prop_name, prop_val in data['prop'].items():
                                if prop_name in PROPNAME_MAPPING and prop_name in PROP_MAPPING:
                                    PROP_MAPPING[prop_name](session, eid, PROPNAME_MAPPING[prop_name], prop_val)
                        session.db.commit()

        return eid
示例#2
0
    def delete_wide_object(cls, eid):
        PROPNAME_MAPPING = EntityProp.map_name_id()

        PROP_MAPPING = {
            'image':
                lambda _eid, _id: PropMedia.delete(_eid, _id, False),
            'priority':
                lambda _eid, _id: PropInt.delete(_eid, _id, False)
        }

        for key, propid in PROPNAME_MAPPING.items():
            if key in PROP_MAPPING:
                PROP_MAPPING[key](eid, propid)
示例#3
0
    def delete_wide_object(cls, eid):
        from each.Prop.PropGame import PropGame
        PROPNAME_MAPPING = EntityProp.map_name_id()

        PROP_MAPPING = {
            'game': lambda _eid, _id: PropGame.delete_value(_eid, False),
            'image': lambda _eid, _id: PropMedia.delete(_eid, _id, False),
            'scenario': lambda _eid, _id: PropScenario.delete(_eid, _id, False),
            'rating': lambda _eid, _id: PropLike.delete(_eid, _id, False),
            'comment': lambda _eid, _id: PropComment.delete(_eid, _id, False)
        }

        for key, propid in PROPNAME_MAPPING.items():
            if key in PROP_MAPPING:
                PROP_MAPPING[key](eid, propid)
示例#4
0
 def mediaPropMapping(_eid, _id):
     PropMedia.delete(_eid, _id, False)
示例#5
0
 def mediaPropMapping(s, _eid, _id, _val):
     PropMedia.delete(_eid, _id, False)
     PropMedia(eid, _id, cls.convert_media_value_to_media_item('image', _eid, _val))\
         .add_or_update(session=s, no_commit=True)