def get_buttons_row(self): return [ no_columns('_save_btn', '_create_btn', '_cancel_btn', ' ', '_copybtn', ' ', '_remove_btn') ]
class OrderEditFormWidget(ModelFormWidget): MODEL = Order LAYOUT_POSITION = conf.ORQUESTRA_NEW_TAB HAS_CANCEL_BTN_ON_EDIT = False CLOSE_ON_REMOVE = True TITLE = 'Edit order' READ_ONLY = [ 'responsible', ] INLINES = [OrderExpenseCodeInline, OrderFileInline] FIELDSETS = [('order_req', 'group'), ( segment( 'finance', 'order_desc', ('order_amount', 'currency', 'order_paymethod'), field_css='fourteen wide', ), segment( ('order_reqnum', 'order_reqdate'), ('order_podate', 'expected_date'), ('order_deldate', ' '), 'order_notes', css='secondary', ), ), segment('OrderExpenseCodeInline', css='green'), segment('OrderFileInline', css='blue'), no_columns('responsible', )] AUTHORIZED_GROUPS = ['superuser', settings.APP_PROFILE_ORDERS] @classmethod def has_permissions(cls, user): from .orders_list import OrderAdminWidget return OrderAdminWidget.has_permissions(user) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) user = PyFormsMiddleware.user() # Filter Auth Groups to the groups the user is a member of. self.group.queryset = self.group.queryset.order_by('name') if not user.is_superuser: self.group.queryset = self.group.queryset & user.groups.all() if self.group.queryset.count() == 1: self.group.value = self.group.queryset.first().pk if self.object_pk is not None: self._duplicate_btn = ControlButton( 'Duplicate', default=self.__duplicate_btn_evt, label_visible=False, css='basic brown') def autocomplete_search(self, queryset, keyword, control): qs = super().autocomplete_search(queryset, keyword, control) if control.name == 'group' and keyword is not None: return qs.filter(name__icontains=keyword) else: return qs def __duplicate_btn_evt(self): user = PyFormsMiddleware.user() order = self.model_object.duplicate(user) OrderEditFormWidget(pk=order.pk, parent_win=self.parent) def get_buttons_row(self): buttons = [] if self.has_update_permissions(): buttons.append('_save_btn') if self.has_add_permissions(): buttons.append('_create_btn') if self.has_cancel_btn: buttons.append('_cancel_btn') if self.has_remove_permissions(): buttons.append('_remove_btn') if self.object_pk is not None: buttons.append('_duplicate_btn') return [no_columns(*buttons)] def create_newobject(self): obj = super().create_newobject() obj.responsible = PyFormsMiddleware.user() return obj def delete_event(self): res = super().delete_event() self._duplicate_btn.hide() return res @property def title(self): obj = self.model_object if obj is None: return ModelFormWidget.title.fget(self) else: return "Order: {0}".format(obj.order_id) @title.setter def title(self, value): ModelFormWidget.title.fset(self, value)
class ViewFundApp(ModelViewFormWidget): UID = 'viewfund-app' TITLE = 'Funding opportunities' ORQUESTRA_MENU = 'left' ORQUESTRA_MENU_ORDER = 0 ORQUESTRA_MENU_ICON = 'money' LAYOUT_POSITION = conf.ORQUESTRA_NEW_WINDOW MODEL = FundingOpportunity FIELDSETS = [ no_columns('_favoritebtn', '_urlbtn', '_editbtn'), 'h2:Opportunity details', segment([ ('subject', 'fundingopportunity_link'), ('fundingopportunity_name', 'fundingopportunity_end'), ('fundingopportunity_loideadline', 'fundingopportunity_fullproposal'), 'topics', ]), 'h2:Financing info', segment([ 'financingAgency', ('fundingopportunity_value', 'currency', 'paymentfrequency', 'fundingopportunity_duration'), ]), 'h2:Description', segment([ 'fundingopportunity_eligibility', 'fundingopportunity_scope', 'fundingopportunity_brifdesc', ]) ] ADD_FAVORITE_LABEL = '<i class="icon star" ></i> Add to favorites' REMOVE_FAVORITE_LABEL = '<i class="icon empty star" ></i> Remove from favorites' def __init__(self, obj_pk): self.obj = FundingOpportunity.objects.get(pk=obj_pk) ModelViewFormWidget.__init__(self, title=self.obj.fundingopportunity_name, pk=obj_pk) if self.fundingopportunity_loideadline.value is None: self.fundingopportunity_loideadline.hide() if self.fundingopportunity_fullproposal.value is None: self.fundingopportunity_fullproposal.hide() user = PyFormsMiddleware.user() self._editbtn = ControlButton('<i class="icon edit" ></i> Edit', label_visible=False) self._editbtn.value = 'window.location = "/app/opportunities-app/#/funding.apps.fundingopportunities.EditFundingApp/?fund_pk={0}";'.format( obj_pk) if not user.groups.filter( name__in=[settings.PERMISSION_EDIT_FUNDING]).exists(): self._editbtn.hide() self._favoritebtn = ControlButton('Favorite') self._favoritebtn.label_visible = False self._favoritebtn.value = self.__mark_as_favorite if Favorite.objects.filter(user=user, funding=self.obj, active=True).exists(): self._favoritebtn.label = self.REMOVE_FAVORITE_LABEL self._favoritebtn.css = 'primary basic' else: self._favoritebtn.label = self.ADD_FAVORITE_LABEL self._favoritebtn.css = 'blue' self._urlbtn = ControlButton("<i class='ui icon external'></i> URL") self._urlbtn.label_visible = False self._urlbtn.css = 'basic blue' if self.obj and self.obj.fundingopportunity_link: self._urlbtn.value = "window.open('{0}', '_blank');".format( self.obj.fundingopportunity_link) else: self._urlbtn.hide() def __mark_as_favorite(self): user = PyFormsMiddleware.user() favorite = None try: favorite = Favorite.objects.get(user=user, funding=self.obj) if favorite.active: self._favoritebtn.label = self.ADD_FAVORITE_LABEL self._favoritebtn.css = 'blue' favorite.active = False favorite.save() else: self._favoritebtn.label = self.REMOVE_FAVORITE_LABEL self._favoritebtn.css = 'primary basic' favorite.active = True favorite.save() except Favorite.DoesNotExist: Favorite(user=user, funding=self.obj, active=True).save() self._favoritebtn.label = self.REMOVE_FAVORITE_LABEL self._favoritebtn.css = 'primary basic' sidemenu_app = PyFormsMiddleware.get_instance('sidemenu-app') sidemenu_app.reload()
def get_buttons_row(self): return [no_columns('_cancel_btn', '_revokebtn')]
class HumanResourcesForm(ModelFormWidget): """ The advanced version of the form should only be available to administrators. """ LAYOUT_POSITION = conf.ORQUESTRA_NEW_TAB HAS_CANCEL_BTN_ON_EDIT = False CLOSE_ON_REMOVE = True FIELDSETS = [ no_columns('_privateinfo_btn', '_proposals_btn', '_contracts_btn', 'active'), ' ', 'h3:PERSONAL INFORMATION', ( segment( 'full_name', ('first_name', 'last_name'), ('gender', 'birthday'), ('position', 'curriculum_vitae'), 'biography', field_css='fourteen wide', ), segment( '_img', '_rotimg_btn', 'img', field_style='max-width:330px;' ) ), 'h3:EDUCATION', segment('AcademicCareerInline'), 'h3:CONTACT INFORMATION', segment( ('email', 'personal_email'), ('phone_number', 'phone_extension'), 'emergency_contact', css='secondary' ), 'h3:INSTITUTIONAL INFORMATION', segment( 'InstitutionAffiliationInline', ('card_number', 'room'), 'auth_user', css='secondary' ), 'h3:GROUPS', segment('GroupsInline', css='blue'), 'h3:AUTH GROUPS', segment('AuthGroupsInline', css='red') ] READ_ONLY = ['auth_user'] INLINES = [ AcademicCareerInline, InstitutionAffiliationInline, GroupsInline, AuthGroupsInline, ] AUTHORIZED_GROUPS = ['superuser'] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if hasattr(self, 'active'): self.active.label_visible = False self.active.field_style = 'text-align: right;margin-top:5px;' self.active.field_css = 'two wide' self._rotimg_btn = ControlButton( '<i class="icon undo" ></i>Rotate', default=self.__rotimg_evt, label_visible=False, style='margin-top:5px;', field_style='text-align: right;', css='mini') self._img = ControlImg('Image', label_visible=False) self.img.changed_event = self.__update_image_evt ############################################### ## Human Resources related buttons ############################################### self._privateinfo_btn = ControlButton( '<i class="icon lock" ></i>Private info', default=self.__privateinfo_btn_evt, label_visible=False, css='basic red' ) self._contracts_btn = ControlButton( '<i class="icon file alternate" ></i>Contracts', default=self.__contracts_btn_evt, label_visible=False, css='basic' ) self._proposals_btn = ControlButton( '<i class="icon file alternate outline" ></i>Proposals', default=self.__proposals_btn_evt, label_visible=False, css='basic' ) # Only show this buttons if the humanresources modules is installed. if not hr_module_installed: self._privateinfo_btn.hide() self._contracts_btn.hide() self._proposals_btn.hide() else: if self.model_object is None: self._contracts_btn.hide() self._proposals_btn.hide() self._privateinfo_btn.hide() if self.model_object is not None: self.__update_image_evt() @classmethod def has_permissions(cls, user): from .humanresources_list import HumanResourcesList return HumanResourcesList.has_permissions(user) def __update_image_evt(self): url = self.model_object.thumbnail_url(geometry_string='300x300') self._img.value = url + '?t=' + str(timezone.now().timestamp()) def __rotimg_evt(self): delete(self.img.filepath, delete_file=False) im = Image.open(self.img.filepath) rot = im.rotate(90) rot.save(self.img.filepath) self.__update_image_evt() def __privateinfo_btn_evt(self): obj = self.model_object if obj: privateinfo = obj.get_privateinfo() app = PrivateInfoFormWidget( pk=privateinfo.pk, title=str(privateinfo), has_cancel_btn=False, ) app.LAYOUT_POSITION = conf.ORQUESTRA_NEW_TAB def __proposals_btn_evt(self): obj = self.model_object if not obj: return app = ContractProposalsListWidget( parent_pk=obj.pk, parent_model=Person, has_cancel_btn=False, ) app.LAYOUT_POSITION = conf.ORQUESTRA_NEW_TAB def __contracts_btn_evt(self): obj = self.model_object if not obj: return app = ContractsListWidget( parent_pk=obj.pk, parent_model=Person, has_cancel_btn=False, ) app.LAYOUT_POSITION = conf.ORQUESTRA_NEW_TAB @property def title(self): obj = self.model_object if obj is None: return ModelFormWidget.title.fget(self) else: return "Person: {0}".format(obj.name) @title.setter def title(self, value): ModelFormWidget.title.fset(self, value)
class AllOrderEditFormWidget(OrderEditFormWidget): #UID = 'edit-all-orders' TITLE = 'Edit order (full access)' AUTHORIZED_GROUPS = ['superuser', settings.APP_PROFILE_ALL_ORDERS] #sub models to show in the interface INLINES = [ AllOrderExpenseCodeInline, ] #formset of the edit form FIELDSETS = [ no_columns('order_req', 'group'), ( segment( 'finance', 'order_desc', ('order_amount', 'currency', 'order_paymethod'), field_css='fourteen wide', ), segment( ('order_reqnum', 'order_reqdate'), ('order_podate', 'expected_date'), ('order_deldate', ' '), 'order_notes', css='secondary', ), ), segment('AllOrderExpenseCodeInline', css='green'), no_columns('responsible', ) ] @classmethod def has_permissions(cls, user): from .all_orders_list import OrderAdminWidget return OrderAdminWidget.has_permissions(user) @property def title(self): obj = self.model_object if obj is None: return ModelFormWidget.title.fget(self) else: return "Order(full access): {0}".format(obj.order_id) @title.setter def title(self, value): ModelFormWidget.title.fset(self, value) def has_add_permissions(self): return True def has_view_permissions(self): return True def has_remove_permissions(self): return True def has_update_permissions(self): return True
class RequestReimbursementForm(ModelFormWidget): """ """ TITLE = "Request Reimbursement" MODEL = Reimbursement HAS_CANCEL_BTN_ON_ADD = False HAS_CANCEL_BTN_ON_EDIT = False CLOSE_ON_REMOVE = True READ_ONLY = ["created", "modified", "status_changed", 'status'] INLINES = [ExpenseInline] FIELDSETS = [ no_columns('_previous', '_submit', "_print", '_printed', '_submit2approve','_reject', '_accept', 'bank_transfer_date', '_close', style="float:right"), "h3:Requester Information", segment( ("person", "iban") ), "h3:Expenses", segment("ExpenseInline"), ("created", "modified", "status", "status_changed") ] # Orquestra =============================================================== LAYOUT_POSITION = conf.ORQUESTRA_NEW_TAB # ========================================================================= def __init__(self, *args, **kwargs): self._previous = ControlButton( '<i class="ui icon paper plane outline"></i>Previous status', css="basic gray", visible = False, label_visible=False, default = self.__previous_status_evt ) self._submit = ControlButton( '<i class="ui icon paper plane outline"></i>Submit', css="blue", visible=False, label_visible=False, default = self.__submit_2_pending_evt ) self._print = ControlButton( '<i class="ui icon print"></i>Print', visible=False, css="basic blue", label_visible=False ) self._printed = ControlButton( '<i class="ui icon paper plane outline"></i>Set printed', visible=False, css="blue", label_visible=False, default=self.__set_printed_evt ) self._submit2approve = ControlButton( '<i class="ui icon paper plane outline"></i>Submit to approval', visible=False, css="blue", label_visible=False, default=self.__submit_2_approve_evt ) self._accept = ControlButton( '<i class="ui icon thumbs up"></i>Accept', visible=False, css="green", label_visible=False, default = self.__accept_evt ) self._reject = ControlButton( '<i class="ui icon thumbs down"></i>Reject', visible=False, css="red", label_visible=False, default=self.__reject_evt ) self._close = ControlButton( '<i class="ui icon thumbs up"></i>It was paid', visible=False, css="green basic", default=self.__set_closed_evt ) super().__init__(*args, **kwargs) self.person.enabled = False if self.model_object is None: user = PyFormsMiddleware.user() person = user.person_user.first() if person is not None: self.person.value = person.pk self.iban.value = person.privateinfo.iban else: self.warning( 'You need a Person profile associated to your account to be able to create reimbursements.' ) self.update_fields_visibility() def update_fields_visibility(self): obj = self.model_object if obj: self._print.value = 'window.open("{0}", "_blank");'.format( reverse("print-reimbursement-form", args=[obj.pk]) ) self._print.show() else: self._print.hide() # show submit button only when is draft if obj is None or obj.status != 'draft': self._submit.hide() # show print button only when the reimbursement is pending if obj is None: self._print.hide() if obj and self.has_update_permissions(): if obj.status == 'draft': self.bank_transfer_date.hide() self._submit.show() self._previous.hide() self._print.hide() self._printed.hide() self._submit2approve.hide() self._accept.hide() self._reject.hide() self._close.hide() self.iban.enabled = True elif obj.status == 'pending': self.bank_transfer_date.hide() self._previous.show() self._submit.hide() self._print.show() self._printed.show() self._submit2approve.hide() self._accept.hide() self._reject.hide() self._close.hide() self.iban.enabled = False elif obj.status == 'printed': self.bank_transfer_date.hide() self._previous.show() self._submit.hide() self._print.hide() self._printed.hide() self._submit2approve.show() self._accept.hide() self._reject.hide() self._close.hide() self.iban.enabled = False elif obj.status == 'submitted': self.bank_transfer_date.hide() self._previous.show() self._submit.hide() self._print.hide() self._printed.hide() self._submit2approve.hide() self._accept.show() self._reject.show() self._close.hide() self.iban.enabled = False elif obj.status in ['rejected', 'approved']: self._previous.hide() self._submit.hide() self._print.hide() self._printed.hide() self._submit2approve.hide() self._accept.hide() self._reject.hide() self.iban.enabled = False if obj.status == 'approved': self.bank_transfer_date.show() self._close.show() else: self.bank_transfer_date.hide() self._close.hide() elif obj.status == 'closed': self.bank_transfer_date.show() self.bank_transfer_date.readonly = True self._previous.hide() self._submit.hide() self._print.hide() self._printed.hide() self._submit2approve.hide() self._accept.hide() self._reject.hide() self._close.hide() self.iban.enabled = False else: self.bank_transfer_date.hide() self._submit.hide() self._previous.hide() self._print.hide() self._printed.hide() self._submit2approve.hide() self._accept.hide() self._reject.hide() self._close.hide() self.iban.enabled = True if obj.status == 'closed': self.bank_transfer_date.show() self.bank_transfer_date.readonly = True def save_btn_event(self): super().save_btn_event() self.update_fields_visibility() def __previous_status_evt(self): if not self.has_update_permissions(): raise Exception('No permission') obj = self.model_object obj.previous_status() self.show_edit_form(self.object_pk) self.update_fields_visibility() def __set_printed_evt(self): if not self.has_update_permissions(): raise Exception('No permission') obj = self.model_object obj.set_printed() self.show_edit_form(self.object_pk) self.update_fields_visibility() def __submit_2_pending_evt(self): """ Notify the users with approval responsibility about the new reimbursement """ if not self.has_update_permissions(): raise Exception('No permission') obj = self.model_object obj.submit_to_pending() self.show_edit_form(self.object_pk) self.update_fields_visibility() def __submit_2_approve_evt(self): if not self.has_update_permissions(): raise Exception('No permission') obj = self.model_object obj.submit_for_approval() self.show_edit_form(self.object_pk) self.update_fields_visibility() def __accept_evt(self): if not self.has_update_permissions(): raise Exception('No permission') obj = self.model_object obj.accept() self.show_edit_form(self.object_pk) self.update_fields_visibility() def __reject_evt(self): if not self.has_update_permissions(): raise Exception('No permission') obj = self.model_object obj.reject() self.show_edit_form(self.object_pk) self.update_fields_visibility() def __set_closed_evt(self): if not self.has_update_permissions(): raise Exception('No permission') obj = self.model_object obj.bank_transfer_date = self.bank_transfer_date.value obj.set_closed() # this function will save the object self.show_edit_form(self.object_pk) self.update_fields_visibility() def get_readonly(self, default): res = super().get_readonly(default) obj = self.model_object if obj and obj.status in ['rejected', 'approved']: return res + ['status'] if obj and obj.has_approve_permissions(PyFormsMiddleware.user()): return res else: return res + ['status'] def update_object_fields(self, obj): """ Update the created by field. :param Reimbursement obj: :return: Return the updated reimbursement object. """ obj = super().update_object_fields(obj) if obj.pk is None: obj.created_by = PyFormsMiddleware.user() return obj @property def title(self): obj = self.model_object if obj: name = obj.requester_name total = obj.total return f"({obj.pk}) {obj.person} ({obj.total})" else: return super().title
class AccessRequestFormWidget(ModelFormWidget): TITLE = "Access request" MODEL = AccessRequest LAYOUT_POSITION = conf.ORQUESTRA_NEW_TAB READ_ONLY = [ 'resource', 'requested_by', 'requested_on', 'reason', 'closed_by', 'closed_on' ] FIELDSETS = [ no_columns('resource', 'requested_by', 'requested_on'), 'reason', 'comment', no_columns('_until', '_acceptbtn', '_rejectbtn', 'closed_by', 'closed_on') ] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.resource.field_css = 'eleven wide' self._until = ControlDateTime('Access until', visible=False) self._acceptbtn = ControlButton('Accept', default=self.__accept_evt, css='basic green', visible=False) self._rejectbtn = ControlButton('Reject', default=self.__reject_evt, css='red', visible=False) req = self.model_object if req.is_approved() is None: self._acceptbtn.show() self._rejectbtn.show() self._until.show() self.closed_by.hide() self.closed_on.hide() else: self._until.hide() self.closed_by.show() self.closed_on.show() self.comment.readonly = True def has_remove_permissions(self): return False def has_add_permissions(self): return False def has_update_permissions(self): return False def __open_access_evt(self): pass def __accept_evt(self): req = self.model_object req.comment = self.comment.value req.accept(PyFormsMiddleware.user(), until=self._until.value, comment=self.comment.value) self._acceptbtn.hide() self._rejectbtn.hide() self._until.hide() self.success('The access request was accepted successfully.') self.closed_by.show() self.closed_on.show() self.closed_by.value = str(req.closed_by) self.closed_on.value = req.closed_on self.comment.readonly = True def __reject_evt(self): req = self.model_object req.comment = self.comment.value req.reject(PyFormsMiddleware.user(), comment=self.comment.value) self._acceptbtn.hide() self._rejectbtn.hide() self._until.hide() self.alert('The access request was rejected!') self.closed_by.show() self.closed_on.show() self.closed_by.value = str(req.closed_by) self.closed_on.value = req.closed_on self.comment.readonly = True @property def title(self): obj = self.model_object if obj is None: return ModelFormWidget.title.fget(self) else: return str(obj) @title.setter def title(self, value): ModelFormWidget.title.fset(self, value)