Commits

Anonymous committed 44a1094

Shared tasklist can be viewed by the sharing user

  • Participants
  • Parent commits 01a1c58

Comments (0)

Files changed (1)

File taskhood/tasks/views.py

 #returns:
 # types - all available field types
 # user - current connected user
-# tasklist - 
+# tasklist - selected tasklist
 # tasklist_key - either the key entered originally, or the key generated for a new tasklist
 # tasks - a list of all the tasklist tasks
 # visible_columns - an ordered list of the visible columns
     check_types_existance()
     types = Type.all()
     user = users.get_current_user()
-    tasklist = get_tasklist_of_user(user, tasklist_key)
+    shared_task_lists = get_shared_task_lists(user)
+    tasklist = get_tasklist_of_user(user, tasklist_key, shared_task_lists)
     tasklist_key = tasklist.key()  #required when a new tasklist was created
     tasks = []   
     if (tasklist.created_by == user) or (user.email() in tasklist.shared_users_emails):
     (visible_columns, fields, all_columns_of_user) = get_tasklist_data(tasklist, user)
     (my_items, get_parameters) = search_filter_paginate(tasks, request)
     task_lists = TaskList.all().filter('created_by =', user)
-    shared_task_lists = get_shared_task_lists(user)
     return render_to_response("main.html", locals())
 
 def get_shared_task_lists(user):
         #user not connected to google account (User=None)
         #login to google account, main will create a default tasklist for him
         return HttpResponseRedirect(users.create_login_url("/main/%s" % 'None'))
-    
-def get_tasklist_of_user(user, tasklist_key):
-    if tasklist_key == "None" or not db.Key(tasklist_key) or db.get(tasklist_key).created_by != user:
+
+#returns a tasklist for the current user
+#if the tasklist key matches a tasklist that is owned
+#or shared with the user it is returned
+#otherwise the first tasklist belonging to the user is returned
+#if the user has no tasklist a default is created    
+def get_tasklist_of_user(user, tasklist_key, shared_task_lists):
+    tasklist = db.get(tasklist_key)
+    shared = False
+    for task_list in shared_task_lists:
+        if (tasklist.key() == task_list.key()):
+            shared=True
+    if tasklist_key == "None" or not db.Key(tasklist_key) or (tasklist.created_by != user and shared == False):
         if TaskList.all().filter('created_by =', user).count() == 0:
             t = TaskList(name='My Tasks', created_by=user, owner=user).put()
             v = VisibleColumns(tasklist=t, columns=['name', 'description', 'status', 'created_by', 'create_time'])
             tasklist = TaskList.all().filter('name =', 'My Tasks').filter('created_by =', user)[0]
         else:
             tasklist = TaskList.all().filter('created_by =', user)[0]
-        tasklist_key = tasklist.key()
-    else: 
-        tasklist = db.get(tasklist_key)
-#    logging.info('tasklist_key')
-#    logging.info(tasklist_key)
+        tasklist_key = tasklist.key() 
     return tasklist   
         
 def create_task(request, tasklist_key):