From e22cc432b35c50ba5cede6829c3dee6e9e3f0312 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 19 Feb 2016 21:55:09 +0530 Subject: [PATCH] use transaction.atomic --- pandora/annotation/management/commands/import_srt.py | 2 +- pandora/annotation/models.py | 4 ++-- pandora/annotation/tasks.py | 4 ++-- pandora/edit/models.py | 4 ++-- pandora/edit/views.py | 2 +- pandora/entity/models.py | 2 +- pandora/event/models.py | 2 +- pandora/item/management/commands/get_frame.py | 2 +- pandora/item/models.py | 6 +++--- pandora/item/tasks.py | 2 +- pandora/itemlist/views.py | 4 ++-- pandora/place/models.py | 2 +- pandora/user/views.py | 2 +- 13 files changed, 19 insertions(+), 19 deletions(-) diff --git a/pandora/annotation/management/commands/import_srt.py b/pandora/annotation/management/commands/import_srt.py index 8659b6e8a..03daf68cb 100644 --- a/pandora/annotation/management/commands/import_srt.py +++ b/pandora/annotation/management/commands/import_srt.py @@ -38,7 +38,7 @@ class Command(BaseCommand): for i in range(len(annotations)-1): if annotations[i]['out'] == annotations[i+1]['in']: annotations[i]['out'] = annotations[i]['out'] - 0.001 - with transaction.commit_on_success(): + with transaction.atomic(): for a in annotations: if a['value']: annotation = models.Annotation( diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index b9b777cb7..db7d58d34 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -160,7 +160,7 @@ class Annotation(models.Model): self.sortvalue = None self.languages = None - with transaction.commit_on_success(): + with transaction.atomic(): if not self.clip or self.start != self.clip.start or self.end != self.clip.end: self.clip, created = Clip.get_or_create(self.item, self.start, self.end) @@ -184,7 +184,7 @@ class Annotation(models.Model): update_matches(self.id, 'event') def delete(self, *args, **kwargs): - with transaction.commit_on_success(): + with transaction.atomic(): super(Annotation, self).delete(*args, **kwargs) if self.clip and self.clip.annotations.count() == 0: self.clip.delete() diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index 5584639e3..658fd4f05 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -113,7 +113,7 @@ def update_item(id, force=False): #cleanup orphaned clips Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete() #update facets if needed - with transaction.commit_on_success(): + with transaction.atomic(): if filter(lambda f: f['id'] == a.layer and f.get('filter'), settings.CONFIG['itemKeys']): a.item.update_layer_facet(a.layer) Item.objects.filter(id=a.item.id).update(modified=a.modified) @@ -129,7 +129,7 @@ def update_item(id, force=False): def update_annotations(layers, value): items = {} - with transaction.commit_on_success(): + with transaction.atomic(): for a in models.Annotation.objects.filter( layer__in=layers, value=value diff --git a/pandora/edit/models.py b/pandora/edit/models.py index 7da980f24..263673a26 100644 --- a/pandora/edit/models.py +++ b/pandora/edit/models.py @@ -101,7 +101,7 @@ class Edit(models.Model): index = self.clips.count() ids = [i['id'] for i in self.clips.order_by('index').values('id')] added = [] - with transaction.commit_on_success(): + with transaction.atomic(): for data in clips: c = self.add_clip(data) if c: @@ -116,7 +116,7 @@ class Edit(models.Model): def sort_clips(self, ids): index = 0 - with transaction.commit_on_success(): + with transaction.atomic(): for i in ids: Clip.objects.filter(id=i).update(index=index) index += 1 diff --git a/pandora/edit/views.py b/pandora/edit/views.py index 1a4177047..338d6bc45 100644 --- a/pandora/edit/views.py +++ b/pandora/edit/views.py @@ -148,7 +148,7 @@ def orderClips(request, data): if edit.editable(request.user): if edit.type == 'static': index = 0 - with transaction.commit_on_success(): + with transaction.atomic(): for i in ids: models.Clip.objects.filter(edit=edit, id=i).update(index=index) index += 1 diff --git a/pandora/entity/models.py b/pandora/entity/models.py index 11455e721..6ab3ea542 100644 --- a/pandora/entity/models.py +++ b/pandora/entity/models.py @@ -196,7 +196,7 @@ class Entity(models.Model): entity = get_by_id(settings.CONFIG['entities'], self.type) if not entity: return - with transaction.commit_on_success(): + with transaction.atomic(): ids = ['name'] for key in entity['keys']: value = self.data.get(key['id']) diff --git a/pandora/event/models.py b/pandora/event/models.py index 9e2e3825e..faa57ac8d 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -84,7 +84,7 @@ class Event(models.Model): def get_super_matches(self): return get_super_matches(self, Event) - @transaction.commit_on_success + @transaction.atomic def update_matches(self, annotations=None): matches = self.get_matches(annotations) if not annotations: diff --git a/pandora/item/management/commands/get_frame.py b/pandora/item/management/commands/get_frame.py index 823a66969..c1ee0bb44 100644 --- a/pandora/item/management/commands/get_frame.py +++ b/pandora/item/management/commands/get_frame.py @@ -17,7 +17,7 @@ class Command(BaseCommand): def handle(self, id, height, position, **options): position = float(position) height = int(height) - with transaction.commit_on_success(): + with transaction.atomic(): i = models.Item.objects.get(public_id=id) path = i.frame(position, height) if path: diff --git a/pandora/item/models.py b/pandora/item/models.py index 4839fb70c..3821c256c 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -769,7 +769,7 @@ class Item(models.Model): return titles - with transaction.commit_on_success(): + with transaction.atomic(): for key in settings.CONFIG['itemKeys']: i = key['id'] if i == 'title': @@ -1547,7 +1547,7 @@ class Item(models.Model): # only import on 0xdb for now or if forced manually # since this will remove all existing subtitles if force or not existing.count() or settings.USE_IMDB: - with transaction.commit_on_success(): + with transaction.atomic(): Annotation.objects.filter(layer=layer, item=self).delete() AnnotationSequence.reset(self) offset = 0 @@ -1790,7 +1790,7 @@ class AnnotationSequence(models.Model): @classmethod def nextid(cls, item): - with transaction.commit_on_success(): + with transaction.atomic(): s, created = cls.objects.get_or_create(item=item) if created: nextid = s.value diff --git a/pandora/item/tasks.py b/pandora/item/tasks.py index f45a622be..e371057ca 100644 --- a/pandora/item/tasks.py +++ b/pandora/item/tasks.py @@ -32,7 +32,7 @@ def update_random_sort(): def update_random_clip_sort(): if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']): - with transaction.commit_on_success(): + with transaction.atomic(): cursor = connection.cursor() cursor.execute('DROP TABLE clip_random;') cursor.execute('CREATE TABLE "clip_random" AS SELECT id AS clip_id, row_number() OVER (ORDER BY random()) AS random FROM "clip_clip"') diff --git a/pandora/itemlist/views.py b/pandora/itemlist/views.py index ad742f615..ef0b55474 100644 --- a/pandora/itemlist/views.py +++ b/pandora/itemlist/views.py @@ -149,7 +149,7 @@ def addListItems(request, data): list = get_list_or_404_json(data['list']) if 'items' in data: if list.editable(request.user): - with transaction.commit_on_success(): + with transaction.atomic(): for item in Item.objects.filter(public_id__in=data['items']): list.add(item) response = json_response(status=200, text='items added') @@ -208,7 +208,7 @@ def orderListItems(request, data): response = json_response() if list.editable(request.user) and list.type == 'static': index = 0 - with transaction.commit_on_success(): + with transaction.atomic(): for i in data['ids']: models.ListItem.objects.filter(list=list, item__public_id=i).update(index=index) index += 1 diff --git a/pandora/place/models.py b/pandora/place/models.py index f126e6c1e..3ae0559ca 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -96,7 +96,7 @@ class Place(models.Model): def get_super_matches(self): return get_super_matches(self, Place) - @transaction.commit_on_success + @transaction.atomic def update_matches(self, annotations=None): matches = self.get_matches(annotations) if not annotations: diff --git a/pandora/user/views.py b/pandora/user/views.py index 7601cfebc..6eb2c4cd7 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -122,7 +122,7 @@ def signout(request, data): profile.save() response = json_response(text='logged out') logout(request) - with transaction.commit_on_success(): + with transaction.atomic(): for s in Session.objects.all(): if s.get_decoded().get('_auth_user_id') == uid: s.delete()