def action_save_item(self): #form = BiblioHoldForm(self.request.POST) form = ReservesForm(self.request.POST) if not form.is_valid(): form_vms = vm_list() self.add_form_viewmodels(form, form_vms) return form_vms hold = form.save() biblio = hold.biblio if biblio.totalholds: biblio.totalholds+=1 else: biblio.totalholds=1 biblio.timestamp_updated = timezone.now() biblio.save() # Instantiate related HoldGrid to use it's .postprocess_qs() method # to update it's row via grid viewmodel 'prepend_rows' key value. hold_grid = HoldGrid() hold_grid.request = self.request hold_grid.init_class() return vm_list({ 'update_rows': self.postprocess_qs([biblio]), # return grid rows for client-side HoldGrid component .updatePage(), 'hold_grid_view': { 'prepend_rows': hold_grid.postprocess_qs([hold]) } })
def action_edit_note(self): member = self.get_object_for_action() note = self.request_get('note') modified_members = [] if member.note != note: member.note = note member.save() modified_members.append(member) if len(modified_members) == 0: return vm_list({ 'view': 'alert', 'title': str(member.profile), 'message': 'Note was not changed.' }) else: return vm_list({ 'update_rows': self.postprocess_qs(modified_members), })
def change_endorsement(self, is_endorsed): member = self.get_object_for_action() modified_members = [] if member.is_endorsed != is_endorsed: member.is_endorsed = is_endorsed member.save() modified_members.append(member) return vm_list({ 'update_rows': self.postprocess_qs(modified_members), })
def action_endorse_members(self): member_ids = json.loads(self.request_get('member_ids', '{}')) if not isinstance(member_ids, dict): return vm_list({ 'view': 'alert_error', 'title': 'Invalid value of member_ids', 'message': self.request_get('member_ids') }) members = self.model.objects.filter(pk__in=member_ids) modified_members = [] for member in members: if member.is_endorsed != member_ids[str(member.pk)]: member.is_endorsed = member_ids[str(member.pk)] member.save() modified_members.append(member) return vm_list({ 'description': [list(member.get_str_fields().values()) for member in modified_members], 'update_rows': self.postprocess_qs(modified_members), })
def action_edit_form(self, obj=None): if obj is None: obj = self.get_object_for_action() if self.request.user.is_superuser or obj == self.request.user: return super().action_edit_form(obj) else: return vm_list({ 'view': 'alert_error', 'message': 'You do not have the rights to edit another user preferences.' })
def action_save_equipment(self): form = ClubEquipmentForm(self.request.POST) if not form.is_valid(): form_vms = vm_list() self.add_form_viewmodels(form, form_vms) return form_vms equipment = form.save() club = equipment.club club.last_update = timezone.now() club.save() # Instantiate related EquipmentGrid to use it's .postprocess_qs() method # to update it's row via grid viewmodel 'prepend_rows' key value. equipment_grid = EquipmentGrid() equipment_grid.setup(self.request) return vm_list({ 'update_rows': self.postprocess_qs([club]), # return grid rows for client-side EquipmentGrid component .updatePage(), 'equipment_grid_view': { 'prepend_rows': equipment_grid.postprocess_qs([equipment]) } })
def action_add_equipment(self): club = self.get_object_for_action() if club is None: return vm_list({ 'view': 'alert_error', 'title': 'Error', 'message': 'Unknown instance of Club' }) equipment_form = ClubEquipmentForm(initial={'club': club.pk}) # Generate equipment_form viewmodel vms = self.vm_form(equipment_form, form_action='save_equipment') return vms
def action_add_item(self): biblio = self.get_object_for_action() if biblio is None: return vm_list({ 'view': 'alert_error', 'title': 'Error', 'message': 'Unknown instance of Biblio' }) item_form = BiblioItemForm(initial={'biblio': biblio.pk}) # Generate item_form viewmodel vms = self.vm_form(item_form, form_action='save_item') return vms
def action_save_equipment(self): form = ClubEquipmentForm(self.request.POST) if not form.is_valid(): form_vms = vm_list() self.add_form_viewmodels(form, form_vms) return form_vms equipment = form.save() club = equipment.club club.last_update = timezone.now() club.save() # Instantiate related EquipmentGrid to use it's .postprocess_qs() method # to update it's row via grid viewmodel 'prepend_rows' key value. equipment_grid = EquipmentGrid() equipment_grid.request = self.request equipment_grid.init_class() return vm_list({ 'update_rows': self.postprocess_qs([club]), # return grid rows for client-side EquipmentGrid component .updatePage(), 'equipment_grid_view': { 'prepend_rows': equipment_grid.postprocess_qs([equipment]) } })
def action_save_item(self): form = BiblioItemsForm(self.request.POST) if not form.is_valid(): form_vms = vm_list() self.add_form_viewmodels(form, form_vms) return form_vms item = form.save() biblio = item.biblionumber #biblio.timestamp_updated = timezone.now() #biblio.save() # Instantiate related ItemGrid to use it's .postprocess_qs() method # to update it's row via grid viewmodel 'prepend_rows' key value. item_grid = ItemsGrid() item_grid.request = self.request item_grid.init_class() return vm_list({ 'update_rows': self.postprocess_qs([biblio]), # return grid rows for client-side ItemGrid component .updatePage(), 'item_grid_view': { 'prepend_rows': item_grid.postprocess_qs([item]) } })
def action_add_equipment(self): club = self.get_object_for_action() if club is None: return vm_list({ 'view': 'alert_error', 'title': 'Error', 'message': 'Unknown instance of Club' }) equipment_form = ClubEquipmentForm(initial={'club': club.pk}) # Generate equipment_form viewmodel vms = self.vm_form( equipment_form, form_action='save_equipment' ) return vms
def action_endorse_members(self): member_ids = json.loads(self.request_get('member_ids', '{}')) if not isinstance(member_ids, dict): return vm_list({ 'view': 'alert_error', 'title': 'Invalid value of member_ids', 'message': self.request_get('member_ids') }) members = self.model.objects.filter(pk__in=member_ids) modified_members = [] for member in members: if member.is_endorsed != member_ids[str(member.pk)]: member.is_endorsed = member_ids[str(member.pk)] member.save() modified_members.append(member) return vm_list({ 'description': [ list(member.get_str_fields().values()) for member in modified_members ], 'update_rows': self.postprocess_qs(modified_members), })