Skip to content

Commit

Permalink
Merge pull request #852 from dotKom/rule-refactor
Browse files Browse the repository at this point in the history
Fixed so all rules are treated at the same time.
  • Loading branch information
melwil committed Sep 3, 2014
2 parents c184ce8 + 9a30a9a commit b510c58
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions apps/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,44 +339,26 @@ class RuleBundle(models.Model):
grade_rules = models.ManyToManyField(GradeRule, null=True, blank=True)
user_group_rules = models.ManyToManyField(UserGroupRule, null=True, blank=True)

def get_rule_strings(self):
def get_all_rules(self):
rules = []
for rule in self.field_of_study_rules.all():
rules.append(unicode(rule))
for rule in self.grade_rules.all():
rules.append(unicode(rule))
for rule in self.user_group_rules.all():
rules.append(unicode(rule))
rules.extend(self.field_of_study_rules.all())
rules.extend(self.grade_rules.all())
rules.extend(self.user_group_rules.all())
return rules

def get_rule_strings(self):
return map(lambda r: unicode(r), self.get_all_rules())

def satisfied(self, user, registration_start):

errors = []

if self.grade_rules:
for grade_rule in self.grade_rules.all():
response = grade_rule.satisfied(user, registration_start)
if response['status']:
return [response]
else:
errors.append(response)

if self.field_of_study_rules:
for fos_rule in self.field_of_study_rules.all():
response = fos_rule.satisfied(user, registration_start)
if response['status']:
return [response]
else:
errors.append(response)

if self.user_group_rules:
for user_group_rule in self.user_group_rules.all():
response = user_group_rule.satisfied(user, registration_start)
if response['status']:
return [response]
else:
errors.append(response)

for rule in self.get_all_rules():
response = rule.satisfied(user, registration_start)
if response['status']:
return [response]
else:
errors.append(response)

return errors

Expand Down

0 comments on commit b510c58

Please sign in to comment.