Skip to content
Snippets Groups Projects
Commit 3002d457 authored by Ben Adida's avatar Ben Adida
Browse files

added ability to distinguish teachers and students and do eligibility by grade

parent 1aeec1c4
Branches
No related tags found
No related merge requests found
......@@ -187,7 +187,7 @@ def can_create_election(request):
if helios.ADMIN_ONLY:
return user.admin_p
else:
return user != None
return user.can_create_election()
def user_can_feature_election(user, election):
if not user:
......
......@@ -242,3 +242,11 @@ def eligibility_category_id(constraint):
def pretty_eligibility(constraint):
return "Members of the Class of %s" % constraint['year']
#
# Election Creation
#
def can_create_election(user_id, user_info):
return True
......@@ -71,13 +71,14 @@ def get_user_info_after_auth(request):
user_name = "%s %s" % (response['data']['name']['first'], response['data']['name']['last'])
user_type = response['type']
user_district = response['data']['district']
user_grade = response['data'].get('grade', None)
print content
# watch out, response also contains email addresses, but not sure whether thsoe are verified or not
# so for email address we will only look at the id_token
return {'type' : 'clever', 'user_id': user_id, 'name': user_name , 'info': {"district": user_district, "type": user_type}, 'token': {'access_token': access_token}}
return {'type' : 'clever', 'user_id': user_id, 'name': user_name , 'info': {"district": user_district, "type": user_type, "grade": user_grade}, 'token': {'access_token': access_token}}
def do_logout(user):
"""
......@@ -97,8 +98,39 @@ def send_message(user_id, name, user_info, subject, body):
"""
pass
def check_constraint(constraint, user_info):
#
# eligibility
#
def check_constraint(constraint, user):
if not user.info.has_key('grade'):
return False
return constraint['grade'] == user.info['grade']
def generate_constraint(category, user):
"""
for eligibility
generate the proper basic data structure to express a constraint
based on the category string
"""
pass
return {'grade': category}
def list_categories(user):
return [{"id": str(g), "name": "Grade %d" % g} for g in range(3,13)]
def eligibility_category_id(constraint):
return constraint['grade']
def pretty_eligibility(constraint):
return "Grade %s" % constraint['grade']
#
# Election Creation
#
def can_create_election(user_id, user_info):
"""
Teachers only for now
"""
return user_info['type'] == 'teacher'
......@@ -116,3 +116,10 @@ def eligibility_category_id(constraint):
def pretty_eligibility(constraint):
return "Facebook users who are members of the \"%s\" group" % constraint['group']['name']
#
# Election Creation
#
def can_create_election(user_id, user_info):
return True
......@@ -82,3 +82,11 @@ def check_constraint(constraint, user_info):
for eligibility
"""
pass
#
# Election Creation
#
def can_create_election(user_id, user_info):
return True
......@@ -89,3 +89,10 @@ def send_notification(user_id, user_info, message):
pass
#
# Election Creation
#
def can_create_election(user_id, user_info):
return True
......@@ -65,3 +65,11 @@ def update_status(user_id, user_info, token, message):
def send_message(user_id, user_name, user_info, subject, body):
pass
#
# Election Creation
#
def can_create_election(user_id, user_info):
return True
......@@ -117,3 +117,11 @@ def send_message(user_id, user_name, user_info, subject, body):
email = user_id
name = user_name or user_info.get('name', email)
send_mail(subject, body, settings.SERVER_EMAIL, ["\"%s\" <%s>" % (name, email)], fail_silently=False)
#
# Election Creation
#
def can_create_election(user_id, user_info):
return True
......@@ -118,3 +118,10 @@ def follow_view(request):
return HttpResponseRedirect(reverse(after_intervention))
#
# Election Creation
#
def can_create_election(user_id, user_info):
return True
......@@ -52,3 +52,11 @@ def check_constraint(constraint, user_info):
for eligibility
"""
pass
#
# Election Creation
#
def can_create_election(user_id, user_info):
return True
......@@ -70,6 +70,16 @@ class User(models.Model):
return AUTH_SYSTEMS[self.user_type].STATUS_UPDATES
def can_create_election(self):
"""
Certain auth systems can choose to limit election creation
to certain users.
"""
if not AUTH_SYSTEMS.has_key(self.user_type):
return False
return AUTH_SYSTEMS[self.user_type].can_create_election(self.user_id, self.info)
def update_status_template(self):
if not self.can_update_status():
return None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment