Skip to content

Commit

Permalink
Merge pull request #218 from ispras/tmprefactor
Browse files Browse the repository at this point in the history
Version 1.0
  • Loading branch information
al-indigo committed Dec 21, 2015
2 parents f40c9f9 + 627b252 commit dab1f1c
Show file tree
Hide file tree
Showing 60 changed files with 87,215 additions and 32,821 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""additional metadata on perspectives and dictionaries
Revision ID: 34c4a3c687b
Revises: 28894fa7718
Create Date: 2015-11-13 13:53:15.258799
"""

# revision identifiers, used by Alembic.
revision = '34c4a3c687b'
down_revision = '28894fa7718'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
op.add_column('dictionaryperspective', sa.Column('additional_metadata', sa.UnicodeText(), nullable=True))
op.add_column('dictionary', sa.Column('additional_metadata', sa.UnicodeText(), nullable=True))
pass


def downgrade():
op.drop_column('dictionary', 'additional_metadata')
op.drop_column('dictionaryperspective', 'additional_metadata')
pass
42 changes: 42 additions & 0 deletions alembic/versions/479841e119f_added_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Added indexes
Revision ID: 479841e119f
Revises: 34c4a3c687b
Create Date: 2015-12-01 16:21:32.634476
"""

# revision identifiers, used by Alembic.
revision = '479841e119f'
down_revision = '34c4a3c687b'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_index('pl1e_parent_idx', 'publishleveloneentity', ['parent_client_id', 'parent_object_id'], unique=False)
op.create_index('pl1e_entity_type_idx', 'publishleveloneentity', ['entity_type'], unique=False)
op.create_index('pl1e_entity_idx', 'publishleveloneentity', ['entity_client_id', 'entity_object_id'], unique=False)
op.create_index('pl1e_deleted_idx', 'publishleveloneentity', ['marked_for_deletion'], unique=False)
op.create_index('l1e_parent_idx', 'leveloneentity', ['parent_client_id', 'parent_object_id'], unique=False)
op.create_index('l1e_entity_type_idx', 'leveloneentity', ['entity_type'], unique=False)
op.create_index('l1e_deleted_idx', 'leveloneentity', ['marked_for_deletion'], unique=False)
op.create_index('l1e_content_idx', 'leveloneentity', ['content'], unique=False)
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_index('l1e_content_idx', table_name='leveloneentity')
op.drop_index('l1e_deleted_idx', table_name='leveloneentity')
op.drop_index('l1e_entity_type_idx', table_name='leveloneentity')
op.drop_index('l1e_parent_idx', table_name='leveloneentity')
op.drop_index('pl1e_deleted_idx', table_name='publishleveloneentity')
op.drop_index('pl1e_entity_idx', table_name='publishleveloneentity')
op.drop_index('pl1e_entity_type_idx', table_name='publishleveloneentity')
op.drop_index('pl1e_parent_idx', table_name='publishleveloneentity')
### end Alembic commands ###
56 changes: 56 additions & 0 deletions alembic/versions/4eaaa494e36_added_more_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Added more indexes
Revision ID: 4eaaa494e36
Revises: 479841e119f
Create Date: 2015-12-01 16:53:27.562361
"""

# revision identifiers, used by Alembic.
revision = '4eaaa494e36'
down_revision = '479841e119f'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
op.create_index('pl2e_parent_idx', 'publishleveltwoentity', ['parent_client_id', 'parent_object_id'], unique=False)
op.create_index('pl2e_entity_type_idx', 'publishleveltwoentity', ['entity_type'], unique=False)
op.create_index('pl2e_entity_idx', 'publishleveltwoentity', ['entity_client_id', 'entity_object_id'], unique=False)
op.create_index('pl2e_deleted_idx', 'publishleveltwoentity', ['marked_for_deletion'], unique=False)
op.create_index('l2e_parent_idx', 'leveltwoentity', ['parent_client_id', 'parent_object_id'], unique=False)
op.create_index('l2e_entity_type_idx', 'leveltwoentity', ['entity_type'], unique=False)
op.create_index('l2e_deleted_idx', 'leveltwoentity', ['marked_for_deletion'], unique=False)
op.create_index('l2e_content_idx', 'leveltwoentity', ['content'], unique=False)
op.create_index('pge_parent_idx', 'publishgroupingentity', ['parent_client_id', 'parent_object_id'], unique=False)
op.create_index('pge_entity_type_idx', 'publishgroupingentity', ['entity_type'], unique=False)
op.create_index('pge_entity_idx', 'publishgroupingentity', ['entity_client_id', 'entity_object_id'], unique=False)
op.create_index('pge_deleted_idx', 'publishgroupingentity', ['marked_for_deletion'], unique=False)
op.create_index('ge_parent_idx', 'groupingentity', ['parent_client_id', 'parent_object_id'], unique=False)
op.create_index('ge_entity_type_idx', 'groupingentity', ['entity_type'], unique=False)
op.create_index('ge_deleted_idx', 'groupingentity', ['marked_for_deletion'], unique=False)
op.create_index('ge_content_idx', 'groupingentity', ['content'], unique=False)
pass


def downgrade():
op.drop_index('l2e_content_idx', table_name='leveltwoentity')
op.drop_index('l2e_deleted_idx', table_name='leveltwoentity')
op.drop_index('l2e_entity_type_idx', table_name='leveltwoentity')
op.drop_index('l2e_parent_idx', table_name='leveltwoentity')
op.drop_index('pl2e_deleted_idx', table_name='publishleveltwoentity')
op.drop_index('pl2e_entity_idx', table_name='publishleveltwoentity')
op.drop_index('pl2e_entity_type_idx', table_name='publishleveltwoentity')
op.drop_index('pl2e_parent_idx', table_name='publishleveltwoentity')
op.drop_index('ge_content_idx', table_name='groupingentity')
op.drop_index('ge_deleted_idx', table_name='groupingentity')
op.drop_index('ge_entity_type_idx', table_name='groupingentity')
op.drop_index('ge_parent_idx', table_name='groupingentity')
op.drop_index('pge_deleted_idx', table_name='publishgroupingentity')
op.drop_index('pge_entity_idx', table_name='publishgroupingentity')
op.drop_index('pge_entity_type_idx', table_name='publishgroupingentity')
op.drop_index('pge_parent_idx', table_name='publishgroupingentity')
pass
67 changes: 64 additions & 3 deletions lingvodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,22 @@ def configure_routes(config):
# web-view #GET
config.add_route(name='languages', pattern='/languages/map')

# web-view #GET
config.add_route(name='maps', pattern='/dashboard/maps')

# API #GET && PUT && DELETE
# Gets/puts info about language
config.add_route(name='language', pattern='/language/{client_id}/{object_id}',
factory='lingvodoc.models.LanguageAcl') # 100% ready

# API #POST
# Convert blob
config.add_route(name='convert', pattern='/convert/blob') # 100% ready

# API #POST
# Convert markup
config.add_route(name='convert_markup', pattern='/convert/markup') # 100% ready

# API #POST
# Create language
config.add_route(name='create_language', pattern='/language',
Expand Down Expand Up @@ -106,6 +117,8 @@ def configure_routes(config):
# Gets/puts info about dictionary (name/additional authors/etc)
config.add_route(name='dictionary', pattern='/dictionary/{client_id}/{object_id}',
factory='lingvodoc.models.DictionaryAcl') # 100% ready
config.add_route(name='dictionary_copy', pattern='/dictionary/{client_id}/{object_id}/copy',
factory='lingvodoc.models.DictionaryAcl')


config.add_route(name='dictionary_info',
Expand Down Expand Up @@ -159,6 +172,31 @@ def configure_routes(config):
config.add_route(name='perspective_outside',
pattern='perspective/{perspective_client_id}/{perspective_id}',
factory='lingvodoc.models.PerspectiveAcl')
# API #POST
# creates hash in metadata on objects
config.add_route(name='perspective_hash',
pattern='/dictionary/{dictionary_client_id}/{dictionary_object_id}/'
'perspective/{perspective_client_id}/{perspective_id}/hash',
factory='lingvodoc.models.PerspectiveAcl')

config.add_route(name='dangerous_perspectives_hash',
pattern='/perspectives/hash',
factory='lingvodoc.models.AdminAcl')
# API #GET && PUT && DELETE
# {<some_data_name>:{"type""<datatype>, "content":<content>},}
# for geo: {"location":{"type":"location", "content":{"lat":<lat>, "lng":<lng>}}}
# for info:{"info":{"type":"list",
# "content":[{"info":{"type":"blob",
# "content":{"client_id":<client_id>, "object_id":<object_id>}
# }
# },
# ]
# }
# }
config.add_route(name='perspective_meta',
pattern='/dictionary/{dictionary_client_id}/{dictionary_object_id}/'
'perspective/{perspective_client_id}/{perspective_id}/meta',
factory='lingvodoc.models.PerspectiveAcl')

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

# seems to be redundant
# not anymore
# API #GET
# no params, returns file
#config.add_route(name="get_user_blob",
# pattern="/blobs/{client_id}/{object_id}")
config.add_route(name="get_user_blob",
pattern="/blobs/{client_id}/{object_id}")
# API #GET
# no params, lists only own blobs
config.add_route(name="list_user_blobs",
pattern="/blobs/")
pattern="/blobs")

# TODO: LOCALES!
# API #GET && DELETE
Expand Down Expand Up @@ -302,8 +341,25 @@ def configure_routes(config):

# API #GET
# like
# perspective_client_id
# perspective_object_id
config.add_route(name='basic_search', pattern='/basic_search')

# API #POST
# {"searchstrings":[{"searchstring":<searchstring>, "entity_type":<entity_type>, "search_by_or":true/false},
# ],
# "perspectives":[{"client_id":<persp_client_id>,"object_id":<persp_object_id>},
# ]
# "adopted":True/False,
# "adopted_type":<entity_type_where_to_search_if_lexical_entry_is_adopted>,
# "count":True/False,
# "with_etimology":True/False}
config.add_route(name='advanced_search', pattern='/advanced_search')

# API #GET
# like
config.add_route(name='entity_metadata_search', pattern='/meta_search')

# API #GET
# like
config.add_route(name='basic_search_old', pattern='/basic_search_old')
Expand Down Expand Up @@ -506,6 +562,10 @@ def configure_routes(config):
# client_id = <client_id>
# Response example:
# {"id": <userid>, "login": <login>, "name": <name>, "intl_name": <international_name>, "userpic": <url_to_userpic>}
# #PUT
# {"client_id":<client_id> OR "user_id":<user_id>,
# "new_password": <new_password>, "old_password":<old_password>,
# "name":<name>, "birthday":<birthday>, "email":<email>, "about":<about>}
config.add_route(name='get_user_info', pattern='/user') # ready, not tested
# API #GET
# Returns translations for a list of words for current or default or fallback locale
Expand All @@ -520,6 +580,7 @@ def configure_routes(config):
# params:
# {"blob_client_id": <id>, "blob_object_id": <id>, "parent_client_id": <language_client_id>, "parent_object_id": <language_object_id>}
config.add_route(name='convert_dictionary', pattern='/convert')
config.add_route(name='convert_dictionary_check', pattern='/convert_check')


def main(global_config, **settings):
Expand Down
60 changes: 56 additions & 4 deletions lingvodoc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,12 @@ def find_by_translation_string(locale_id, translation_string):


def add_translation_to_translation_string(locale_id, translation, translation_string, client_id):
if not translation:
translation = translation_string

client = DBSession.query(Client).filter_by(id=client_id).first()
uets = DBSession.query(UserEntitiesTranslationString).filter_by(locale_id=locale_id,
translation_string=translation_string).first()
if not translation:
translation = translation_string
if not uets:
uets = UserEntitiesTranslationString(object_id=DBSession.query(UserEntitiesTranslationString).filter_by(client_id=client.id).count()+1,
client_id=client.id,
Expand Down Expand Up @@ -306,7 +307,7 @@ def set_translation(cls, request):
else:
req = request.json_body

translation = req.get('translation_string')
translation = None
if 'translation' in req:
translation = req['translation']
translation_string = req.get('translation_string')
Expand All @@ -320,7 +321,7 @@ def set_translation(cls, request):
return


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

def get_translation(cls, request):
return find_by_translation_string(find_locale_id(request), cls.translation_string)

def set_translation(self, request):
if type(request.json_body) == str:
req = json.loads(request.json_body)
else:
req = request.json_body

translation = None
if 'translation' in req:
translation = req['translation']
translation_string = req.get('translation_string')
if not translation_string:
if self.translation_string:
translation_string = self.translation_string
else:
return
client_id = request.authenticated_userid
locale_id = find_locale_id(request)
client = DBSession.query(Client).filter_by(id=client_id).first()
search_translation_string = self.translation_string
if not search_translation_string:
search_translation_string = translation_string
print('SHEEEET', search_translation_string)
uets = DBSession.query(UserEntitiesTranslationString).filter_by(locale_id=locale_id,
translation_string=search_translation_string).first()
if not translation:
translation = translation_string
if not uets:
uets = UserEntitiesTranslationString(object_id=DBSession.query(UserEntitiesTranslationString).filter_by(client_id=client.id).count()+1,
client_id=client.id,
locale_id=locale_id,
translation_string=translation_string,
translation=translation)
self.translation_string = translation_string
DBSession.add(uets)
DBSession.flush()
print('HEY, LISTEN! WTF')
else:
uets.translation_string = translation_string
self.translation_string = translation_string
uets.translation = translation
print('HEY, LISTEN!')
return


class Locale(Base, TableNameMixin, IdMixin, RelationshipMixin):
"""
Expand Down Expand Up @@ -384,6 +431,7 @@ class Dictionary(Base, TableNameMixin, CompositeIdMixin, RelationshipMixin, Tran
authors = Column(UnicodeText)
translation_string = Column(UnicodeText)
marked_for_deletion = Column(Boolean, default=False)
additional_metadata = Column(UnicodeText)
# about = Column(UnicodeText)


Expand All @@ -407,6 +455,7 @@ class DictionaryPerspective(Base, TableNameMixin, CompositeIdMixin, Relationship
is_template = Column(Boolean, default=False)
import_source = Column(UnicodeText)
import_hash = Column(UnicodeText)
additional_metadata = Column(UnicodeText)
# about = Column(UnicodeText)


Expand Down Expand Up @@ -558,6 +607,8 @@ def track(self, publish):
'marked_for_deletion': self.marked_for_deletion,
'locale_id': self.locale_id
}
if self.additional_metadata:
dictionary['additional_metadata'] = self.additional_metadata
children = recursive_content(self, publish)
if children:
dictionary['contains'] = children
Expand Down Expand Up @@ -799,6 +850,7 @@ def acl_by_groups(object_id, client_id, subject):
base_group = group.parent
if group.subject_override:
group_name = base_group.action + ":" + base_group.subject + ":" + str(group.subject_override)
group_name = base_group.action + ":" + base_group.subject + ":" + str(group.subject_override)
else:
group_name = base_group.action + ":" + base_group.subject \
+ ":" + str(group.subject_client_id) + ":" + str(group.subject_object_id)
Expand Down
Loading

0 comments on commit dab1f1c

Please sign in to comment.