コード例 #1
0
ファイル: usage.py プロジェクト: Cowoop/cowspa3
 def info(self, usage_id):
     """
     return dict containg information of usage
     """
     usage = usage_store.get(usage_id)
     usage['member_name'] = dbaccess.oid2name(usage.member)
     return usage
コード例 #2
0
ファイル: resource.py プロジェクト: Cowoop/cowspa3
 def info(self, res_id):
     """
     returns dict containing essential information of specified business
     """
     info_attributes = ['name', 'owner', 'short_description', 'long_description', 'enabled', 'id', 'type', 'host_only',
             'archived', 'calc_mode', 'accnt_code']
     info = resource_store.get(res_id, info_attributes)
     # TODO change owner ref to name
     info['owner_id'] = info['owner']
     info['owner_name'] = dbaccess.oid2name(info['owner'])
     return info
コード例 #3
0
ファイル: resource.py プロジェクト: Cowoop/cowspa3
    def new(self, name, short_description, type, owner, default_price=None, enabled=True, calendar=False, host_only=False, long_description=None, calc_mode=CalcMode.monthly, archived=False, picture=None, accnt_code=None):
        #TODO make default_price parameter mandatory post migration
        created = datetime.datetime.now()
        data = dict(name=name, owner=owner, created=created, short_description=short_description, enabled=enabled, calendar=calendar, host_only=host_only, long_description=long_description, type=type, calc_mode=calc_mode, archived=archived, picture=picture, accnt_code=accnt_code)
        res_id = resource_store.add(**data)

        data = dict(id=res_id, name=name, bizplace_name=dbaccess.oid2name(owner), bizplace_id=owner, user_id=env.context.user_id, created=created, type=type)
        if type == 'tariff':
            activity_id = activitylib.add('tariff_management', 'tariff_created', data, created)
        else:
            activity_id = activitylib.add('resource_management', 'resource_created', data, created)

        if default_price is not None:
            default_tariff_id = bizplace_store.get(owner, fields=['default_tariff'], hashrows=False)
            # default_tariff_id would be None when we are creating default_tariff for a new location. This is because we are adding location and there is no default_tariff yet. Now this tariff is a resource so further we need to create pricing for it. In pricing we need to specify some tariff so tariff refers itself as default_tariff.
            if default_tariff_id is None:
                default_tariff_id = res_id

            signals.send_signal('resource_created', res_id, default_tariff_id, None, default_price)
            # TODO this is not right way to send signals

        return res_id
コード例 #4
0
ファイル: role.py プロジェクト: Cowoop/cowspa3
def get_roles(user_id=None, role_filter=[]):
    """
    role_filter: eg. ['host', 'director']
    returns [{context: 1, label: '<name>', roles: [{role:'<role1>', label:<label1>, order: <int>}, {role:'<role2>', ..}, ...], ...]
    order: <int> higher the order value lower are the permissions to that role
    """
    if user_id is None:
        user_id = env.context.user_id
    ctx_roles = collections.defaultdict(list)
    # TODO : roles should be list dicts containing role names and role labels
    memberships = dbaccess.get_member_current_memberships(user_id)
    member_roles = [('member', membership.bizplace_id) for membership in memberships]
    team_roles = dbaccess.userrole_store.get_by(dict(user_id=user_id), ['role', 'context'], False)
    all_roles = team_roles + member_roles
    for (role, context) in all_roles:
        if not role_filter or role in role_filter:
            label = roledefs.all_roles[role].label
            order = roledefs.ordered_roles.index(role)
            ctx_roles[context].append(dict(label=label, role=role, order=order))
    sorter = lambda d: d['label']
    role_sorter = lambda d: d['order']
    return sorted((dict(label=dbaccess.oid2name(ctx), context=ctx, roles=sorted(roles, key=role_sorter)) \
        for ctx, roles in ctx_roles.items()), key=sorter)
コード例 #5
0
ファイル: request.py プロジェクト: Cowoop/cowspa3
 def to_html(self):
     label = self.label
     requestor_name = dbaccess.oid2name(self.requestor_name)
     requestor = requestor_name + " (%s) " % requestor_id
     bizplace = dbaccess.oid2name(bizplace_id)
     return '"%(label)s by %(requestor)s for %(bizplace)s"' % locals()
コード例 #6
0
ファイル: request.py プロジェクト: Cowoop/cowspa3
 def to_html(self):
     label = self.label
     requestor_name = dbaccess.oid2name(self.requestor_id)
     requestor = requestor_name + " [%s]" % self.requestor_id
     tariff_name = dbaccess.stores.resource_store.get(self.params['tariff_id']).name
     return '%(label)s by "%(requestor)s" for tariff "%(tariff_name)s"' % locals()
コード例 #7
0
ファイル: request.py プロジェクト: Cowoop/cowspa3
 def to_html(self):
     requestor_name = dbaccess.oid2name(self.requestor_id)
     requestor = requestor_name + " (%s) " % self.requestor_id
     msg_data = dict(label=self.label, api=self.api, params=self.params, requestor=requestor)
     return "%(label)s by %(member)s for %(api)s with data %(params)s" % msg_data