Пример #1
0
Файл: card.py Проект: omo/blbr
        owner = self.parent.get(params)
        if not owner:
            logging.info(self.__class__.__name__, ".put: No owner")            
            return None
        if not params.get('card_id'):
            logging.info(self.__class__.__name__, ".put: Missing ID for PUT")
            return None
        try:
            return self.update_by_bag(params['card_id'], bag)
        except db.BadValueError as e:
            logging.info(self.__class__.__name__, ".put: BadValueError:", e)
            return None

    def delete(self, params):
        owner = self.parent.get(params)
        if not owner:
            return False
        if not params.get('card_id'):
            logging.info(self.__class__.__name__, ".delete: Missing ID for DELETE")
            return False
        try:
            return self.delete_by_keylike(params['card_id'])
        except db.BadValueError as e:
            logging.info(self.__class__.__name__, ".delete: BadValueError", e)
            return False



CardController = restics.item_controller_for(CardRepo)
CardCollectionController = restics.collection_controller_for(CardRepo)
Пример #2
0
Файл: user.py Проект: omo/blbr
        self.level_round = level.round
        self.put()


class UserRepo(restics.Repo):
    item_url_pattern = '/r/<user_id>'

    def find_by_keylike(self, keylike):
        if (keylike == "me"):
            return self.me
        try:
            found = User.get(db.Key(keylike))
            if not found or found.account != self.account:
                return None
            return found
        except db.BadKeyError:
            return None
        
    @property
    def me(self):
        return User.ensure_by_account(self.account)
        
    def get(self, params):
        if not params.get('user_id'):
            logging.info(self.__class__.__name__, '.get: Missing user_id')
            return None
        return self.find_by_keylike(params['user_id'])
        

UserController = restics.item_controller_for(UserRepo)
Пример #3
0
Файл: level.py Проект: omo/blbr
    item_url_pattern = '/r/<user_id:[^/]+>/level/latest'
    item_namespace = 'r/me/level'
    
    def __init__(self):
        restics.Repo.__init__(self)
        self.parent = blbr.user.UserRepo()

    @wsgis.login_required
    def get(self, params):
        owner = self.parent.get(params)
        if not owner:
            logging.info(self.__class__.__name__, ".get: No owner")
            return None
        return owner.level

    @wsgis.login_required
    def put(self, params, bag):
        owner = self.parent.get(params)
        if not owner:
            logging.info(self.__class__.__name__, ".put: No owner")
            return None
        try:
            owner.put_level(owner.level.updated_by_bag(bag))
            return owner.level
        except db.BadValueError as e:
            logging.info("CardRepo.put: BadValueError %s", e)
            return None


LevelController = restics.item_controller_for(LevelRepo)