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 update_object_fields(self, obj): obj = super().update_object_fields(obj) app_uid = self._parmsapp_uid if app_uid: app = PyFormsMiddleware.get_instance(self._parmsapp_uid) obj.field_parms = str(app.get_parameters()) return obj
def deserialize(self, properties): #self._label = properties.get('label','') #self._help = properties.get('help','') #self._visible = properties.get('visible',True) if isinstance(self.value, BaseWidget): self.value = PyFormsMiddleware.get_instance(self.value.uid) if self.value is not None: self.value.parent = self.parent else: self.value = None
def validate_object(self, obj): obj = super().validate_object(obj) formtype = self.select_form.objects.first() if formtype is not None: if self._custom_form_app_id: custom_form_app = PyFormsMiddleware.get_instance( self._custom_form_app_id) custom_form_app.validate_custom_form(self.model_object) return obj
def save_custom_model_form(self): formtype = self.select_form.objects.first() if formtype is None: ctype = ContentType.objects.get_for_model(self.model) FormObject.objects.filter(content_type=ctype, object_id=self.object_pk).delete() else: if self._custom_form_app_id: custom_form_app = PyFormsMiddleware.get_instance( self._custom_form_app_id) custom_form_app.save_custom_form(self.model_object)
def __copybtn_event(self): obj = self.model_object obj.pk = None obj.fundingopportunity_name += ' (copy)' obj.save() for topic in self.model_object.topics.all(): obj.topics.add(topic) app = PyFormsMiddleware.get_instance('opportunities-app') app.populate_list() app.show_edit_form(obj.pk) self.info('Copied')
def __item_selection_changed_evt(self): request_form = PyFormsMiddleware.get_instance(self.request_form_id) req = AccessRequest.objects.get(pk=self._list.selected_row_id) if req.is_closed(): if req.is_approved(): self.success_popup('The request was approved!', 'Approved') else: if req.comment: self.alert_popup(req.comment, title='Rejected!') else: self.alert_popup('No further information was provided.', title='Rejected!') request_form.show_create_form() else: request_form.show_edit_form( pk=self._list.selected_row_id )
def get_instance(request, application_id, app_data=None): app = PyFormsMiddleware.get_instance(application_id) if app is None: return None if not app.has_permissions(request.user): raise PermissionDenied( 'The user do not have access to the application') if not app.has_session_permissions(request.user): raise PermissionDenied( 'The user do not have access to the application') if app_data is not None: app.load_serialized_form(app_data) for m in request.updated_apps.applications: m.commit() return app
def update_instance(request, application_id, app_data=None): app = PyFormsMiddleware.get_instance(application_id) if app is None: return None if app_data is not None: try: app.load_serialized_form(app_data) except Exception as e: traceback.print_exc() app.alert(str(e)) data = [ r.serialize_form() for r in request.updated_apps.applications if r.is_new_app ] for m in request.updated_apps.applications: m.commit() return data
def load_custom_model_form(self): if self._custom_form_app_id: custom_form_app = self._custom_form_app if self._custom_form_app else PyFormsMiddleware.get_instance( self._custom_form_app_id) custom_form_app.load_custom_form(self.model_object)
def save_event(self, obj, new_object): res = super(EditFundingApp, self).save_event(obj, new_object) if res: app = PyFormsMiddleware.get_instance('opportunities-app') app.populate_list() return res
def delete_event(self): res = super(EditFundingApp, self).delete_event() if res: app = PyFormsMiddleware.get_instance('opportunities-app') app.populate_list() return res