From 2e5a776beb3dc1f9e3cf3d4bbfc0859ffd75b350 Mon Sep 17 00:00:00 2001 From: "A. Tapekhin" Date: Thu, 12 Nov 2015 15:47:34 +0300 Subject: [PATCH 1/2] bulk move admin rights check fixed --- lingvodoc/views.py | 84 ++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/lingvodoc/views.py b/lingvodoc/views.py index a8660e437..6116d9ce1 100755 --- a/lingvodoc/views.py +++ b/lingvodoc/views.py @@ -3478,46 +3478,58 @@ def move_lexical_entry_bulk(request): cli_id = par['client_id'] obj_id = par['object_id'] parent = DBSession.query(LexicalEntry).filter_by(client_id=cli_id, object_id=obj_id).first() - if not override: - if {'client_id': parent.parent_client_id, 'object_id': parent.parent_object_id} in ids: + can = True + if parent: + if not override: + if {'client_id': parent.parent_client_id, 'object_id': parent.parent_object_id} not in ids: + can = False + if can: for ent in par['lexical_entries']: + can = True object_id = ent['object_id'] client_id = ent['client_id'] entry = DBSession.query(LexicalEntry).filter_by(client_id=client_id, object_id=object_id).first() - if not override: - if {'client_id': entry.parent_client_id, 'object_id': entry.parent_object_id} in ids: - if entry and parent: - if parent.moved_to is None: - if entry.moved_to is None: - - if not entry.marked_for_deletion and not parent.marked_for_deletion: - l1e = DBSession.query(LevelOneEntity).filter_by(parent = entry).all() - for entity in l1e: - ent = DBSession.query(LevelOneEntity)\ - .filter_by(parent=parent, entity_type=entity.entity_type, content = entity.content)\ - .first() - if ent: - entity.marked_for_deletion = True - if real_delete: - for publent in entity.publishleveloneentity: - DBSession.delete(publent) - DBSession.delete(entity) - continue - entity.parent = parent - - for publent in entity.publishleveloneentity: - publent.marked_for_deletion = True - publent.parent = parent - DBSession.flush() - ge = DBSession.query(GroupingEntity).filter_by(parent = entry).all() - for entity in ge: - entity.parent = parent - for publent in entity.publishgroupingentity: - publent.marked_for_deletion = True - publent.parent = parent - DBSession.flush() - entry.moved_to = str(cli_id) + '/' + str(obj_id) - entry.marked_for_deletion = True + if entry: + if not override: + if {'client_id': entry.parent_client_id, 'object_id': entry.parent_object_id} not in ids: + can = False + + if can: + if entry: + if parent.moved_to is None: + if entry.moved_to is None: + + if not entry.marked_for_deletion and not parent.marked_for_deletion: + l1e = DBSession.query(LevelOneEntity).filter_by(parent = entry).all() + for entity in l1e: + ent = DBSession.query(LevelOneEntity)\ + .filter_by(parent=parent, + entity_type=entity.entity_type, + content = entity.content)\ + .first() + if ent: + entity.marked_for_deletion = True + if real_delete: + for publent in entity.publishleveloneentity: + DBSession.delete(publent) + DBSession.delete(entity) + continue + entity.parent = parent + + for publent in entity.publishleveloneentity: + publent.marked_for_deletion = True + publent.parent = parent + DBSession.flush() + ge = DBSession.query(GroupingEntity).filter_by(parent = entry).all() + for entity in ge: + entity.parent = parent + for publent in entity.publishgroupingentity: + publent.marked_for_deletion = True + publent.parent = parent + DBSession.flush() + entry.moved_to = str(cli_id) + '/' + str(obj_id) + entry.marked_for_deletion = True + print(client_id, object_id) request.response.status = HTTPOk.code return {} From c32e862e70392998c705483c882703e80c40ef59 Mon Sep 17 00:00:00 2001 From: "A. Tapekhin" Date: Thu, 12 Nov 2015 16:05:59 +0300 Subject: [PATCH 2/2] all_perspectives template fix --- lingvodoc/__init__.py | 4 ++-- lingvodoc/views.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lingvodoc/__init__.py b/lingvodoc/__init__.py index 345e8e34f..f2e8797e8 100755 --- a/lingvodoc/__init__.py +++ b/lingvodoc/__init__.py @@ -86,8 +86,8 @@ def configure_routes(config): # API #GET # Perspective list # 1. Filter by: - # a) template - # b) state + # a) template (param is_template=true/false) + # b) state (param state=) config.add_route('all_perspectives', '/perspectives') config.add_route('users', '/users') diff --git a/lingvodoc/views.py b/lingvodoc/views.py index 6116d9ce1..543249551 100755 --- a/lingvodoc/views.py +++ b/lingvodoc/views.py @@ -53,7 +53,7 @@ and_ ) from sqlalchemy.orm import joinedload, subqueryload, noload, join, joinedload_all -from sqlalchemy.sql.expression import case +from sqlalchemy.sql.expression import case, true, false from collections import deque @@ -1743,10 +1743,15 @@ def perspectives_list(request): except: pass persps = DBSession.query(DictionaryPerspective) - if is_template: - persps = persps.filter(DictionaryPerspective).filter_by(is_template=is_template) + if is_template is not None: + if type(is_template) == str: + if is_template.lower() == 'true': + is_template = True + else: + is_template = False + persps = persps.filter(DictionaryPerspective.is_template == is_template) if state: - persps = persps.filter(DictionaryPerspective).filter_by(state=state) + persps = persps.filter(DictionaryPerspective.state==state) perspectives = [] for perspective in persps: path = request.route_url('perspective',