app/soc/modules/ghop/views/models/task.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Sun, 25 Oct 2009 11:24:46 -0700
changeset 3038 34eeacafc5dc
parent 3034 aa5ebb226b22
child 3059 14421976288a
permissions -rw-r--r--
Once a task has been approved it can no longer be unapproved. Patch by: Madhusudan C.S. and Lennard de Rijk
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
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
    37
from soc.logic.models import host as host_logic
2885
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 '
3018
0653f924ee7e Fix typographical error and changes in status messages for Task workflow.
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents: 3017
diff changeset
    83
      'have already claimed %d task(s).')
2885
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
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
    93
  DEF_TASK_CLAIMED_BY_YOU_MSG = ugettext(
3018
0653f924ee7e Fix typographical error and changes in status messages for Task workflow.
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents: 3017
diff changeset
    94
      'You have claimed this task!')
2885
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 '
3018
0653f924ee7e Fix typographical error and changes in status messages for Task workflow.
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents: 3017
diff changeset
   104
      'reject the request.')
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
3018
0653f924ee7e Fix typographical error and changes in status messages for Task workflow.
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents: 3017
diff changeset
   106
  DEF_TASK_CLOSED_MSG = ugettext('This task is closed.')
2885
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(
3018
0653f924ee7e Fix typographical error and changes in status messages for Task workflow.
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents: 3017
diff changeset
   123
      'This task is open. If you are a GHOP student, you can claim it!')
2885
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, '
3018
0653f924ee7e Fix typographical error and changes in status messages for Task workflow.
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents: 3017
diff changeset
   127
      'you can claim it!')
2885
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',
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   153
            [['ghop/org_admin'], ['active'],
2885
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',
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   158
            [['ghop/org_admin'], ['active'],
2885
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',
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   167
            [['ghop/org_admin', 'ghop/mentor'], ['active'],
3027
a223fff4cca8 Fixed access check and seed for Task Suggest page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3026
diff changeset
   168
            ['Unapproved']])]
2885
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
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   185
    new_params['list_heading'] = 'modules/ghop/task/list/heading.html'
2885
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',
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   189
                                       'student', 'program', 'status',
2885
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']
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   251
    self._params['base_edit_form'] = self._params['edit_form']
2885
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
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   308
    comment_form = dynaform.newDynaForm(dynamodel=None,
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   309
        dynabase=helper.forms.BaseForm, dynainclude=None,
2885
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
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   321
    # obtain program_entity using scope_path which holds
2885
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(
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   329
        program_entity)
2885
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
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   336
    tts = ghop_task_model.TaskTypeTag.get_by_scope(program_entity)
2885
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
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   342
    # create the difficultly level field containing the choices
2885
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
    # extend edit_form to include difficulty levels
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   419
    params['edit_form'] = self._getTagsForProgram(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   420
        'edit_form', params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   421
3026
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   422
    if entity.status == 'Unapproved':
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   423
      dynafields = [
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   424
          {'name': 'approved',
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   425
           'required': False,
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   426
           'initial': False,
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   427
           'base': forms.fields.BooleanField,
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   428
           'label': 'Approve the task',
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   429
           'help_text': 'By ticking this box, the task will be'
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   430
               'will be approved for publishing.',
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   431
          }
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   432
          ]
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   433
3026
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   434
      dynaproperties = params_helper.getDynaFields(dynafields)
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   435
3026
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   436
      edit_form = dynaform.extendDynaForm(
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   437
          dynaform=params['edit_form'],
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   438
          dynaproperties=dynaproperties)
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   439
3026
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   440
      params['edit_form'] = edit_form
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   441
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   442
    if request.method == 'POST':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   443
      return self.editPost(request, entity, context, params=params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   444
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   445
      return self.editGet(request, entity, context, params=params)
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
  def _editGet(self, request, entity, form):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   448
    """See base.View._editGet().
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   449
    """
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
    if entity.task_type:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   452
      form.fields['type_tags'].initial = entity.tags_string(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   453
          entity.task_type, ret_list=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   454
    if entity.arbit_tag:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   455
      form.fields['arbit_tags'].initial = entity.tags_string(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   456
          entity.arbit_tag)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   457
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   458
    if entity.difficulty:
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   459
      form.fields['difficulty'].initial = entity.tags_string(
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   460
          entity.difficulty)
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
    if entity.mentors and 'mentors_list' in form.fields:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   463
      mentor_entities = db.get(entity.mentors)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   464
      mentors_list = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   465
      for mentor in mentor_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   466
        mentors_list.append(mentor.link_id)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   467
      form.fields['mentors_list'].initial = ', '.join(mentors_list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   468
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   469
    form.fields['link_id'].initial = entity.link_id
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   470
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   471
    # 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
   472
    # the form approved field
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   473
    if 'approved' in form.fields:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   474
      if entity.status == 'Unapproved':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   475
        form.fields['approved'].initial = False
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   476
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   477
        form.fields['approved'].initial = True
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   478
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   479
    # checks if the task is already published or not and sets
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   480
    # the form published field
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   481
    if 'published' in form.fields:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   482
      if entity.status == 'Unapproved' or entity.status == 'Unpublished':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   483
        form.fields['published'].initial = False
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   484
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   485
        form.fields['published'].initial = True
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   486
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   487
    return super(View, self)._editGet(request, entity, form)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   488
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   489
  def _editPost(self, request, entity, fields):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   490
    """See base._editPost().
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   491
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   492
3038
34eeacafc5dc Once a task has been approved it can no longer be unapproved.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3034
diff changeset
   493
    # set the scope field
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   494
    super(View, self)._editPost(request, entity, fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   495
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   496
    # 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
   497
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   498
    if not entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   499
      program_entity = fields['scope'].scope
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   500
      fields['program'] = program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   501
    else:
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   502
      program_entity = entity.program
2885
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
    user_account = user_logic.logic.getForCurrentAccount()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   505
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   506
    filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   507
        'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   508
        'status': 'active'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   509
        }
2978
2b3c39483f6f Fixes the problem of GHOP Task editing after it is created.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2942
diff changeset
   510
    if not entity:
2b3c39483f6f Fixes the problem of GHOP Task editing after it is created.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2942
diff changeset
   511
      filter['scope'] = fields['scope']
2b3c39483f6f Fixes the problem of GHOP Task editing after it is created.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2942
diff changeset
   512
    else:
3033
8a18ac7ca909 When a task is edited, 'modified_by' field is not cleared any more.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3028
diff changeset
   513
      filter['scope'] = entity.scope
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   514
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   515
    role_entity = ghop_org_admin_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   516
        filter, unique=True)
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
    if role_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   519
      # this user can publish/approve the task
3038
34eeacafc5dc Once a task has been approved it can no longer be unapproved.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3034
diff changeset
   520
      if fields.get('published'):
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   521
        fields['status'] = 'Open'
3038
34eeacafc5dc Once a task has been approved it can no longer be unapproved.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3034
diff changeset
   522
      elif fields.get('approved'):
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   523
        fields['status'] = 'Unpublished'
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
      fields['mentors'] = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   526
      if fields.get('mentors_list'):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   527
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   528
        for mentor_link_id in fields['mentors_list']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   529
          properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   530
              'scope_path': fields['scope_path'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   531
              'link_id': mentor_link_id,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   532
              }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   533
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   534
          mentor_entity = ghop_mentor_logic.logic.getFromKeyFields(properties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   535
          fields['mentors'].append(mentor_entity.key())
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   536
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   537
      role_entity = ghop_mentor_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   538
          filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   539
      if not entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   540
        # creating a new task
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   541
        fields['status'] = 'Unapproved'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   542
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   543
    # 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
   544
    fields['modified_on'] = datetime.datetime.now()
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
    if not entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   547
      fields['link_id'] = 't%i' % (int(time.time()*100))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   548
      fields['modified_by'] = role_entity
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   549
      fields['created_by'] = role_entity
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   550
      fields['created_on'] = datetime.datetime.now()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   551
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   552
      fields['link_id'] = entity.link_id
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   553
      fields['modified_by'] = role_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   554
      if 'status' not in fields:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   555
        fields['status'] = entity.status
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   556
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   557
    fields['difficulty'] = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   558
        'tags': fields['difficulty'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   559
        'scope': program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   560
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   561
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   562
    fields['task_type'] = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   563
        'tags': fields['type_tags'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   564
        'scope': program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   565
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   566
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   567
    fields['arbit_tag'] = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   568
        'tags': fields['arbit_tags'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   569
        'scope': program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   570
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   571
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   572
    return
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
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   575
  @decorators.check_access
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   576
  def suggestTask(self, request, access_type, page_name=None,
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   577
                  params=None, **kwargs):
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   578
    """View used to allow mentors to create or edit a task.
2885
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
    Tasks created by mentors must be approved by org admins
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   581
    before they are published.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   582
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   583
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   584
    params = dicts.merge(params, self._params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   585
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   586
    if 'link_id' in kwargs:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   587
      # extend create_form to include difficulty levels
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   588
      params['mentor_form'] = self._getTagsForProgram(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   589
          'base_edit_form', params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   590
      try:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   591
        entity = self._logic.getFromKeyFieldsOr404(kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   592
      except out_of_band.Error, error:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   593
        return helper.responses.errorResponse(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   594
            error, request, template=params['error_public'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   595
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   596
      # extend create_form to include difficulty levels
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   597
      params['mentor_form'] = self._getTagsForProgram(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   598
          'base_create_form', params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   599
      entity = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   600
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   601
    context = helper.responses.getUniversalContext(request)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   602
    helper.responses.useJavaScript(context, params['js_uses_all'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   603
    context['page_name'] = page_name
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   604
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   605
    if request.method == 'POST':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   606
      return self.suggestTaskPost(request, context,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   607
                                  params, entity)
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
      return self.suggestTaskGet(request, context,
3027
a223fff4cca8 Fixed access check and seed for Task Suggest page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3026
diff changeset
   610
                                 params, entity, kwargs)
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   611
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   612
  def suggestTaskPost(self, request, context, params, entity):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   613
    """Handles the POST request for the suggest task view.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   614
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   615
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   616
    form = params['mentor_form'](request.POST)
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 not form.is_valid():
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   619
      return self._constructResponse(request, None, context, form, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   620
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   621
    _, fields = helper.forms.collectCleanedFields(form)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   622
    # 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
   623
    self._editPost(request, entity, fields)
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
    logic = params['logic']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   626
    if entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   627
      entity = logic.updateEntityProperties(entity, fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   628
    else:
3026
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   629
      # TODO: Redirect to standard edit page which already has the ability to
75ef22dc5a8a Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3018
diff changeset
   630
      # hide certain fields.
3028
1852a74ba03a Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3027
diff changeset
   631
      # get the mentor entity of the current user that is suggesting the task
1852a74ba03a Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3027
diff changeset
   632
      user_entity = user_logic.logic.getForCurrentAccount()
1852a74ba03a Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3027
diff changeset
   633
1852a74ba03a Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3027
diff changeset
   634
      filter = {'user': user_entity,
1852a74ba03a Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3027
diff changeset
   635
                'scope': fields['scope'],
1852a74ba03a Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3027
diff changeset
   636
                'status': 'active'}
1852a74ba03a Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3027
diff changeset
   637
1852a74ba03a Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3027
diff changeset
   638
      mentor_entity = ghop_mentor_logic.logic.getForFields(filter, unique=True)
1852a74ba03a Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3027
diff changeset
   639
      fields['mentors'] = [mentor_entity.key()]
1852a74ba03a Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 3027
diff changeset
   640
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   641
      entity = logic.updateOrCreateFromFields(fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   642
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   643
    redirect = ghop_redirects.getSuggestTaskRedirect(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   644
        entity, 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
    return http.HttpResponseRedirect(redirect)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   647
3027
a223fff4cca8 Fixed access check and seed for Task Suggest page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3026
diff changeset
   648
  def suggestTaskGet(self, request, context, params, entity, seed):
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   649
    """Handles the GET request for the suggest task view.
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   652
    if entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   653
      # populate form with the existing entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   654
      form = params['mentor_form'](instance=entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   655
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   656
      self._editGet(request, entity, form)
3027
a223fff4cca8 Fixed access check and seed for Task Suggest page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3026
diff changeset
   657
    elif seed:
a223fff4cca8 Fixed access check and seed for Task Suggest page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3026
diff changeset
   658
      form = params['mentor_form'](initial=seed)
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   659
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   660
      form = params['mentor_form']()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   661
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   662
    return self._constructResponse(request, entity, context, form, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   663
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   664
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   665
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   666
  def listOrgTasks(self, request, access_type,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   667
                   page_name=None, params=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   668
    """See base.View.list()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   669
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   670
    if request.method == 'POST':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   671
      return self.listOrgTasksPost(request, params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   672
    else: # request.method == 'GET'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   673
      return self.listOrgTasksGet(request, page_name, params, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   674
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   675
  def listOrgTasksPost(self, request, params, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   676
    """Handles the POST request for the list tasks view.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   677
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   678
3017
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   679
    # get the org entity for which we are listing these tasks
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   680
    org_entity = ghop_org_logic.logic.getFromKeyNameOr404(kwargs['scope_path'])
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   681
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   682
    # save the state to which the selected tasks must be changed
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   683
    # to based on the actions.
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   684
    if request.POST.get('Approve'):
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   685
      changed_status = 'Unpublished'
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   686
    elif request.POST.get('Publish'):
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   687
      changed_status = 'Open'
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   688
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   689
    # update the status of task entities that should be approved or published
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   690
    task_entities = []
3017
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   691
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   692
    # get all the task keys to update, will return empty list if doesn't exist
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   693
    task_keys = request.POST.getlist('task_id')
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   694
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   695
    for key_name in task_keys:
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   696
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   697
      task_entity = ghop_task_logic.logic.getFromKeyName(key_name)
3017
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   698
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   699
      # Of course only the tasks from this organization and those with a valid
3017
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   700
      # state can be updated.
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   701
      if task_entity and task_entity.scope.key() == org_entity.key() and \
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   702
          task_entity.status in ['Unapproved', 'Unpublished']:
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   703
        task_entity.status = changed_status
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   704
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   705
        task_entities.append(task_entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   706
3017
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   707
    # bulk put the task_entities
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   708
    # TODO: replace with Task API call?
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   709
    db.put(task_entities)
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
    # redirect to the same page
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   712
    return http.HttpResponseRedirect('')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   713
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   714
  def listOrgTasksGet(self, request, page_name, params, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   715
    """Handles the GET request for the list tasks view.
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   718
    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
   719
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   720
    org_entity =  ghop_org_logic.logic.getFromKeyNameOr404(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   721
        kwargs['scope_path'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   722
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   723
    contents = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   724
    context = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   725
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   726
    user_account = user_logic.logic.getForCurrentAccount()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   727
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   728
    fields = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   729
        'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   730
        'scope': org_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   731
        'status': 'active'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   732
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   733
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   734
    up_params = params.copy()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   735
    # give the capability to approve tasks for the org_admins
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   736
    if ghop_org_admin_logic.logic.getForFields(fields, unique=True):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   737
      up_params['list_template'] = 'modules/ghop/task/approve/approve.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   738
      up_params['list_heading'] = 'modules/ghop/task/approve/heading.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   739
      up_params['list_row'] = 'modules/ghop/task/approve/row.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   740
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   741
    up_params['list_action'] = (redirects.getPublicRedirect,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   742
                                up_params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   743
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   744
    up_params['list_description'] = ugettext(
3017
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   745
       'List of Unapproved tasks.')
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   746
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   747
    filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   748
        'scope': org_entity,
3017
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   749
        'status': 'Unapproved',
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   750
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   751
2942
996e64ba2db8 Removed undefined order argument in GHOP Task View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2893
diff changeset
   752
    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
   753
                                   need_content=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   754
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   755
    if up_list:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   756
      up_mentors_list = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   757
      for task_entity in up_list['data']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   758
        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
   759
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   760
      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
   761
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   762
      contents.append(up_list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   763
      context['up_list'] = True
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   764
3017
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   765
    aup_params = params.copy()
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   766
    aup_params['list_heading'] = 'modules/ghop/task/approve/heading.html'
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   767
    aup_params['list_row'] = 'modules/ghop/task/approve/row.html'
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   768
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   769
    aup_params['list_action'] = (redirects.getPublicRedirect,
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   770
                                 aup_params)
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   771
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   772
    aup_params['list_description'] = ugettext(
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   773
       'List of Approved but Unpublished tasks.')
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   774
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   775
    filter = {
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   776
        'scope': org_entity,
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   777
        'status': 'Unpublished',
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   778
        }
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   779
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   780
    aup_list = lists.getListContent(request, aup_params, filter, idx=1,
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   781
                                    need_content=True)
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   782
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   783
    if aup_list:
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   784
      aup_mentors_list = {}
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   785
      for task_entity in aup_list['data']:
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   786
        aup_mentors_list[task_entity.key()] = db.get(task_entity.mentors)
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   787
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   788
      aup_list['info'] = (list_info_helper.getTasksInfo(aup_mentors_list), None)
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   789
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   790
      contents.append(aup_list)
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   791
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   792
    ap_params = up_params.copy()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   793
    ap_params['list_template'] = 'soc/models/list.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   794
    ap_params['list_heading'] = 'modules/ghop/task/list/heading.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   795
    ap_params['list_row'] = 'modules/ghop/task/list/row.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   796
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   797
    ap_params['list_action'] = (redirects.getPublicRedirect,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   798
                                ap_params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   799
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   800
    ap_params['list_description'] = ugettext(
3017
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   801
       'List of Published tasks.')
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   802
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   803
    filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   804
        'scope': org_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   805
        'status': ['Open', 'Reopened', 'ClaimRequested', 'Claimed',
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   806
            'ActionNeeded', 'Closed', 'AwaitingRegistration',
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   807
            'NeedsWork', 'NeedsReview'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   808
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   809
3017
6689a4c8f02e Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 3002
diff changeset
   810
    ap_list = lists.getListContent(request, ap_params, filter, idx=2,
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   811
                                   need_content=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   812
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   813
    if ap_list:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   814
      ap_mentors_list = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   815
      for task_entity in ap_list['data']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   816
        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
   817
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   818
      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
   819
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   820
      contents.append(ap_list)
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
    # call the _list method from base to display the list
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   823
    return self._list(request, up_params, contents, page_name, context)
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
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   826
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   827
  def public(self, request, access_type,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   828
             page_name=None, params=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   829
    """See base.View.public().
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   830
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   831
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   832
    # create default template context for use with any templates
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   833
    context = helper.responses.getUniversalContext(request)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   834
    helper.responses.useJavaScript(context, params['js_uses_all'])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   835
    context['page_name'] = page_name
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   836
    entity = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   837
    logic = params['logic']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   838
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   839
    try:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   840
      entity, comment_entities, ws_entities = (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   841
          logic.getFromKeyFieldsWithCWSOr404(kwargs))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   842
    except out_of_band.Error, error:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   843
      return helper.responses.errorResponse(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   844
          error, request, template=params['error_public'], context=context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   845
2981
8a99de852dc2 Fixed Task public view to always call the update method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2978
diff changeset
   846
    # because we are not sure if the Task API has called this for us we do it
8a99de852dc2 Fixed Task public view to always call the update method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2978
diff changeset
   847
    entity, comment_entity = ghop_task_logic.logic.updateTaskStatus(entity)
8a99de852dc2 Fixed Task public view to always call the update method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2978
diff changeset
   848
    if comment_entity:
8a99de852dc2 Fixed Task public view to always call the update method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2978
diff changeset
   849
      comment_entities.append(comment_entity)
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   850
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   851
    context['entity'] = entity
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   852
    context['entity_key_name'] = entity.key().id_or_name()
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   853
    context['entity_type'] = params['name']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   854
    context['entity_type_url'] = params['url_name']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   855
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   856
    user_account = user_logic.logic.getForCurrentAccount()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   857
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   858
    # get some entity specific context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   859
    self.updatePublicContext(context, entity, comment_entities,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   860
                             ws_entities, user_account, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   861
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   862
    validation = self._constructActionsList(context, entity,
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   863
                                            user_account, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   864
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   865
    context = dicts.merge(params['context'], context)
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
    if request.method == 'POST':
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   868
      return self.publicPost(request, context, params, entity,
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   869
                             user_account, validation, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   870
    else: # request.method == 'GET'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   871
      return self.publicGet(request, context, params, entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   872
                            user_account, **kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   873
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   874
  def publicPost(self, request, context, params, entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   875
                 user_account=None, validation=None, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   876
    """Handles the POST request for the entity's public page.
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
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   879
        entity: the task entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   880
        rest: see base.View.public()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   881
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   882
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   883
    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
   884
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   885
    form = params['comment_form'](request.POST)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   886
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   887
    if not form.is_valid():
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   888
      template = params['public_template']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   889
      context['comment_form'] = form
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   890
      return self._constructResponse(request, entity, context,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   891
                                     form, params, template=template)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   892
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   893
    _, fields = helper.forms.collectCleanedFields(form)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   894
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   895
    changes = []
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
    action = fields['action']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   898
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   899
    properties = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   900
    ws_properties = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   901
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   902
    # 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
   903
    if validation == 'claim_request' and action == 'request':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   904
      properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   905
          'status': 'ClaimRequested',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   906
          'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   907
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   908
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   909
      st_filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   910
          'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   911
          'scope': entity.program,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   912
          'status': 'active'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   913
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   914
      student_entity = ghop_student_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   915
          st_filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   916
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   917
      if student_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   918
        properties['student'] = student_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   919
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   920
      changes.extend([ugettext('User-Student'),
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   921
                      ugettext('Action-Claim Requested'),
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   922
                      ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   923
                      ])
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
   924
    elif (validation == 'claim_withdraw' or
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   925
        validation == 'needs_review') and action == 'withdraw':
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
          'user': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   928
          'student': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   929
          'status': 'Reopened',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   930
          'deadline': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   931
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   932
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   933
      changes.extend([ugettext('User-Student'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   934
                      ugettext('Action-Withdrawn'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   935
                      ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   936
                      ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   937
    elif validation == 'needs_review' and action == 'needs_review':
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
          'status': 'NeedsReview',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   940
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   941
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   942
      changes.extend([
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   943
          ugettext('User-Student'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   944
          ugettext('Action-Submitted work and Requested for review'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   945
          ugettext('Status-%s' % (properties['status']))])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   946
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   947
      ws_properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   948
          'parent': entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   949
          'link_id': 't%i' % (int(time.time()*100)),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   950
          'scope_path': entity.key().name(),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   951
          'scope': entity.scope,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   952
          'user': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   953
          'information': fields['comment'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   954
          'url_to_work': fields['work_submission'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   955
          'submitted_on': datetime.datetime.now(),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   956
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   957
    elif validation == 'accept_claim':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   958
      if action == 'accept':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   959
        deadline = datetime.datetime.now() + datetime.timedelta(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   960
            hours=entity.time_to_complete)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   961
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   962
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   963
            'status': 'Claimed',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   964
            '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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   967
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   968
                        ugettext('Action-Claim Accepted'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   969
                        ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   970
                        ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   971
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   972
        task_update.spawnUpdateTask(entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   973
      if action == 'reject':
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-Claim Rejected'),
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 validation == 'close':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   986
      if action == 'needs_work':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   987
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   988
            'status': 'NeedsWork',
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   991
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   992
                        ugettext('Action-Requested more work'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   993
                        ugettext('Status-%s' % (properties['status']))
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   996
        if fields['extended_deadline'] > 0:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   997
          deadline = entity.deadline + datetime.timedelta(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   998
              hours=fields['extended_deadline'])
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
          properties['deadline'] = deadline
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1001
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1002
          changes.append(ugettext('DeadlineExtendedBy-%d hrs to %s' % (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1003
              fields['extended_deadline'], deadline.strftime(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1004
                  '%d %B %Y, %H :%M'))))
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
          task_update.spawnUpdateTask(entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1007
        else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1008
          changes.append(ugettext('NoDeadlineExtensionGiven'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1009
      elif action == 'reopened':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1010
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1011
          'user': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1012
          'student': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1013
          'status': 'Reopened',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1014
          'deadline': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1015
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1016
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1017
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1018
                        ugettext('Action-Reopened'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1019
                        ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1020
                        ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1021
      elif action == 'closed':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1022
        properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1023
            'deadline': None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1024
            }
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
        if entity.student:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1027
          properties['status'] = 'Closed'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1028
        else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1029
          properties['status'] = 'AwaitingRegistration'
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
        changes.extend([ugettext('User-Mentor'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1032
                        ugettext('Action-Closed the task'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1033
                        ugettext('Status-%s' % (properties['status']))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1034
                        ])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1035
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1036
    comment_properties = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1037
        'parent': entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1038
        'scope_path': entity.key().name(),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1039
        'created_by': user_account,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1040
        'changes': changes,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1041
        }
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
    if ws_properties:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1044
      comment_properties['content'] = self.DEF_WS_MSG_FMT
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1045
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1046
      comment_properties['content'] = fields['comment']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1047
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1048
    ghop_task_logic.logic.updateEntityPropertiesWithCWS(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1049
        entity, properties, comment_properties, ws_properties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1050
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1051
    # redirect to the same page
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1052
    return http.HttpResponseRedirect('')
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
  def publicGet(self, request, context, params, entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1055
                user_account, **kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1056
    """Handles the GET request for the entity's public page.
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
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1059
        entity: the task entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1060
        rest see base.View.public()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1061
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1062
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1063
    context['comment_form'] = params['comment_form']()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1064
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1065
    template = params['public_template']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1066
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1067
    return responses.respond(request, template, context=context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1068
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1069
  def updatePublicContext(self, context, entity, comment_entities,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1070
                          ws_entities, user_account, params):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1071
    """Updates the context for the public page with information.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1072
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1073
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1074
      context: the context that should be updated
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1075
      entity: a task used to set context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1076
      user_account: user entity of the logged in user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1077
      params: dict with params for the view using this context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1078
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1079
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1080
    mentor_entities = db.get(entity.mentors)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1081
    mentors_str = ""
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1082
    for mentor in mentor_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1083
      mentors_str += mentor.name() + ", "
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1084
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1085
    if mentors_str:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1086
      context['mentors_str'] = mentors_str[:-2]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1087
    else:
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
  1088
      context['mentors_str'] = "Not Assigned"
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1089
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1090
    context['difficulty_str'] = entity.tags_string(entity.difficulty)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1091
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1092
    context['task_type_str'] = entity.tags_string(entity.task_type)
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
    if entity.deadline:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1095
      # 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
  1096
      ttc = entity.deadline - datetime.datetime.now()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1097
      (ttc_min, ttc_hour) = ((ttc.seconds / 60), (ttc.seconds / 3600))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1098
      if ttc_min >= 60:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1099
        ttc_min = ttc_min % 60
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1100
      if ttc_hour > 1:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1101
        if ttc_min == 0:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1102
          ttc_str = '%d hours' % (ttc_hour)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1103
        else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1104
          ttc_str = '%d:%02d hours' % (ttc_hour, ttc_min)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1105
        if ttc.days == 1:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1106
          ttc_str = '%d day, %s' % (ttc.days, ttc_str)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1107
        elif ttc.days > 1:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1108
          ttc_str = '%d days, %s' % (ttc.days, ttc_str)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1109
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1110
        ttc_str = '%d mins' % (ttc_min)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1111
      context['time_to_complete'] = ttc_str
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1112
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1113
      if entity.status == 'NeedsReview':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1114
        context['time_to_complete'] = 'No Time Left'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1115
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1116
        context['time_to_complete'] = '%d hours' % (entity.time_to_complete)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1117
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1118
    context['comments'] = comment_entities
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1119
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1120
    context['work_submissions'] = ws_entities
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1121
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1122
  def _constructActionsList(self, context, entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1123
                            user_account, params):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1124
    """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
  1125
    the comment form with this list.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1126
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
  1127
    This method also returns the validation used by POST method to
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1128
    validate the user input data.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1129
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1130
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1131
      context: the context that should be updated
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1132
      entity: a task used to set context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1133
      user_account: user entity of the logged in user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1134
      params: dict with params for the view using this context
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1135
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1136
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1137
    # variable that holds what kind of validation this user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1138
    # and task combination pass.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1139
    validation = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1140
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1141
    # The following header messages are shown for non-logged in
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1142
    # general public, logged in public and the student.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1143
    if entity.status is 'Closed':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1144
      context['header_msg'] = self.DEF_TASK_CLOSED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1145
      validation = 'closed'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1146
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1147
    if entity.status == 'Open':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1148
      context['header_msg'] = self.DEF_TASK_OPEN_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1149
    elif entity.status == 'Reopened':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1150
      context['header_msg'] = self.DEF_TASK_REOPENED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1151
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1152
    if user_account:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1153
      actions = [('noaction', 'Comment without action')]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1154
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1155
      # if the user is logged give him the permission to claim
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1156
      # 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
  1157
      filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1158
          'user': user_account,
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1161
      host_entity = host_logic.logic.getForFields(filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1162
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1163
      filter['scope_path'] = entity.scope_path
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1164
      org_admin_entity = ghop_org_admin_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1165
          filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1166
      mentor_entity = ghop_mentor_logic.logic.getForFields(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1167
          filter, unique=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1168
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1169
      if host_entity or org_admin_entity or mentor_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1170
        validation, mentor_actions = self._constructMentorActions(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1171
            context, entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1172
        actions += mentor_actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1173
        if entity.status in ['Unapproved', 'Unpublished', 'Open']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1174
          if host_entity or org_admin_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1175
            context['edit_link'] = redirects.getEditRedirect(entity, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1176
          elif mentor_entity:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1177
            context['suggest_link'] = ghop_redirects.getSuggestTaskRedirect(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1178
                entity, params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1179
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1180
        validation, student_actions = self._constructStudentActions(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1181
            context, entity, user_account)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1182
        actions += student_actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1183
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
  1184
      # create the difficultly level field containing the choices
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1185
      # defined in the program entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1186
      dynafields = [
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1187
          {'name': 'action',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1188
           'base': forms.ChoiceField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1189
           'label': 'Action',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1190
           'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1191
           'passthrough': ['initial', 'required', 'choices'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1192
           'choices': actions,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1193
           },
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1194
         ]
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1195
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1196
      if validation == 'needs_review':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1197
        dynafields.append(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1198
            {'name': 'work_submission',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1199
             'base': forms.URLField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1200
             'label': 'Submit Work',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1201
             'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1202
             '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
  1203
                 'Please use the comment box if you need to explain '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1204
                 'of your work.',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1205
             })
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
      if validation == 'close':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1208
        dynafields.append(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1209
            {'name': 'extended_deadline',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1210
             'base': forms.IntegerField,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1211
             'min_value': 1,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1212
             'label': 'Extend deadline by',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1213
             'required': False,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1214
             'passthrough': ['min_value', 'required', 'help_text'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1215
             'help_text': 'Optional: Specify the number of hours by '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1216
                 'which you want to extend the deadline for the task '
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1217
                 'for this student. ',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1218
             })
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
      dynaproperties = params_helper.getDynaFields(dynafields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1221
      if validation == 'needs_review':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1222
        dynaproperties['clean_work_submission'] = cleaning.clean_url(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1223
            'work_submission')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1224
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1225
      extended_comment_form = dynaform.extendDynaForm(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1226
          dynaform=params['comment_form'],
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1227
          dynaproperties=dynaproperties)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1228
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1229
      params['comment_form'] = extended_comment_form
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1230
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1231
      # 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
  1232
      # claimed before closing or re-opening
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1233
      claim_status = ['ClaimRequested', 'Claimed', 'ActionNeeded',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1234
                      'NeedsWork', 'NeedsReview']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1235
      if entity.status in claim_status:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1236
        context['header_msg'] = self.DEF_TASK_CLAIMED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1237
      elif entity.status in ['AwaitingRegistration', 'Closed']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1238
        context['header_msg'] = self.DEF_TASK_CLOSED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1239
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1240
      context['signin_comment_msg'] = self.DEF_SIGNIN_TO_COMMENT_MSG % (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1241
          context['sign_in'])
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
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 _constructMentorActions(self, context, entity):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1246
    """Constructs the list of actions for mentors, org admins and
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1247
    hosts.
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1250
    # variable that holds what kind of validation this user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1251
    # and task combination pass.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1252
    validation = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1253
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1254
    actions = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1255
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1256
    if entity.status in ['Unapproved', 'Unpublished']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1257
      context['header_msg'] = self.DEF_TASK_UNPUBLISHED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1258
      context['comment_disabled'] = True
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1259
    elif entity.status == 'Open':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1260
      context['header_msg'] = self.DEF_CAN_EDIT_TASK_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1261
    elif entity.status == 'Reopened':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1262
      context['header_msg'] = self.DEF_TASK_MENTOR_REOPENED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1263
    elif entity.status == 'ClaimRequested':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1264
      actions.extend([('accept', 'Accept claim request'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1265
                      ('reject', 'Reject claim request')])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1266
      context['header_msg'] = self.DEF_TASK_CLAIM_REQUESTED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1267
      validation = 'accept_claim'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1268
    elif entity.status == 'Claimed':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1269
      context['header_msg'] = self.DEF_TASK_CLAIMED_BY_STUDENT_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1270
    elif entity.status == 'NeedsReview':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1271
      context['header_msg'] = self.DEF_TASK_NEEDS_REVIEW_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1272
      actions.extend([('needs_work', 'Needs More Work'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1273
                      ('reopened', 'Reopen the task'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1274
                      ('closed', 'Close the task')])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1275
      validation = 'close'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1276
    elif entity.status in ['AwaitingRegistration', 'Closed']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1277
      context['header_msg'] = self.DEF_TASK_CLOSED_MSG
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
    return validation, actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1280
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1281
  def _constructStudentActions(self, context, entity, user_account):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1282
    """Constructs the list of actions for students.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1283
    """
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1284
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1285
    # variable that holds what kind of validation this user
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1286
    # and task combination pass.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1287
    validation = None
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1288
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1289
    actions = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1290
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1291
    if entity.status in ['Open', 'Reopened']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1292
      task_filter = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1293
          'user': user_account,
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
  1294
          'status': ['ClaimRequested', 'Claimed', 'ActionNeeded',
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1295
                     'NeedsWork', 'NeedsReview']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1296
          }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1297
      task_entities = ghop_task_logic.logic.getForFields(task_filter)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1298
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1299
      if len(task_entities) >= entity.program.nr_simultaneous_tasks:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1300
        context['header_msg'] = self.DEF_MAX_TASK_LIMIT_MSG_FMT % (
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1301
            entity.program.nr_simultaneous_tasks)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1302
        validation = 'claim_ineligible'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1303
        return validation, actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1304
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1305
      task_filter['status'] = 'AwaitingRegistration'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1306
      task_entities = ghop_task_logic.logic.getForFields(task_filter)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1307
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1308
      if task_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1309
        context['header_msg'] = self.DEF_AWAITING_REG_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1310
        validation = 'claim_ineligible'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1311
      else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1312
        actions.append(('request', 'Request to claim the task'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1313
        validation = 'claim_request'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1314
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1315
    # TODO: lot of double information here that can be simplified
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1316
    if entity.user and user_account.key() == entity.user.key():
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1317
      if entity.status  == 'ClaimRequested':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1318
        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
  1319
        actions.append(('withdraw', 'Withdraw from the task'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1320
        validation = 'claim_withdraw'
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
  1321
      elif entity.status in ['Claimed', 'NeedsWork',
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1322
                             'NeedsReview', 'ActionNeeded']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1323
        context['header_msg'] = self.DEF_TASK_CLAIMED_BY_YOU_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1324
        actions.extend([
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1325
            ('withdraw', 'Withdraw from the task'),
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1326
            ('needs_review', 'Submit work and Request for review')])
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1327
        validation = 'needs_review'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1328
      elif entity.status == 'NeedsReview':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1329
        context['header_msg'] = self.DEF_TASK_NO_MORE_SUBMIT_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1330
        actions.append(('withdraw', 'Withdraw from the task'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1331
        if datetime.datetime.now < entity.deadline:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1332
          actions.append(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1333
              ('needs_review', 'Submit work and Request for review'))
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1334
        validation = 'needs_review'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1335
      elif entity.status == 'AwaitingRegistration':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1336
        context['header_msg'] = self.DEF_STUDENT_SIGNUP_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1337
      elif entity.status == 'Closed':
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1338
        context['header_msg'] = self.DEF_TASK_CMPLTD_BY_YOU_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1339
    else:
3034
aa5ebb226b22 Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents: 3033
diff changeset
  1340
      if entity.status in ['ClaimRequested', 'Claimed',
2885
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1341
                           'ActionNeeded', 'NeedsWork',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1342
                           'NeedsReview']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1343
        context['header_msg'] = self.DEF_TASK_CLAIMED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1344
      if entity.status in ['AwaitingRegistration', 'Closed']:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1345
        context['header_msg'] = self.DEF_TASK_CLOSED_MSG
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1346
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1347
    return validation, actions
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1348
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1349
  @decorators.merge_params
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1350
  @decorators.check_access
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1351
  def search(self, request, access_type, page_name=None,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1352
             params=None, filter=None, order=None,**kwargs):
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1353
    """View method to search for GHOP Tasks.
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1354
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1355
    Args:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1356
      request: the standard Django HTTP request object
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1357
      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
  1358
      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
  1359
      params: a dict with params for this View
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1360
      kwargs: the Key Fields for the specified entity
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
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1363
    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
  1364
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1365
    get_params = request.GET
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1366
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1367
    contents = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1368
    context = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1369
    if not filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1370
      filter = {}
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1371
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1372
    public_status = ['Open', 'Reopened', 'ClaimRequested', 'Claimed',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1373
                     'ActionNeeded', 'Closed', 'AwaitingRegistration',
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1374
                     'NeedsWork', 'NeedsReview']
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1375
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1376
    task_params = params.copy()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1377
    task_params['list_template'] = 'modules/ghop/task/search/search.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1378
    task_params['list_heading'] = 'modules/ghop/task/search/heading.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1379
    task_params['list_row'] = 'modules/ghop/task/search/row.html'
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1380
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1381
    task_params['list_action'] = (redirects.getPublicRedirect,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1382
                                  task_params)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1383
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1384
    task_params['list_description'] = ugettext(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1385
       'Search results: ')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1386
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1387
    program_entity = ghop_program_logic.logic.getFromKeyFields(kwargs)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1388
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1389
    org_fields = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1390
        'scope': program_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1391
        }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1392
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1393
    org_entities = ghop_org_logic.logic.getForFields(org_fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1394
    org_names = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1395
    for org in org_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1396
      org_names.append(org.name)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1397
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1398
    df_entities = ghop_task_model.TaskDifficultyTag.get_by_scope(
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1399
        program_entity)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1400
    difficulties = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1401
    for df_entity in df_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1402
      difficulties.append(df_entity.tag)
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
    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
  1405
    task_types = []
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1406
    for tt_entity in tt_entities:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1407
      task_types.append(tt_entity.tag)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1408
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1409
    context['org_entities'] = org_names
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1410
    context['public_status'] = public_status
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1411
    context['difficulties'] =  difficulties
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1412
    context['tags'] = task_types
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1413
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1414
    org_filter = get_params.getlist('Organization')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1415
    status_filter = get_params.getlist('Status')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1416
    df_filter = get_params.getlist('Difficulty')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1417
    tag_filter = get_params.getlist('Tags')
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1418
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1419
    if org_filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1420
      org_fields = {
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1421
        'scope': program_entity,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1422
        'name': org_filter,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1423
      }
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1424
      org_entities = ghop_org_logic.logic.getForFields(org_fields)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1425
      filter['scope'] = org_entities
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1426
    if status_filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1427
      filter['status']= status_filter
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1428
    else:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1429
      filter['status'] = public_status
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1430
    if df_filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1431
      filter['difficulty'] = df_filter
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1432
    if tag_filter:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1433
      filter['task_type'] = tag_filter
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1434
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1435
    filter['program'] = program_entity
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1436
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1437
    task_list = lists.getListContent(request, task_params, filter,
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1438
                                     order=order, idx=0, need_content=True)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1439
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1440
    if task_list:
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1441
      contents.append(task_list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1442
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1443
    # call the _list method from base to display the list
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1444
    return self._list(request, task_params, contents, page_name, context)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1445
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1446
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1447
view = View()
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1448
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1449
create = decorators.view(view.create)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1450
delete = decorators.view(view.delete)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1451
edit = decorators.view(view.edit)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1452
list = decorators.view(view.list)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1453
list_org_tasks = decorators.view(view.listOrgTasks)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1454
suggest_task = decorators.view(view.suggestTask)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1455
public = decorators.view(view.public)
f064654837f7 Added GHOP Task View.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
  1456
search = decorators.view(view.search)