|
@@ -208,12 +208,34 @@ class Question(db.Model):
|
|
)
|
|
)
|
|
|
|
|
|
def has_voten(self, user_id):
|
|
def has_voten(self, user_id):
|
|
|
|
+ """Check if user has voted"""
|
|
for option in self.options:
|
|
for option in self.options:
|
|
if option.votes.filter(Vote.user_id == user_id).first():
|
|
if option.votes.filter(Vote.user_id == user_id).first():
|
|
return True
|
|
return True
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
+ def get_option(self, option):
|
|
|
|
+ """Get the pro option"""
|
|
|
|
+ return self.options.filter(Option.name == option).first()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def score(self):
|
|
|
|
+ """Get winning option from question"""
|
|
|
|
+ if self.combined_approval_voting:
|
|
|
|
+ pro_option = self.get_option('Voor')
|
|
|
|
+ pro_votes = pro_option.votes.count()
|
|
|
|
+ against_option = self.get_option('Tegen')
|
|
|
|
+ against_votes = against_option.votes.count()
|
|
|
|
+ return pro_votes - against_votes
|
|
|
|
+
|
|
|
|
+ higest = Option()
|
|
|
|
+ for option in self.options:
|
|
|
|
+ if higest.votes.count() < option.votes.count():
|
|
|
|
+ higest = option
|
|
|
|
+ return higest.name
|
|
|
|
+
|
|
|
|
+
|
|
class Option(db.Model):
|
|
class Option(db.Model):
|
|
"""Model for Option"""
|
|
"""Model for Option"""
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
id = db.Column(db.Integer, primary_key=True)
|