app/soc/views/models/timeline.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 24 Oct 2009 16:23:31 -0700
changeset 3043 187c1709756b
parent 2936 75f9c945ed8a
permissions -rw-r--r--
GSoC Views
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
768
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
1307
091a21cf3627 Update the copyright notice for 2009.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1108
diff changeset
     3
# Copyright 2009 the Melange authors.
768
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
847
b1077116fe59 Add calendar widget support for timeline fields. Fix docstring typo in soc.views.models.timeline module. Add timeline edit template which loads necessary javascript files for datetimepicker widget.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 799
diff changeset
    17
"""Views for Timeline.
768
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
2810
e63b3e0845a9 Make the timeline View work directly on the GSoC timeline for the time being.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2787
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
847
b1077116fe59 Add calendar widget support for timeline fields. Fix docstring typo in soc.views.models.timeline module. Add timeline edit template which loads necessary javascript files for datetimepicker widget.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 799
diff changeset
    23
    '"Pawel Solyga" <pawel.solyga@gmail.com>',
768
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
  ]
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from django import forms
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.logic import dicts
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 776
diff changeset
    30
from soc.logic.models import program as program_logic
1108
64acc3c02ad1 Added rights to soc/views/models/timeline.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 949
diff changeset
    31
from soc.views.helper import access
1583
1e4c785f1adf Added decorators
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1475
diff changeset
    32
from soc.views.helper import decorators
949
07fdadbd6dc7 Check if timeline exists and when somebody tries to edit non existing timelime display error message. Add TODO regarding error message customization for Timeline. Add support for calendar widget in timeline for both gsoc and ghop programs (gsoc was hardcoded before).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 858
diff changeset
    33
from soc.views.helper import dynaform
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 776
diff changeset
    34
from soc.views.helper import params as params_helper
768
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
from soc.views.models import base
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
2810
e63b3e0845a9 Make the timeline View work directly on the GSoC timeline for the time being.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2787
diff changeset
    37
import gsoc.logic.models.timeline
768
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
class View(base.View):
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
  """View methods for the Timeline model.
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
  """
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
  def __init__(self, params=None):
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
    """Defines the fields and methods required for the base View class
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
    to provide the user with list, public, create, edit and delete views.
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
    Params:
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
      params: a dict with params for this View
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
    """
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
1108
64acc3c02ad1 Added rights to soc/views/models/timeline.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 949
diff changeset
    52
    rights = access.Checker(params)
2936
75f9c945ed8a Added program_logic parameter to checkCanEditTimeline access check and corresponding changes in timeline views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2810
diff changeset
    53
    rights['edit'] = [('checkCanEditTimeline', [program_logic.logic])]
1108
64acc3c02ad1 Added rights to soc/views/models/timeline.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 949
diff changeset
    54
768
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
    new_params = {}
1108
64acc3c02ad1 Added rights to soc/views/models/timeline.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 949
diff changeset
    56
    new_params['rights'] = rights
2810
e63b3e0845a9 Make the timeline View work directly on the GSoC timeline for the time being.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2787
diff changeset
    57
    # TODO: Change to basic timeline when GSoC has been moved to module system
e63b3e0845a9 Make the timeline View work directly on the GSoC timeline for the time being.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2787
diff changeset
    58
    new_params['logic'] = gsoc.logic.models.timeline.logic
847
b1077116fe59 Add calendar widget support for timeline fields. Fix docstring typo in soc.views.models.timeline module. Add timeline edit template which loads necessary javascript files for datetimepicker widget.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 799
diff changeset
    59
    new_params['edit_template'] = 'soc/timeline/edit.html'
768
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
    new_params['name'] = "Timeline"
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
776
f86a76f52bf4 Started on edit timeline
Sverre Rabbelier <srabbelier@gmail.com>
parents: 768
diff changeset
    62
    patterns = [(r'^%(url_name)s/(?P<access_type>edit)/%(key_fields)s$',
2936
75f9c945ed8a Added program_logic parameter to checkCanEditTimeline access check and corresponding changes in timeline views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 2810
diff changeset
    63
                  '%(module_package)s.%(module_name)s.edit',
847
b1077116fe59 Add calendar widget support for timeline fields. Fix docstring typo in soc.views.models.timeline module. Add timeline edit template which loads necessary javascript files for datetimepicker widget.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 799
diff changeset
    64
                  "Edit %(name_short)s")]
776
f86a76f52bf4 Started on edit timeline
Sverre Rabbelier <srabbelier@gmail.com>
parents: 768
diff changeset
    65
1475
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1451
diff changeset
    66
    new_params['create_extra_dynaproperties'] = {
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1451
diff changeset
    67
        'link_id': forms.CharField(widget=forms.HiddenInput)
22b63ab59b27 Make timeline a Linkable
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1451
diff changeset
    68
        }
776
f86a76f52bf4 Started on edit timeline
Sverre Rabbelier <srabbelier@gmail.com>
parents: 768
diff changeset
    69
    new_params['django_patterns_defaults'] = patterns
f86a76f52bf4 Started on edit timeline
Sverre Rabbelier <srabbelier@gmail.com>
parents: 768
diff changeset
    70
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1343
diff changeset
    71
    new_params['edit_dynaproperties'] = []
847
b1077116fe59 Add calendar widget support for timeline fields. Fix docstring typo in soc.views.models.timeline module. Add timeline edit template which loads necessary javascript files for datetimepicker widget.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 799
diff changeset
    72
768
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
    params = dicts.merge(params, new_params)
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
    super(View, self).__init__(params=params)
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
1451
ef134d062b83 Add generic datepicker support
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    77
793
4bde741aa2bb Resolved a bug when editing a timeline.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 784
diff changeset
    78
  def _editPost(self, request, entity, fields):
4bde741aa2bb Resolved a bug when editing a timeline.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 784
diff changeset
    79
    """See base.View._editPost().
4bde741aa2bb Resolved a bug when editing a timeline.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 784
diff changeset
    80
    """
2810
e63b3e0845a9 Make the timeline View work directly on the GSoC timeline for the time being.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2787
diff changeset
    81
793
4bde741aa2bb Resolved a bug when editing a timeline.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 784
diff changeset
    82
    # a timeline can only be edited, so set the scope path using entity
4bde741aa2bb Resolved a bug when editing a timeline.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 784
diff changeset
    83
    fields['scope_path'] = entity.scope_path
778
bc13cd968946 Added support for mutliple edit forms based on entity type
Sverre Rabbelier <srabbelier@gmail.com>
parents: 776
diff changeset
    84
768
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
view = View()
002d3141ff99 Added logic and view classes for the Timeline model
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
1584
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
    88
edit = decorators.view(view.edit)
d8ba8c917f37 Make use of decorators.view for all views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1583
diff changeset
    89
public = decorators.view(view.public)