mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 02:44:18 +00:00
Insert metadata to corpus file in constructor
This commit is contained in:
parent
8ef6d3a04b
commit
69387ee183
@ -113,7 +113,6 @@ def add_corpus_file(corpus_id):
|
|||||||
corpus=corpus, dir=dir, filename=filename,
|
corpus=corpus, dir=dir, filename=filename,
|
||||||
publishing_year=add_corpus_file_form.publishing_year.data,
|
publishing_year=add_corpus_file_form.publishing_year.data,
|
||||||
title=add_corpus_file_form.title.data)
|
title=add_corpus_file_form.title.data)
|
||||||
corpus_file.insert_metadata()
|
|
||||||
db.session.add(corpus_file)
|
db.session.add(corpus_file)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Corpus file added!')
|
flash('Corpus file added!')
|
||||||
|
@ -2,6 +2,7 @@ from flask import current_app
|
|||||||
from flask_login import UserMixin, AnonymousUserMixin
|
from flask_login import UserMixin, AnonymousUserMixin
|
||||||
from itsdangerous import BadSignature, TimedJSONWebSignatureSerializer
|
from itsdangerous import BadSignature, TimedJSONWebSignatureSerializer
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
from . import db
|
from . import db
|
||||||
from . import login_manager
|
from . import login_manager
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -410,6 +411,18 @@ class CorpusFile(db.Model):
|
|||||||
title = db.Column(db.String(64))
|
title = db.Column(db.String(64))
|
||||||
corpus_id = db.Column(db.Integer, db.ForeignKey('corpora.id'))
|
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):
|
def delete(self):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.warning('Called CorpusFile.delete')
|
logger.warning('Called CorpusFile.delete')
|
||||||
@ -424,9 +437,6 @@ class CorpusFile(db.Model):
|
|||||||
db.session.delete(self)
|
db.session.delete(self)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
def insert_metadata(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Corpus(db.Model):
|
class Corpus(db.Model):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user