mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-03 20:02:47 +00:00 
			
		
		
		
	Add function to dynamically add followers to CorpusFollowerList
This commit is contained in:
		@@ -31,6 +31,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):
 | 
			
		||||
 
 | 
			
		||||
@@ -1489,22 +1489,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) => {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user