示例#1
0
def test_agency_layout():
    request = DummyRequest()
    model = ExtendedAgency('Agency')

    layout = AgencyLayout(model, request)
    assert isinstance(layout.collection, ExtendedAgencyCollection)
    assert layout.editbar_links is None
    assert path(layout.breadcrumbs) == \
        'DummyOrg/ExtendedAgencyCollection/ExtendedAgency'
    assert layout.move_agency_url_template == 'AgencyMove/?csrf-token=x'
    assert layout.move_membership_within_agency_url_template == \
        'AgencyMembershipMoveWithinAgency/?csrf-token=x'

    # Log in as manager
    request.is_manager = True
    layout = AgencyLayout(model, request)
    assert list(hrefs(layout.editbar_links)) == [
        'AgencyProxy/edit',
        'AgencyProxy/move',
        'ExtendedAgency/?csrf-token=x',
        'AgencyProxy/create-pdf',
        'AgencyProxy/new',
        'AgencyProxy/new-membership',
        'AgencyProxy/sort-children?csrf-token=x',
        'AgencyProxy/sort-relationships?csrf-token=x',
    ]
示例#2
0
def create_agency_pdf(self, request, form):

    if form.submitted(request):
        self.pdf_file = request.app.pdf_class.from_agencies(
            agencies=[self],
            title=self.title,
            toc=False,
            exclude=request.app.org.hidden_people_fields,
            page_break_on_level=1)
        request.success(_("PDF created"))
        # FIXME: clear cache for redirect so that pdf link is updated
        return redirect(request.link(self))

    layout = AgencyLayout(self, request)
    layout.breadcrumbs.append(Link(_("Create PDF"), '#'))

    return {
        'layout':
        layout,
        'title':
        _("Create PDF"),
        'helptext':
        _("Create a PDF of this agency and all its suborganizations. "
          "This may take a while."),
        'form':
        form
    }
示例#3
0
def view_agency(self, request):

    return {
        'title': self.title,
        'agency': self,
        'layout': AgencyLayout(self, request)
    }
示例#4
0
def report_agency_change(self, request, form):
    if form.submitted(request):
        session = request.session
        with session.no_autoflush:
            ticket = TicketCollection(session).open_ticket(
                handler_code='AGN',
                handler_id=uuid4().hex,
                handler_data={
                    'id': str(self.id),
                    'submitter_email': form.email.data,
                    'submitter_message': form.message.data
                })
            TicketMessage.create(ticket, request, 'opened')
            ticket.create_snapshot(request)

        send_ticket_mail(request=request,
                         template='mail_ticket_opened.pt',
                         subject=_("Your ticket has been opened"),
                         receivers=(form.email.data, ),
                         ticket=ticket)

        request.success(_("Thank you for your submission!"))
        return redirect(request.link(ticket, 'status'))

    layout = AgencyLayout(self, request)
    layout.breadcrumbs.append(Link(_("Report change"), '#'))

    return {
        'layout': layout,
        'title': _("Report change"),
        'lead': self.title,
        'form': form
    }
示例#5
0
 def get_summary(self, request):
     layout = AgencyLayout(self.agency, request)
     return render_macro(
         layout.macros['display_agency_mutation'], request, {
             'agency': self.agency,
             'message': self.data['handler_data']['submitter_message'],
             'layout': layout
         })
示例#6
0
def add_membership(self, request, form):

    if form.submitted(request):
        self.add_person(**form.get_useful_data())
        request.success(_("Added a new membership"))
        return redirect(request.link(self))

    layout = AgencyLayout(self, request)
    layout.breadcrumbs.append(Link(_("New membership"), '#'))

    return {'layout': layout, 'title': _("New membership"), 'form': form}
示例#7
0
def add_agency(self, request, form):

    if form.submitted(request):
        collection = ExtendedAgencyCollection(request.session)
        agency = collection.add(self, **form.get_useful_data())
        request.success(_("Added a new agency"))
        return redirect(request.link(agency))

    layout = AgencyLayout(self, request)
    layout.breadcrumbs.append(Link(_("New"), '#'))

    return {'layout': layout, 'title': _("New agency"), 'form': form}
示例#8
0
def edit_agency(self, request, form):

    if form.submitted(request):
        form.update_model(self)
        request.success(_("Your changes were saved"))
        return redirect(request.link(self))

    if not form.errors:
        form.apply_model(self)

    layout = AgencyLayout(self, request)
    layout.breadcrumbs.append(Link(_("Edit"), '#'))

    return {'layout': layout, 'title': self.title, 'form': form}
示例#9
0
def move_agency(self, request, form):

    if form.submitted(request):
        form.update_model(self)
        request.success(_("Agency moved"))
        return redirect(request.link(self))

    if not form.errors:
        form.apply_model(self)

    layout = AgencyLayout(self, request)
    layout.breadcrumbs.append(Link(_("Move"), '#'))

    return {
        'layout':
        layout,
        'title':
        self.title,
        'helptext':
        _("Moves the whole agency and all its people and suborganizations "
          "to the given destination."),
        'form':
        form
    }