app/soc/modules/ghop/views/models/task.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Sat, 03 Oct 2009 22:17:58 +0530
changeset 3002 2c5e9cd4ba4d
parent 2981 8a99de852dc2
child 3017 6689a4c8f02e
permissions -rw-r--r--
Fix the deadline counter to start counting only after Task claim is accepted. Deadline counter used to start when the task was claimed to be requested. This commit fixes that.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
#
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
#
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
#
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
#
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
"""Views for Tasks.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
"""
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
__authors__ = [
2942
996e64ba2db8 Removed undefined order argument in GHOP Task View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2893
diff changeset
    21
    '"Madhusudan.C.S" <madhusudancs@gmail.com>',
996e64ba2db8 Removed undefined order argument in GHOP Task View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2893
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
  ]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
import datetime
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
import time
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
from google.appengine.ext import db
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    30
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    31
from django import forms
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    32
from django import http
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    33
from django.utils.translation import ugettext
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    34
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
from soc.logic import cleaning
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
from soc.logic import dicts
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
from soc.logic.models import host as host_logic 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
from soc.logic.models import student as student_logic
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
from soc.logic.models import user as user_logic
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
from soc.views import helper
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
from soc.views import out_of_band
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
from soc.views.helper import decorators
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
from soc.views.helper import dynaform
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
from soc.views.helper import lists
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
from soc.views.helper import params as params_helper
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
from soc.views.helper import requests
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    47
from soc.views.helper import redirects
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    48
from soc.views.helper import responses
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    49
from soc.views.helper import widgets
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
from soc.views.models import base
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    51
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
from soc.modules.ghop.logic import cleaning as ghop_cleaning
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
from soc.modules.ghop.logic.models import comment as ghop_comment_logic
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
from soc.modules.ghop.logic.models import mentor as ghop_mentor_logic
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    55
from soc.modules.ghop.logic.models import organization as ghop_org_logic
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    57
from soc.modules.ghop.logic.models import program as ghop_program_logic
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    58
from soc.modules.ghop.logic.models import task as ghop_task_logic
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    59
from soc.modules.ghop.models import task as ghop_task_model
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    60
from soc.modules.ghop.views.helper import access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
from soc.modules.ghop.views.helper import redirects as ghop_redirects
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    62
from soc.modules.ghop.views.models import organization as ghop_org_view
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
from soc.modules.ghop.tasks import task_update
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
import soc.modules.ghop.logic.models.task
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
class View(base.View):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    69
  """View methods for the Tasks.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
  """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    71
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
  DEF_AWAITING_REG_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
      'The task is open but you cannot claim this task since you '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
      'have not completed the student signup after finishing your '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
      'first task.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
  DEF_CAN_EDIT_TASK_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    78
      'The task can be edited by clicking on the edit link '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    79
      'next to the title above.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
  DEF_MAX_TASK_LIMIT_MSG_FMT = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
      'The task is open but you cannot claim this task since you '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
      'either have already claimed %d task.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
  DEF_SIGNIN_TO_COMMENT_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
      '<a href=%s>Sign in</a> to perform any action or comment on '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    87
      'this task.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
  DEF_STUDENT_SIGNUP_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
      'You have successfully completed this task. Sign up as a student '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
      'before you proceed further.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    92
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    93
  DEF_TASK_CLAIMED_BY_YOU_MSG = ugettext( 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    94
      'This task has been claimed by you!')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    95
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    96
  DEF_TASK_CLAIMED_BY_STUDENT_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
      'This task has been claimed by a student!')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    98
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    99
  DEF_TASK_CLAIMED_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   100
      'The task is already claimed and the work is in progress.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   101
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   102
  DEF_TASK_CLAIM_REQUESTED_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
      'A student has requested to claim this task. Accept or '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   104
      'Reject the request.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   106
  DEF_TASK_CLOSED_MSG = ugettext('The task is closed.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   108
  DEF_TASK_CMPLTD_BY_YOU_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
      'You have successfully completed this task!')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   110
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   111
  DEF_TASK_NO_MORE_SUBMIT_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   112
      'You have submitted the work to this task, but deadline has passed '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   113
      'You cannot submit any more work until your mentor extends the '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   114
      'deadline.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   115
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   116
  DEF_TASK_MENTOR_REOPENED_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   117
      'The task has been reopened.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   118
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   119
  DEF_TASK_NEEDS_REVIEW_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   120
      'Student has submitted his work for this task! It needs review.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   121
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   122
  DEF_TASK_OPEN_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   123
      'This task is open. If you are GHOP student, you can claim it!')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   124
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   125
  DEF_TASK_REOPENED_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   126
      'This task has been reopened. If you are a GHOP student, '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   127
      'you can clam it!')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   128
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   129
  DEF_TASK_REQ_CLAIMED_BY_YOU_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   130
      'You have requested to claim this task!')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   131
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   132
  DEF_TASK_UNPUBLISHED_MSG = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   133
      'The task is not yet published. It can be edited by clicking on '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   134
      'the edit button below.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   135
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   136
  DEF_WS_MSG_FMT = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   137
      '(To see the work submitted <a href=#ws%d>click here</a>.)')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   138
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   139
  def __init__(self, params=None):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   140
    """Defines the fields and methods required for the task View class
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   141
    to provide the user with the necessary views.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   142
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   143
    Params:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   144
      params: a dict with params for this View
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   145
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   146
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   147
    rights = access.GHOPChecker(params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   148
    # TODO: create and suggest_task don't need access checks which use state
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   149
    # also feels like roles are being checked twice?
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   150
    rights['create'] = [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   151
        ('checkCanOrgAdminOrMentorEdit', ['scope_path', True]),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   152
        ('checkRoleAndStatusForTask',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   153
            [['ghop/org_admin'], ['active'], 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   154
            []])]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   155
    rights['edit'] = [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   156
        ('checkCanOrgAdminOrMentorEdit', ['scope_path', False]),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   157
        ('checkRoleAndStatusForTask',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   158
            [['ghop/org_admin'], ['active'], 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   159
            ['Unapproved', 'Unpublished', 'Open']])]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   160
    rights['delete'] = ['checkIsDeveloper']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   161
    rights['show'] = ['checkStatusForTask']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   162
    rights['list_org_tasks'] = [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   163
        ('checkCanOrgAdminOrMentorEdit', ['scope_path', False])]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   164
    rights['suggest_task'] = [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   165
        ('checkCanOrgAdminOrMentorEdit', ['scope_path', True]),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   166
        ('checkRoleAndStatusForTask',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   167
            [['ghop/org_admin', 'ghop/mentor'], ['active'], 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   168
            []])]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   169
    rights['search'] = ['allow']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   170
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   171
    new_params = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   172
    new_params['logic'] = soc.modules.ghop.logic.models.task.logic
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   173
    new_params['rights'] = rights
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   174
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   175
    new_params['name'] = "Task"
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   176
    new_params['module_name'] = "task"
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   177
    new_params['sidebar_grouping'] = 'Tasks'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   178
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   179
    new_params['module_package'] = 'soc.modules.ghop.views.models'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   180
    new_params['url_name'] = 'ghop/task'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   181
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   182
    new_params['scope_view'] = ghop_org_view
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   183
    new_params['scope_redirect'] = redirects.getCreateRedirect
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   184
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   185
    new_params['list_heading'] = 'modules/ghop/task/list/heading.html' 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   186
    new_params['list_row'] = 'modules/ghop/task/list/row.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   187
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   188
    new_params['extra_dynaexclude'] = ['task_type', 'mentors', 'user',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   189
                                       'student', 'program', 'status', 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   190
                                       'deadline', 'created_by',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   191
                                       'created_on', 'modified_by',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   192
                                       'modified_on', 'history',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   193
                                       'link_id', 'difficulty']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   194
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   195
    patterns = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   196
    patterns += [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   197
        (r'^%(url_name)s/(?P<access_type>suggest_task)/%(scope)s$',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   198
        '%(module_package)s.%(module_name)s.suggest_task',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   199
        'Mentors suggest %(name)s'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   200
        (r'^%(url_name)s/(?P<access_type>suggest_task)/%(key_fields)s$',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   201
        '%(module_package)s.%(module_name)s.suggest_task',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   202
        'Mentors edit a %(name)s'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   203
        (r'^%(url_name)s/(?P<access_type>list_org_tasks)/%(scope)s$',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   204
        '%(module_package)s.%(module_name)s.list_org_tasks',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   205
        'List Organization %(name)s'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   206
        (r'^%(url_name)s/(?P<access_type>search)/'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   207
         '(?P<scope_path>%(ulnp)s)/%(lnp)s$',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   208
        '%(module_package)s.%(module_name)s.search',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   209
        'Search for %(name)ss'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   210
        ]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   211
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   212
    new_params['extra_django_patterns'] = patterns
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   213
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   214
    new_params['create_dynafields'] = [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   215
        {'name': 'arbit_tags',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   216
         'base': forms.fields.CharField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   217
         'label': 'Arbitrary Tags',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   218
         'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   219
         'group': ugettext('Tags'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   220
         'help_text': ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   221
             'Enter arbitrary Tags for this task separated by comma.\n'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   222
             '<b>Note:</b> Tag names are case sensitive. If the tag is same '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   223
             'as the program mandated tag, it will be considered as a '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   224
             'mandatory tag.')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   225
         },
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
        ]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   227
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   228
    new_params['create_extra_dynaproperties'] = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   229
        'description': forms.fields.CharField(required=True,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   230
            widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   231
        'scope_path': forms.CharField(widget=forms.HiddenInput,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   232
            required=True),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   233
        'time_to_complete': forms.IntegerField(min_value=1,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   234
                                               required=True),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   235
        'clean_description': cleaning.clean_html_content('description'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   236
        'clean_arbit_tags': cleaning.str2set('arbit_tags'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   237
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   238
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   239
    new_params['edit_extra_dynaproperties'] = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   240
        'link_id': forms.CharField(widget=forms.HiddenInput)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   241
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   242
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   243
    new_params['public_template'] = 'modules/ghop/task/public.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   244
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   245
    params = dicts.merge(params, new_params, sub_merge=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   246
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   247
    super(View, self).__init__(params=params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   248
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   249
    # holds the base form for the task creation and editing
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   250
    self._params['base_create_form'] = self._params['create_form']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   251
    self._params['base_edit_form'] = self._params['edit_form'] 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   252
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   253
    # extend create and edit form for org admins
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   254
    dynafields = [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   255
        {'name': 'mentors_list',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   256
         'required': True,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   257
         'base': forms.fields.CharField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   258
         'label': 'Assign mentors',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   259
         'help_text': 'Assign mentors to this task by '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   260
             'giving their link_ids separated by comma.',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   261
         },
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   262
        {'name': 'published',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   263
         'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   264
         'initial': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   265
         'base': forms.fields.BooleanField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   266
         'label': 'Publish the task',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   267
         'help_text': ugettext('By ticking this box, the task will be'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   268
                               'made public and can be claimed by students.'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   269
         }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   270
        ]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   271
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   272
    dynaproperties = params_helper.getDynaFields(dynafields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   273
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   274
    dynaproperties['clean_mentors_list'] = ghop_cleaning.cleanMentorsList(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   275
        'mentors_list')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   276
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   277
    create_form = dynaform.extendDynaForm(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   278
        dynaform=self._params['create_form'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   279
        dynaproperties=dynaproperties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   280
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   281
    self._params['create_form'] = create_form
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   282
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   283
    edit_form = dynaform.extendDynaForm(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   284
        dynaform=self._params['edit_form'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   285
        dynaproperties=dynaproperties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   286
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   287
    self._params['edit_form'] = edit_form
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   288
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   289
    # create the comment form
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   290
    dynafields = [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   291
        {'name': 'comment',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   292
         'base': forms.CharField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   293
         'widget': widgets.FullTinyMCE(attrs={'rows': 10, 'cols': 40}),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   294
         'label': 'Comment',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   295
         'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   296
         'example_text': 'Comment is optional.<br/>'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   297
             'Choose an appropriate Action below and Save your '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   298
             'changes.<br /><br />Caution, you will not be able '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   299
             'to edit your comment!',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   300
         },
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   301
         ]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   302
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   303
    dynaproperties = params_helper.getDynaFields(dynafields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   304
    dynaproperties['clean_comment'] = cleaning.clean_html_content('comment')
2893
1adc6a815c71 Several style and import fixes regarding the GHOP module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2885
diff changeset
   305
    dynaproperties['clean'] = ghop_cleaning.cleanTaskComment(
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   306
        'comment', 'action', 'work_submission')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   307
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   308
    comment_form = dynaform.newDynaForm(dynamodel=None, 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   309
        dynabase=helper.forms.BaseForm, dynainclude=None, 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   310
        dynaexclude=None, dynaproperties=dynaproperties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   311
    self._params['comment_form'] = comment_form
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   312
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   313
  def _getTagsForProgram(self, form_name, params, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   314
    """Extends form dynamically from difficulty levels in program entity.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   315
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   316
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   317
     form_name: the Form entry in params to extend
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   318
     params: the params for the view
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   319
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   320
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   321
    # obtain program_entity using scope_path which holds 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   322
    # the org_entity key_name
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   323
    org_entity = ghop_org_logic.logic.getFromKeyName(kwargs['scope_path'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   324
    program_entity = ghop_program_logic.logic.getFromKeyName(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   325
        org_entity.scope_path)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   326
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   327
    # get a list difficulty levels stored for the program entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   328
    tds = ghop_task_model.TaskDifficultyTag.get_by_scope(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   329
        program_entity) 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   330
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   331
    difficulties = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   332
    for td in tds:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   333
      difficulties.append((td.tag, td.tag))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   334
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   335
    # get a list of task type tags stored for the program entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   336
    tts = ghop_task_model.TaskTypeTag.get_by_scope(program_entity) 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   337
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   338
    type_tags = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   339
    for tt in tts:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   340
      type_tags.append((tt.tag, tt.tag))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   341
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   342
    # create the difficultly level field containing the choices 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   343
    # defined in the program entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   344
    dynafields = [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   345
        {'name': 'difficulty',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   346
         'base': forms.ChoiceField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   347
         'label': 'Difficulty level',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   348
         'required': True,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   349
         'passthrough': ['initial', 'required', 'choices',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   350
                         'label', 'help_text'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   351
         'choices': difficulties,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   352
         'group': ugettext('Tags'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   353
         'help_text': ugettext('Difficulty Level of this task.'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   354
         },
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   355
         {'name': 'type_tags',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   356
         'base': forms.MultipleChoiceField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   357
         'label': 'Task Types',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   358
         'required': True,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   359
         'passthrough': ['initial', 'required', 'choices',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   360
                         'label', 'help_text'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   361
         'choices': type_tags,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   362
         'group': ugettext('Tags'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   363
         'help_text': ugettext('Task Type tags mandated by the program. You '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   364
                               'must select one or more of them.'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   365
         },
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   366
       ]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   367
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   368
    dynaproperties = params_helper.getDynaFields(dynafields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   369
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   370
    extended_form = dynaform.extendDynaForm(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   371
        dynaform=params[form_name],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   372
        dynaproperties=dynaproperties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   373
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   374
    return extended_form
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   375
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   376
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   377
  def create(self, request, access_type,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   378
             page_name=None, params=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   379
    """Replaces the create Form with the dynamic one.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   380
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   381
    For args see base.View.create().
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   382
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   383
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   384
    params = dicts.merge(params, self._params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   385
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   386
    # extend create_form to include difficulty levels
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   387
    params['create_form'] = self._getTagsForProgram(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   388
        'create_form', params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   389
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   390
    return super(View, self).create(request, 'allow', page_name=page_name,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   391
                                    params=params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   392
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   393
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   394
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   395
  def edit(self, request, access_type,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   396
           page_name=None, params=None, seed=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   397
    """See base.View.edit().
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   398
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   399
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   400
    logic = params['logic']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   401
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   402
    context = helper.responses.getUniversalContext(request)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   403
    helper.responses.useJavaScript(context, params['js_uses_all'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   404
    context['page_name'] = page_name
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   405
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   406
    try:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   407
      entity = logic.getFromKeyFieldsOr404(kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   408
    except out_of_band.Error, error:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   409
      msg = self.DEF_CREATE_NEW_ENTITY_MSG_FMT % {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   410
          'entity_type_lower' : params['name'].lower(),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   411
          'entity_type' : params['name'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   412
          'create' : params['missing_redirect']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   413
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   414
      error.message_fmt = error.message_fmt + msg
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   415
      return helper.responses.errorResponse(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   416
          error, request, context=context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   417
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   418
    user_account = user_logic.logic.getForCurrentAccount()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   419
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   420
    filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   421
        'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   422
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   423
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   424
    # extend edit_form to include difficulty levels
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   425
    params['edit_form'] = self._getTagsForProgram(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   426
        'edit_form', params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   427
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   428
    org_admin_entities = ghop_org_admin_logic.logic.getForFields(filter) 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   429
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   430
    if entity and entity.status == 'Unapproved':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   431
      approval_req = True 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   432
      for org_admin_entity in org_admin_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   433
        if org_admin_entity.key().name() == entity.created_by.key().name():
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   434
          approval_req = False
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   435
          break
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   436
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   437
      if approval_req:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   438
        dynafields = [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   439
            {'name': 'approved',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   440
             'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   441
             'initial': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   442
             'base': forms.fields.BooleanField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   443
             'label': 'Approve the task',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   444
             'help_text': 'By ticking this box, the task will be'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   445
                 'will be approved for publishing.',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   446
            }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   447
            ]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   448
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   449
        dynaproperties = params_helper.getDynaFields(dynafields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   450
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   451
        edit_form = dynaform.extendDynaForm(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   452
            dynaform=params['edit_form'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   453
            dynaproperties=dynaproperties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   454
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   455
        params['edit_form'] = edit_form
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   456
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   457
    if request.method == 'POST':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   458
      return self.editPost(request, entity, context, params=params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   459
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   460
      return self.editGet(request, entity, context, params=params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   461
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   462
  def _editGet(self, request, entity, form):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   463
    """See base.View._editGet().
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   464
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   465
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   466
    if entity.task_type:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   467
      form.fields['type_tags'].initial = entity.tags_string(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   468
          entity.task_type, ret_list=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   469
    if entity.arbit_tag:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   470
      form.fields['arbit_tags'].initial = entity.tags_string(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   471
          entity.arbit_tag)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   472
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   473
    if entity.difficulty:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   474
      form.fields['difficulty'].initial = entity.tags_string( 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   475
          entity.difficulty)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   476
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   477
    if entity.mentors and 'mentors_list' in form.fields:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   478
      mentor_entities = db.get(entity.mentors)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   479
      mentors_list = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   480
      for mentor in mentor_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   481
        mentors_list.append(mentor.link_id)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   482
      form.fields['mentors_list'].initial = ', '.join(mentors_list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   483
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   484
    form.fields['link_id'].initial = entity.link_id
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   485
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   486
    # checks if the task is already approved or not and sets
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   487
    # the form approved field
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   488
    if 'approved' in form.fields:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   489
      if entity.status == 'Unapproved':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   490
        form.fields['approved'].initial = False
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   491
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   492
        form.fields['approved'].initial = True
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   493
 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   494
    # checks if the task is already published or not and sets
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   495
    # the form published field 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   496
    if 'published' in form.fields:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   497
      if entity.status == 'Unapproved' or entity.status == 'Unpublished':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   498
        form.fields['published'].initial = False
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   499
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   500
        form.fields['published'].initial = True
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   501
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   502
    return super(View, self)._editGet(request, entity, form)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   503
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   504
  def _editPost(self, request, entity, fields):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   505
    """See base._editPost().
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   506
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   507
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   508
    super(View, self)._editPost(request, entity, fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   509
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   510
    # TODO: this method can be made more clear, it seems a bit of a mess
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   511
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   512
    if not entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   513
      program_entity = fields['scope'].scope
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   514
      fields['program'] = program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   515
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   516
      program_entity = entity.program 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   517
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   518
    user_account = user_logic.logic.getForCurrentAccount()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   519
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   520
    filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   521
        'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   522
        'status': 'active'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   523
        }
2978
2b3c39483f6f Fixes the problem of GHOP Task editing after it is created.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2942
diff changeset
   524
    if not entity:
2b3c39483f6f Fixes the problem of GHOP Task editing after it is created.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2942
diff changeset
   525
      filter['scope'] = fields['scope']
2b3c39483f6f Fixes the problem of GHOP Task editing after it is created.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2942
diff changeset
   526
    else:
2b3c39483f6f Fixes the problem of GHOP Task editing after it is created.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2942
diff changeset
   527
      filter['scope'] = entity.program
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   528
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   529
    role_entity = ghop_org_admin_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   530
        filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   531
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   532
    if role_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   533
      # this user can publish/approve the task
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   534
      if fields.get('approved') and fields.get('published'):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   535
        fields['status'] = 'Open'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   536
      elif not fields.get('approved'):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   537
        fields['status'] = 'Unapproved'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   538
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   539
        fields['status'] = 'Unpublished'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   540
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   541
      fields['mentors'] = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   542
      if fields.get('mentors_list'):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   543
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   544
        for mentor_link_id in fields['mentors_list']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   545
          properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   546
              'scope_path': fields['scope_path'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   547
              'link_id': mentor_link_id,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   548
              }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   549
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   550
          mentor_entity = ghop_mentor_logic.logic.getFromKeyFields(properties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   551
          fields['mentors'].append(mentor_entity.key())
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   552
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   553
      role_entity = ghop_mentor_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   554
          filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   555
      if not entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   556
        # creating a new task
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   557
        fields['status'] = 'Unapproved'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   558
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   559
    # explicitly change the last_modified_on since the content has been edited
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   560
    fields['modified_on'] = datetime.datetime.now()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   561
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   562
    if not entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   563
      fields['link_id'] = 't%i' % (int(time.time()*100))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   564
      fields['modified_by'] = role_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   565
      fields['created_by'] = role_entity 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   566
      fields['created_on'] = datetime.datetime.now()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   567
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   568
      fields['link_id'] = entity.link_id
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   569
      fields['modified_by'] = role_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   570
      if 'status' not in fields:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   571
        fields['status'] = entity.status
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   572
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   573
    fields['difficulty'] = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   574
        'tags': fields['difficulty'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   575
        'scope': program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   576
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   577
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   578
    fields['task_type'] = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   579
        'tags': fields['type_tags'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   580
        'scope': program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   581
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   582
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   583
    fields['arbit_tag'] = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   584
        'tags': fields['arbit_tags'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   585
        'scope': program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   586
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   587
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   588
    return
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   589
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   590
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   591
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   592
  def suggestTask(self, request, access_type, page_name=None, 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   593
                  params=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   594
    """View used to allow mentors to create or edit a task. 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   595
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   596
    Tasks created by mentors must be approved by org admins
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   597
    before they are published.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   598
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   599
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   600
    params = dicts.merge(params, self._params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   601
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   602
    if 'link_id' in kwargs:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   603
      # extend create_form to include difficulty levels
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   604
      params['mentor_form'] = self._getTagsForProgram(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   605
          'base_edit_form', params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   606
      try:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   607
        entity = self._logic.getFromKeyFieldsOr404(kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   608
      except out_of_band.Error, error:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   609
        return helper.responses.errorResponse(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   610
            error, request, template=params['error_public'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   611
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   612
      # extend create_form to include difficulty levels
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   613
      params['mentor_form'] = self._getTagsForProgram(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   614
          'base_create_form', params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   615
      entity = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   616
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   617
    context = helper.responses.getUniversalContext(request)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   618
    helper.responses.useJavaScript(context, params['js_uses_all'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   619
    context['page_name'] = page_name
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   620
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   621
    if request.method == 'POST':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   622
      return self.suggestTaskPost(request, context,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   623
                                  params, entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   624
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   625
      return self.suggestTaskGet(request, context,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   626
                                 params, entity, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   627
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   628
  def suggestTaskPost(self, request, context, params, entity):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   629
    """Handles the POST request for the suggest task view.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   630
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   631
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   632
    form = params['mentor_form'](request.POST)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   633
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   634
    if not form.is_valid():
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   635
      return self._constructResponse(request, None, context, form, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   636
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   637
    _, fields = helper.forms.collectCleanedFields(form)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   638
    # TODO: this non-standard view shouldn't call _editPost but its own method
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   639
    self._editPost(request, entity, fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   640
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   641
    logic = params['logic']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   642
    if entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   643
      entity = logic.updateEntityProperties(entity, fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   644
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   645
      entity = logic.updateOrCreateFromFields(fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   646
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   647
    page_params = params['edit_params']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   648
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   649
    redirect = ghop_redirects.getSuggestTaskRedirect(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   650
        entity, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   651
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   652
    return http.HttpResponseRedirect(redirect)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   653
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   654
  def suggestTaskGet(self, request, context, params, entity, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   655
    """Handles the GET request for the suggest task view.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   656
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   657
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   658
    if entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   659
      # populate form with the existing entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   660
      form = params['mentor_form'](instance=entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   661
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   662
      self._editGet(request, entity, form)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   663
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   664
      form = params['mentor_form']()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   665
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   666
    return self._constructResponse(request, entity, context, form, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   667
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   668
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   669
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   670
  def listOrgTasks(self, request, access_type,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   671
                   page_name=None, params=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   672
    """See base.View.list()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   673
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   674
    if request.method == 'POST':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   675
      return self.listOrgTasksPost(request, params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   676
    else: # request.method == 'GET'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   677
      return self.listOrgTasksGet(request, page_name, params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   678
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   679
  def listOrgTasksPost(self, request, params, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   680
    """Handles the POST request for the list tasks view.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   681
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   682
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   683
    # update the status of task entities that have been approved
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   684
    # and published
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   685
    task_entities = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   686
    for key_name, published in request.POST.items():
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   687
      task_entity = ghop_task_logic.logic.getFromKeyName(key_name)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   688
      if task_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   689
        task_entity.status = 'Open'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   690
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   691
        task_entities.append(task_entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   692
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   693
    # bulk update the task_entities
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   694
    # TODO: Have to be replaced by Task Queue APIs later
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   695
    db.put(task_entities)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   696
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   697
    # redirect to the same page
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   698
    return http.HttpResponseRedirect('')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   699
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   700
  def listOrgTasksGet(self, request, page_name, params, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   701
    """Handles the GET request for the list tasks view.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   702
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   703
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   704
    from soc.modules.ghop.views.helper import list_info as list_info_helper
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   705
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   706
    org_entity =  ghop_org_logic.logic.getFromKeyNameOr404(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   707
        kwargs['scope_path'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   708
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   709
    contents = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   710
    context = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   711
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   712
    user_account = user_logic.logic.getForCurrentAccount()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   713
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   714
    fields = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   715
        'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   716
        'scope': org_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   717
        'status': 'active'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   718
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   719
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   720
    up_params = params.copy()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   721
    # give the capability to approve tasks for the org_admins
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   722
    if ghop_org_admin_logic.logic.getForFields(fields, unique=True):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   723
      up_params['list_template'] = 'modules/ghop/task/approve/approve.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   724
      up_params['list_heading'] = 'modules/ghop/task/approve/heading.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   725
      up_params['list_row'] = 'modules/ghop/task/approve/row.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   726
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   727
    up_params['list_action'] = (redirects.getPublicRedirect,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   728
                                up_params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   729
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   730
    up_params['list_description'] = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   731
       'List of Unapproved or Unpublished tasks')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   732
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   733
    filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   734
        'scope': org_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   735
        'status': ['Unapproved', 'Unpublished'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   736
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   737
2942
996e64ba2db8 Removed undefined order argument in GHOP Task View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2893
diff changeset
   738
    up_list = lists.getListContent(request, up_params, filter, idx=0,
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   739
                                   need_content=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   740
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   741
    if up_list:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   742
      up_mentors_list = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   743
      for task_entity in up_list['data']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   744
        up_mentors_list[task_entity.key()] = db.get(task_entity.mentors)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   745
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   746
      up_list['info'] = (list_info_helper.getTasksInfo(up_mentors_list), None)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   747
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   748
      contents.append(up_list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   749
      context['up_list'] = True
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   750
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   751
    ap_params = up_params.copy()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   752
    ap_params['list_template'] = 'soc/models/list.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   753
    ap_params['list_heading'] = 'modules/ghop/task/list/heading.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   754
    ap_params['list_row'] = 'modules/ghop/task/list/row.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   755
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   756
    ap_params['list_action'] = (redirects.getPublicRedirect,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   757
                                ap_params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   758
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   759
    ap_params['list_description'] = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   760
       'List of published tasks')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   761
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   762
    filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   763
        'scope': org_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   764
        'status': ['Open', 'Reopened', 'ClaimRequested', 'Claimed',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   765
            'ActionNeeded', 'Closed', 'AwaitingRegistration', 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   766
            'NeedsWork', 'NeedsReview'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   767
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   768
2942
996e64ba2db8 Removed undefined order argument in GHOP Task View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2893
diff changeset
   769
    ap_list = lists.getListContent(request, ap_params, filter, idx=1,
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   770
                                   need_content=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   771
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   772
    if ap_list:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   773
      ap_mentors_list = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   774
      for task_entity in ap_list['data']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   775
        ap_mentors_list[task_entity.key()] = db.get(task_entity.mentors)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   776
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   777
      ap_list['info'] = (list_info_helper.getTasksInfo(ap_mentors_list), None)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   778
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   779
      contents.append(ap_list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   780
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   781
    # call the _list method from base to display the list
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   782
    return self._list(request, up_params, contents, page_name, context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   783
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   784
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   785
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   786
  def public(self, request, access_type,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   787
             page_name=None, params=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   788
    """See base.View.public().
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   789
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   790
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   791
    # create default template context for use with any templates
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   792
    context = helper.responses.getUniversalContext(request)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   793
    helper.responses.useJavaScript(context, params['js_uses_all'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   794
    context['page_name'] = page_name
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   795
    entity = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   796
    logic = params['logic']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   797
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   798
    try:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   799
      entity, comment_entities, ws_entities = (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   800
          logic.getFromKeyFieldsWithCWSOr404(kwargs))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   801
    except out_of_band.Error, error:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   802
      return helper.responses.errorResponse(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   803
          error, request, template=params['error_public'], context=context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   804
2981
8a99de852dc2 Fixed Task public view to always call the update method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2978
diff changeset
   805
    # because we are not sure if the Task API has called this for us we do it
8a99de852dc2 Fixed Task public view to always call the update method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2978
diff changeset
   806
    entity, comment_entity = ghop_task_logic.logic.updateTaskStatus(entity)
8a99de852dc2 Fixed Task public view to always call the update method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2978
diff changeset
   807
    if comment_entity:
8a99de852dc2 Fixed Task public view to always call the update method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2978
diff changeset
   808
      comment_entities.append(comment_entity)
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   809
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   810
    context['entity'] = entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   811
    context['entity_key_name'] = entity.key().id_or_name() 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   812
    context['entity_type'] = params['name']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   813
    context['entity_type_url'] = params['url_name']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   814
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   815
    user_account = user_logic.logic.getForCurrentAccount()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   816
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   817
    # get some entity specific context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   818
    self.updatePublicContext(context, entity, comment_entities,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   819
                             ws_entities, user_account, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   820
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   821
    validation = self._constructActionsList(context, entity, 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   822
                                            user_account, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   823
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   824
    context = dicts.merge(params['context'], context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   825
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   826
    if request.method == 'POST':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   827
      return self.publicPost(request, context, params, entity, 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   828
                             user_account, validation, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   829
    else: # request.method == 'GET'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   830
      return self.publicGet(request, context, params, entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   831
                            user_account, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   832
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   833
  def publicPost(self, request, context, params, entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   834
                 user_account=None, validation=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   835
    """Handles the POST request for the entity's public page.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   836
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   837
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   838
        entity: the task entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   839
        rest: see base.View.public()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   840
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   841
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   842
    from soc.modules.ghop.logic.models import student as ghop_student_logic
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   843
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   844
    form = params['comment_form'](request.POST)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   845
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   846
    if not form.is_valid():
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   847
      template = params['public_template']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   848
      context['comment_form'] = form
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   849
      return self._constructResponse(request, entity, context,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   850
                                     form, params, template=template)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   851
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   852
    _, fields = helper.forms.collectCleanedFields(form)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   853
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   854
    changes = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   855
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   856
    action = fields['action']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   857
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   858
    properties = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   859
    ws_properties = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   860
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   861
    # TODO: this can be separated into several methods that handle the changes
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   862
    if validation == 'claim_request' and action == 'request':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   863
      properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   864
          'status': 'ClaimRequested',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   865
          'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   866
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   867
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   868
      st_filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   869
          'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   870
          'scope': entity.program,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   871
          'status': 'active'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   872
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   873
      student_entity = ghop_student_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   874
          st_filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   875
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   876
      if student_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   877
        properties['student'] = student_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   878
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   879
      changes.extend([ugettext('User-Student'), 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   880
                      ugettext('Action-Claim Requested'), 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   881
                      ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   882
                      ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   883
    elif (validation == 'claim_withdraw' or 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   884
        validation == 'needs_review') and action == 'withdraw':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   885
      properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   886
          'user': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   887
          'student': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   888
          'status': 'Reopened',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   889
          'deadline': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   890
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   891
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   892
      changes.extend([ugettext('User-Student'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   893
                      ugettext('Action-Withdrawn'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   894
                      ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   895
                      ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   896
    elif validation == 'needs_review' and action == 'needs_review':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   897
      properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   898
          'status': 'NeedsReview',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   899
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   900
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   901
      changes.extend([
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   902
          ugettext('User-Student'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   903
          ugettext('Action-Submitted work and Requested for review'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   904
          ugettext('Status-%s' % (properties['status']))])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   905
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   906
      ws_properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   907
          'parent': entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   908
          'link_id': 't%i' % (int(time.time()*100)),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   909
          'scope_path': entity.key().name(),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   910
          'scope': entity.scope,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   911
          'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   912
          'information': fields['comment'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   913
          'url_to_work': fields['work_submission'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   914
          'submitted_on': datetime.datetime.now(),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   915
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   916
    elif validation == 'accept_claim':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   917
      if action == 'accept':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   918
        deadline = datetime.datetime.now() + datetime.timedelta(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   919
            hours=entity.time_to_complete)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   920
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   921
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   922
            'status': 'Claimed',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   923
            'deadline': deadline,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   924
            }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   925
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   926
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   927
                        ugettext('Action-Claim Accepted'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   928
                        ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   929
                        ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   930
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   931
        task_update.spawnUpdateTask(entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   932
      if action == 'reject':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   933
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   934
            'user': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   935
            'student': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   936
            'status': 'Reopened',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   937
            'deadline': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   938
            }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   939
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   940
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   941
                        ugettext('Action-Claim Rejected'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   942
                        ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   943
                        ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   944
    elif validation == 'close':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   945
      if action == 'needs_work':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   946
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   947
            'status': 'NeedsWork',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   948
            }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   949
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   950
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   951
                        ugettext('Action-Requested more work'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   952
                        ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   953
                        ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   954
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   955
        if fields['extended_deadline'] > 0:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   956
          deadline = entity.deadline + datetime.timedelta(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   957
              hours=fields['extended_deadline'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   958
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   959
          properties['deadline'] = deadline
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   960
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   961
          changes.append(ugettext('DeadlineExtendedBy-%d hrs to %s' % (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   962
              fields['extended_deadline'], deadline.strftime(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   963
                  '%d %B %Y, %H :%M'))))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   964
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   965
          task_update.spawnUpdateTask(entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   966
        else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   967
          changes.append(ugettext('NoDeadlineExtensionGiven'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   968
      elif action == 'reopened':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   969
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   970
          'user': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   971
          'student': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   972
          'status': 'Reopened',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   973
          'deadline': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   974
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   975
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   976
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   977
                        ugettext('Action-Reopened'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   978
                        ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   979
                        ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   980
      elif action == 'closed':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   981
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   982
            'deadline': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   983
            }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   984
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   985
        if entity.student:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   986
          properties['status'] = 'Closed'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   987
        else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   988
          properties['status'] = 'AwaitingRegistration'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   989
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   990
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   991
                        ugettext('Action-Closed the task'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   992
                        ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   993
                        ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   994
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   995
    comment_properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   996
        'parent': entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   997
        'scope_path': entity.key().name(),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   998
        'created_by': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   999
        'changes': changes,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1000
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1001
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1002
    if ws_properties:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1003
      comment_properties['content'] = self.DEF_WS_MSG_FMT
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1004
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1005
      comment_properties['content'] = fields['comment']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1006
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1007
    ghop_task_logic.logic.updateEntityPropertiesWithCWS(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1008
        entity, properties, comment_properties, ws_properties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1009
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1010
    # redirect to the same page
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1011
    return http.HttpResponseRedirect('')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1012
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1013
  def publicGet(self, request, context, params, entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1014
                user_account, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1015
    """Handles the GET request for the entity's public page.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1016
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1017
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1018
        entity: the task entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1019
        rest see base.View.public()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1020
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1021
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1022
    context['comment_form'] = params['comment_form']()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1023
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1024
    template = params['public_template']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1025
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1026
    return responses.respond(request, template, context=context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1027
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1028
  def updatePublicContext(self, context, entity, comment_entities,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1029
                          ws_entities, user_account, params):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1030
    """Updates the context for the public page with information.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1031
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1032
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1033
      context: the context that should be updated
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1034
      entity: a task used to set context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1035
      user_account: user entity of the logged in user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1036
      params: dict with params for the view using this context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1037
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1038
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1039
    mentor_entities = db.get(entity.mentors)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1040
    mentors_str = ""
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1041
    for mentor in mentor_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1042
      mentors_str += mentor.name() + ", "
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1043
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1044
    if mentors_str:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1045
      context['mentors_str'] = mentors_str[:-2]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1046
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1047
      context['mentors_str'] = "Not Assigned" 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1048
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1049
    context['difficulty_str'] = entity.tags_string(entity.difficulty)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1050
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1051
    context['task_type_str'] = entity.tags_string(entity.task_type)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1052
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1053
    if entity.deadline:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1054
      # TODO: it should be able to abuse Django functionality for this
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1055
      ttc = entity.deadline - datetime.datetime.now()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1056
      (ttc_min, ttc_hour) = ((ttc.seconds / 60), (ttc.seconds / 3600))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1057
      if ttc_min >= 60:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1058
        ttc_min = ttc_min % 60
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1059
      if ttc_hour > 1:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1060
        if ttc_min == 0:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1061
          ttc_str = '%d hours' % (ttc_hour)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1062
        else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1063
          ttc_str = '%d:%02d hours' % (ttc_hour, ttc_min)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1064
        if ttc.days == 1:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1065
          ttc_str = '%d day, %s' % (ttc.days, ttc_str)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1066
        elif ttc.days > 1:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1067
          ttc_str = '%d days, %s' % (ttc.days, ttc_str)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1068
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1069
        ttc_str = '%d mins' % (ttc_min)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1070
      context['time_to_complete'] = ttc_str
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1071
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1072
      if entity.status == 'NeedsReview':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1073
        context['time_to_complete'] = 'No Time Left'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1074
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1075
        context['time_to_complete'] = '%d hours' % (entity.time_to_complete)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1076
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1077
    context['comments'] = comment_entities
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1078
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1079
    context['work_submissions'] = ws_entities
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1080
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1081
  def _constructActionsList(self, context, entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1082
                            user_account, params):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1083
    """Constructs a list of actions for the task page and extends
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1084
    the comment form with this list.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1085
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1086
    This method also returns the validation used by POST method to 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1087
    validate the user input data.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1088
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1089
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1090
      context: the context that should be updated
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1091
      entity: a task used to set context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1092
      user_account: user entity of the logged in user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1093
      params: dict with params for the view using this context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1094
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1095
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1096
    # variable that holds what kind of validation this user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1097
    # and task combination pass.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1098
    validation = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1099
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1100
    # The following header messages are shown for non-logged in
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1101
    # general public, logged in public and the student.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1102
    if entity.status is 'Closed':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1103
      context['header_msg'] = self.DEF_TASK_CLOSED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1104
      validation = 'closed'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1105
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1106
    if entity.status == 'Open':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1107
      context['header_msg'] = self.DEF_TASK_OPEN_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1108
    elif entity.status == 'Reopened':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1109
      context['header_msg'] = self.DEF_TASK_REOPENED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1110
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1111
    if user_account:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1112
      actions = [('noaction', 'Comment without action')]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1113
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1114
      # if the user is logged give him the permission to claim
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1115
      # the task only if he none of program host, org admin or mentor
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1116
      filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1117
          'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1118
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1119
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1120
      host_entity = host_logic.logic.getForFields(filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1121
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1122
      filter['scope_path'] = entity.scope_path
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1123
      org_admin_entity = ghop_org_admin_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1124
          filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1125
      mentor_entity = ghop_mentor_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1126
          filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1127
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1128
      if host_entity or org_admin_entity or mentor_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1129
        validation, mentor_actions = self._constructMentorActions(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1130
            context, entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1131
        actions += mentor_actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1132
        if entity.status in ['Unapproved', 'Unpublished', 'Open']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1133
          if host_entity or org_admin_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1134
            context['edit_link'] = redirects.getEditRedirect(entity, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1135
          elif mentor_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1136
            context['suggest_link'] = ghop_redirects.getSuggestTaskRedirect(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1137
                entity, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1138
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1139
        validation, student_actions = self._constructStudentActions(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1140
            context, entity, user_account)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1141
        actions += student_actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1142
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1143
      # create the difficultly level field containing the choices 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1144
      # defined in the program entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1145
      dynafields = [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1146
          {'name': 'action',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1147
           'base': forms.ChoiceField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1148
           'label': 'Action',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1149
           'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1150
           'passthrough': ['initial', 'required', 'choices'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1151
           'choices': actions,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1152
           },
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1153
         ]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1154
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1155
      if validation == 'needs_review':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1156
        dynafields.append(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1157
            {'name': 'work_submission',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1158
             'base': forms.URLField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1159
             'label': 'Submit Work',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1160
             'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1161
             'help_text': 'Provide a link to your work in this box. '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1162
                 'Please use the comment box if you need to explain '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1163
                 'of your work.',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1164
             })
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1165
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1166
      if validation == 'close':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1167
        dynafields.append(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1168
            {'name': 'extended_deadline',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1169
             'base': forms.IntegerField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1170
             'min_value': 1,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1171
             'label': 'Extend deadline by',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1172
             'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1173
             'passthrough': ['min_value', 'required', 'help_text'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1174
             'help_text': 'Optional: Specify the number of hours by '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1175
                 'which you want to extend the deadline for the task '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1176
                 'for this student. ',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1177
             })
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1178
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1179
      dynaproperties = params_helper.getDynaFields(dynafields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1180
      if validation == 'needs_review':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1181
        dynaproperties['clean_work_submission'] = cleaning.clean_url(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1182
            'work_submission')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1183
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1184
      extended_comment_form = dynaform.extendDynaForm(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1185
          dynaform=params['comment_form'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1186
          dynaproperties=dynaproperties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1187
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1188
      params['comment_form'] = extended_comment_form
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1189
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1190
      # list of statuses a task can be in after it is requested to be
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1191
      # claimed before closing or re-opening
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1192
      claim_status = ['ClaimRequested', 'Claimed', 'ActionNeeded',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1193
                      'NeedsWork', 'NeedsReview']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1194
      if entity.status in claim_status:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1195
        context['header_msg'] = self.DEF_TASK_CLAIMED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1196
      elif entity.status in ['AwaitingRegistration', 'Closed']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1197
        context['header_msg'] = self.DEF_TASK_CLOSED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1198
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1199
      context['signin_comment_msg'] = self.DEF_SIGNIN_TO_COMMENT_MSG % (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1200
          context['sign_in'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1201
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1202
    return validation
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1203
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1204
  def _constructMentorActions(self, context, entity):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1205
    """Constructs the list of actions for mentors, org admins and
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1206
    hosts.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1207
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1208
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1209
    # variable that holds what kind of validation this user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1210
    # and task combination pass.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1211
    validation = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1212
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1213
    actions = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1214
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1215
    if entity.status in ['Unapproved', 'Unpublished']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1216
      context['header_msg'] = self.DEF_TASK_UNPUBLISHED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1217
      context['comment_disabled'] = True
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1218
    elif entity.status == 'Open':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1219
      context['header_msg'] = self.DEF_CAN_EDIT_TASK_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1220
    elif entity.status == 'Reopened':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1221
      context['header_msg'] = self.DEF_TASK_MENTOR_REOPENED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1222
    elif entity.status == 'ClaimRequested':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1223
      actions.extend([('accept', 'Accept claim request'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1224
                      ('reject', 'Reject claim request')])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1225
      context['header_msg'] = self.DEF_TASK_CLAIM_REQUESTED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1226
      validation = 'accept_claim'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1227
    elif entity.status == 'Claimed':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1228
      context['header_msg'] = self.DEF_TASK_CLAIMED_BY_STUDENT_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1229
    elif entity.status == 'NeedsReview':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1230
      context['header_msg'] = self.DEF_TASK_NEEDS_REVIEW_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1231
      actions.extend([('needs_work', 'Needs More Work'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1232
                      ('reopened', 'Reopen the task'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1233
                      ('closed', 'Close the task')])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1234
      validation = 'close'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1235
    elif entity.status in ['AwaitingRegistration', 'Closed']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1236
      context['header_msg'] = self.DEF_TASK_CLOSED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1237
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1238
    return validation, actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1239
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1240
  def _constructStudentActions(self, context, entity, user_account):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1241
    """Constructs the list of actions for students.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1242
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1243
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1244
    # variable that holds what kind of validation this user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1245
    # and task combination pass.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1246
    validation = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1247
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1248
    actions = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1249
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1250
    if entity.status in ['Open', 'Reopened']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1251
      task_filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1252
          'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1253
          'status': ['ClaimRequested', 'Claimed', 'ActionNeeded', 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1254
                     'NeedsWork', 'NeedsReview']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1255
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1256
      task_entities = ghop_task_logic.logic.getForFields(task_filter)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1257
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1258
      if len(task_entities) >= entity.program.nr_simultaneous_tasks:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1259
        context['header_msg'] = self.DEF_MAX_TASK_LIMIT_MSG_FMT % (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1260
            entity.program.nr_simultaneous_tasks)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1261
        validation = 'claim_ineligible'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1262
        return validation, actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1263
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1264
      task_filter['status'] = 'AwaitingRegistration'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1265
      task_entities = ghop_task_logic.logic.getForFields(task_filter)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1266
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1267
      if task_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1268
        context['header_msg'] = self.DEF_AWAITING_REG_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1269
        validation = 'claim_ineligible'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1270
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1271
        actions.append(('request', 'Request to claim the task'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1272
        validation = 'claim_request'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1273
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1274
    # TODO: lot of double information here that can be simplified
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1275
    if entity.user and user_account.key() == entity.user.key():
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1276
      if entity.status  == 'ClaimRequested':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1277
        context['header_msg'] = self.DEF_TASK_REQ_CLAIMED_BY_YOU_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1278
        actions.append(('withdraw', 'Withdraw from the task'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1279
        validation = 'claim_withdraw'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1280
      elif entity.status in ['Claimed', 'NeedsWork', 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1281
                             'NeedsReview', 'ActionNeeded']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1282
        context['header_msg'] = self.DEF_TASK_CLAIMED_BY_YOU_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1283
        actions.extend([
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1284
            ('withdraw', 'Withdraw from the task'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1285
            ('needs_review', 'Submit work and Request for review')])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1286
        validation = 'needs_review'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1287
      elif entity.status == 'NeedsReview':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1288
        context['header_msg'] = self.DEF_TASK_NO_MORE_SUBMIT_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1289
        actions.append(('withdraw', 'Withdraw from the task'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1290
        if datetime.datetime.now < entity.deadline:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1291
          actions.append(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1292
              ('needs_review', 'Submit work and Request for review'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1293
        validation = 'needs_review'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1294
      elif entity.status == 'AwaitingRegistration':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1295
        context['header_msg'] = self.DEF_STUDENT_SIGNUP_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1296
      elif entity.status == 'Closed':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1297
        context['header_msg'] = self.DEF_TASK_CMPLTD_BY_YOU_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1298
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1299
      if entity.status in ['ClaimRequested', 'Claimed', 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1300
                           'ActionNeeded', 'NeedsWork',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1301
                           'NeedsReview']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1302
        context['header_msg'] = self.DEF_TASK_CLAIMED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1303
      if entity.status in ['AwaitingRegistration', 'Closed']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1304
        context['header_msg'] = self.DEF_TASK_CLOSED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1305
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1306
    return validation, actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1307
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1308
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1309
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1310
  def search(self, request, access_type, page_name=None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1311
             params=None, filter=None, order=None,**kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1312
    """View method to search for GHOP Tasks.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1313
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1314
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1315
      request: the standard Django HTTP request object
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1316
      access_type : the name of the access type which should be checked
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1317
      page_name: the page name displayed in templates as page and header title
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1318
      params: a dict with params for this View
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1319
      kwargs: the Key Fields for the specified entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1320
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1321
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1322
    from soc.modules.ghop.views.helper import list_info as list_info_helper
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1323
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1324
    get_params = request.GET
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1325
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1326
    contents = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1327
    context = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1328
    if not filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1329
      filter = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1330
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1331
    public_status = ['Open', 'Reopened', 'ClaimRequested', 'Claimed',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1332
                     'ActionNeeded', 'Closed', 'AwaitingRegistration',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1333
                     'NeedsWork', 'NeedsReview']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1334
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1335
    task_params = params.copy()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1336
    task_params['list_template'] = 'modules/ghop/task/search/search.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1337
    task_params['list_heading'] = 'modules/ghop/task/search/heading.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1338
    task_params['list_row'] = 'modules/ghop/task/search/row.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1339
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1340
    task_params['list_action'] = (redirects.getPublicRedirect,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1341
                                  task_params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1342
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1343
    task_params['list_description'] = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1344
       'Search results: ')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1345
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1346
    program_entity = ghop_program_logic.logic.getFromKeyFields(kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1347
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1348
    org_fields = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1349
        'scope': program_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1350
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1351
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1352
    org_entities = ghop_org_logic.logic.getForFields(org_fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1353
    org_names = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1354
    for org in org_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1355
      org_names.append(org.name)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1356
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1357
    df_entities = ghop_task_model.TaskDifficultyTag.get_by_scope(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1358
        program_entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1359
    difficulties = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1360
    for df_entity in df_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1361
      difficulties.append(df_entity.tag)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1362
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1363
    tt_entities = ghop_task_model.TaskTypeTag.get_by_scope(program_entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1364
    task_types = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1365
    for tt_entity in tt_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1366
      task_types.append(tt_entity.tag)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1367
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1368
    context['org_entities'] = org_names
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1369
    context['public_status'] = public_status
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1370
    context['difficulties'] =  difficulties
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1371
    context['tags'] = task_types
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1372
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1373
    org_filter = get_params.getlist('Organization')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1374
    status_filter = get_params.getlist('Status')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1375
    df_filter = get_params.getlist('Difficulty')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1376
    tag_filter = get_params.getlist('Tags')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1377
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1378
    if org_filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1379
      org_fields = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1380
        'scope': program_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1381
        'name': org_filter,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1382
      }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1383
      org_entities = ghop_org_logic.logic.getForFields(org_fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1384
      filter['scope'] = org_entities
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1385
    if status_filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1386
      filter['status']= status_filter
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1387
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1388
      filter['status'] = public_status
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1389
    if df_filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1390
      filter['difficulty'] = df_filter
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1391
    if tag_filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1392
      filter['task_type'] = tag_filter
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1393
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1394
    filter['program'] = program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1395
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1396
    task_list = lists.getListContent(request, task_params, filter,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1397
                                     order=order, idx=0, need_content=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1398
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1399
    if task_list:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1400
      contents.append(task_list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1401
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1402
    # call the _list method from base to display the list
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1403
    return self._list(request, task_params, contents, page_name, context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1404
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1405
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1406
view = View()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1407
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1408
create = decorators.view(view.create)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1409
delete = decorators.view(view.delete)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1410
edit = decorators.view(view.edit)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1411
list = decorators.view(view.list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1412
list_org_tasks = decorators.view(view.listOrgTasks)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1413
suggest_task = decorators.view(view.suggestTask)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1414
public = decorators.view(view.public)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1415
search = decorators.view(view.search)