def test_delete_many_elements(self): channel_layers[DEFAULT_CHANNEL_LAYER].flush() inform_deleted_data('topics/topic', 1, 'topics/topic', 2, 'testmodule/model', 1) channel_message = self.get_next_message('autoupdate.send_data', require=True) self.assertEqual(len(channel_message['elements']), 3)
def test_delete_many_elements(self): channel_layers[DEFAULT_CHANNEL_LAYER].flush() inform_deleted_data("topics/topic", 1, "topics/topic", 2, "testmodule/model", 1) channel_message = self.get_next_message("autoupdate.send_data", require=True) self.assertEqual(len(channel_message["elements"]), 3)
def test_delete_one_element(self): channel_layers[DEFAULT_CHANNEL_LAYER].flush() inform_deleted_data('topics/topic', 1) channel_message = self.get_next_message('autoupdate.send_data', require=True) self.assertEqual(len(channel_message['elements']), 1) self.assertTrue(channel_message['elements'][0]['deleted'])
def test_delete_one_element(self): channel_layers[DEFAULT_CHANNEL_LAYER].flush() inform_deleted_data("topics/topic", 1) channel_message = self.get_next_message("autoupdate.send_data", require=True) self.assertEqual(len(channel_message["elements"]), 1) self.assertTrue(channel_message["elements"][0]["deleted"])
def clear(self, request, *args, **kwargs): """ Deletes all chat messages of the group. """ messages = self.get_object().messages.all() messages_id = [message.id for message in messages] messages.delete() collection = ChatMessage.get_collection_string() inform_deleted_data((collection, id) for id in messages_id) return Response()
def clear(cls, request): logs = AttendanceLog.objects.all() args = [] for log in logs: args.append((log.get_collection_string(), log.pk)) logs.delete() # Trigger autoupdate and setup response. if len(args) > 0: inform_deleted_data(args) return Response({'detail': 'All attendance logs deleted successfully.'})
def clear(cls, request): logs = AttendanceLog.objects.all() args = [] for log in logs: args.append((log.get_collection_string(), log.pk)) logs.delete() # Trigger autoupdate and setup response. if len(args) > 0: inform_deleted_data(args) return Response( {'detail': 'All attendance logs deleted successfully.'})
def delete_ballots(self): """ Deletes all AssignmentPollBallot objects of the current poll. """ deleted = [] collection_string = AssignmentPollBallot.get_collection_string() for pk in AssignmentPollBallot.objects.filter(poll=self.poll).values_list('pk', flat=True): deleted.append((collection_string, pk)) deleted_count, _ = AssignmentPollBallot.objects.filter(poll=self.poll).delete() inform_deleted_data(deleted) return deleted_count
def delete_ballots(self): """ Deletes all motion poll ballots of the current poll. :return: Number of ballots deleted. """ deleted = [] collection_string = MotionPollBallot.get_collection_string() for pk in MotionPollBallot.objects.filter(poll=self.poll).values_list('pk', flat=True): deleted.append((collection_string, pk)) deleted_count, _ = MotionPollBallot.objects.filter(poll=self.poll).delete() inform_deleted_data(deleted) return deleted_count
def clear_votes(self, poll): # poll is MotionPoll or AssignmentPoll if poll.has_votes(): poll.get_votes().delete() poll.votescast = poll.votesinvalid = poll.votesvalid = None poll.save() model = MotionPollKeypadConnection if type(poll) == MotionPoll else AssignmentPollKeypadConnection # collect all votes of the poll (with their collection_string and id) args = [] for instance_dict in model.objects.filter(poll=poll).values('pk'): pk = instance_dict['pk'] args.append((model.get_collection_string(), pk)) model.objects.filter(poll=poll).delete() # trigger autoupdate if len(args) > 0: inform_deleted_data(args)
def clear_votes(self, poll): # poll is MotionPoll or AssignmentPoll if poll.has_votes(): poll.get_votes().delete() poll.votescast = poll.votesinvalid = poll.votesvalid = None poll.save() model = MotionPollKeypadConnection if type( poll) == MotionPoll else AssignmentPollKeypadConnection # collect all votes of the poll (with their collection_string and id) args = [] for instance_dict in model.objects.filter(poll=poll).values('pk'): pk = instance_dict['pk'] args.append((model.get_collection_string(), pk)) model.objects.filter(poll=poll).delete() # trigger autoupdate if len(args) > 0: inform_deleted_data(args)
def inform_keypad_deleted(sender, instance, **kwargs): keypad = (Keypad.get_collection_string(), instance.pk) inform_deleted_data([keypad])
def inform_keypad_deleted(sender, instance, **kwargs): keypad = (Keypad.get_collection_string(), instance.pk) inform_deleted_data([keypad])
def test_delete_wrong_arguments(self): with self.assertRaises(ValueError): inform_deleted_data('testmodule/model') with self.assertRaises(ValueError): inform_deleted_data('testmodule/model', 5, 'testmodule/model')
def test_delete_no_element(self): with self.assertRaises(ValueError): inform_deleted_data()