Exemple #1
0
class BizMethods(bases.app.ObjectMethods):
    methods_available = ['info']
    id_name = 'biz_id'

class Bizplaces(bases.app.Collection):
    methods_available = ['new', 'list']
    def new(self, name, city, tz, email, biz_id, enabled=True, langs=['en'], holidays=[], address=None, country=None, pincode=None, mobile=None, fax=None, skype=None, sip=None, director_id=None, short_description=None, long_description=None, tags=[], website=None, twitter=None, facebook=None, blog=None, linkedin=None):
        created = datetime.datetime.now()
        bizplace_id = self.store.add(name, enabled, created, langs, tz, holidays, biz_id)
        bizplace_ref = self.store.ref(bizplace_id)
        homephone = None
        contact_id = stores.contactstore.add(bizplace_ref, email, address, city, country, pincode, homephone, mobile, fax, skype, sip)
        self.store.update(biz_id, contact=contact_id)
        stores.bizplaceprofile_store.add(short_description, long_description, tags, website, twitter, facebook, linkedin, blog)
        if not director_id:
            director_id = env.context.user_id
        signals.send_signal('assign_roles', director_id, bizplace_id, ['host'])
        return bizplace_id

class BizplaceMethods(bases.app.ObjectMethods):
    methods_available = ['info', 'plans']
    id_name = 'bizplace_id'
    def plans(self, bizplace_id):
        return plan_store.get_by(bizplace_id=bizplace_id)

biz = Biz(biz_store)
bizplaces = Bizplaces(bizplace_store)
biz_methods = BizMethods(biz_store)
bizplace_methods = BizplaceMethods(bizplace_store)
signals.connect("newbiz_approved", biz.new)
Exemple #2
0
    crit = dict(plan=pricing.plan, resource=pricing.resource, ends=pricing.starts-datetime.timedelta(1))
    prev_pricing = pricing_store.get_by(crit)
    if prev_pricing: set(prev_pricing[0].id, 'ends', pricing.ends)
    return pricing_store.remove(pricing_id)

pricings = applib.Collection()
pricings.new = new
pricings.get = get
pricings.list = lst
pricings.by_resource = by_resource
pricings.by_tariff = by_tariff
pricings.by_location = by_location
pricings.default_tariff = default_tariff_price
pricings.new_tariff = new_tariff_pricing
pricings.delete = delete
signals.connect("resource_created", pricings.new)

settable_attrs = ['starts', 'ends', 'cost']

def info(pricing_id):
    return pricing_store.get(pricing_id)

def set(pricing_id, attr, value):
    if attr not in settable_attrs:
        return
    pricing_store.update(pricing_id, **{attr: value})

def update(pricing_id, **mod_data):
    pricing = pricing_store.get(pricing_id)
    new_starts = commonlib.helpers.iso2date(mod_data['starts']) if 'starts' in mod_data else pricing.starts
Exemple #3
0
class Plans(bases.app.Collection):
    methods_available = ['new', 'list']
    def new(self, name, bizplace_id, description, enabled=True):
        created = datetime.datetime.now()
        return self.store.add(name, bizplace_id, description, enabled, created)

class PlanMethods(bases.app.ObjectMethods):
    methods_available = ['info', 'get', 'set']
    id_name = 'plan_id'
    def info(self, plan_id):
        return self.store.get(plan_id)

class Subscribers(bases.app.Collection):
    methods_available = ['new', 'list', 'delete']
    def new(self, subscriber_id, plan_id):
        if self.store.get_by(plan_id=plan_id, subscriber_id=subscriber_id):
            pass
        else:
            self.store.add(plan_id, subscriber_id)
    def list(self, plan_id):
        plan = self.store.get(plan_id)
        return [memberslib.member_methods.info(s) for s in plan.subscribers]
    def delete(self, plan_id, subscriber_id):
        raise NotImplemented

plans = Plans(plan_store)
plan_methods = PlanMethods(plan_store)
subscribers = Subscribers(plansubscribers_store)

signals.connect("plan_approved", subscribers.new)
Exemple #4
0
    def info(self, username):
        user = self.store.get_one_by(username=username)
        return dict(role=get_biggest_role(user.id), id=user.id)

    def assign_roles(self, username, biz_id, role_names):
        if isinstance(role_names, basestring):
            role_names = [role_names]

        if isinstance(username, int) or (isinstance(username, basestring) and username.isdigit()):
            user = userstore.get(username)
        else:
            user = userstore.get_one_by(username=username)

        user_roles = user_roles_store.soft_get_one_by(user_id=user.id)
        roles = [role_store.get_one_by(name=name) for name in role_names]
        user_perms = user_perms_store.soft_get_one_by(user_id=user.id)
        permission_ids = list(itertools.chain(*[role.permissions for role in roles]))

        biz_ref = None
        if biz_id:
            biz_ref = biz_store.ref(biz_id)

        user_roles_store.add(user, biz_ref, roles)
        user_perms_store.add(user, biz_ref, permission_ids)

        return True

users = Users(userstore)
user_methods = UserMethods(userstore)
signals.connect("assign_roles", user_methods.assign_roles)