diff --git a/app/corpora/events.py b/app/corpora/events.py index 42e3249d..f02e1ac3 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -7,6 +7,7 @@ from ..events import connected_sessions from ..models import Corpus, User import cqi import math +from app import logger ''' @@ -36,14 +37,27 @@ def corpus_analysis_get_meta_data(corpus_id): db_corpus = Corpus.query.get(corpus_id) # TODO: Check if current user is actually the creator of the corpus? metadata = {} - metadata["corpus_name"] = db_corpus.title - metadata["corpus_description"] = db_corpus.description - metadata["corpus_creation_date"] = db_corpus.creation_date.isoformat() + metadata['corpus_name'] = db_corpus.title + metadata['corpus_description'] = db_corpus.description + metadata['corpus_creation_date'] = db_corpus.creation_date.isoformat() + metadata['corpus_last_edited_date'] = db_corpus.last_edited_date.isoformat() # get meta data from corpus in cqp server client = corpus_analysis_clients.get(request.sid) client_corpus = client.corpora.get('CORPUS') - metadata["corpus_properties"] = client_corpus.attrs['properties'] - # metadata["corpus_properties"] = client.api.corpus_properties('CORPUS') + metadata['corpus_properties'] = client_corpus.attrs['properties'] + metadata['corpus_size_tokens'] = client_corpus.attrs['size'] + + texts = {} + text_attr = client_corpus.structural_attributes.get('text') + for text_id in range(0, (text_attr.attrs['size'])): + texts[text_id] = {} + logger.warning('Text ID: {}'.format(text_id)) + struct_attrs = client_corpus.structural_attributes.list(filters={'part_of': text_attr}) + for struct_attr in struct_attrs: + logger.warning(struct_attr) + for struct_id in list(range(0, struct_attr.attrs['size'])): + logger.warning(struct_attr.values_by_ids([struct_id])) + payload = metadata response = {'code': 200, 'desc': 'Corpus meta data', 'msg': 'OK', 'payload': payload} socketio.emit('corpus_analysis_send_meta_data', response, room=request.sid) diff --git a/app/corpora/tasks.py b/app/corpora/tasks.py index c1ad6d83..ec7cd817 100644 --- a/app/corpora/tasks.py +++ b/app/corpora/tasks.py @@ -1,3 +1,4 @@ +from datetime import datetime from .. import db from ..decorators import background from ..models import Corpus, CorpusFile @@ -45,6 +46,7 @@ def build_corpus(corpus_id, *args, **kwargs): master_element_tree.write(output_file, xml_declaration=True, encoding='utf-8') corpus.status = 'submitted' + corpus.last_edited_date = datetime.utcnow() db.session.commit() diff --git a/app/models.py b/app/models.py index f5f31003..ccb54f7e 100644 --- a/app/models.py +++ b/app/models.py @@ -443,6 +443,7 @@ class Corpus(db.Model): user_id = db.Column(db.Integer, db.ForeignKey('users.id')) # Fields creation_date = db.Column(db.DateTime(), default=datetime.utcnow) + last_edited_date = db.Column(db.DateTime(), default=datetime.utcnow) description = db.Column(db.String(255)) status = db.Column(db.String(16)) title = db.Column(db.String(32)) diff --git a/app/static/js/nopaque.Results.js b/app/static/js/nopaque.Results.js index 28d63ff0..2358ec18 100644 --- a/app/static/js/nopaque.Results.js +++ b/app/static/js/nopaque.Results.js @@ -80,9 +80,11 @@ class ResultsJSON { class MetaDataJSON { // Sets empty object structure. Also usefull to delete old results. init() { - this["corpus_name"] = ""; - this["corpus_description"] = ""; - this["corpus_creation_date"] = ""; - this["corpus_properties"] = ""; + this["corpus_name"] = undefined; + this["corpus_description"] = undefined; + this["corpus_creation_date"] = undefined; + this["corpus_last_edited_date"] = undefined; + this["corpus_properties"] = undefined; + this["corpus_size_tokens"] = undefined; } } \ No newline at end of file diff --git a/app/static/js/nopaque.callbacks.js b/app/static/js/nopaque.callbacks.js index 3ccfd0f4..4341472c 100644 --- a/app/static/js/nopaque.callbacks.js +++ b/app/static/js/nopaque.callbacks.js @@ -2,7 +2,9 @@ function recvMetaData(payload) { results.metaDataJSON.corpus_name = payload.corpus_name; results.metaDataJSON.corpus_description = payload.corpus_description; results.metaDataJSON.corpus_creation_date = payload.corpus_creation_date; + results.metaDataJSON.corpus_last_edited_date = payload.corpus_last_edited_date; results.metaDataJSON.corpus_properties = payload.corpus_properties; + results.metaDataJSON.corpus_size_tokens = payload.corpus_size_tokens; console.log(results.metaDataJSON); } diff --git a/app/templates/admin/user.html.j2 b/app/templates/admin/user.html.j2 index f6825976..69bb6c58 100644 --- a/app/templates/admin/user.html.j2 +++ b/app/templates/admin/user.html.j2 @@ -15,7 +15,7 @@
  • Username: {{ user.username }}
  • Email: {{ user.email }}
  • ID: {{ user.id }}
  • -
  • Member sinse: {{ user.member_since.strftime('%m/%d/%Y, %H:%M:%S %p') }}
  • +
  • Member since: {{ user.member_since.strftime('%m/%d/%Y, %H:%M:%S %p') }}
  • Confirmed status: {{ user.confirmed }}
  • Last seen: {{ user.last_seen.strftime('%m/%d/%Y, %H:%M:%S %p') }}
  • Role ID: {{ user.role_id }}
  • diff --git a/app/templates/corpora/corpus.html.j2 b/app/templates/corpora/corpus.html.j2 index fb3f73ab..b07cad0a 100644 --- a/app/templates/corpora/corpus.html.j2 +++ b/app/templates/corpora/corpus.html.j2 @@ -31,6 +31,12 @@ +
    +
    + + +
    +
    diff --git a/migrations/versions/68772b6560c3_.py b/migrations/versions/68772b6560c3_.py new file mode 100644 index 00000000..ee1228d3 --- /dev/null +++ b/migrations/versions/68772b6560c3_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: 68772b6560c3 +Revises: 49a42c69e523 +Create Date: 2020-04-28 07:47:40.495698 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '68772b6560c3' +down_revision = '49a42c69e523' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('corpora', sa.Column('last_edited_date', sa.DateTime(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('corpora', 'last_edited_date') + # ### end Alembic commands ###