app/soc/modules/ghop/views/models/task.py
author Lennard de Rijk <ljvderijk@gmail.com>
Thu, 17 Sep 2009 21:59:30 +0200
changeset 2942 996e64ba2db8
parent 2893 1adc6a815c71
child 2978 2b3c39483f6f
permissions -rw-r--r--
Removed undefined order argument in GHOP Task View.
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
        'scope': fields['scope'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   523
        'status': 'active'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   524
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   525
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   526
    role_entity = ghop_org_admin_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   527
        filter, unique=True)
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
    if role_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   530
      # this user can publish/approve the task
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   531
      if fields.get('approved') and fields.get('published'):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   532
        fields['status'] = 'Open'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   533
      elif not fields.get('approved'):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   534
        fields['status'] = 'Unapproved'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   535
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   536
        fields['status'] = 'Unpublished'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   537
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   538
      fields['mentors'] = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   539
      if fields.get('mentors_list'):
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
        for mentor_link_id in fields['mentors_list']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   542
          properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   543
              'scope_path': fields['scope_path'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   544
              'link_id': mentor_link_id,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   545
              }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   546
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   547
          mentor_entity = ghop_mentor_logic.logic.getFromKeyFields(properties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   548
          fields['mentors'].append(mentor_entity.key())
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   549
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   550
      role_entity = ghop_mentor_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   551
          filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   552
      if not entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   553
        # creating a new task
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   554
        fields['status'] = 'Unapproved'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   555
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   556
    # 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
   557
    fields['modified_on'] = datetime.datetime.now()
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
    if not entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   560
      fields['link_id'] = 't%i' % (int(time.time()*100))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   561
      fields['modified_by'] = role_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   562
      fields['created_by'] = role_entity 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   563
      fields['created_on'] = datetime.datetime.now()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   564
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   565
      fields['link_id'] = entity.link_id
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   566
      fields['modified_by'] = role_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   567
      if 'status' not in fields:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   568
        fields['status'] = entity.status
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   569
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   570
    fields['difficulty'] = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   571
        'tags': fields['difficulty'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   572
        'scope': program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   573
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   574
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   575
    fields['task_type'] = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   576
        'tags': fields['type_tags'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   577
        'scope': program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   578
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   579
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   580
    fields['arbit_tag'] = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   581
        'tags': fields['arbit_tags'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   582
        'scope': program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   583
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   584
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   585
    return
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
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   588
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   589
  def suggestTask(self, request, access_type, page_name=None, 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   590
                  params=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   591
    """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
   592
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   593
    Tasks created by mentors must be approved by org admins
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   594
    before they are published.
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   597
    params = dicts.merge(params, self._params)
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
    if 'link_id' in kwargs:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   600
      # extend create_form to include difficulty levels
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   601
      params['mentor_form'] = self._getTagsForProgram(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   602
          'base_edit_form', params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   603
      try:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   604
        entity = self._logic.getFromKeyFieldsOr404(kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   605
      except out_of_band.Error, error:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   606
        return helper.responses.errorResponse(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   607
            error, request, template=params['error_public'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   608
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   609
      # extend create_form to include difficulty levels
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   610
      params['mentor_form'] = self._getTagsForProgram(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   611
          'base_create_form', params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   612
      entity = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   613
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   614
    context = helper.responses.getUniversalContext(request)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   615
    helper.responses.useJavaScript(context, params['js_uses_all'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   616
    context['page_name'] = page_name
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   617
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   618
    if request.method == 'POST':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   619
      return self.suggestTaskPost(request, context,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   620
                                  params, entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   621
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   622
      return self.suggestTaskGet(request, context,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   623
                                 params, entity, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   624
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   625
  def suggestTaskPost(self, request, context, params, entity):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   626
    """Handles the POST request for the suggest task view.
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   629
    form = params['mentor_form'](request.POST)
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
    if not form.is_valid():
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   632
      return self._constructResponse(request, None, context, form, params)
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
    _, fields = helper.forms.collectCleanedFields(form)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   635
    # 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
   636
    self._editPost(request, entity, fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   637
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   638
    logic = params['logic']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   639
    if entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   640
      entity = logic.updateEntityProperties(entity, fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   641
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   642
      entity = logic.updateOrCreateFromFields(fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   643
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   644
    page_params = params['edit_params']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   645
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   646
    redirect = ghop_redirects.getSuggestTaskRedirect(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   647
        entity, 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
    return http.HttpResponseRedirect(redirect)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   650
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   651
  def suggestTaskGet(self, request, context, params, entity, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   652
    """Handles the GET request for the suggest task view.
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   655
    if entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   656
      # populate form with the existing entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   657
      form = params['mentor_form'](instance=entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   658
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   659
      self._editGet(request, entity, form)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   660
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   661
      form = params['mentor_form']()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   662
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   663
    return self._constructResponse(request, entity, context, form, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   664
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   665
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   666
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   667
  def listOrgTasks(self, request, access_type,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   668
                   page_name=None, params=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   669
    """See base.View.list()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   670
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   671
    if request.method == 'POST':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   672
      return self.listOrgTasksPost(request, params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   673
    else: # request.method == 'GET'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   674
      return self.listOrgTasksGet(request, page_name, params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   675
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   676
  def listOrgTasksPost(self, request, params, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   677
    """Handles the POST request for the list tasks view.
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   680
    # update the status of task entities that have been approved
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   681
    # and published
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   682
    task_entities = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   683
    for key_name, published in request.POST.items():
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   684
      task_entity = ghop_task_logic.logic.getFromKeyName(key_name)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   685
      if task_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   686
        task_entity.status = 'Open'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   687
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   688
        task_entities.append(task_entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   689
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   690
    # bulk update the task_entities
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   691
    # TODO: Have to be replaced by Task Queue APIs later
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   692
    db.put(task_entities)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   693
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   694
    # redirect to the same page
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   695
    return http.HttpResponseRedirect('')
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
  def listOrgTasksGet(self, request, page_name, params, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   698
    """Handles the GET request for the list tasks view.
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   701
    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
   702
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   703
    org_entity =  ghop_org_logic.logic.getFromKeyNameOr404(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   704
        kwargs['scope_path'])
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
    contents = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   707
    context = {}
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
    user_account = user_logic.logic.getForCurrentAccount()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   710
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   711
    fields = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   712
        'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   713
        'scope': org_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   714
        'status': 'active'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   715
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   716
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   717
    up_params = params.copy()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   718
    # give the capability to approve tasks for the org_admins
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   719
    if ghop_org_admin_logic.logic.getForFields(fields, unique=True):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   720
      up_params['list_template'] = 'modules/ghop/task/approve/approve.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   721
      up_params['list_heading'] = 'modules/ghop/task/approve/heading.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   722
      up_params['list_row'] = 'modules/ghop/task/approve/row.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   723
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   724
    up_params['list_action'] = (redirects.getPublicRedirect,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   725
                                up_params)
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_description'] = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   728
       'List of Unapproved or Unpublished tasks')
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
    filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   731
        'scope': org_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   732
        'status': ['Unapproved', 'Unpublished'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   733
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   734
2942
996e64ba2db8 Removed undefined order argument in GHOP Task View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2893
diff changeset
   735
    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
   736
                                   need_content=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   737
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   738
    if up_list:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   739
      up_mentors_list = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   740
      for task_entity in up_list['data']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   741
        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
   742
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   743
      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
   744
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   745
      contents.append(up_list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   746
      context['up_list'] = True
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
    ap_params = up_params.copy()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   749
    ap_params['list_template'] = 'soc/models/list.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   750
    ap_params['list_heading'] = 'modules/ghop/task/list/heading.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   751
    ap_params['list_row'] = 'modules/ghop/task/list/row.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   752
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   753
    ap_params['list_action'] = (redirects.getPublicRedirect,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   754
                                ap_params)
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_description'] = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   757
       'List of published tasks')
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
    filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   760
        'scope': org_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   761
        'status': ['Open', 'Reopened', 'ClaimRequested', 'Claimed',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   762
            'ActionNeeded', 'Closed', 'AwaitingRegistration', 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   763
            'NeedsWork', 'NeedsReview'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   764
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   765
2942
996e64ba2db8 Removed undefined order argument in GHOP Task View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2893
diff changeset
   766
    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
   767
                                   need_content=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   768
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   769
    if ap_list:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   770
      ap_mentors_list = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   771
      for task_entity in ap_list['data']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   772
        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
   773
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   774
      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
   775
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   776
      contents.append(ap_list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   777
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   778
    # call the _list method from base to display the list
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   779
    return self._list(request, up_params, contents, page_name, context)
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
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   782
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   783
  def public(self, request, access_type,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   784
             page_name=None, params=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   785
    """See base.View.public().
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   786
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   787
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   788
    # create default template context for use with any templates
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   789
    context = helper.responses.getUniversalContext(request)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   790
    helper.responses.useJavaScript(context, params['js_uses_all'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   791
    context['page_name'] = page_name
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   792
    entity = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   793
    logic = params['logic']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   794
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   795
    try:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   796
      entity, comment_entities, ws_entities = (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   797
          logic.getFromKeyFieldsWithCWSOr404(kwargs))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   798
    except out_of_band.Error, error:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   799
      return helper.responses.errorResponse(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   800
          error, request, template=params['error_public'], context=context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   801
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   802
    if entity.status in ['Claimed', 'NeedsReview',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   803
                         'ActionNeeded', 'NeedsWork']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   804
      entity, comment_entity, ws_entity = (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   805
          ghop_task_logic.logic.updateTaskStatus(entity))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   806
      if comment_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   807
        comment_entities.append(comment_entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   808
      if ws_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   809
        ws_entities.append(ws_entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   810
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   811
    context['entity'] = entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   812
    context['entity_key_name'] = entity.key().id_or_name() 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   813
    context['entity_type'] = params['name']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   814
    context['entity_type_url'] = params['url_name']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   815
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   816
    user_account = user_logic.logic.getForCurrentAccount()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   817
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   818
    # get some entity specific context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   819
    self.updatePublicContext(context, entity, comment_entities,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   820
                             ws_entities, user_account, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   821
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   822
    validation = self._constructActionsList(context, entity, 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   823
                                            user_account, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   824
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   825
    context = dicts.merge(params['context'], context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   826
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   827
    if request.method == 'POST':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   828
      return self.publicPost(request, context, params, entity, 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   829
                             user_account, validation, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   830
    else: # request.method == 'GET'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   831
      return self.publicGet(request, context, params, entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   832
                            user_account, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   833
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   834
  def publicPost(self, request, context, params, entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   835
                 user_account=None, validation=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   836
    """Handles the POST request for the entity's public page.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   837
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   838
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   839
        entity: the task entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   840
        rest: see base.View.public()
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   843
    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
   844
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   845
    form = params['comment_form'](request.POST)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   846
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   847
    if not form.is_valid():
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   848
      template = params['public_template']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   849
      context['comment_form'] = form
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   850
      return self._constructResponse(request, entity, context,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   851
                                     form, params, template=template)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   852
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   853
    _, fields = helper.forms.collectCleanedFields(form)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   854
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   855
    changes = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   856
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   857
    action = fields['action']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   858
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   859
    properties = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   860
    ws_properties = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   861
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   862
    # 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
   863
    if validation == 'claim_request' and action == 'request':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   864
      deadline = datetime.datetime.now() + datetime.timedelta(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   865
            hours=entity.time_to_complete)
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
      properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   868
          'status': 'ClaimRequested',
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
          'deadline': deadline,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   871
          }
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
      st_filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   874
          'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   875
          'scope': entity.program,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   876
          'status': 'active'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   877
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   878
      student_entity = ghop_student_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   879
          st_filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   880
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   881
      if student_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   882
        properties['student'] = student_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   883
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   884
      changes.extend([ugettext('User-Student'), 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   885
                      ugettext('Action-Claim Requested'), 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   886
                      ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   887
                      ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   888
    elif (validation == 'claim_withdraw' or 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   889
        validation == 'needs_review') and action == 'withdraw':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   890
      properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   891
          'user': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   892
          'student': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   893
          'status': 'Reopened',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   894
          'deadline': None,
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   897
      changes.extend([ugettext('User-Student'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   898
                      ugettext('Action-Withdrawn'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   899
                      ugettext('Status-%s' % (properties['status']))
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
    elif validation == 'needs_review' and action == 'needs_review':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   902
      properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   903
          'status': 'NeedsReview',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   904
          }
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
      changes.extend([
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   907
          ugettext('User-Student'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   908
          ugettext('Action-Submitted work and Requested for review'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   909
          ugettext('Status-%s' % (properties['status']))])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   910
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   911
      ws_properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   912
          'parent': entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   913
          'link_id': 't%i' % (int(time.time()*100)),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   914
          'scope_path': entity.key().name(),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   915
          'scope': entity.scope,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   916
          'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   917
          'information': fields['comment'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   918
          'url_to_work': fields['work_submission'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   919
          'submitted_on': datetime.datetime.now(),
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
    elif validation == 'accept_claim':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   922
      if action == 'accept':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   923
        deadline = datetime.datetime.now() + datetime.timedelta(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   924
            hours=entity.time_to_complete)
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
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   927
            'status': 'Claimed',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   928
            'deadline': deadline,
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
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   932
                        ugettext('Action-Claim Accepted'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   933
                        ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   934
                        ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   935
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   936
        task_update.spawnUpdateTask(entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   937
      if action == 'reject':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   938
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   939
            'user': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   940
            'student': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   941
            'status': 'Reopened',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   942
            'deadline': None,
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   945
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   946
                        ugettext('Action-Claim Rejected'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   947
                        ugettext('Status-%s' % (properties['status']))
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
    elif validation == 'close':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   950
      if action == 'needs_work':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   951
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   952
            'status': 'NeedsWork',
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
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   956
                        ugettext('Action-Requested more work'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   957
                        ugettext('Status-%s' % (properties['status']))
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   960
        if fields['extended_deadline'] > 0:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   961
          deadline = entity.deadline + datetime.timedelta(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   962
              hours=fields['extended_deadline'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   963
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   964
          properties['deadline'] = deadline
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   965
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   966
          changes.append(ugettext('DeadlineExtendedBy-%d hrs to %s' % (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   967
              fields['extended_deadline'], deadline.strftime(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   968
                  '%d %B %Y, %H :%M'))))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   969
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   970
          task_update.spawnUpdateTask(entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   971
        else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   972
          changes.append(ugettext('NoDeadlineExtensionGiven'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   973
      elif action == 'reopened':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   974
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   975
          'user': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   976
          'student': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   977
          'status': 'Reopened',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   978
          'deadline': None,
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   981
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   982
                        ugettext('Action-Reopened'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   983
                        ugettext('Status-%s' % (properties['status']))
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
      elif action == 'closed':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   986
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   987
            'deadline': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   988
            }
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
        if entity.student:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   991
          properties['status'] = 'Closed'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   992
        else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   993
          properties['status'] = 'AwaitingRegistration'
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
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   996
                        ugettext('Action-Closed the task'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   997
                        ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   998
                        ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   999
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1000
    comment_properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1001
        'parent': entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1002
        'scope_path': entity.key().name(),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1003
        'created_by': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1004
        'changes': changes,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1005
        }
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
    if ws_properties:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1008
      comment_properties['content'] = self.DEF_WS_MSG_FMT
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1009
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1010
      comment_properties['content'] = fields['comment']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1011
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1012
    ghop_task_logic.logic.updateEntityPropertiesWithCWS(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1013
        entity, properties, comment_properties, ws_properties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1014
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1015
    # redirect to the same page
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1016
    return http.HttpResponseRedirect('')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1017
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1018
  def publicGet(self, request, context, params, entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1019
                user_account, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1020
    """Handles the GET request for the entity's public page.
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
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1023
        entity: the task entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1024
        rest see base.View.public()
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1027
    context['comment_form'] = params['comment_form']()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1028
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1029
    template = params['public_template']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1030
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1031
    return responses.respond(request, template, context=context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1032
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1033
  def updatePublicContext(self, context, entity, comment_entities,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1034
                          ws_entities, user_account, params):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1035
    """Updates the context for the public page with information.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1036
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1037
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1038
      context: the context that should be updated
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1039
      entity: a task used to set context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1040
      user_account: user entity of the logged in user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1041
      params: dict with params for the view using this context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1042
    """
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
    mentor_entities = db.get(entity.mentors)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1045
    mentors_str = ""
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1046
    for mentor in mentor_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1047
      mentors_str += mentor.name() + ", "
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
    if mentors_str:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1050
      context['mentors_str'] = mentors_str[:-2]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1051
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1052
      context['mentors_str'] = "Not Assigned" 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1053
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1054
    context['difficulty_str'] = entity.tags_string(entity.difficulty)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1055
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1056
    context['task_type_str'] = entity.tags_string(entity.task_type)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1057
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1058
    if entity.deadline:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1059
      # 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
  1060
      ttc = entity.deadline - datetime.datetime.now()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1061
      (ttc_min, ttc_hour) = ((ttc.seconds / 60), (ttc.seconds / 3600))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1062
      if ttc_min >= 60:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1063
        ttc_min = ttc_min % 60
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1064
      if ttc_hour > 1:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1065
        if ttc_min == 0:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1066
          ttc_str = '%d hours' % (ttc_hour)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1067
        else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1068
          ttc_str = '%d:%02d hours' % (ttc_hour, ttc_min)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1069
        if ttc.days == 1:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1070
          ttc_str = '%d day, %s' % (ttc.days, ttc_str)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1071
        elif ttc.days > 1:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1072
          ttc_str = '%d days, %s' % (ttc.days, ttc_str)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1073
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1074
        ttc_str = '%d mins' % (ttc_min)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1075
      context['time_to_complete'] = ttc_str
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1076
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1077
      if entity.status == 'NeedsReview':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1078
        context['time_to_complete'] = 'No Time Left'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1079
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1080
        context['time_to_complete'] = '%d hours' % (entity.time_to_complete)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1081
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1082
    context['comments'] = comment_entities
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1083
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1084
    context['work_submissions'] = ws_entities
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
  def _constructActionsList(self, context, entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1087
                            user_account, params):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1088
    """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
  1089
    the comment form with this list.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1090
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1091
    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
  1092
    validate the user input data.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1093
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1094
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1095
      context: the context that should be updated
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1096
      entity: a task used to set context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1097
      user_account: user entity of the logged in user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1098
      params: dict with params for the view using this context
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1101
    # variable that holds what kind of validation this user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1102
    # and task combination pass.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1103
    validation = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1104
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1105
    # The following header messages are shown for non-logged in
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1106
    # general public, logged in public and the student.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1107
    if entity.status is 'Closed':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1108
      context['header_msg'] = self.DEF_TASK_CLOSED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1109
      validation = 'closed'
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 entity.status == 'Open':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1112
      context['header_msg'] = self.DEF_TASK_OPEN_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1113
    elif entity.status == 'Reopened':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1114
      context['header_msg'] = self.DEF_TASK_REOPENED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1115
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1116
    if user_account:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1117
      actions = [('noaction', 'Comment without action')]
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
      # 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
  1120
      # 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
  1121
      filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1122
          'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1123
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1124
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1125
      host_entity = host_logic.logic.getForFields(filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1126
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1127
      filter['scope_path'] = entity.scope_path
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1128
      org_admin_entity = ghop_org_admin_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1129
          filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1130
      mentor_entity = ghop_mentor_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1131
          filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1132
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1133
      if host_entity or org_admin_entity or mentor_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1134
        validation, mentor_actions = self._constructMentorActions(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1135
            context, entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1136
        actions += mentor_actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1137
        if entity.status in ['Unapproved', 'Unpublished', 'Open']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1138
          if host_entity or org_admin_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1139
            context['edit_link'] = redirects.getEditRedirect(entity, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1140
          elif mentor_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1141
            context['suggest_link'] = ghop_redirects.getSuggestTaskRedirect(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1142
                entity, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1143
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1144
        validation, student_actions = self._constructStudentActions(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1145
            context, entity, user_account)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1146
        actions += student_actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1147
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1148
      # create the difficultly level field containing the choices 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1149
      # defined in the program entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1150
      dynafields = [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1151
          {'name': 'action',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1152
           'base': forms.ChoiceField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1153
           'label': 'Action',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1154
           'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1155
           'passthrough': ['initial', 'required', 'choices'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1156
           'choices': actions,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1157
           },
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1158
         ]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1159
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1160
      if validation == 'needs_review':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1161
        dynafields.append(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1162
            {'name': 'work_submission',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1163
             'base': forms.URLField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1164
             'label': 'Submit Work',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1165
             'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1166
             '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
  1167
                 'Please use the comment box if you need to explain '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1168
                 'of your work.',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1169
             })
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1170
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1171
      if validation == 'close':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1172
        dynafields.append(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1173
            {'name': 'extended_deadline',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1174
             'base': forms.IntegerField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1175
             'min_value': 1,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1176
             'label': 'Extend deadline by',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1177
             'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1178
             'passthrough': ['min_value', 'required', 'help_text'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1179
             'help_text': 'Optional: Specify the number of hours by '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1180
                 'which you want to extend the deadline for the task '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1181
                 'for this student. ',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1182
             })
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
      dynaproperties = params_helper.getDynaFields(dynafields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1185
      if validation == 'needs_review':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1186
        dynaproperties['clean_work_submission'] = cleaning.clean_url(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1187
            'work_submission')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1188
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1189
      extended_comment_form = dynaform.extendDynaForm(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1190
          dynaform=params['comment_form'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1191
          dynaproperties=dynaproperties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1192
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1193
      params['comment_form'] = extended_comment_form
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1194
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1195
      # 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
  1196
      # claimed before closing or re-opening
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1197
      claim_status = ['ClaimRequested', 'Claimed', 'ActionNeeded',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1198
                      'NeedsWork', 'NeedsReview']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1199
      if entity.status in claim_status:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1200
        context['header_msg'] = self.DEF_TASK_CLAIMED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1201
      elif entity.status in ['AwaitingRegistration', 'Closed']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1202
        context['header_msg'] = self.DEF_TASK_CLOSED_MSG
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
      context['signin_comment_msg'] = self.DEF_SIGNIN_TO_COMMENT_MSG % (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1205
          context['sign_in'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1206
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1207
    return validation
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
  def _constructMentorActions(self, context, entity):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1210
    """Constructs the list of actions for mentors, org admins and
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1211
    hosts.
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1214
    # variable that holds what kind of validation this user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1215
    # and task combination pass.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1216
    validation = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1217
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1218
    actions = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1219
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1220
    if entity.status in ['Unapproved', 'Unpublished']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1221
      context['header_msg'] = self.DEF_TASK_UNPUBLISHED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1222
      context['comment_disabled'] = True
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1223
    elif entity.status == 'Open':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1224
      context['header_msg'] = self.DEF_CAN_EDIT_TASK_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1225
    elif entity.status == 'Reopened':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1226
      context['header_msg'] = self.DEF_TASK_MENTOR_REOPENED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1227
    elif entity.status == 'ClaimRequested':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1228
      actions.extend([('accept', 'Accept claim request'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1229
                      ('reject', 'Reject claim request')])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1230
      context['header_msg'] = self.DEF_TASK_CLAIM_REQUESTED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1231
      validation = 'accept_claim'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1232
    elif entity.status == 'Claimed':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1233
      context['header_msg'] = self.DEF_TASK_CLAIMED_BY_STUDENT_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1234
    elif entity.status == 'NeedsReview':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1235
      context['header_msg'] = self.DEF_TASK_NEEDS_REVIEW_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1236
      actions.extend([('needs_work', 'Needs More Work'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1237
                      ('reopened', 'Reopen the task'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1238
                      ('closed', 'Close the task')])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1239
      validation = 'close'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1240
    elif entity.status in ['AwaitingRegistration', 'Closed']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1241
      context['header_msg'] = self.DEF_TASK_CLOSED_MSG
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
    return validation, actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1244
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1245
  def _constructStudentActions(self, context, entity, user_account):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1246
    """Constructs the list of actions for students.
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1249
    # variable that holds what kind of validation this user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1250
    # and task combination pass.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1251
    validation = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1252
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1253
    actions = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1254
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1255
    if entity.status in ['Open', 'Reopened']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1256
      task_filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1257
          'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1258
          'status': ['ClaimRequested', 'Claimed', 'ActionNeeded', 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1259
                     'NeedsWork', 'NeedsReview']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1260
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1261
      task_entities = ghop_task_logic.logic.getForFields(task_filter)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1262
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1263
      if len(task_entities) >= entity.program.nr_simultaneous_tasks:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1264
        context['header_msg'] = self.DEF_MAX_TASK_LIMIT_MSG_FMT % (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1265
            entity.program.nr_simultaneous_tasks)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1266
        validation = 'claim_ineligible'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1267
        return validation, actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1268
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1269
      task_filter['status'] = 'AwaitingRegistration'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1270
      task_entities = ghop_task_logic.logic.getForFields(task_filter)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1271
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1272
      if task_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1273
        context['header_msg'] = self.DEF_AWAITING_REG_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1274
        validation = 'claim_ineligible'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1275
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1276
        actions.append(('request', 'Request to claim the task'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1277
        validation = 'claim_request'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1278
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1279
    # TODO: lot of double information here that can be simplified
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1280
    if entity.user and user_account.key() == entity.user.key():
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1281
      if entity.status  == 'ClaimRequested':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1282
        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
  1283
        actions.append(('withdraw', 'Withdraw from the task'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1284
        validation = 'claim_withdraw'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1285
      elif entity.status in ['Claimed', 'NeedsWork', 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1286
                             'NeedsReview', 'ActionNeeded']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1287
        context['header_msg'] = self.DEF_TASK_CLAIMED_BY_YOU_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1288
        actions.extend([
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1289
            ('withdraw', 'Withdraw from the task'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1290
            ('needs_review', 'Submit work and Request for review')])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1291
        validation = 'needs_review'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1292
      elif entity.status == 'NeedsReview':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1293
        context['header_msg'] = self.DEF_TASK_NO_MORE_SUBMIT_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1294
        actions.append(('withdraw', 'Withdraw from the task'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1295
        if datetime.datetime.now < entity.deadline:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1296
          actions.append(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1297
              ('needs_review', 'Submit work and Request for review'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1298
        validation = 'needs_review'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1299
      elif entity.status == 'AwaitingRegistration':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1300
        context['header_msg'] = self.DEF_STUDENT_SIGNUP_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1301
      elif entity.status == 'Closed':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1302
        context['header_msg'] = self.DEF_TASK_CMPLTD_BY_YOU_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1303
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1304
      if entity.status in ['ClaimRequested', 'Claimed', 
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1305
                           'ActionNeeded', 'NeedsWork',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1306
                           'NeedsReview']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1307
        context['header_msg'] = self.DEF_TASK_CLAIMED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1308
      if entity.status in ['AwaitingRegistration', 'Closed']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1309
        context['header_msg'] = self.DEF_TASK_CLOSED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1310
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1311
    return validation, actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1312
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1313
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1314
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1315
  def search(self, request, access_type, page_name=None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1316
             params=None, filter=None, order=None,**kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1317
    """View method to search for GHOP Tasks.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1318
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1319
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1320
      request: the standard Django HTTP request object
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1321
      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
  1322
      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
  1323
      params: a dict with params for this View
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1324
      kwargs: the Key Fields for the specified entity
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1327
    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
  1328
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1329
    get_params = request.GET
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
    contents = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1332
    context = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1333
    if not filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1334
      filter = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1335
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1336
    public_status = ['Open', 'Reopened', 'ClaimRequested', 'Claimed',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1337
                     'ActionNeeded', 'Closed', 'AwaitingRegistration',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1338
                     'NeedsWork', 'NeedsReview']
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 = params.copy()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1341
    task_params['list_template'] = 'modules/ghop/task/search/search.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1342
    task_params['list_heading'] = 'modules/ghop/task/search/heading.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1343
    task_params['list_row'] = 'modules/ghop/task/search/row.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1344
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1345
    task_params['list_action'] = (redirects.getPublicRedirect,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1346
                                  task_params)
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
    task_params['list_description'] = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1349
       'Search results: ')
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
    program_entity = ghop_program_logic.logic.getFromKeyFields(kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1352
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1353
    org_fields = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1354
        'scope': program_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1355
        }
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
    org_entities = ghop_org_logic.logic.getForFields(org_fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1358
    org_names = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1359
    for org in org_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1360
      org_names.append(org.name)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1361
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1362
    df_entities = ghop_task_model.TaskDifficultyTag.get_by_scope(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1363
        program_entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1364
    difficulties = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1365
    for df_entity in df_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1366
      difficulties.append(df_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
    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
  1369
    task_types = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1370
    for tt_entity in tt_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1371
      task_types.append(tt_entity.tag)
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
    context['org_entities'] = org_names
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1374
    context['public_status'] = public_status
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1375
    context['difficulties'] =  difficulties
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1376
    context['tags'] = task_types
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
    org_filter = get_params.getlist('Organization')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1379
    status_filter = get_params.getlist('Status')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1380
    df_filter = get_params.getlist('Difficulty')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1381
    tag_filter = get_params.getlist('Tags')
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
    if org_filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1384
      org_fields = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1385
        'scope': program_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1386
        'name': org_filter,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1387
      }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1388
      org_entities = ghop_org_logic.logic.getForFields(org_fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1389
      filter['scope'] = org_entities
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1390
    if status_filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1391
      filter['status']= status_filter
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1392
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1393
      filter['status'] = public_status
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1394
    if df_filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1395
      filter['difficulty'] = df_filter
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1396
    if tag_filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1397
      filter['task_type'] = tag_filter
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
    filter['program'] = program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1400
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1401
    task_list = lists.getListContent(request, task_params, filter,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1402
                                     order=order, idx=0, need_content=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1403
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1404
    if task_list:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1405
      contents.append(task_list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1406
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1407
    # call the _list method from base to display the list
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1408
    return self._list(request, task_params, contents, page_name, context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1409
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1410
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1411
view = View()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1412
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1413
create = decorators.view(view.create)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1414
delete = decorators.view(view.delete)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1415
edit = decorators.view(view.edit)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1416
list = decorators.view(view.list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1417
list_org_tasks = decorators.view(view.listOrgTasks)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1418
suggest_task = decorators.view(view.suggestTask)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1419
public = decorators.view(view.public)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1420
search = decorators.view(view.search)