예제 #1
0
def index_workflow_state(resource, default) -> [str]:
    """Return value for the workflow_state index."""
    registry = get_current_registry(resource)
    state = registry.content.get_sheet_field(resource,
                                             IWorkflowAssignment,
                                             'workflow_state')
    return state
def _get_creation_date(proposal):
    registry = get_current_registry(proposal)
    creation_date = registry.content.get_sheet_field(proposal,
                                                     IMetadata,
                                                     'item_creation_date')
    date = creation_date.date().strftime('%d.%m.%Y')
    return date
def _get_date(sheet, field, resource):
    registry = get_current_registry(resource)
    value = registry.content.get_sheet_field(resource, sheet, field)
    if not value:
        return ''
    date = value.date().strftime('%d.%m.%Y')
    return date
예제 #4
0
def index_user_name(resource, default) -> str:
    """Return value for the user_name index."""
    registry = get_current_registry(resource)
    name = registry.content.get_sheet_field(resource,
                                            IUserBasic,
                                            'name')
    return name
예제 #5
0
def index_user_email(resource, default) -> str:
    """Return value for the private_user_email index."""
    registry = get_current_registry(resource)
    name = registry.content.get_sheet_field(resource,
                                            IUserExtended,
                                            'email')
    return name
예제 #6
0
def index_service_konto_userid(resource, default) -> str:
    """Return value for the service konto index."""
    registry = get_current_registry(resource)
    userid = registry.content.get_sheet_field(resource,
                                              IServiceKonto,
                                              'userid')
    return userid
예제 #7
0
def index_creator(resource, default) -> str:
    """Return creator userid value for the creator index."""
    registry = get_current_registry(resource)
    creator = registry.content.get_sheet_field(resource, IMetadata, 'creator')
    if creator == '':  # FIXME the default value should be None
        return creator
    userid = resource_path(creator)
    return userid
예제 #8
0
def _get_affected_commentables(commentable):
    registry = get_current_registry(commentable)
    commentables = [commentable]
    while IComment.providedBy(commentable):
        commentable = registry.content.get_sheet_field(commentable, IComment,
                                                       'refers_to')
        if commentable:
            commentables.append(commentable)
    return commentables
예제 #9
0
def index_tag(resource, default) -> [str]:
    """Return value for the tag index."""
    item = find_interface(resource, IItem)
    if item is None:  # ease testing
        return
    registry = get_current_registry(resource)
    tags_sheet = registry.content.get_sheet(item, ITags)
    tagnames = [f for f, v in tags_sheet.get().items() if v is resource]
    return tagnames if tagnames else default
예제 #10
0
def index_workflow_state(resource, default) -> str:
    """Return value for the workflow_state index."""
    registry = get_current_registry(resource)
    try:
        state = registry.content.get_sheet_field(resource,
                                                 IWorkflowAssignment,
                                                 'workflow_state')
    except (RuntimeConfigurationError, KeyError):
        return default
    return state
예제 #11
0
 def reset_password(self, password):
     """Set `password` for creator user and delete itself."""
     registry = get_current_registry(self)
     user = registry.content.get_sheet_field(self, IMetadata, 'creator')
     password_sheet = registry.content.get_sheet(
         user, adhocracy_core.sheets.principal.IPasswordAuthentication)
     password_sheet.set({'password': password}, send_event=False)
     if not user.active:  # pragma: no cover
         user.activate()
     del self.__parent__[self.__name__]
     statsd_incr('pwordresets.reset', 1)
예제 #12
0
def index_workflow_state_of_item(resource, default) -> [str]:
    """Find item and return it`s value for the workflow_state index."""
    registry = get_current_registry(resource)
    item = find_interface(resource, IItem)
    try:
        state = registry.content.get_sheet_field(item,
                                                 IWorkflowAssignment,
                                                 'workflow_state')
    except (RuntimeConfigurationError, AttributeError):
        return default
    else:
        return state
예제 #13
0
 def activate_new_email(self):
     """Activate email stored in the IEmailNew sheet."""
     registry = get_current_registry(self)
     email_new_sheet = registry.content.get_sheet(self, IEmailNew)
     email_new_appstruct = email_new_sheet.get()
     user_extended_sheet = registry.content.get_sheet(self,
                                                      IUserExtended)
     user_extended_appstruct = user_extended_sheet.get()
     user_extended_appstruct['email'] = email_new_appstruct['email']
     user_extended_sheet.set(user_extended_appstruct)
     email_new_appstruct['email'] = ''
     email_new_sheet.set(email_new_appstruct)
예제 #14
0
    def activate(self, active: bool=True):
        """
        Activate or deactivate the user.

        Inactivate users are always hidden.
        """
        self.active = active
        registry = get_current_registry(self)
        sheet = registry.content.get_sheet(self, IMetadata)
        appstruct = sheet.get()
        appstruct['hidden'] = not active
        statsd_incr('users.activated', 1)
        sheet.set(appstruct)
def _get_sheet_field_from_subresource(sheet,
                                      sheet_field,
                                      sub_sheet_field,
                                      proposal,
                                      ):
    registry = get_current_registry(proposal)
    sub_resource = registry.content.get_sheet_field(proposal,
                                                    IMercatorSubResources,
                                                    sheet_field)
    sub_field = registry.content.get_sheet_field(sub_resource,
                                                 sheet,
                                                 sub_sheet_field)
    return sub_field
예제 #16
0
def index_decision_date(context, default) -> datetime:
    """Return value for `decision_date` index."""
    context = find_interface(context, IWorkflowAssignment)
    if context is None:
        return 'default'
    registry = get_current_registry(context)
    state_data = registry.content.get_sheet_field(context,
                                                  IWorkflowAssignment,
                                                  'state_data')
    datas = [x for x in state_data
             if x['name'] in ['result', 'selected', 'rejected']]
    if datas:
        decision_date = datas[0].get('start_date', default)
        return decision_date
    else:
        return default
예제 #17
0
파일: pool.py 프로젝트: liqd/adhocracy3
    def remove(self, name, send_events: bool=True, registry: Registry=None,
               **kwargs):
        """Delete subresource `name` from database.

        :raises KeyError: if `name` is not a valid subresource name
        """
        subresource = self[name]
        registry = registry or get_current_registry(self)
        if send_events:  # pragma: no branch
            event = ResourceWillBeDeleted(object=subresource,
                                          parent=self,
                                          registry=registry)
            registry.notify(event)
        graph = find_graph(subresource)
        references = graph.get_refernces_for_removal_notificaton(subresource)
        res = super().remove(name,
                             registry=registry,
                             send_events=send_events,
                             **kwargs)
        graph.send_back_reference_removal_notificatons(references, registry)
        return res
예제 #18
0
    def remove(self,
               name,
               send_events: bool = True,
               registry: Registry = None,
               **kwargs):
        """Delete subresource `name` from database.

        :raises KeyError: if `name` is not a valid subresource name
        """
        subresource = self[name]
        registry = registry or get_current_registry(self)
        if send_events:  # pragma: no branch
            event = ResourceWillBeDeleted(object=subresource,
                                          parent=self,
                                          registry=registry)
            registry.notify(event)
        graph = find_graph(subresource)
        references = graph.get_refernces_for_removal_notificaton(subresource)
        res = super().remove(name,
                             registry=registry,
                             send_events=send_events,
                             **kwargs)
        graph.send_back_reference_removal_notificatons(references, registry)
        return res
예제 #19
0
def index_user_name(resource, default) -> str:
    """Return value for the user_name index."""
    registry = get_current_registry(resource)
    name = registry.content.get_sheet_field(resource, IUserBasic, 'name')
    return name
예제 #20
0
def index_user_email(resource, default) -> str:
    """Return value for the private_user_email index."""
    registry = get_current_registry(resource)
    name = registry.content.get_sheet_field(resource, IUserExtended, 'email')
    return name
예제 #21
0
def index_service_konto_userid(resource, default) -> str:
    """Return value for the service konto index."""
    registry = get_current_registry(resource)
    userid = registry.content.get_sheet_field(resource, IServiceKonto,
                                              'userid')
    return userid
예제 #22
0
def index_item_creation_date(resource, default) -> str:
    """Return creator userid value for the creator index."""
    registry = get_current_registry(resource)
    date = registry.content.get_sheet_field(resource, IMetadata,
                                            'item_creation_date')
    return date
예제 #23
0
def index_rate(resource, default) -> int:
    """Return the value of field name `rate` for :class:`IRate` resources."""
    registry = get_current_registry(resource)
    rate = registry.content.get_sheet_field(resource, IRate, 'rate')
    return rate
예제 #24
0
def index_title(resource, default) -> str:
    """Return the value of field name ` title`."""
    registry = get_current_registry(resource)
    title = registry.content.get_sheet_field(resource, ITitle, 'title')
    return title
예제 #25
0
 def has_new_email_pending(self):
     registry = get_current_registry(self)
     email_new = registry.content.get_sheet_field(self, IEmailNew, 'email')
     return bool(email_new)
def _get_creator_email(proposal):
    registry = get_current_registry(proposal)
    creator = registry.content.get_sheet_field(proposal, IMetadata, 'creator')
    email = registry.content.get_sheet_field(creator, IUserExtended, 'email')
    return email
def _get_creator_name(proposal):
    registry = get_current_registry(proposal)
    creator = registry.content.get_sheet_field(proposal, IMetadata, 'creator')
    name = registry.content.get_sheet_field(creator, IUserBasic, 'name')
    return name
예제 #28
0
 def has_new_email_pending(self):
     registry = get_current_registry(self)
     email_new = registry.content.get_sheet_field(self, IEmailNew, 'email')
     return bool(email_new)
예제 #29
0
def get_sheet_field_for_partial(sheet: ISheet, field: str,
                                resource: IResource) -> object:
    """Get sheet field with resource as last parameter to use with partial."""
    registry = get_current_registry(resource)
    return registry.content.get_sheet_field(resource, sheet, field)
예제 #30
0
def index_rate(resource, default) -> int:
    """Return the value of field name `rate` for :class:`IRate` resources."""
    registry = get_current_registry(resource)
    rate = registry.content.get_sheet_field(resource, IRate, 'rate')
    return rate
예제 #31
0
def get_sheet_field_for_partial(sheet: ISheet,
                                field: str,
                                resource: IResource) -> object:
    """Get sheet field with resource as last parameter to use with partial."""
    registry = get_current_registry(resource)
    return registry.content.get_sheet_field(resource, sheet, field)
def _get_creator_name(proposal):
    registry = get_current_registry(proposal)
    creator = registry.content.get_sheet_field(proposal, IMetadata, 'creator')
    name = registry.content.get_sheet_field(creator, IUserBasic, 'name')
    return name
예제 #33
0
def index_item_creation_date(resource, default) -> str:
    """Return creator userid value for the creator index."""
    registry = get_current_registry(resource)
    date = registry.content.get_sheet_field(resource, IMetadata,
                                            'item_creation_date')
    return date
예제 #34
0
def index_title(resource, default) -> str:
    """Return the value of field name ` title`."""
    registry = get_current_registry(resource)
    title = registry.content.get_sheet_field(resource, ITitle, 'title')
    return title
def _get_creator_email(proposal):
    registry = get_current_registry(proposal)
    creator = registry.content.get_sheet_field(proposal, IMetadata, 'creator')
    email = registry.content.get_sheet_field(creator, IUserExtended, 'email')
    return email