break out individual editor methods for account_old_enough, enough_edits, and not_blocked.
@@ -275,8 +275,8 @@ class Editor(models.Model):
else:
return None
- @property
- def is_bundle_eligible(self, identity, global_userinfo):
+ @cached_property
+ def bundle_eligible(self, identity, global_userinfo):
# prev_editcount is set to 0 for the first 30 days, all edits get counted here for new users.
recent_edits = self.wp_editcount - self.prev_editcount
@@ -286,24 +286,7 @@ class Editor(models.Model):
else:
return False
- def _is_user_valid(self, identity, global_userinfo):
- """
- Check for the eligibility criteria laid out in the terms of service.
- To wit, users must:
- * Have >= 500 edits
- * Be active for >= 6 months
- * Not be blocked on any projects
-
- Note that we won't prohibit signups or applications on this basis.
- Coordinators have discretion to approve people who are near the cutoff.
- """
- # If, for some reason, this information hasn't come through,
- # default to user not being valid.
- if not global_userinfo:
- return False
- # Check: >= 500 edits
- enough_edits = int(global_userinfo["editcount"]) >= 500
-
+ def account_old_enough(self, identity, global_userinfo):
# Check: registered >= 6 months ago
# Try oauth registration date first. If it's not valid,
# try the global_userinfo date
@@ -313,12 +296,37 @@ class Editor(models.Model):
reg_date = datetime.strptime(
global_userinfo["registration"], "%Y-%m-%dT%H:%M:%SZ"
).date()
- account_old_enough = datetime.today().date() - timedelta(days=182) >= reg_date
+ return datetime.today().date() - timedelta(days=182) >= reg_date
+ def enough_edits(self, global_userinfo):
+ # If, for some reason, this information hasn't come through,
+ # default to user not being valid.
+ if not global_userinfo:
+ return False
+ # Check: >= 500 edits
+ return int(global_userinfo["editcount"]) >= 500
+
+ def not_blocked(self, identity):
# Check: not blocked
- not_blocked = identity["blocked"] == False
+ return identity["blocked"] == False
- if enough_edits and account_old_enough and not_blocked:
+ def _is_user_valid(self, identity, global_userinfo):
+ """
+ Check for the eligibility criteria laid out in the terms of service.
+ To wit, users must:
+ * Have >= 500 edits
+ * Be active for >= 6 months
+ * Not be blocked on any projects
+
+ Note that we won't prohibit signups or applications on this basis.
+ Coordinators have discretion to approve people who are near the cutoff.
+ """
+
+ if (
+ self.enough_edits(global_userinfo)
+ and self.account_old_enough(identity, global_userinfo)
+ and self.not_blocked(identity)
+ ):
return True
else:
logger.info(
