mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Merge branch 'public-corpus' of gitlab.ub.uni-bielefeld.de:sfb1288inf/nopaque into public-corpus
This commit is contained in:
commit
5881588160
@ -32,6 +32,16 @@ from .forms import (
|
||||
)
|
||||
|
||||
|
||||
@bp.route('/fake-add')
|
||||
@login_required
|
||||
def fake_add():
|
||||
pjentsch = User.query.filter_by(username='pjentsch').first()
|
||||
alice = Corpus.query.filter_by(title='Alice in Wonderland').first()
|
||||
pjentsch.follow_corpus(alice)
|
||||
db.session.commit()
|
||||
return ''
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/is_public/enable', methods=['POST'])
|
||||
@login_required
|
||||
def enable_corpus_is_public(corpus_id):
|
||||
|
@ -205,6 +205,8 @@ class Role(HashidMixin, db.Model):
|
||||
if self.has_permission(x.value)
|
||||
]
|
||||
}
|
||||
if backrefs:
|
||||
pass
|
||||
if relationships:
|
||||
json_serializeable['users'] = {
|
||||
x.hashid: x.to_json_serializeable(relationships=True)
|
||||
@ -256,6 +258,27 @@ class Token(db.Model):
|
||||
self.access_expiration = datetime.utcnow()
|
||||
self.refresh_expiration = datetime.utcnow()
|
||||
|
||||
def to_json_serializeable(self, backrefs=False, relationships=False):
|
||||
json_serializeable = {
|
||||
'id': self.hashid,
|
||||
'access_token': self.access_token,
|
||||
'access_expiration': (
|
||||
None if self.access_expiration is None
|
||||
else f'{self.access_expiration.isoformat()}Z'
|
||||
),
|
||||
'refresh_token': self.refresh_token,
|
||||
'refresh_expiration': (
|
||||
None if self.refresh_expiration is None
|
||||
else f'{self.refresh_expiration.isoformat()}Z'
|
||||
)
|
||||
}
|
||||
if backrefs:
|
||||
json_serializeable['user'] = \
|
||||
self.user.to_json_serializeable(backrefs=True)
|
||||
if relationships:
|
||||
pass
|
||||
return json_serializeable
|
||||
|
||||
@staticmethod
|
||||
def clean():
|
||||
"""Remove any tokens that have been expired for more than a day."""
|
||||
@ -288,6 +311,11 @@ class Avatar(HashidMixin, FileMixin, db.Model):
|
||||
'id': self.hashid,
|
||||
**self.file_mixin_to_json_serializeable()
|
||||
}
|
||||
if backrefs:
|
||||
json_serializeable['user'] = \
|
||||
self.user.to_json_serializeable(backrefs=True)
|
||||
if relationships:
|
||||
pass
|
||||
return json_serializeable
|
||||
|
||||
|
||||
@ -328,6 +356,13 @@ class CorpusFollowerAssociation(HashidMixin, db.Model):
|
||||
'corpus': self.corpus.to_json_serializeable(),
|
||||
'follower': self.follower.to_json_serializeable()
|
||||
}
|
||||
if backrefs:
|
||||
json_serializeable['corpus'] = \
|
||||
self.corpus.to_json_serializeable(backrefs=True)
|
||||
json_serializeable['follower'] = \
|
||||
self.follower.to_json_serializeable(backrefs=True)
|
||||
if relationships:
|
||||
pass
|
||||
return json_serializeable
|
||||
|
||||
|
||||
@ -620,7 +655,6 @@ class User(HashidMixin, UserMixin, db.Model):
|
||||
def is_following_corpus(self, corpus):
|
||||
return corpus in self.followed_corpora
|
||||
|
||||
|
||||
def to_json_serializeable(self, backrefs=False, relationships=False, filter_by_privacy_settings=False):
|
||||
json_serializeable = {
|
||||
'id': self.hashid,
|
||||
@ -628,9 +662,9 @@ class User(HashidMixin, UserMixin, db.Model):
|
||||
'email': self.email,
|
||||
'last_seen': (
|
||||
None if self.last_seen is None
|
||||
else self.last_seen.strftime('%Y-%m-%d %H:%M')
|
||||
else f'{self.last_seen.isoformat()}Z'
|
||||
),
|
||||
'member_since': self.member_since.strftime('%Y-%m-%d'),
|
||||
'member_since': f'{self.member_since.isoformat()}Z',
|
||||
'username': self.username,
|
||||
'full_name': self.full_name,
|
||||
'about_me': self.about_me,
|
||||
@ -804,6 +838,8 @@ class TesseractOCRPipelineModel(FileMixin, HashidMixin, db.Model):
|
||||
if backrefs:
|
||||
json_serializeable['user'] = \
|
||||
self.user.to_json_serializeable(backrefs=True)
|
||||
if relationships:
|
||||
pass
|
||||
return json_serializeable
|
||||
|
||||
|
||||
@ -930,7 +966,10 @@ class SpaCyNLPPipelineModel(FileMixin, HashidMixin, db.Model):
|
||||
**self.file_mixin_to_json_serializeable()
|
||||
}
|
||||
if backrefs:
|
||||
json_serializeable['user'] = self.user.to_json_serializeable(backrefs=True)
|
||||
json_serializeable['user'] = \
|
||||
self.user.to_json_serializeable(backrefs=True)
|
||||
if relationships:
|
||||
pass
|
||||
return json_serializeable
|
||||
|
||||
|
||||
@ -989,6 +1028,8 @@ class JobInput(FileMixin, HashidMixin, db.Model):
|
||||
if backrefs:
|
||||
json_serializeable['job'] = \
|
||||
self.job.to_json_serializeable(backrefs=True)
|
||||
if relationships:
|
||||
pass
|
||||
return json_serializeable
|
||||
|
||||
|
||||
@ -1053,6 +1094,8 @@ class JobResult(FileMixin, HashidMixin, db.Model):
|
||||
if backrefs:
|
||||
json_serializeable['job'] = \
|
||||
self.job.to_json_serializeable(backrefs=True)
|
||||
if relationships:
|
||||
pass
|
||||
return json_serializeable
|
||||
|
||||
|
||||
@ -1132,7 +1175,6 @@ class Job(HashidMixin, db.Model):
|
||||
raise e
|
||||
return job
|
||||
|
||||
|
||||
def delete(self):
|
||||
''' Delete the job and its inputs and results from the database. '''
|
||||
if self.status not in [JobStatus.COMPLETED, JobStatus.FAILED]: # noqa
|
||||
@ -1177,8 +1219,7 @@ class Job(HashidMixin, db.Model):
|
||||
'service_args': self.service_args,
|
||||
'service_version': self.service_version,
|
||||
'status': self.status.name,
|
||||
'title': self.title,
|
||||
'url': self.url
|
||||
'title': self.title
|
||||
}
|
||||
if backrefs:
|
||||
json_serializeable['user'] = \
|
||||
@ -1264,9 +1305,9 @@ class CorpusFile(FileMixin, HashidMixin, db.Model):
|
||||
def to_json_serializeable(self, backrefs=False, relationships=False):
|
||||
json_serializeable = {
|
||||
'id': self.hashid,
|
||||
'url': self.url,
|
||||
'address': self.address,
|
||||
'author': self.author,
|
||||
'description': self.description,
|
||||
'booktitle': self.booktitle,
|
||||
'chapter': self.chapter,
|
||||
'editor': self.editor,
|
||||
@ -1285,6 +1326,8 @@ class CorpusFile(FileMixin, HashidMixin, db.Model):
|
||||
if backrefs:
|
||||
json_serializeable['corpus'] = \
|
||||
self.corpus.to_json_serializeable(backrefs=True)
|
||||
if relationships:
|
||||
pass
|
||||
return json_serializeable
|
||||
|
||||
|
||||
@ -1489,22 +1532,22 @@ def ressource_after_insert_handler(mapper, connection, ressource):
|
||||
socketio.emit('PATCH', jsonpatch, room=room)
|
||||
|
||||
|
||||
# @db.event.listens_for(CorpusFollowerAssociation, 'after_insert')
|
||||
# def corpus_follower_association_after_insert_handler(mapper, connection, ressource):
|
||||
# corpus_owner_hashid = ressource.corpus.user.hashid
|
||||
# corpus_hashid = hashids.encode(ressource.corpus_id)
|
||||
# follower_hashid = hashids.encode(ressource.follower_id)
|
||||
# value = ressource.to_json_serializeable()
|
||||
# # Send a PATCH to the corpus owner
|
||||
# jsonpatch_path = f'/users/{corpus_owner_hashid}/corpora/{corpus_hashid}/corpus_follower_associations/{ressource.hashid}'
|
||||
# jsonpatch = [{'op': 'add', 'path': jsonpatch_path, 'value': value}]
|
||||
# room = f'/users/{corpus_owner_hashid}'
|
||||
# socketio.emit('PATCH', jsonpatch, room=room)
|
||||
# # Send a PATCH to the follower
|
||||
# jsonpatch_path = f'/users/{follower_hashid}/corpus_follower_associations/{ressource.hashid}'
|
||||
# jsonpatch = [{'op': 'add', 'path': jsonpatch_path, 'value': value}]
|
||||
# room = f'/users/{follower_hashid}'
|
||||
# socketio.emit('PATCH', jsonpatch, room=room)
|
||||
@db.event.listens_for(CorpusFollowerAssociation, 'after_insert')
|
||||
def corpus_follower_association_after_insert_handler(mapper, connection, ressource):
|
||||
corpus_owner_hashid = ressource.corpus.user.hashid
|
||||
corpus_hashid = hashids.encode(ressource.corpus_id)
|
||||
follower_hashid = hashids.encode(ressource.follower_id)
|
||||
value = ressource.to_json_serializeable()
|
||||
# Send a PATCH to the corpus owner
|
||||
jsonpatch_path = f'/users/{corpus_owner_hashid}/corpora/{corpus_hashid}/corpus_follower_associations/{ressource.hashid}'
|
||||
jsonpatch = [{'op': 'add', 'path': jsonpatch_path, 'value': value}]
|
||||
room = f'/users/{corpus_owner_hashid}'
|
||||
socketio.emit('PATCH', jsonpatch, room=room)
|
||||
# Send a PATCH to the follower
|
||||
jsonpatch_path = f'/users/{follower_hashid}/corpus_follower_associations/{ressource.hashid}'
|
||||
jsonpatch = [{'op': 'add', 'path': jsonpatch_path, 'value': value}]
|
||||
room = f'/users/{follower_hashid}'
|
||||
socketio.emit('PATCH', jsonpatch, room=room)
|
||||
|
||||
|
||||
@db.event.listens_for(Corpus, 'after_update')
|
||||
|
@ -175,8 +175,8 @@ class CorpusFollowerList extends ResourceList {
|
||||
for (let operation of filteredPatch) {
|
||||
switch(operation.op) {
|
||||
case 'add': {
|
||||
// let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/corpus_follower_associations/([A-Za-z0-9]*)$`);
|
||||
// if (re.test(operation.path)) {this.add(operation.value);}
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/corpus_follower_associations/([A-Za-z0-9]*)$`);
|
||||
if (re.test(operation.path)) {this.add(operation.value);}
|
||||
break;
|
||||
}
|
||||
case 'remove': {
|
||||
|
@ -43,7 +43,8 @@ class ResourceList {
|
||||
}
|
||||
|
||||
add(resources, callback) {
|
||||
let values = resources.map((resource) => {
|
||||
let tmp = Array.isArray(resources) ? resources : [resources];
|
||||
let values = tmp.map((resource) => {
|
||||
return this.mapResourceToValue(resource);
|
||||
});
|
||||
this.listjs.add(values, (items) => {
|
||||
|
Loading…
Reference in New Issue
Block a user