-
Notifications
You must be signed in to change notification settings - Fork 8
Activity Page Design
yongwen edited this page Mar 28, 2011
·
8 revisions
Activity Page Code Walkthrough
- data model
- admin
- data flow
- header
- scoreboard
- Smart grid game
- grid.html
- parameters
- categories : categories_list = __get_categories(user) code:
## return the category list with the tasks info
def __get_categories(user):
categories = Category.objects.all()
for cat in categories:
task_list = []
for task in cat.activitybase_set.all():
task.is_unlock = is_unlock(user, task)
task.is_pau = is_pau(user, task)
task_list.append(task)
cat.task_list = task_list
return categories
- Task page
- task.html
- parameters:
"task" : activity object
"type" : is event or not
"pau" : is pau
"approved" : is approved
"form" : input form for the task
"question" : activity question if any
"member_all" : number of person completed the task
"member_floor": number of person of the floor completed the task
- Events
- events.html
- parameters:
- events = get_available_events(user)
def get_available_events(user):
"""Retrieves only the events that a user can participate in."""
events = Activity.objects.exclude(
activitymember__user=user,
).filter(
type='event',
pub_date__lte=datetime.date.today(),
expire_date__gte=datetime.date.today(),
).order_by("priority", "title")
return events # Filters out inactive activities.
- Unlocking (in init.py)
def is_unlock(user, task):
"""determine the unlock status of a task by dependency expression"""
expr = task.depends_on
if expr == None or expr == "":
return False
expr = expr.replace("completedAllOf(", "completedAllOf(user,")
expr = expr.replace("completedSomeOf(", "completedSomeOf(user,")
expr = expr.replace("completed(", "completed(user,")
expr = expr.replace("afterPublished(", "afterPublished('"+task.name+"'")
allow_dict = {'completedAllOf':completedAllOf,
'completedSomeOf':completedSomeOf,
'completed':completed,
'afterPublished':afterPublished,
'True':True,
'False':False,
'user':user,
}
return eval(expr, {"__builtins__":None}, allow_dict)
- Tests