Skip to content

Commit

Permalink
Merge pull request #166 from LukeTapekhin/tmprefactor
Browse files Browse the repository at this point in the history
bulk move admin rights check fixed and all_perspectives template fix
  • Loading branch information
LukeTapekhin authored and LukeTapekhin committed Nov 12, 2015
2 parents ad0f3b3 + c32e862 commit f40c9f9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 42 deletions.
4 changes: 2 additions & 2 deletions lingvodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=<state>)
config.add_route('all_perspectives', '/perspectives')
config.add_route('users', '/users')

Expand Down
97 changes: 57 additions & 40 deletions lingvodoc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -3478,46 +3483,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 {}

Expand Down

0 comments on commit f40c9f9

Please sign in to comment.