Skip to content

Commit dab1f1c

Browse files
committed
Merge pull request #218 from ispras/tmprefactor
Version 1.0
2 parents f40c9f9 + 627b252 commit dab1f1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+87215
-32821
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""additional metadata on perspectives and dictionaries
2+
3+
Revision ID: 34c4a3c687b
4+
Revises: 28894fa7718
5+
Create Date: 2015-11-13 13:53:15.258799
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = '34c4a3c687b'
11+
down_revision = '28894fa7718'
12+
branch_labels = None
13+
depends_on = None
14+
15+
from alembic import op
16+
import sqlalchemy as sa
17+
18+
19+
def upgrade():
20+
op.add_column('dictionaryperspective', sa.Column('additional_metadata', sa.UnicodeText(), nullable=True))
21+
op.add_column('dictionary', sa.Column('additional_metadata', sa.UnicodeText(), nullable=True))
22+
pass
23+
24+
25+
def downgrade():
26+
op.drop_column('dictionary', 'additional_metadata')
27+
op.drop_column('dictionaryperspective', 'additional_metadata')
28+
pass
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Added indexes
2+
3+
Revision ID: 479841e119f
4+
Revises: 34c4a3c687b
5+
Create Date: 2015-12-01 16:21:32.634476
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = '479841e119f'
11+
down_revision = '34c4a3c687b'
12+
branch_labels = None
13+
depends_on = None
14+
15+
from alembic import op
16+
import sqlalchemy as sa
17+
18+
19+
def upgrade():
20+
### commands auto generated by Alembic - please adjust! ###
21+
op.create_index('pl1e_parent_idx', 'publishleveloneentity', ['parent_client_id', 'parent_object_id'], unique=False)
22+
op.create_index('pl1e_entity_type_idx', 'publishleveloneentity', ['entity_type'], unique=False)
23+
op.create_index('pl1e_entity_idx', 'publishleveloneentity', ['entity_client_id', 'entity_object_id'], unique=False)
24+
op.create_index('pl1e_deleted_idx', 'publishleveloneentity', ['marked_for_deletion'], unique=False)
25+
op.create_index('l1e_parent_idx', 'leveloneentity', ['parent_client_id', 'parent_object_id'], unique=False)
26+
op.create_index('l1e_entity_type_idx', 'leveloneentity', ['entity_type'], unique=False)
27+
op.create_index('l1e_deleted_idx', 'leveloneentity', ['marked_for_deletion'], unique=False)
28+
op.create_index('l1e_content_idx', 'leveloneentity', ['content'], unique=False)
29+
### end Alembic commands ###
30+
31+
32+
def downgrade():
33+
### commands auto generated by Alembic - please adjust! ###
34+
op.drop_index('l1e_content_idx', table_name='leveloneentity')
35+
op.drop_index('l1e_deleted_idx', table_name='leveloneentity')
36+
op.drop_index('l1e_entity_type_idx', table_name='leveloneentity')
37+
op.drop_index('l1e_parent_idx', table_name='leveloneentity')
38+
op.drop_index('pl1e_deleted_idx', table_name='publishleveloneentity')
39+
op.drop_index('pl1e_entity_idx', table_name='publishleveloneentity')
40+
op.drop_index('pl1e_entity_type_idx', table_name='publishleveloneentity')
41+
op.drop_index('pl1e_parent_idx', table_name='publishleveloneentity')
42+
### end Alembic commands ###
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Added more indexes
2+
3+
Revision ID: 4eaaa494e36
4+
Revises: 479841e119f
5+
Create Date: 2015-12-01 16:53:27.562361
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = '4eaaa494e36'
11+
down_revision = '479841e119f'
12+
branch_labels = None
13+
depends_on = None
14+
15+
from alembic import op
16+
import sqlalchemy as sa
17+
18+
19+
def upgrade():
20+
op.create_index('pl2e_parent_idx', 'publishleveltwoentity', ['parent_client_id', 'parent_object_id'], unique=False)
21+
op.create_index('pl2e_entity_type_idx', 'publishleveltwoentity', ['entity_type'], unique=False)
22+
op.create_index('pl2e_entity_idx', 'publishleveltwoentity', ['entity_client_id', 'entity_object_id'], unique=False)
23+
op.create_index('pl2e_deleted_idx', 'publishleveltwoentity', ['marked_for_deletion'], unique=False)
24+
op.create_index('l2e_parent_idx', 'leveltwoentity', ['parent_client_id', 'parent_object_id'], unique=False)
25+
op.create_index('l2e_entity_type_idx', 'leveltwoentity', ['entity_type'], unique=False)
26+
op.create_index('l2e_deleted_idx', 'leveltwoentity', ['marked_for_deletion'], unique=False)
27+
op.create_index('l2e_content_idx', 'leveltwoentity', ['content'], unique=False)
28+
op.create_index('pge_parent_idx', 'publishgroupingentity', ['parent_client_id', 'parent_object_id'], unique=False)
29+
op.create_index('pge_entity_type_idx', 'publishgroupingentity', ['entity_type'], unique=False)
30+
op.create_index('pge_entity_idx', 'publishgroupingentity', ['entity_client_id', 'entity_object_id'], unique=False)
31+
op.create_index('pge_deleted_idx', 'publishgroupingentity', ['marked_for_deletion'], unique=False)
32+
op.create_index('ge_parent_idx', 'groupingentity', ['parent_client_id', 'parent_object_id'], unique=False)
33+
op.create_index('ge_entity_type_idx', 'groupingentity', ['entity_type'], unique=False)
34+
op.create_index('ge_deleted_idx', 'groupingentity', ['marked_for_deletion'], unique=False)
35+
op.create_index('ge_content_idx', 'groupingentity', ['content'], unique=False)
36+
pass
37+
38+
39+
def downgrade():
40+
op.drop_index('l2e_content_idx', table_name='leveltwoentity')
41+
op.drop_index('l2e_deleted_idx', table_name='leveltwoentity')
42+
op.drop_index('l2e_entity_type_idx', table_name='leveltwoentity')
43+
op.drop_index('l2e_parent_idx', table_name='leveltwoentity')
44+
op.drop_index('pl2e_deleted_idx', table_name='publishleveltwoentity')
45+
op.drop_index('pl2e_entity_idx', table_name='publishleveltwoentity')
46+
op.drop_index('pl2e_entity_type_idx', table_name='publishleveltwoentity')
47+
op.drop_index('pl2e_parent_idx', table_name='publishleveltwoentity')
48+
op.drop_index('ge_content_idx', table_name='groupingentity')
49+
op.drop_index('ge_deleted_idx', table_name='groupingentity')
50+
op.drop_index('ge_entity_type_idx', table_name='groupingentity')
51+
op.drop_index('ge_parent_idx', table_name='groupingentity')
52+
op.drop_index('pge_deleted_idx', table_name='publishgroupingentity')
53+
op.drop_index('pge_entity_idx', table_name='publishgroupingentity')
54+
op.drop_index('pge_entity_type_idx', table_name='publishgroupingentity')
55+
op.drop_index('pge_parent_idx', table_name='publishgroupingentity')
56+
pass

lingvodoc/__init__.py

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,22 @@ def configure_routes(config):
5656
# web-view #GET
5757
config.add_route(name='languages', pattern='/languages/map')
5858

59+
# web-view #GET
60+
config.add_route(name='maps', pattern='/dashboard/maps')
61+
5962
# API #GET && PUT && DELETE
6063
# Gets/puts info about language
6164
config.add_route(name='language', pattern='/language/{client_id}/{object_id}',
6265
factory='lingvodoc.models.LanguageAcl') # 100% ready
6366

67+
# API #POST
68+
# Convert blob
69+
config.add_route(name='convert', pattern='/convert/blob') # 100% ready
70+
71+
# API #POST
72+
# Convert markup
73+
config.add_route(name='convert_markup', pattern='/convert/markup') # 100% ready
74+
6475
# API #POST
6576
# Create language
6677
config.add_route(name='create_language', pattern='/language',
@@ -106,6 +117,8 @@ def configure_routes(config):
106117
# Gets/puts info about dictionary (name/additional authors/etc)
107118
config.add_route(name='dictionary', pattern='/dictionary/{client_id}/{object_id}',
108119
factory='lingvodoc.models.DictionaryAcl') # 100% ready
120+
config.add_route(name='dictionary_copy', pattern='/dictionary/{client_id}/{object_id}/copy',
121+
factory='lingvodoc.models.DictionaryAcl')
109122

110123

111124
config.add_route(name='dictionary_info',
@@ -159,6 +172,31 @@ def configure_routes(config):
159172
config.add_route(name='perspective_outside',
160173
pattern='perspective/{perspective_client_id}/{perspective_id}',
161174
factory='lingvodoc.models.PerspectiveAcl')
175+
# API #POST
176+
# creates hash in metadata on objects
177+
config.add_route(name='perspective_hash',
178+
pattern='/dictionary/{dictionary_client_id}/{dictionary_object_id}/'
179+
'perspective/{perspective_client_id}/{perspective_id}/hash',
180+
factory='lingvodoc.models.PerspectiveAcl')
181+
182+
config.add_route(name='dangerous_perspectives_hash',
183+
pattern='/perspectives/hash',
184+
factory='lingvodoc.models.AdminAcl')
185+
# API #GET && PUT && DELETE
186+
# {<some_data_name>:{"type""<datatype>, "content":<content>},}
187+
# for geo: {"location":{"type":"location", "content":{"lat":<lat>, "lng":<lng>}}}
188+
# for info:{"info":{"type":"list",
189+
# "content":[{"info":{"type":"blob",
190+
# "content":{"client_id":<client_id>, "object_id":<object_id>}
191+
# }
192+
# },
193+
# ]
194+
# }
195+
# }
196+
config.add_route(name='perspective_meta',
197+
pattern='/dictionary/{dictionary_client_id}/{dictionary_object_id}/'
198+
'perspective/{perspective_client_id}/{perspective_id}/meta',
199+
factory='lingvodoc.models.PerspectiveAcl')
162200

163201
config.add_route(name='perspective_tree',
164202
pattern='/dictionary/{dictionary_client_id}/{dictionary_object_id}/'
@@ -236,14 +274,15 @@ def configure_routes(config):
236274
pattern="/blob")
237275

238276
# seems to be redundant
277+
# not anymore
239278
# API #GET
240279
# no params, returns file
241-
#config.add_route(name="get_user_blob",
242-
# pattern="/blobs/{client_id}/{object_id}")
280+
config.add_route(name="get_user_blob",
281+
pattern="/blobs/{client_id}/{object_id}")
243282
# API #GET
244283
# no params, lists only own blobs
245284
config.add_route(name="list_user_blobs",
246-
pattern="/blobs/")
285+
pattern="/blobs")
247286

248287
# TODO: LOCALES!
249288
# API #GET && DELETE
@@ -302,8 +341,25 @@ def configure_routes(config):
302341

303342
# API #GET
304343
# like
344+
# perspective_client_id
345+
# perspective_object_id
305346
config.add_route(name='basic_search', pattern='/basic_search')
306347

348+
# API #POST
349+
# {"searchstrings":[{"searchstring":<searchstring>, "entity_type":<entity_type>, "search_by_or":true/false},
350+
# ],
351+
# "perspectives":[{"client_id":<persp_client_id>,"object_id":<persp_object_id>},
352+
# ]
353+
# "adopted":True/False,
354+
# "adopted_type":<entity_type_where_to_search_if_lexical_entry_is_adopted>,
355+
# "count":True/False,
356+
# "with_etimology":True/False}
357+
config.add_route(name='advanced_search', pattern='/advanced_search')
358+
359+
# API #GET
360+
# like
361+
config.add_route(name='entity_metadata_search', pattern='/meta_search')
362+
307363
# API #GET
308364
# like
309365
config.add_route(name='basic_search_old', pattern='/basic_search_old')
@@ -506,6 +562,10 @@ def configure_routes(config):
506562
# client_id = <client_id>
507563
# Response example:
508564
# {"id": <userid>, "login": <login>, "name": <name>, "intl_name": <international_name>, "userpic": <url_to_userpic>}
565+
# #PUT
566+
# {"client_id":<client_id> OR "user_id":<user_id>,
567+
# "new_password": <new_password>, "old_password":<old_password>,
568+
# "name":<name>, "birthday":<birthday>, "email":<email>, "about":<about>}
509569
config.add_route(name='get_user_info', pattern='/user') # ready, not tested
510570
# API #GET
511571
# Returns translations for a list of words for current or default or fallback locale
@@ -520,6 +580,7 @@ def configure_routes(config):
520580
# params:
521581
# {"blob_client_id": <id>, "blob_object_id": <id>, "parent_client_id": <language_client_id>, "parent_object_id": <language_object_id>}
522582
config.add_route(name='convert_dictionary', pattern='/convert')
583+
config.add_route(name='convert_dictionary_check', pattern='/convert_check')
523584

524585

525586
def main(global_config, **settings):

lingvodoc/models.py

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,12 @@ def find_by_translation_string(locale_id, translation_string):
270270

271271

272272
def add_translation_to_translation_string(locale_id, translation, translation_string, client_id):
273-
if not translation:
274-
translation = translation_string
273+
275274
client = DBSession.query(Client).filter_by(id=client_id).first()
276275
uets = DBSession.query(UserEntitiesTranslationString).filter_by(locale_id=locale_id,
277276
translation_string=translation_string).first()
277+
if not translation:
278+
translation = translation_string
278279
if not uets:
279280
uets = UserEntitiesTranslationString(object_id=DBSession.query(UserEntitiesTranslationString).filter_by(client_id=client.id).count()+1,
280281
client_id=client.id,
@@ -306,7 +307,7 @@ def set_translation(cls, request):
306307
else:
307308
req = request.json_body
308309

309-
translation = req.get('translation_string')
310+
translation = None
310311
if 'translation' in req:
311312
translation = req['translation']
312313
translation_string = req.get('translation_string')
@@ -320,7 +321,7 @@ def set_translation(cls, request):
320321
return
321322

322323

323-
class Language(Base, TableNameMixin, TranslationStringMixin):
324+
class Language(Base, TableNameMixin):
324325
"""
325326
This is grouping entity that isn't related with dictionaries directly. Locale can have pointer to language.
326327
"""
@@ -334,6 +335,52 @@ class Language(Base, TableNameMixin, TranslationStringMixin):
334335
marked_for_deletion = Column(Boolean, default=False)
335336
parent = relationship('Language', remote_side=[client_id, object_id], backref=backref('language'))
336337

338+
def get_translation(cls, request):
339+
return find_by_translation_string(find_locale_id(request), cls.translation_string)
340+
341+
def set_translation(self, request):
342+
if type(request.json_body) == str:
343+
req = json.loads(request.json_body)
344+
else:
345+
req = request.json_body
346+
347+
translation = None
348+
if 'translation' in req:
349+
translation = req['translation']
350+
translation_string = req.get('translation_string')
351+
if not translation_string:
352+
if self.translation_string:
353+
translation_string = self.translation_string
354+
else:
355+
return
356+
client_id = request.authenticated_userid
357+
locale_id = find_locale_id(request)
358+
client = DBSession.query(Client).filter_by(id=client_id).first()
359+
search_translation_string = self.translation_string
360+
if not search_translation_string:
361+
search_translation_string = translation_string
362+
print('SHEEEET', search_translation_string)
363+
uets = DBSession.query(UserEntitiesTranslationString).filter_by(locale_id=locale_id,
364+
translation_string=search_translation_string).first()
365+
if not translation:
366+
translation = translation_string
367+
if not uets:
368+
uets = UserEntitiesTranslationString(object_id=DBSession.query(UserEntitiesTranslationString).filter_by(client_id=client.id).count()+1,
369+
client_id=client.id,
370+
locale_id=locale_id,
371+
translation_string=translation_string,
372+
translation=translation)
373+
self.translation_string = translation_string
374+
DBSession.add(uets)
375+
DBSession.flush()
376+
print('HEY, LISTEN! WTF')
377+
else:
378+
uets.translation_string = translation_string
379+
self.translation_string = translation_string
380+
uets.translation = translation
381+
print('HEY, LISTEN!')
382+
return
383+
337384

338385
class Locale(Base, TableNameMixin, IdMixin, RelationshipMixin):
339386
"""
@@ -384,6 +431,7 @@ class Dictionary(Base, TableNameMixin, CompositeIdMixin, RelationshipMixin, Tran
384431
authors = Column(UnicodeText)
385432
translation_string = Column(UnicodeText)
386433
marked_for_deletion = Column(Boolean, default=False)
434+
additional_metadata = Column(UnicodeText)
387435
# about = Column(UnicodeText)
388436

389437

@@ -407,6 +455,7 @@ class DictionaryPerspective(Base, TableNameMixin, CompositeIdMixin, Relationship
407455
is_template = Column(Boolean, default=False)
408456
import_source = Column(UnicodeText)
409457
import_hash = Column(UnicodeText)
458+
additional_metadata = Column(UnicodeText)
410459
# about = Column(UnicodeText)
411460

412461

@@ -558,6 +607,8 @@ def track(self, publish):
558607
'marked_for_deletion': self.marked_for_deletion,
559608
'locale_id': self.locale_id
560609
}
610+
if self.additional_metadata:
611+
dictionary['additional_metadata'] = self.additional_metadata
561612
children = recursive_content(self, publish)
562613
if children:
563614
dictionary['contains'] = children
@@ -799,6 +850,7 @@ def acl_by_groups(object_id, client_id, subject):
799850
base_group = group.parent
800851
if group.subject_override:
801852
group_name = base_group.action + ":" + base_group.subject + ":" + str(group.subject_override)
853+
group_name = base_group.action + ":" + base_group.subject + ":" + str(group.subject_override)
802854
else:
803855
group_name = base_group.action + ":" + base_group.subject \
804856
+ ":" + str(group.subject_client_id) + ":" + str(group.subject_object_id)

0 commit comments

Comments
 (0)