Esempio n. 1
0
 def update(self, value, name):
     ID = value.ID
     if ID is None:
         raise BiiStoreException('Object without ID %s, %s' % (value, name))
     collection = getattr(self, name)
     if ID not in collection:
         raise BiiStoreException('Non existing ID (%s) in update' % ID)
     if self._store:
         meth = getattr(self._store, 'update_' + name)
         meth(value)
     collection[ID] = self._get_item(value)
Esempio n. 2
0
    def create_multi(self, values, name, **kwargs):
        '''create has an extra kwargs for extra options, as update_if_current
        '''
        collection = getattr(self, name)
        values_dict = {}
        for value in values:
            ID = value.ID
            if ID is None:
                raise BiiStoreException('Object without ID %s, %s' %
                                        (value, name))
            if ID in collection:
                raise BiiStoreException('Duplicate key %s in %s' % (ID, name))
            values_dict[ID] = value

        if self._store:
            create_method = getattr(self._store, 'create_%ss' % name)
            create_method(values, **kwargs)
        collection.update(self._get_item(values_dict))
Esempio n. 3
0
 def delete(self, key, name):
     '''use with caution :P, only for edition'''
     collection = getattr(self, name)
     if key not in collection:
         raise BiiStoreException('key error in : %s' % collection)
     if self._store:
         meth = getattr(self._store, 'delete_%s' % name)
         meth(key)
     del collection[key]
Esempio n. 4
0
 def upsert(self, value, name):
     ID = value.ID
     collection = getattr(self, name)
     if ID is None:
         raise BiiStoreException('Object without ID %s, %s' % (value, name))
     if self._store:
         meth = getattr(self._store, 'upsert_' + name)
         meth(value)
     collection[ID] = self._get_item(value)
Esempio n. 5
0
 def delete_multi(self, ids, name):
     '''use with caution :P, only for edition'''
     collection = getattr(self, name)
     if any(ID not in collection for ID in ids):
         raise BiiStoreException('key error in : %s' % name)
     if self._store:
         meth = getattr(self._store, 'delete_%ss' % name)
         meth(ids)
     for ID in ids:
         del collection[ID]
Esempio n. 6
0
    def upsert_multi(self, values, name):
        collection = getattr(self, name)
        values_dict = {}
        for value in values:
            ID = value.ID
            if ID is None:
                raise BiiStoreException('Object without ID %s, %s' %
                                        (value, name))
            values_dict[ID] = value

        if self._store:
            create_method = getattr(self._store, 'upsert_%ss' % name)
            create_method(values)
        collection.update(self._get_item(values_dict))
Esempio n. 7
0
 def create(self, value, name, **kwargs):
     '''create has an extra kwargs for extra options, as update_if_current
     '''
     ID = value.ID
     if ID is None:
         raise BiiStoreException('Object without ID %s, %s' % (value, name))
     collection = getattr(self, name)
     if ID in collection:
         raise AlreadyInStoreException('Duplicate key %s in %s' %
                                       (ID, name))
     if self._store:
         create_method = getattr(self._store, 'create_' + name)
         create_method(value, **kwargs)
     collection[ID] = self._get_item(value)
     return ID
    def create_user(self, user, numeric_id=None):
        '''Creates a user. user is a User instance.
        Params:
            user: user Object
            numeric_id: if specified, the numeric_id will be setted. Otherwise
                        it will be calculated due the user counter'''

        if not numeric_id:
            numeric_id = self.generate_user_id()

        user.numeric_id = numeric_id

        id_or_error = self.create(user,
                                  GenericServerStore.USER_ST,
                                  enable_update_if_current=True)
        if user.ID != id_or_error:
            raise BiiStoreException('Error (%s) creating user %s' %
                                    (id_or_error, user.ID))

        # Create user subscription
        user_subscription = UserSubscription(user.ID)
        user_subscription.plan_id = FREE_PLAN_ID
        self.create(user_subscription, GenericServerStore.USER_SUBSCRIPTION_ST)