diff --git a/app/corpora/views.py b/app/corpora/views.py index 3a06b204..e7862b17 100644 --- a/app/corpora/views.py +++ b/app/corpora/views.py @@ -113,7 +113,6 @@ def add_corpus_file(corpus_id): corpus=corpus, dir=dir, filename=filename, publishing_year=add_corpus_file_form.publishing_year.data, title=add_corpus_file_form.title.data) - corpus_file.insert_metadata() db.session.add(corpus_file) db.session.commit() flash('Corpus file added!') diff --git a/app/models.py b/app/models.py index 5c08da59..4987fb4c 100644 --- a/app/models.py +++ b/app/models.py @@ -2,6 +2,7 @@ from flask import current_app from flask_login import UserMixin, AnonymousUserMixin from itsdangerous import BadSignature, TimedJSONWebSignatureSerializer from werkzeug.security import generate_password_hash, check_password_hash +import xml.etree.ElementTree as ET from . import db from . import login_manager from datetime import datetime @@ -410,6 +411,18 @@ class CorpusFile(db.Model): title = db.Column(db.String(64)) corpus_id = db.Column(db.Integer, db.ForeignKey('corpora.id')) + def __init__(self, **kwargs): + super(CorpusFile, self).__init__(**kwargs) + file = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'], + self.dir, + self.filename) + element_tree = ET.parse(file) + text_node = element_tree.find('text') + text_node.set('author', self.author) + text_node.set('publishing_year', str(self.publishing_year)) + text_node.set('title', self.title) + element_tree.write(file) + def delete(self): logger = logging.getLogger(__name__) logger.warning('Called CorpusFile.delete') @@ -424,9 +437,6 @@ class CorpusFile(db.Model): db.session.delete(self) db.session.commit() - def insert_metadata(self): - pass - class Corpus(db.Model): """