def view_dashboard(self, request): """ The dashboard view (for editors). Shows the drafted, submitted and rejected notices, shows warnings and allows to create a new notice. """ layout = Layout(self, request) user_ids, group_ids = get_user_and_group(request) collection = GazetteNoticeCollection(request.session, user_ids=user_ids, group_ids=group_ids) # rejected rejected = collection.for_state('rejected').query().all() if rejected: request.message(_("You have rejected messages."), 'warning') # drafted drafted = collection.for_state('drafted').query().all() now = utcnow() limit = now + timedelta(days=2) past_issues_selected = False deadline_reached_soon = False for notice in drafted: for issue in notice.issue_objects: if issue.deadline < now: past_issues_selected = True elif issue.deadline < limit: deadline_reached_soon = True if past_issues_selected: request.message(_("You have drafted messages with past issues."), 'warning') if deadline_reached_soon: request.message( _("You have drafted messages with issues close to the deadline."), 'warning') # submitted submitted = collection.for_state('submitted').query().all() new_notice = request.link(collection.for_state('drafted'), name='new-notice') return { 'layout': layout, 'title': _("Dashboard"), 'rejected': rejected, 'drafted': drafted, 'submitted': submitted, 'new_notice': new_notice, 'current_issue': layout.current_issue }
def delete_notice(self, request, form): """ Delete a notice. Editors may only delete their own drafted and rejected notices. Publishers may delete any drafted, rejected and accepted notices. Admins may delete any drafted, submitted, rejected and accepted notices. """ layout = Layout(self, request) is_secret = request.is_secret(self) is_private = request.is_private(self) if not is_private: user_ids, group_ids = get_user_and_group(request) if not ((self.group_id in group_ids) or (self.user_id in user_ids)): raise HTTPForbidden() if ((self.state == 'submitted' and not is_secret) or (self.state == 'accepted' and not is_private) or (self.state == 'published')): request.message( _("Only drafted or rejected official notices may be deleted."), 'alert') return { 'layout': layout, 'title': self.title, 'subtitle': _("Delete Official Notice"), 'show_form': False } if self.state == 'accepted': request.message(_("This official notice has already been accepted!"), 'warning') if form.submitted(request): collection = GazetteNoticeCollection(request.session) collection.delete(self) request.message(_("Official notice deleted."), 'success') return redirect(layout.dashboard_or_notices_link) return { 'message': _('Do you really want to delete "${item}"?', mapping={'item': self.title}), 'layout': layout, 'form': form, 'title': self.title, 'subtitle': _("Delete Official Notice"), 'button_text': _("Delete Official Notice"), 'button_class': 'alert', 'cancel': request.link(self) }
def view_notice(self, request): """ View a notice. View the notice and its meta data. This is the main view for the notices to do the state changes. """ layout = Layout(self, request) user_ids, group_ids = get_user_and_group(request) editor = request.is_personal(self) publisher = request.is_private(self) admin = request.is_secret(self) owner = self.user_id in user_ids same_group = self.group_id in group_ids def _action(label, name, class_, target='_self'): return (label, request.link(self, name), class_, target) action = { 'accept': _action(_("Accept"), 'accept', 'primary'), 'attachments': _action(_("Attachments"), 'attachments', 'secondary'), 'copy': (_("Copy"), request.link(GazetteNoticeCollection(request.session, state=self.state, source=self.id), name='new-notice'), 'secondary', '_self'), 'delete': _action(_("Delete"), 'delete', 'alert right'), 'edit_un': _action(_("Edit"), 'edit-unrestricted', 'secondary'), 'edit': _action(_("Edit"), 'edit', 'secondary'), 'preview': _action(_("Preview"), 'preview', 'secondary', '_blank'), 'reject': _action(_("Reject"), 'reject', 'alert right'), 'submit': _action(_("Submit"), 'submit', 'primary'), } actions = [] if self.state == 'drafted' or self.state == 'rejected': if publisher or (editor and (same_group or owner)): actions.append(action['submit']) actions.append(action['edit']) actions.append(action['delete']) if publisher: actions.append(action['attachments']) elif self.state == 'submitted': if publisher: actions.append(action['accept']) actions.append(action['edit']) actions.append(action['reject']) actions.append(action['attachments']) if admin: actions.append(action['delete']) elif self.state == 'accepted': actions.append(action['copy']) if publisher: actions.append(action['edit_un']) if admin: actions.append(action['attachments']) if publisher: actions.append(action['delete']) elif self.state == 'imported': if publisher: actions.append(action['accept']) actions.append(action['delete']) elif self.state == 'published': actions.append(action['copy']) if publisher: actions.append(action['edit_un']) if admin: actions.append(action['attachments']) actions.append(action['preview']) return { 'layout': layout, 'notice': self, 'actions': actions, 'publisher': publisher }
def edit_notice(self, request, form): """ Edit a notice. This view is used by the editors and publishers. Editors may only edit their own notices, publishers may edit any notice. It's not possible to change already accepted or published notices (although you can use the unrestricted view for this). """ layout = Layout(self, request) is_private = request.is_private(self) if not is_private: user_ids, group_ids = get_user_and_group(request) if not ((self.group_id in group_ids) or (self.user_id in user_ids)): raise HTTPForbidden() if self.state == 'accepted' or self.state == 'published': return { 'layout': layout, 'title': self.title, 'subtitle': _("Edit Official Notice"), 'callout': _("Accepted official notices may not be edited."), 'show_form': False } if self.expired_issues: request.message( _("The official notice has past issue. Please re-select issues."), 'warning') elif self.overdue_issues and not is_private: request.message( _("The official notice has issues for which the deadlines are " "reached. Please re-select valid issues."), 'warning') if self.invalid_category: request.message( _("The official notice has an invalid category. " "Please re-select the category."), 'warning') if self.invalid_organization: request.message( _("The official notice has an invalid organization. " "Please re-select the organization."), 'warning') if form.submitted(request): form.update_model(self) self.add_change(request, _("edited")) request.message(_("Official notice modified."), 'success') return redirect(request.link(self)) if not form.errors: form.apply_model(self) return { 'layout': layout, 'form': form, 'title': self.title, 'subtitle': _("Edit Official Notice"), 'helptext': _("The fields marked with an asterisk * are mandatory fields."), 'button_text': _("Save"), 'cancel': request.link(self), 'current_issue': layout.current_issue }
def submit_notice(self, request, form): """ Submit a notice. This view is used by the editors to submit their drafts for the publishers to review. Only drafted notices may be submitted. Editors may only submit their own notices (publishers may submit any notice). If a notice has invalid/past issues or an invalid/inactive category/organization, the user is redirected to the edit view. """ layout = Layout(self, request) is_private = request.is_private(self) if not is_private: user_ids, group_ids = get_user_and_group(request) if not ((self.group_id in group_ids) or (self.user_id in user_ids)): raise HTTPForbidden() if self.state != 'drafted' and self.state != 'rejected': return { 'layout': layout, 'title': self.title, 'subtitle': _("Submit Official Note"), 'callout': _("Only drafted or rejected official notices may be submitted."), 'show_form': False } if (self.expired_issues or (self.overdue_issues and not is_private) or self.invalid_category or self.invalid_organization): return redirect(request.link(self, name='edit')) if form.submitted(request): self.submit(request) request.message(_("Official notice submitted."), 'success') return redirect(layout.dashboard_or_notices_link) return { 'message': _('Do you really want to submit "${item}"?', mapping={'item': self.title}), 'layout': layout, 'form': form, 'title': self.title, 'subtitle': _("Submit Official Note"), 'button_text': _("Submit Official Note"), 'cancel': request.link(self) }
def view_notices(self, request): """ View the list of notices. This view is only visible by a publisher. This (in the state 'accepted') is the view used by the publisher. """ self.on_request(request) layout = Layout(self, request) is_publisher = request.is_private(self) states = ['drafted', 'submitted', 'accepted', 'rejected'] if layout.importation: states.append('imported') if layout.publishing: states.append('published') filters = ( { 'title': _(state), 'link': request.link(self.for_state(state)), 'class': 'active' if state == self.state else '' } for state in states ) orderings = { 'title': { 'title': _("Title"), 'href': request.link(self.for_order('title')), 'sort': self.direction if self.order == 'title' else '', }, 'organization': { 'title': _("Organization"), 'href': request.link(self.for_order('organization')), 'sort': self.direction if self.order == 'organization' else '', }, 'category': { 'title': _("Category"), 'href': request.link(self.for_order('category')), 'sort': self.direction if self.order == 'category' else '', }, 'group': { 'title': _("Group"), 'href': request.link(self.for_order('group.name')), 'sort': self.direction if self.order == 'group.name' else '', }, 'user': { 'title': _("User"), 'href': request.link(self.for_order('user.name')), 'sort': self.direction if self.order == 'user.name' else '', }, 'first_issue': { 'title': _("Issue(s)"), 'href': request.link(self.for_order('first_issue')), 'sort': self.direction if self.order == 'first_issue' else '', } } title = _("Official Notices") if not is_publisher: self.user_ids, self.group_ids = get_user_and_group(request) filters = None title = _("Published Official Notices") preview = None index = None if is_publisher: preview = request.link(self, name='preview-pdf') if is_publisher and self.state == 'published': index = request.link(self, name='index') clear = {} if self.term: clear['term'] = request.link(self.for_term(None)) if self.from_date or self.to_date: clear['dates'] = request.link(self.for_dates(None, None)) if self.organizations: clear['organization'] = request.link(self.for_organizations(None)) if self.categories: clear['category'] = request.link(self.for_categories(None)) return { 'layout': layout, 'collection': self, 'is_publisher': is_publisher, 'notices': self.batch, 'title': title, 'filters': filters, 'orderings': orderings, 'clear': clear, 'new_notice': request.link(self, name='new-notice'), 'preview': preview, 'index': index }