def group_action(booking, action): assert action in ('join', 'leave') if attendees_count == 1 and action == 'leave': traits = ( Intercooler( request_method='POST', redirect_after=request.class_link(BookingCollection) ), ) else: traits = ( Intercooler( request_method='POST', redirect_after=request.link(self) ), ) url = URL(request.link(self, action))\ .query_param('booking_id', booking.id)\ .as_string() return Link( text=(action == 'join' and _("Join Group") or _("Leave Group")), url=layout.csrf_protected_url(url), traits=traits )
def editbar_links(self): result = [] result.append( Link(text=_("Print delivery note"), url=self.request.link(self.model, 'delivery-note'), attrs={'class': 'print-icon'})) if self.request.has_permission(self.model, EditModelUnrestricted): result.append( Link(text=_("Edit"), url=self.request.link(self.model, 'edit-unrestricted'), attrs={'class': 'edit-icon'})) elif self.request.has_permission(self.model, EditModel): result.append( Link(text=_("Edit"), url=self.request.link(self.model, 'edit'), attrs={'class': 'edit-icon'})) if self.request.has_permission(self.model, DeleteModel): result.append( Link(text=_("Delete"), url=self.csrf_protected_url(self.request.link( self.model)), attrs={'class': 'delete-icon'}, traits=(Confirm( _("Do you really want to delete this " "scan job?"), _("This cannot be undone."), _("Delete"), _("Cancel")), Intercooler(request_method='DELETE', redirect_after=self.scan_jobs_url)))) return result
def editbar_links(self): result = [] if self.request.has_permission(self.model, EditModel): result.append( Link(text=_("Edit"), url=self.request.link(self.model, 'edit'), attrs={'class': 'edit-icon'})) result.append( Link(text=_("Delete pick-up dates"), url=self.request.link(self.model, 'delete-dates'), attrs={'class': 'delete-icon'})) if self.request.has_permission(self.model, DeleteModel): result.append( Link(text=_("Delete"), url=self.csrf_protected_url(self.request.link( self.model)), attrs={'class': 'delete-icon'}, traits=(Confirm( _("Do you really want to delete this " "municipality?"), _("This cannot be undone."), _("Delete"), _("Cancel")), Intercooler( request_method='DELETE', redirect_after=self.municipalities_url)))) return result
def as_link(action, traits): traits = (*(traits or tuple()), Intercooler(request_method='POST')) return Link(action.text, attrs={'class': action.action}, url=csrf_protected(request.link(action)), traits=traits)
def family_removal_links(self): attrs = {'class': ('remove-manual', 'extend-to-family')} for record in self.families: text = _('Delete "${text}"', mapping={ 'text': record.text, }) url = self.csrf_protected_url( self.request.class_link( InvoiceAction, { 'id': record.item, 'action': 'remove-manual', 'extend_to': 'family' })) if record.has_online_payments: traits = (Block( _("This booking cannot be removed, at least one " "booking has been paid online."), _("You may remove the bookings manually one by one."), _("Cancel")), ) else: traits = (Confirm( _('Do you really want to remove "${text}"?', mapping={'text': record.text}), _("${count} bookings will be removed", mapping={'count': record.count}), _("Remove ${count} bookings", mapping={'count': record.count}), _("Cancel")), Intercooler(request_method='POST')) yield Link(text=text, url=url, attrs=attrs, traits=traits)
def get_period_bound_links(self, request): if self.activity.state in ('proposed', 'archived'): yield Link(text=_("Publish"), url=request.link(self.activity, name='accept'), attrs={'class': 'accept-activity'}, traits=(Confirm( _("Do you really want to publish this activity?"), _("This cannot be undone."), _("Publish Activity"), _("Cancel")), Intercooler(request_method='POST', redirect_after=request.url))) if self.activity.state == 'accepted': yield Link(text=_("Archive"), url=request.link(self.activity, name='archive'), attrs={'class': 'archive-activity'}, traits=(Confirm( _("Do you really want to archive this activity?"), _("This cannot be undone. " "The activity will be made private as a result."), _("Archive Activity"), _("Cancel")), Intercooler(request_method='POST', redirect_after=request.url)))
def payment_actions(payment): if payment.state == 'paid': amount = '{:02f} {}'.format(payment.amount, payment.currency) yield Link(text=_("Refund Payment"), url=layout.csrf_protected_url( request.link(payment, 'refund')), attrs={'class': 'payment-refund'}, traits=(Confirm( _("Do you really want to refund ${amount}?", mapping={'amount': amount}), _("This cannot be undone."), _("Refund ${amount}", mapping={'amount': amount}), _("Cancel")), Intercooler(request_method='POST', redirect_after=request.url)))
def offer_again_link(self, activity, title): return Link(text=title, url=self.request.class_link(VacationActivity, {'name': activity.name}, name="offer-again"), traits=(Confirm( _('Do you really want to provide "${title}" again?', mapping={'title': activity.title}), _("You will have to request publication again"), _("Provide Again"), _("Cancel")), Intercooler(request_method="POST", redirect_after=self.request.class_link( VacationActivity, {'name': activity.name}, ))), attrs={'class': 'offer-again'})
def editbar_links(self): if not self.request.is_manager: return return [ Link( text=_("Update"), url=self.csrf_protected_url( self.request.link(self.model, '+update') ), attrs={'class': 'sync'}, traits=Intercooler( request_method='POST', redirect_after=self.request.url ) ) ]
def editbar_links(self): if self.request.is_manager: return [ Link(text=_("Edit"), url=self.request.link(self.model, 'edit'), attrs={'class': 'edit-link'}), Link(text=_("Delete"), url=self.csrf_protected_url(self.request.link( self.model)), attrs={'class': 'delete-link'}, traits=(Confirm( _("Do you really want to delete this membership?"), _("This cannot be undone."), _("Delete membership"), _("Cancel")), Intercooler(request_method='DELETE', redirect_after=self.request.link( self.model.agency)))) ]
def editbar_links(self): # this is a bit different then usual, trying out some things as part # of this project - probably not a good idea to copy this elsewhere if not self.request.is_manager: return if self.suffixes and not getattr(self.suffixes[-1], 'editbar', True): return if isinstance(self.model, MissionReportCollection): return [ Link( _("Vehicles"), self.request.class_link( MissionReportVehicleCollection ), attrs={'class': 'vehicles'} ), LinkGroup( title=_("Add"), links=[ Link( text=_("Mission Report"), url=self.request.link( self.model, name='+new' ), attrs={'class': 'new-report'} ) ] ), ] if isinstance(self.model, MissionReportVehicleCollection): return [ LinkGroup( title=_("Add"), links=[ Link( text=_("Vehicle"), url=self.request.link( self.model, name='+new' ), attrs={'class': 'new-vehicle'} ) ] ), ] if isinstance(self.model, MissionReport): return [ Link( _("Images"), self.request.link(self.model, name='images'), attrs={'class': 'upload-images'} ), Link( _("Edit"), self.request.link(self.model, name='edit'), attrs={'class': 'edit-link'} ), Link( _("Delete"), self.csrf_protected_url( self.request.link(self.model) ), attrs={'class': 'delete-link'}, traits=( Confirm( _( "Do you really want to delete " "this mission report?" ), _("This cannot be undone."), _("Delete mission report"), _("Cancel") ), Intercooler( request_method='DELETE', redirect_after=self.request.class_link( MissionReportCollection ) ) ) ) ] if isinstance(self.model, MissionReportVehicle): if self.model.uses: return [ Link( _("Delete"), '#', attrs={'class': 'delete-link'}, traits=( Block( _("This vehicle can't be deleted."), _( "There are mission reports associated " "with this vehicle." ), _("Cancel") ), ) ) ] else: return [ Link( _("Delete"), self.csrf_protected_url( self.request.link(self.model) ), attrs={'class': 'delete-link'}, traits=( Confirm( _( "Do you really want to delete " "this vehicle?" ), _("This cannot be undone."), _("Delete vehicle"), _("Cancel") ), Intercooler( request_method='DELETE', redirect_after=self.request.class_link( MissionReportVehicleCollection ) ) ) ) ]
def occasion_links(o): # organisers can only edit occasions in active periods if request.is_organiser_only and not o.period.active: return yield Link(text=_("Edit"), url=request.link(o, name='edit')) yield Link(text=_("Clone"), url=request.link(o, name='clone')) title = layout.format_datetime_range( o.dates[0].localized_start, o.dates[0].localized_end ) if o.cancelled and not o.period.finalized: yield Link( text=_("Reinstate"), url=layout.csrf_protected_url( request.link(o, name='reinstate') ), traits=( Confirm( _( 'Do you really want to reinstate "${title}"?', mapping={'title': title} ), _("Previous attendees need to re-apply"), _("Reinstate Occasion"), _("Cancel") ), Intercooler( request_method="POST", redirect_after=request.link(self) ) ) ) elif o.id in occasion_ids_with_bookings and not o.period.finalized: yield Link( text=_("Rescind"), url=layout.csrf_protected_url(request.link(o, name='cancel')), traits=( Confirm( _( 'Do you really want to rescind "${title}"?', mapping={'title': title} ), _( "${count} already accepted bookings will " "be cancelled", mapping={'count': o.attendee_count} ), _( "Rescind Occasion" ), _( "Cancel" ) ), Intercooler( request_method="POST", redirect_after=request.link(self) ) ) ) elif o.id not in occasion_ids_with_bookings: yield Link( text=_("Delete"), url=layout.csrf_protected_url(request.link(o)), traits=( Confirm( _('Do you really want to delete "${title}"?', mapping={ 'title': title }), _(( "There are no accepted bookings associated with " "this occasion, though there might be " "cancelled/blocked bookings which will be deleted." )), _("Delete Occasion"), _("Cancel") ), Intercooler( request_method="DELETE", redirect_after=request.link(self) ) ) )
def editbar_links(self): if self.request.is_manager: return [ Link(text=_("Edit"), url=self.request.link(self.model.proxy(), 'edit'), attrs={'class': 'edit-link'}), Link(text=_("Move"), url=self.request.link(self.model.proxy(), 'move'), attrs={'class': 'move'}), Link(text=_("Delete"), url=self.csrf_protected_url(self.request.link( self.model)), attrs={'class': 'delete-link'}, traits=(Confirm( _("Do you really want to delete this agency?"), _("This cannot be undone."), _("Delete agency"), _("Cancel")), Intercooler(request_method='DELETE', redirect_after=self.request.link( self.collection)))), Link(text=_("Create PDF"), url=self.request.link(self.model.proxy(), 'create-pdf'), attrs={'class': 'create-pdf'}), LinkGroup(title=_("Add"), links=[ Link(text=_("Agency"), url=self.request.link(self.model.proxy(), name='new'), attrs={'class': 'new-agency'}), Link(text=_("Membership"), url=self.request.link( self.model.proxy(), name='new-membership'), attrs={'class': 'new-person'}), ]), LinkGroup( title=_("Sort"), links=[ Link(text=_("Suborganizations"), url=self.csrf_protected_url( self.request.link(self.model.proxy(), 'sort-children')), attrs={'class': 'sort-alphabetically'}, traits=(Confirm( _("Do you really want to sort the " "suborganizations alphabetically by " "title?"), _("This cannot be undone."), _("Sort suborganizations"), _("Cancel")), Intercooler( request_method='POST', redirect_after=self.request.link( self.model)))), Link(text=_("Relationships"), url=self.csrf_protected_url( self.request.link(self.model.proxy(), 'sort-relationships')), attrs={'class': 'sort-alphabetically'}, traits=(Confirm( _("Do you really want to sort the " "relationships alphabetically by " "last name and first name?"), _("This cannot be undone."), _("Sort relationships"), _("Cancel")), Intercooler( request_method='POST', redirect_after=self.request.link( self.model)))), ]), ]
def actions_by_booking(layout, period, booking): actions = [] if not period: return actions if period.wishlist_phase or booking.state in ('accepted', 'open'): if period.wishlist_phase or period.booking_phase: if not booking.group_code: actions.append( Link( text=_("Invite a companion"), url=layout.request.link(booking, 'invite'), attrs={ 'class': 'invite-link', }, ) ) else: # XXX this is not too efficient as there might be many queries if period.wishlist_phase: states = '*' else: states = ('open', 'accepted') count = booking.group_code_count(states) - 1 invite = GroupInvite( layout.request.session, booking.group_code) if count < 1: # the group code is not shown if the attendee is alone actions.append( Link( text=_("Invite a companion"), url=layout.request.link(invite), attrs={ 'class': 'invite-link', }, ) ) elif count == 1: actions.append( Link( text=_("With 1 companion in a group"), url=layout.request.link(invite), attrs={ 'class': 'invite-link', 'data-group': booking.group_code, }, ) ) elif count > 1: actions.append( Link( text=_("With ${n} companions in a group", mapping={ 'n': count }), url=layout.request.link(invite), attrs={ 'class': 'invite-link', 'data-group': booking.group_code, }, ) ) if period.wishlist_phase or booking.state in DELETABLE_STATES: label = ( period.wishlist_phase and _("Remove wish") or _("Remove booking") ) actions.append(Link( text=label, url=layout.csrf_protected_url(layout.request.link(booking)), attrs={ 'class': 'delete-link', }, traits=( Confirm( _('Do you really want to remove "${title}"?', mapping={ 'title': get_booking_title(layout, booking) }), None, label, _("Cancel"), ), Intercooler( request_method='DELETE', redirect_after=layout.request.link(layout.model), target='#booking-{}'.format(booking.id), ), ) )) if period.booking_phase and booking.state == 'accepted': if layout.request.is_admin: may_cancel = True elif not booking.occasion.is_past_cancellation(layout.today()): may_cancel = True else: may_cancel = False if may_cancel: actions.append(Link( text=_("Cancel Booking"), url=layout.csrf_protected_url( layout.request.link(booking, 'cancel') ), attrs={ 'class': 'cancel-link', }, traits=( Confirm( _('Do you really want to cancel "${title}"?', mapping={ 'title': get_booking_title(layout, booking) }), _("This cannot be undone."), _("Cancel Booking"), _("Cancel"), ), Intercooler( request_method='POST', redirect_after=layout.request.link(layout.model) ) ))) return actions
def editbar_links(self): links = [] period = self.request.app.active_period if self.request.is_admin or self.is_owner: if self.model.state == 'archived' and period: links.append( self.offer_again_link(self.model, _("Provide Again"))) if self.is_editable: if self.model.state == 'preview': if not period: links.append( Link(text=_("Request Publication"), url='#', attrs={'class': 'request-publication'}, traits=(Block(_( "There is currently no active period. " "Please retry once a period has been " "activated."), no=_("Cancel")), ))) elif self.model.has_occasion_in_period(period): links.append( Link(text=_("Request Publication"), url=self.request.link(self.model, name='propose'), attrs={'class': 'request-publication'}, traits=(Confirm( _("Do you really want to request " "publication?"), _("This cannot be undone."), _("Request Publication")), Intercooler( request_method="POST", redirect_after=self.request.link( self.model))))) else: links.append( Link(text=_("Request Publication"), url='#', attrs={'class': 'request-publication'}, traits=(Block(_( "Please add at least one occasion " "before requesting publication."), no=_("Cancel")), ))) if not self.model.publication_requests: links.append( Link( text=_("Discard"), url=self.csrf_protected_url( self.request.link(self.model)), attrs={'class': 'delete-link'}, traits=(Confirm( _('Do you really want to discard "${title}"?', mapping={'title': self.model.title}), _("This cannot be undone."), _("Discard Activity"), _("Cancel")), Intercooler( request_method="DELETE", redirect_after=self.request.class_link( VacationActivityCollection))))) links.append( Link(text=_("Edit"), url=self.request.link(self.model, name='edit'), attrs={'class': 'edit-link'})) if not self.request.app.periods: links.append( Link(text=_("New Occasion"), url='#', attrs={'class': 'new-occasion'}, traits=(Block( _("Occasions cannot be created yet"), _("There are no periods defined yet. At least " "one period needs to be defined before " "occasions can be created"), _("Cancel"))))) else: links.append( Link(text=_("New Occasion"), url=self.request.link(self.model, 'new-occasion'), attrs={'class': 'new-occasion'})) if self.request.is_admin or self.is_owner: if self.attendees: links.append( Link(text=_("Attendees"), url=self.request.link(self.attendees), attrs={'class': 'show-attendees'})) if self.request.is_admin: if self.model.state != 'preview' and self.ticket: links.append( Link(text=_("Show Ticket"), url=self.request.link(self.ticket), attrs={'class': 'show-ticket'})) return links
def booking_links(booking): yield Link(_("User"), user_link(booking.attendee.username)) yield Link(_("Attendee"), attendee_link(booking.attendee_id)) yield Link(phase_title, bookings_link(booking.attendee.username)) if booking.group_code: yield Link(_("Group"), group_link(booking.group_code)) if wishlist_phase: yield Link( text=_("Remove Wish"), url=layout.csrf_protected_url( request.class_link(Booking, {'id': booking.id}) ), traits=( Confirm(_( "Do you really want to remove ${attendee}'s wish?", mapping={ 'attendee': booking.attendee.name } ), yes=_("Remove Wish"), no=_("Cancel")), Intercooler( request_method='DELETE', target='#{}'.format(booking.id) ) ) ) elif booking_phase and booking.state != 'accepted': yield Link( text=_("Remove Booking"), url=layout.csrf_protected_url( request.class_link(Booking, {'id': booking.id}) ), traits=( Confirm(_( "Do you really want to delete ${attendee}'s booking?", mapping={ 'attendee': booking.attendee.name } ), yes=_("Remove Booking"), no=_("Cancel")), Intercooler( request_method='DELETE', target='#{}'.format(booking.id) ) ) ) elif booking_phase and booking.state == 'accepted': yield Link( text=_("Cancel Booking"), url=layout.csrf_protected_url( request.class_link( Booking, {'id': booking.id}, 'cancel' ) ), traits=( Confirm( _( "Do you really want to cancel ${attendee}'s " "booking?", mapping={ 'attendee': booking.attendee.name } ), _("This cannot be undone."), _("Cancel Booking"), _("Cancel") ), Intercooler( request_method='POST', ) ) )