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
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
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
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
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
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
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
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
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)
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
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)
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
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
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
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
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
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
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
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
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
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 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
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_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 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
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
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
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