当前位置: 首页>>代码示例>>Python>>正文


Python IPrincipalRoleMap.getSetting方法代码示例

本文整理汇总了Python中zope.securitypolicy.interfaces.IPrincipalRoleMap.getSetting方法的典型用法代码示例。如果您正苦于以下问题:Python IPrincipalRoleMap.getSetting方法的具体用法?Python IPrincipalRoleMap.getSetting怎么用?Python IPrincipalRoleMap.getSetting使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zope.securitypolicy.interfaces.IPrincipalRoleMap的用法示例。


在下文中一共展示了IPrincipalRoleMap.getSetting方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _query

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getSetting [as 别名]
 def _query(self, **kw):
     principal = get_principal()
     roles = get_workspace_roles()
     group_roles_domain_status = self.item_status_filter(kw, roles)
     session = Session()
     results = []
     count = 0
     for domain_class, status in group_roles_domain_status.iteritems():
         query = session.query(domain_class).filter(
             domain_class.status.in_(status)
             )
         if kw.get("filter_short_name", None):
             column = self.title_column(domain_class)
             query = query.filter(
                 """(lower(%s) LIKE '%%%s%%')""" %
                 (column, kw["filter_short_name"].lower())
                 )
         # The first page of the results is loaded the most number of times
         # The limit on the query below optimises for when no filter has
         # been applied by limiting the number of results returned.
         if (not kw.get("start", 0) and not kw.get("sort_on", None)):
             count = count + query.count()
             query = query.order_by(domain_class.status_date).limit(
                 kw.get("limit", 25))
         results.extend(query.all())
     object_roles_domain_status = self.item_status_filter(kw, OBJECT_ROLES)
     for domain_class, status in object_roles_domain_status.iteritems():
         query = session.query(domain_class).filter(
             domain_class.status.in_(status))
         if kw.get("filter_short_name", None):
             column = self.title_column(domain_class)
             query = query.filter(
                 """(lower(%s) LIKE '%%%s%%')""" %
                 (column, kw["filter_short_name"])
                 )
         if (not kw.get("start", 0) and not kw.get("sort_on", None)):
             count = count + query.count()
             query = query.order_by(domain_class.status_date).limit(
                 kw.get("limit", 25))
         for obj in query.all():
             prm = IPrincipalRoleMap(obj)
             for obj_role in OBJECT_ROLES:
                 if (prm.getSetting(obj_role, principal.id) == Allow and
                         obj not in results):
                     results.append(obj)
                     break
     # Sort items
     if (kw.get("sort_on", None) and kw.get("sort_dir", None)):
         rev = True if (kw.get("sort_dir") == "desc") else False
         results.sort(key=lambda x: getattr(x, str(kw.get("sort_on"))),
                      reverse=rev)
     if (kw.get("start", 0) and kw.get("sort_on", None)):
         count = len(results)
     return (results, count)
开发者ID:kohsah,项目名称:bungeni-portal,代码行数:56,代码来源:workspace.py

示例2: _do_save

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getSetting [as 别名]
 def _do_save(self, data):
     group_role_changed = False
     prm = IPrincipalRoleMap(get_group_privilege_extent_context(self.context))
     if (data["group_role"] != self.context.group_role):
         if prm.getSetting(self.context.group_role, self.context.principal_name) == Allow:
             group_role_changed = True
             unset_group_local_role(self.context)
     formlib.form.applyChanges(self.context, self.form_fields, data)
     if group_role_changed:
         set_group_local_role(self.context)
     notify(ObjectModifiedEvent(self.context))
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:13,代码来源:common.py

示例3: _query

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getSetting [as 别名]
 def _query(self, **kw):
     principal = get_principal()
     roles = get_workspace_roles()
     group_roles_domain_status = self.item_status_filter(kw, roles)
     session = Session()
     results = []
     count = 0
     first_page = not kw.get("start", 0)
     reverse = True if (kw.get("sort_dir", "desc") == "desc") else False
     for domain_class, status in group_roles_domain_status.iteritems():
         query = session.query(domain_class).filter(
             domain_class.status.in_(status)
             )
         #filter on title
         query = self.filter_query(query, domain_class, kw)
         # Order results
         query = self.order_query(query, domain_class, kw, reverse)
         # The first page of the results is loaded the most number of times
         # The limit on the query below optimises for when no filter has
         # been applied by limiting the number of results returned.
         if first_page:
             count = count + query.count()
             query = query.limit(kw.get("limit", 25))
         results.extend(query.all())
     object_roles_domain_status = self.item_status_filter(kw, OBJECT_ROLES)
     for domain_class, status in object_roles_domain_status.iteritems():
         object_roles_results = []
         query = session.query(domain_class).filter(
             domain_class.status.in_(status)
             )
         #filter on title
         query = self.filter_query(query, domain_class, kw)
         # Order results
         query = self.order_query(query, domain_class, kw, reverse)
         for obj in query.all():
             prm = IPrincipalRoleMap(obj)
             for obj_role in OBJECT_ROLES:
                 if (prm.getSetting(obj_role, principal.id) == Allow and
                         obj not in results):
                     object_roles_results.append(obj)
                     break
         if first_page:
             count = count + len(object_roles_results)
         results.extend(object_roles_results)
     # Sort items
     if (kw.get("sort_on", None) and kw.get("sort_dir", None)):
         results.sort(key=lambda x: getattr(x, str(kw.get("sort_on"))),
                      reverse=reverse)
     if not first_page:
         count = len(results)
     return (results, count)
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:53,代码来源:workspace.py

示例4: _query

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getSetting [as 别名]
 def _query(self, **kw):
     principal = utils.get_principal()
     roles = get_workspace_roles()
     group_roles_domain_status = self.item_status_filter(kw, roles)
     session = Session()
     results = []
     count = 0
     reverse = True if (kw.get("sort_dir", "desc") == "desc") else False
     for domain_class, status in group_roles_domain_status.iteritems():
         query = session.query(domain_class).filter(
             domain_class.status.in_(status)).enable_eagerloads(False)
         #filter on title
         query = self.filter_title(query, domain_class, kw)
         #filter on status_date
         query = self.filter_status_date(query, domain_class, kw)
         # Order results
         query = self.order_query(query, domain_class, kw, reverse)
         results.extend(query.all())
     for obj_role in ROLES_DIRECTLY_DEFINED_ON_OBJECTS:
         object_roles_domain_status = self.item_status_filter(
             kw, [obj_role])
         for domain_class, status in object_roles_domain_status.iteritems():
             query = session.query(domain_class).filter(
                 domain_class.status.in_(status)).enable_eagerloads(False)
             #filter on title
             query = self.filter_title(query, domain_class, kw)
             #filter on status_date
             query = self.filter_status_date(query, domain_class, kw)
             # Order results
             query = self.order_query(query, domain_class, kw, reverse)
             for obj in query.all():
                 if obj in results:
                     continue
                 prm = IPrincipalRoleMap(obj)
                 if (prm.getSetting(obj_role, principal.id) == Allow):
                     results.append(
                         contained(obj, self, self.string_key(obj)))
     results = [item for item in results if checkPermission(
         view_permission(item), contained(item, self, self.string_key(item)))]
     # Sort items
     if (kw.get("sort_on", None) and kw.get("sort_dir", None)):
         results.sort(key=lambda x: getattr(x, str(kw.get("sort_on"))),
             reverse=reverse)
     count = len(results)
     if not (kw.get("filter_title", None) or
             kw.get("filter_type", None) or
             kw.get("filter_status", None) or
             kw.get("filter_status_date", None)
         ):
         self.set_tab_count(principal.id, count)
     return (results, count)
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:53,代码来源:workspace.py

示例5: extend_results_for_roles

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getSetting [as 别名]
 def extend_results_for_roles(roles):
     domain_status = self.item_status_filter(kw, roles)
     OBJECT_ROLES = [ 
         role for role in roles if role in ROLES_DIRECTLY_DEFINED_ON_OBJECTS ]
     for domain_class, status in domain_status.iteritems():
         query = session.query(domain_class).filter(
             domain_class.status.in_(status)).enable_eagerloads(False)
         query = self.filter_group(query, domain_class, kw)
         query = self.filter_title(query, domain_class, kw)
         query = self.filter_status_date(query, domain_class, kw)
         query = self.order_query(query, domain_class, kw, reverse)
         for obj in query.all():
             if obj in results:
                 continue
             if OBJECT_ROLES:
                 prm = IPrincipalRoleMap(obj)
                 if not prm.getSetting(obj_role, principal_id) == Allow:
                     continue
             results.append(contained(obj, self, self.string_key(obj)))
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:21,代码来源:workspace.py

示例6: _query

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getSetting [as 别名]
 def _query(self, **kw):
     principal = get_principal()
     roles = get_workspace_roles(principal)
     group_roles_domain_status = self.item_status_filter(kw, roles)
     session = Session()
     results = []
     for domain_class, status in group_roles_domain_status.iteritems():
         query = session.query(domain_class).filter(
             domain_class.status.in_(status)
             )
         if kw.get("filter_short_name", None):
             column = self.title_column(domain_class)
             query = query.filter(
                 """(lower(%s) LIKE '%%%s%%')""" %
                 (column, kw["filter_short_name"].lower())
                 )
         results.extend(query.all())
     object_roles_domain_status = self.item_status_filter(kw, OBJECT_ROLES)
     for domain_class, status in object_roles_domain_status.iteritems():
         query = session.query(domain_class).filter(
             domain_class.status.in_(status))
         if kw.get("filter_short_name", None):
             column = self.title_column(domain_class)
             query = query.filter(
                 """(lower(%s) LIKE '%%%s%%')""" %
                 (column, kw["filter_short_name"])
                 )
         for obj in query.all():
             prm = IPrincipalRoleMap(obj)
             for obj_role in OBJECT_ROLES:
                 if (prm.getSetting(obj_role, principal.id) == Allow and
                         obj not in results
                     ):
                     results.append(obj)
                     break
     # Sort items
     if kw.get("sort_on", None):
         if kw.get("sort_dir", None):
             rev = True if (kw.get("sort_dir") == "desc") else False
             results.sort(key=lambda x: getattr(x, str(kw.get("sort_on"))),
                          reverse=rev)
     return results
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:44,代码来源:workspace.py

示例7: UserAssignmentView

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getSetting [as 别名]

#.........这里部分代码省略.........
            else:
                for c_assignable_role in config_assignable_roles:
                    if (c_assignable_role in assigner_role_annt.sub_roles):
                        assignable_roles.append(c_assignable_role)
        self._assignable_roles = assignable_roles
        return self._assignable_roles

    def can_edit(self, action=None):
        return checkPermission("bungeni.user_assignment.Edit", self.context)

    @property
    def columns(self):
        return [
            column.GetterColumn(
                title=_("user name"),
                getter=lambda i, f: i.get("title")
            ),
            column.GetterColumn(
                title=_("assigned"),
                getter=lambda i, f: i,
                cell_formatter=lambda g, i, f: \
                    '<input type="checkbox" name="%s" %s %s/>' % (
                        i["name"],
                        i["is_assigned"] and ' checked="checked"' or "",
                        not i["editable"] and ' disabled="disabled"' or "")
                )
            ]

    @property
    def checkbox_prefix(self):
        return "assignment_users"

    def make_id(self, role_id, user_login_id):
        return ".".join(
            (self.checkbox_prefix, role_id, user_login_id))

    def user_is_assigned(self, user_login, role_id):
        if self.prm.getSetting(role_id, user_login) == Allow:
            return True
        return False

    def role_listing(self, role_id, editable):
        listing = []
        users = common.get_users(role_id)
        if not users:
            return _("No users available for this role.")
        for user in users:
            data = {}
            data["title"] = IDCDescriptiveProperties(user).title
            data["name"] = self.make_id(user.login, role_id)
            data["is_assigned"] = self.user_is_assigned(user.login, role_id)
            data["editable"] = editable
            listing.append(data)
        formatter = TableFormatter(
            self.context, self.request, listing, prefix="assignment",
            columns=self.columns)
        formatter.updateBatching()
        return formatter()

    def update(self):
        self.tables = []
        assignable_roles = self.assignable_roles()
        for role_id in assignable_roles:
            if role_id in assignable_roles:
                editable = True
            else:
                editable = False
            self.tables.append(
                {"title": getUtility(IRole, role_id).title,
                 "table": self.role_listing(role_id, editable)})
        forms.common.BaseForm.update(self)

    def get_selected(self):
        selected = [
            (k[len(self.checkbox_prefix) + 1:].split(".")[0].decode("base64"),
            k[len(self.checkbox_prefix) + 1:].split(".")[1].decode("base64"))
            for k in self.request.form.keys()
            if k.startswith(self.checkbox_prefix) and self.request.form.get(k)
        ]
        return selected

    def process_assignment(self):
        for role_id in self.assignable_roles():
            for user in common.get_users(role_id):
                key = self.make_id(user.login, role_id)
                if key in self.request.form.keys():
                    self.prm.assignRoleToPrincipal(role_id, user.login)
                else:
                    self.prm.unsetRoleForPrincipal(role_id, user.login)

    @formlib.form.action(label=_("Save"), name="save", condition=can_edit)
    def handle_save(self, action, data):
        self.process_assignment()
        next_url = url.absoluteURL(self.context, self.request)
        self.request.response.redirect(next_url)

    @formlib.form.action(label=_("Cancel"), name="", condition=can_edit)
    def handle_cancel(self, action, data):
        next_url = url.absoluteURL(self.context, self.request)
        self.request.response.redirect(next_url)
开发者ID:gelie,项目名称:bungeni_src,代码行数:104,代码来源:assignment.py

示例8: DebateRecordTakes

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getSetting [as 别名]
class DebateRecordTakes(BungeniBrowserView, forms.common.BaseForm):
    """View to generate takes
    """
    form_fields = []
    render = ViewPageTemplateFile("templates/debate-takes.pt")

    def __init__(self, context, request):
        self.context = removeSecurityProxy(context)
        self.prm = IPrincipalRoleMap(self.context)
        super(DebateRecordTakes, self).__init__(context, request)

    def __call__(self):
        self.update()
        self.listing = self.formatted_listing()
        return self.render()

    def columns(self):
        date_formatter = date.getLocaleFormatter(common.get_request(),
            "dateTime", "medium")
        listing_columns = [
            column.GetterColumn(
                title=_("Take start time"),
                getter=lambda i,f: date_formatter.format(i.start_date)
            ),
            column.GetterColumn(
                title=_("Take end time"),
                getter=lambda i,f: date_formatter.format(i.end_date)
            ),
            column.GetterColumn(
                title=_("Take name"),
                getter=lambda i,f: i.debate_take_name
            ),
            column.GetterColumn(
                title=_("Take transcriber"),
                getter=lambda i,f: IDCDescriptiveProperties(i.user).title
            ),
        ]
        return listing_columns

    def formatted_listing(self):
        formatter = TableFormatter(self.context, self.request,
            self.context.debate_takes, columns=self.columns()
        )
        formatter.updateBatching()
        return formatter()

    def get_take_duration(self):
        return component.getUtility(IDebateRecordConfig).get_take_duration()

    def get_transcriber_role(self):
        return component.getUtility(IDebateRecordConfig).get_transcriber_role()
    
    def get_transcribers(self):
        transcribers = []
        transcriber_role = self.get_transcriber_role()
        users = common.get_users(transcriber_role)
        for user in users:
            if self.user_is_assigned(user.login, transcriber_role):
                transcribers.append(user)
        return transcribers

    def user_is_assigned(self, user_login, role_id):
        if self.prm.getSetting(role_id, user_login) == Allow:
            return True
        return False

    def get_take_name(self, take_count):
        take_name_prefix = ""
        b_take_count = take_count
        while (take_count / 26):
            take_count = take_count / 26
            take_name_prefix = take_name_prefix + chr(64+take_count)
        return take_name_prefix + chr(65+(b_take_count%26))

    def has_no_takes(self, action=None):
        return False if len(self.context.debate_takes) > 0 else True
    

    @formlib.form.action(label=_("Generate takes"), name="generate",
        condition=has_no_takes)
    def handle_generate_takes(self, action, data):
        transcribers = self.get_transcribers()
        sitting = self.context.sitting
        take_time_delta = datetime.timedelta(seconds=self.get_take_duration())
        current_end_time = sitting.start_date
        current_start_time = sitting.start_date
        take_count = 0
        session = Session()
        while current_end_time < sitting.end_date:
            take = domain.DebateTake()
            take.debate_record_id = self.context.debate_record_id
            take.start_date = current_start_time
            if ((current_end_time + take_time_delta) > sitting.end_date):
                current_end_time = sitting.end_date
            else:
                current_end_time = current_end_time + take_time_delta
                current_start_time = current_end_time + datetime.timedelta(
                    seconds=1)
            take.end_date = current_end_time
            take.transcriber_id = transcribers[
#.........这里部分代码省略.........
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:103,代码来源:debaterecord.py

示例9: GenerateDebateRecordTakes

# 需要导入模块: from zope.securitypolicy.interfaces import IPrincipalRoleMap [as 别名]
# 或者: from zope.securitypolicy.interfaces.IPrincipalRoleMap import getSetting [as 别名]
class GenerateDebateRecordTakes(BungeniBrowserView, ui.BaseForm):
    """View to generate takes
    """
    form_fields = []
    template = NamedTemplate("alchemist.subform")

    def __init__(self, context, request):
        if IDebateTakeContainer.providedBy(context):
            self.context = removeSecurityProxy(context).__parent__
        else:
            self.context = removeSecurityProxy(context)
        self.prm = IPrincipalRoleMap(self.context)
        self.request = request
        #super(GenerateDebateRecordTakes, self).__init__(context, request)

    def get_take_duration(self):
        return component.getUtility(IDebateRecordConfig).get_take_duration()

    def get_transcriber_role(self):
        return component.getUtility(IDebateRecordConfig).get_transcriber_role()

    def get_transcribers(self):
        transcribers = []
        transcriber_role = self.get_transcriber_role()
        users = common.get_local_users_for_subrole(transcriber_role)
        for user in users:
            if self.user_is_assigned(user.login, transcriber_role):
                transcribers.append(user)
        return transcribers

    def user_is_assigned(self, user_login, role_id):
        if self.prm.getSetting(role_id, user_login) == Allow:
            return True
        return False

    def get_take_name(self, take_count):
        take_name_prefix = ""
        b_take_count = take_count
        while (take_count / 26):
            take_count = take_count / 26
            take_name_prefix = take_name_prefix + chr(64 + take_count)
        return take_name_prefix + chr(65 + (b_take_count % 26))

    def has_no_takes(self, action=None):
        return False if len(self.context.debate_takes) > 0 else True

    @formlib.form.action(label=_("Generate takes"), name="generate",
        condition=has_no_takes)
    def handle_generate_takes(self, action, data):
        transcribers = self.get_transcribers()
        next_url = url.absoluteURL(self.context, self.request)
        if not transcribers:
            return self.request.response.redirect(next_url + "/takes")
        sitting = self.context.sitting
        take_time_delta = datetime.timedelta(seconds=self.get_take_duration())
        current_end_time = sitting.start_date
        current_start_time = sitting.start_date
        take_count = 0
        session = Session()
        while current_end_time < sitting.end_date:
            take = domain.DebateTake()
            take.debate_record_id = self.context.debate_record_id
            take.start_date = current_start_time
            if ((current_end_time + take_time_delta) > sitting.end_date):
                current_end_time = sitting.end_date
            else:
                current_end_time = current_end_time + take_time_delta
                current_start_time = current_end_time + datetime.timedelta(
                    seconds=1)
            take.end_date = current_end_time
            take.transcriber_id = transcribers[
                take_count % len(transcribers)].user_id
            take.debate_take_name = self.get_take_name(take_count)
            take_count = take_count + 1
            session.add(take)
        session.flush()
        return self.request.response.redirect(next_url + "/takes")
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:79,代码来源:debaterecord.py


注:本文中的zope.securitypolicy.interfaces.IPrincipalRoleMap.getSetting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。