def change_and_save(self, update_only_changed_fields=False, **changed_fields): """ Changes a given `changed_fields` on each object in the queryset, saves objects and returns the changed objects in the queryset. """ bulk_change_and_save(self, update_only_changed_fields=update_only_changed_fields, **changed_fields) return self.filter()
def test_bulk_change_and_save(self): obj1 = ShortcutsModel.objects.create(name='test1', datetime=timezone.now(), number=1) obj2 = ShortcutsModel.objects.create(name='test2', datetime=timezone.now(), number=2) bulk_change_and_save([obj1, obj2], name='modified') assert_equal(obj1.name, 'modified') assert_equal(obj2.name, 'modified') assert_equal(ShortcutsModel.objects.first().name, 'modified') # instance is changed but NOT saved to DB assert_equal(ShortcutsModel.objects.last().name, 'modified') # instance is changed but NOT saved to DB
def send_multiple(*multiple_output_sms): mutiple_output_sms_to_sent = [ output_sms for output_sms in multiple_output_sms if output_sms.state == config.ATS_STATES.PROCESSING ] try: parsed_response = send_and_parse_response(*mutiple_output_sms_to_sent) for output_sms in mutiple_output_sms_to_sent: try: update_sms_state_from_response(output_sms, parsed_response) output_sms.save() except SMSSendingError: change_and_save(output_sms, state = config.ATS_STATES.LOCAL_TO_SEND) except SMSSendingError: bulk_change_and_save(mutiple_output_sms_to_sent, config.ATS_STATES.LOCAL_TO_SEND)
def send_multiple(*multiple_output_sms): mutiple_output_sms_to_sent = [ output_sms for output_sms in multiple_output_sms if output_sms.state == ATS_STATES.PROCESSING ] try: parsed_response = send_and_parse_response(*mutiple_output_sms_to_sent) for output_sms in mutiple_output_sms_to_sent: try: update_sms_state_from_response(output_sms, parsed_response) output_sms.save() except SMSSendingError: change_and_save(output_sms, state=ATS_STATES.LOCAL_TO_SEND) except SMSSendingError: bulk_change_and_save(mutiple_output_sms_to_sent, ATS_STATES.LOCAL_TO_SEND)