mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Fix follow corpus mechanics
This commit is contained in:
parent
1d85e96d3a
commit
0609e2cd72
@ -378,8 +378,7 @@ class CorpusFollowerRole(HashidMixin, db.Model):
|
||||
# Relationships
|
||||
corpus_follower_associations = db.relationship(
|
||||
'CorpusFollowerAssociation',
|
||||
back_populates='role',
|
||||
lazy='dynamic'
|
||||
back_populates='role'
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
@ -481,11 +480,9 @@ class CorpusFollowerAssociation(HashidMixin, db.Model):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
if self.role is None:
|
||||
self.role = CorpusFollowerRole.query.filter_by(default=True).first()
|
||||
|
||||
def __repr__(self):
|
||||
return f'<CorpusFollowerAssociation {self.follower.__repr__()} ~ {self.corpus.__repr__()}>'
|
||||
return f'<CorpusFollowerAssociation {self.follower.__repr__()} ~ {self.role.__repr__()} ~ {self.corpus.__repr__()}>'
|
||||
|
||||
def to_json_serializeable(self, backrefs=False, relationships=False):
|
||||
json_serializeable = {
|
||||
@ -545,8 +542,7 @@ class User(HashidMixin, UserMixin, db.Model):
|
||||
)
|
||||
followed_corpora = association_proxy(
|
||||
'corpus_follower_associations',
|
||||
'corpus',
|
||||
creator=lambda c: CorpusFollowerAssociation(corpus=c)
|
||||
'corpus'
|
||||
)
|
||||
jobs = db.relationship(
|
||||
'Job',
|
||||
@ -778,9 +774,11 @@ class User(HashidMixin, UserMixin, db.Model):
|
||||
self.profile_privacy_settings = 0
|
||||
#endregion Profile Privacy settings
|
||||
|
||||
def follow_corpus(self, corpus):
|
||||
if not self.is_following_corpus(corpus):
|
||||
self.followed_corpora.append(corpus)
|
||||
def follow_corpus(self, corpus, role=None):
|
||||
if role is None:
|
||||
r = CorpusFollowerRole.query.filter_by(default=True).first()
|
||||
cfa = CorpusFollowerAssociation(corpus=corpus, role=r, follower=self)
|
||||
db.session.add(cfa)
|
||||
|
||||
def unfollow_corpus(self, corpus):
|
||||
if self.is_following_corpus(corpus):
|
||||
@ -1499,8 +1497,7 @@ class Corpus(HashidMixin, db.Model):
|
||||
)
|
||||
followers = association_proxy(
|
||||
'corpus_follower_associations',
|
||||
'follower',
|
||||
creator=lambda u: CorpusFollowerAssociation(followers=u)
|
||||
'follower'
|
||||
)
|
||||
user = db.relationship('User', back_populates='corpora')
|
||||
# "static" attributes
|
||||
|
Loading…
Reference in New Issue
Block a user