use transaction.atomic

This commit is contained in:
j 2016-02-19 21:55:09 +05:30
parent e738503380
commit e22cc432b3
13 changed files with 19 additions and 19 deletions

View file

@ -38,7 +38,7 @@ class Command(BaseCommand):
for i in range(len(annotations)-1): for i in range(len(annotations)-1):
if annotations[i]['out'] == annotations[i+1]['in']: if annotations[i]['out'] == annotations[i+1]['in']:
annotations[i]['out'] = annotations[i]['out'] - 0.001 annotations[i]['out'] = annotations[i]['out'] - 0.001
with transaction.commit_on_success(): with transaction.atomic():
for a in annotations: for a in annotations:
if a['value']: if a['value']:
annotation = models.Annotation( annotation = models.Annotation(

View file

@ -160,7 +160,7 @@ class Annotation(models.Model):
self.sortvalue = None self.sortvalue = None
self.languages = 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: 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) 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') update_matches(self.id, 'event')
def delete(self, *args, **kwargs): def delete(self, *args, **kwargs):
with transaction.commit_on_success(): with transaction.atomic():
super(Annotation, self).delete(*args, **kwargs) super(Annotation, self).delete(*args, **kwargs)
if self.clip and self.clip.annotations.count() == 0: if self.clip and self.clip.annotations.count() == 0:
self.clip.delete() self.clip.delete()

View file

@ -113,7 +113,7 @@ def update_item(id, force=False):
#cleanup orphaned clips #cleanup orphaned clips
Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete() Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete()
#update facets if needed #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']): if filter(lambda f: f['id'] == a.layer and f.get('filter'), settings.CONFIG['itemKeys']):
a.item.update_layer_facet(a.layer) a.item.update_layer_facet(a.layer)
Item.objects.filter(id=a.item.id).update(modified=a.modified) 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): def update_annotations(layers, value):
items = {} items = {}
with transaction.commit_on_success(): with transaction.atomic():
for a in models.Annotation.objects.filter( for a in models.Annotation.objects.filter(
layer__in=layers, layer__in=layers,
value=value value=value

View file

@ -101,7 +101,7 @@ class Edit(models.Model):
index = self.clips.count() index = self.clips.count()
ids = [i['id'] for i in self.clips.order_by('index').values('id')] ids = [i['id'] for i in self.clips.order_by('index').values('id')]
added = [] added = []
with transaction.commit_on_success(): with transaction.atomic():
for data in clips: for data in clips:
c = self.add_clip(data) c = self.add_clip(data)
if c: if c:
@ -116,7 +116,7 @@ class Edit(models.Model):
def sort_clips(self, ids): def sort_clips(self, ids):
index = 0 index = 0
with transaction.commit_on_success(): with transaction.atomic():
for i in ids: for i in ids:
Clip.objects.filter(id=i).update(index=index) Clip.objects.filter(id=i).update(index=index)
index += 1 index += 1

View file

@ -148,7 +148,7 @@ def orderClips(request, data):
if edit.editable(request.user): if edit.editable(request.user):
if edit.type == 'static': if edit.type == 'static':
index = 0 index = 0
with transaction.commit_on_success(): with transaction.atomic():
for i in ids: for i in ids:
models.Clip.objects.filter(edit=edit, id=i).update(index=index) models.Clip.objects.filter(edit=edit, id=i).update(index=index)
index += 1 index += 1

View file

@ -196,7 +196,7 @@ class Entity(models.Model):
entity = get_by_id(settings.CONFIG['entities'], self.type) entity = get_by_id(settings.CONFIG['entities'], self.type)
if not entity: if not entity:
return return
with transaction.commit_on_success(): with transaction.atomic():
ids = ['name'] ids = ['name']
for key in entity['keys']: for key in entity['keys']:
value = self.data.get(key['id']) value = self.data.get(key['id'])

View file

@ -84,7 +84,7 @@ class Event(models.Model):
def get_super_matches(self): def get_super_matches(self):
return get_super_matches(self, Event) return get_super_matches(self, Event)
@transaction.commit_on_success @transaction.atomic
def update_matches(self, annotations=None): def update_matches(self, annotations=None):
matches = self.get_matches(annotations) matches = self.get_matches(annotations)
if not annotations: if not annotations:

View file

@ -17,7 +17,7 @@ class Command(BaseCommand):
def handle(self, id, height, position, **options): def handle(self, id, height, position, **options):
position = float(position) position = float(position)
height = int(height) height = int(height)
with transaction.commit_on_success(): with transaction.atomic():
i = models.Item.objects.get(public_id=id) i = models.Item.objects.get(public_id=id)
path = i.frame(position, height) path = i.frame(position, height)
if path: if path:

View file

@ -769,7 +769,7 @@ class Item(models.Model):
return titles return titles
with transaction.commit_on_success(): with transaction.atomic():
for key in settings.CONFIG['itemKeys']: for key in settings.CONFIG['itemKeys']:
i = key['id'] i = key['id']
if i == 'title': if i == 'title':
@ -1547,7 +1547,7 @@ class Item(models.Model):
# only import on 0xdb for now or if forced manually # only import on 0xdb for now or if forced manually
# since this will remove all existing subtitles # since this will remove all existing subtitles
if force or not existing.count() or settings.USE_IMDB: 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() Annotation.objects.filter(layer=layer, item=self).delete()
AnnotationSequence.reset(self) AnnotationSequence.reset(self)
offset = 0 offset = 0
@ -1790,7 +1790,7 @@ class AnnotationSequence(models.Model):
@classmethod @classmethod
def nextid(cls, item): def nextid(cls, item):
with transaction.commit_on_success(): with transaction.atomic():
s, created = cls.objects.get_or_create(item=item) s, created = cls.objects.get_or_create(item=item)
if created: if created:
nextid = s.value nextid = s.value

View file

@ -32,7 +32,7 @@ def update_random_sort():
def update_random_clip_sort(): def update_random_clip_sort():
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']): if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
with transaction.commit_on_success(): with transaction.atomic():
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute('DROP TABLE clip_random;') 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"') cursor.execute('CREATE TABLE "clip_random" AS SELECT id AS clip_id, row_number() OVER (ORDER BY random()) AS random FROM "clip_clip"')

View file

@ -149,7 +149,7 @@ def addListItems(request, data):
list = get_list_or_404_json(data['list']) list = get_list_or_404_json(data['list'])
if 'items' in data: if 'items' in data:
if list.editable(request.user): if list.editable(request.user):
with transaction.commit_on_success(): with transaction.atomic():
for item in Item.objects.filter(public_id__in=data['items']): for item in Item.objects.filter(public_id__in=data['items']):
list.add(item) list.add(item)
response = json_response(status=200, text='items added') response = json_response(status=200, text='items added')
@ -208,7 +208,7 @@ def orderListItems(request, data):
response = json_response() response = json_response()
if list.editable(request.user) and list.type == 'static': if list.editable(request.user) and list.type == 'static':
index = 0 index = 0
with transaction.commit_on_success(): with transaction.atomic():
for i in data['ids']: for i in data['ids']:
models.ListItem.objects.filter(list=list, item__public_id=i).update(index=index) models.ListItem.objects.filter(list=list, item__public_id=i).update(index=index)
index += 1 index += 1

View file

@ -96,7 +96,7 @@ class Place(models.Model):
def get_super_matches(self): def get_super_matches(self):
return get_super_matches(self, Place) return get_super_matches(self, Place)
@transaction.commit_on_success @transaction.atomic
def update_matches(self, annotations=None): def update_matches(self, annotations=None):
matches = self.get_matches(annotations) matches = self.get_matches(annotations)
if not annotations: if not annotations:

View file

@ -122,7 +122,7 @@ def signout(request, data):
profile.save() profile.save()
response = json_response(text='logged out') response = json_response(text='logged out')
logout(request) logout(request)
with transaction.commit_on_success(): with transaction.atomic():
for s in Session.objects.all(): for s in Session.objects.all():
if s.get_decoded().get('_auth_user_id') == uid: if s.get_decoded().get('_auth_user_id') == uid:
s.delete() s.delete()