Commit 6b4a09f5 authored by Romain Courteaud's avatar Romain Courteaud

Replace here variable by context.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14906 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c17a3c00
...@@ -81,7 +81,7 @@ Beware this only generates the HTML code, no CSS generation is done in this scri ...@@ -81,7 +81,7 @@ Beware this only generates the HTML code, no CSS generation is done in this scri
\n \n
<tal:block tal:define="basic options/basic;\n <tal:block tal:define="basic options/basic;\n
planning options/planning;\n planning options/planning;\n
address python:basic.here.getUrl()">\n address python:basic.context.getUrl()">\n
\n \n
<!-- hidden fields holding some usefull data-->\n <!-- hidden fields holding some usefull data-->\n
<input type="hidden" name="list_selection_name" value="PLanningView" tal:attributes="value python:basic.field.get_value(\'selection_name\')"/>\n <input type="hidden" name="list_selection_name" value="PLanningView" tal:attributes="value python:basic.field.get_value(\'selection_name\')"/>\n
...@@ -321,7 +321,7 @@ Beware this only generates the HTML code, no CSS generation is done in this scri ...@@ -321,7 +321,7 @@ Beware this only generates the HTML code, no CSS generation is done in this scri
\n \n
<!-- inserting depth widget -->\n <!-- inserting depth widget -->\n
<div tal:condition= "python:axis==planning.X"\n <div tal:condition= "python:axis==planning.X"\n
tal:define="url python:\'%s/%s\' % (basic.here.absolute_url(),basic.form.id);\n tal:define="url python:\'%s/%s\' % (basic.context.absolute_url(),basic.form.id);\n
selection_name python:basic.field.get_value(\'selection_name\')"\n selection_name python:basic.field.get_value(\'selection_name\')"\n
tal:attributes="id python:axis.name + \'_depth\'">\n tal:attributes="id python:axis.name + \'_depth\'">\n
<a tal:repeat="unfold_level python:range(0,4)"\n <a tal:repeat="unfold_level python:range(0,4)"\n
...@@ -332,7 +332,7 @@ Beware this only generates the HTML code, no CSS generation is done in this scri ...@@ -332,7 +332,7 @@ Beware this only generates the HTML code, no CSS generation is done in this scri
</div>\n </div>\n
\n \n
<div tal:condition= "python:axis==planning.Y"\n <div tal:condition= "python:axis==planning.Y"\n
tal:define="url python:\'%s/%s\' % (basic.here.absolute_url(),basic.form.id);\n tal:define="url python:\'%s/%s\' % (basic.context.absolute_url(),basic.form.id);\n
selection_name python:basic.field.get_value(\'selection_name\')"\n selection_name python:basic.field.get_value(\'selection_name\')"\n
tal:attributes="id python:axis.name + \'_depth\'">\n tal:attributes="id python:axis.name + \'_depth\'">\n
<a tal:repeat="unfold_level python:range(0,4)"\n <a tal:repeat="unfold_level python:range(0,4)"\n
...@@ -409,7 +409,7 @@ Beware this only generates the HTML code, no CSS generation is done in this scri ...@@ -409,7 +409,7 @@ Beware this only generates the HTML code, no CSS generation is done in this scri
<a tal:condition="python:block.info[area].info == \'__\'"\n <a tal:condition="python:block.info[area].info == \'__\'"\n
tal:attributes="href python:block.info[area].link;\n tal:attributes="href python:block.info[area].link;\n
class python:\'planning_box_\' + info_area">\n class python:\'planning_box_\' + info_area">\n
<img tal:attributes="src python:basic.here.getUrl() + \'/images/question.png\'"\n <img tal:attributes="src python:basic.context.getUrl() + \'/images/question.png\'"\n
height="15" width="15">\n height="15" width="15">\n
</a>\n </a>\n
</tal:block>\n </tal:block>\n
...@@ -448,7 +448,7 @@ Beware this only generates the HTML code, no CSS generation is done in this scri ...@@ -448,7 +448,7 @@ Beware this only generates the HTML code, no CSS generation is done in this scri
<div id="left" style="position:absolute; width:5px;height:5px; background:#a45d10"></div>\n <div id="left" style="position:absolute; width:5px;height:5px; background:#a45d10"></div>\n
\n \n
<!-- declaring DTML properties -->\n <!-- declaring DTML properties -->\n
<tal:block tal:replace="structure python:here.planning_dhtml(planning=planning)"/>\n <tal:block tal:replace="structure python:context.planning_dhtml(planning=planning)"/>\n
\n \n
<!--/div-->\n <!--/div-->\n
</div>\n </div>\n
......
388 389
\ No newline at end of file \ No newline at end of file
...@@ -89,8 +89,7 @@ class PlanningBoxValidator(Validator.StringBaseValidator): ...@@ -89,8 +89,7 @@ class PlanningBoxValidator(Validator.StringBaseValidator):
""" """
# init params # init params
value = None value = None
form = field.aq_parent context = getContext(field, REQUEST)
here = getattr(form, 'aq_parent', REQUEST)
# recover usefull properties # recover usefull properties
block_moved_string = REQUEST.get('block_moved','') block_moved_string = REQUEST.get('block_moved','')
...@@ -101,10 +100,11 @@ class PlanningBoxValidator(Validator.StringBaseValidator): ...@@ -101,10 +100,11 @@ class PlanningBoxValidator(Validator.StringBaseValidator):
################################################## ##################################################
# build structure # build structure
basic, planning = PlanningBoxWidgetInstance.render_structure(field=field, basic, planning = PlanningBoxWidgetInstance.render_structure(field=field,
key=key, value=value, REQUEST= REQUEST, here=here) key=key, value=value, REQUEST= REQUEST,
context=context)
# getting coordinates script generator # getting coordinates script generator
planning_coordinates_method = getattr(here,'planning_coordinates') planning_coordinates_method = getattr(context, 'planning_coordinates')
# calling script to generate coordinates # calling script to generate coordinates
planning_coordinates = planning_coordinates_method(basic=basic, planning_coordinates = planning_coordinates_method(basic=basic,
planning=planning) planning=planning)
...@@ -296,7 +296,7 @@ class PlanningBoxValidator(Validator.StringBaseValidator): ...@@ -296,7 +296,7 @@ class PlanningBoxValidator(Validator.StringBaseValidator):
start_property = field.get_value('x_start_bloc') start_property = field.get_value('x_start_bloc')
stop_property = field.get_value('x_stop_bloc') stop_property = field.get_value('x_stop_bloc')
# getting round_script if exists # getting round_script if exists
round_script=getattr(here, field.get_value('round_script'), None) round_script=getattr(context, field.get_value('round_script'), None)
# now processing activity updates # now processing activity updates
for activity_name in activity_dict.keys(): for activity_name in activity_dict.keys():
# recovering list of moved blocks in the current activity # recovering list of moved blocks in the current activity
...@@ -913,15 +913,15 @@ class PlanningBoxWidget(Widget.Widget): ...@@ -913,15 +913,15 @@ class PlanningBoxWidget(Widget.Widget):
external PageTemplate (or DTML depending) to render the CSS code external PageTemplate (or DTML depending) to render the CSS code
relative to the structure that need to be rendered relative to the structure that need to be rendered
""" """
here = REQUEST['here'] context = getContext(field, REQUEST)
# build structure # build structure
# render_structure will call all method necessary to build the entire # render_structure will call all method necessary to build the entire
# structure relative to the planning # structure relative to the planning
# creates and fill up self.basic, self.planning and self.build_error_list # creates and fill up self.basic, self.planning and self.build_error_list
basic, planning = self.render_structure(field=field, key=key, value=value, basic, planning = self.render_structure(field=field, key=key, value=value,
REQUEST=REQUEST, here=here) REQUEST=REQUEST, context=context)
# getting CSS script generator # getting CSS script generator
planning_css_method = getattr(REQUEST['here'], 'planning_css') planning_css_method = getattr(context, 'planning_css')
# recover CSS data buy calling DTML document # recover CSS data buy calling DTML document
CSS_data = planning_css_method(basic=basic, planning=planning) CSS_data = planning_css_method(basic=basic, planning=planning)
# saving structure inside the request for HTML render # saving structure inside the request for HTML render
...@@ -944,13 +944,14 @@ class PlanningBoxWidget(Widget.Widget): ...@@ -944,13 +944,14 @@ class PlanningBoxWidget(Widget.Widget):
planning = REQUEST.get('planning') planning = REQUEST.get('planning')
# getting HTML rendering Page Template # getting HTML rendering Page Template
planning_html_method = getattr(REQUEST['here'], 'planning_content') planning_html_method = getattr(getContext(field, REQUEST),
'planning_content')
# recovering HTML data by calling Page Template document # recovering HTML data by calling Page Template document
HTML_data = planning_html_method(basic=basic, planning=planning) HTML_data = planning_html_method(basic=basic, planning=planning)
# return HTML data # return HTML data
return HTML_data return HTML_data
def render_structure(self, field, key, value, REQUEST, here): def render_structure(self, field, key, value, REQUEST, context):
""" """
This method is the begining of the rendering procedure. it calls all This method is the begining of the rendering procedure. it calls all
methods needed to generate BasicStructure with ERP5 objects, and then methods needed to generate BasicStructure with ERP5 objects, and then
...@@ -979,7 +980,7 @@ class PlanningBoxWidget(Widget.Widget): ...@@ -979,7 +980,7 @@ class PlanningBoxWidget(Widget.Widget):
list_error = REQUEST.get('list_block_error') list_error = REQUEST.get('list_block_error')
if list_error is None: if list_error is None:
list_error = [] list_error = []
selection = here.portal_selections.getSelectionFor( selection = context.portal_selections.getSelectionFor(
selection_name, REQUEST) selection_name, REQUEST)
# params contained in the selection object is a dictionnary. # params contained in the selection object is a dictionnary.
# must exist as an empty dictionnary if selection is empty. # must exist as an empty dictionnary if selection is empty.
...@@ -990,16 +991,16 @@ class PlanningBoxWidget(Widget.Widget): ...@@ -990,16 +991,16 @@ class PlanningBoxWidget(Widget.Widget):
###### CALL CLASS METHODS TO BUILD BASIC STRUCTURE ###### ###### CALL CLASS METHODS TO BUILD BASIC STRUCTURE ######
# creating BasicStructure instance (and initializing its internal values) # creating BasicStructure instance (and initializing its internal values)
basic = BasicStructure(here=here, basic = BasicStructure(context=context,
form=form, field=field, form=form, field=field,
REQUEST=REQUEST, list_method=list_method, REQUEST=REQUEST, list_method=list_method,
selection=selection, params=params, selection=selection, params=params,
selection_name=selection_name, selection_name=selection_name,
title_line=title_line, title_line=title_line,
report_root_list=report_root_list, report_root_list=report_root_list,
portal_types=portal_types, portal_types=portal_types,
sort=sort, sort=sort,
list_error=list_error) list_error=list_error)
# call build method to generate BasicStructure # call build method to generate BasicStructure
status = basic.build() status = basic.build()
if status != 1: if status != 1:
...@@ -1030,14 +1031,14 @@ class BasicStructure: ...@@ -1030,14 +1031,14 @@ class BasicStructure:
No zoom is applied on this structure No zoom is applied on this structure
""" """
def __init__ (self, here='', form='', field='', REQUEST='', list_method='', def __init__ (self, context='', form='', field='', REQUEST='', list_method='',
selection=None, params = '', selection_name='', selection=None, params = '', selection_name='',
report_root_list='', title_line='', portal_types='', report_root_list='', title_line='', portal_types='',
sort=None, list_error=None): sort=None, list_error=None):
""" """
Init main internal parameters Init main internal parameters
""" """
self.here = here self.context = context
self.form = form self.form = form
self.field = field self.field = field
self.REQUEST = REQUEST self.REQUEST = REQUEST
...@@ -1084,7 +1085,7 @@ class BasicStructure: ...@@ -1084,7 +1085,7 @@ class BasicStructure:
self.selection.edit(default_sort_on=self.sort) self.selection.edit(default_sort_on=self.sort)
self.selection.edit(sort_on=self.sort) self.selection.edit(sort_on=self.sort)
self.here.portal_selections.setSelectionFor( self.context.portal_selections.setSelectionFor(
self.selection_name, self.selection_name,
self.selection, self.selection,
REQUEST=self.REQUEST) REQUEST=self.REQUEST)
...@@ -1117,7 +1118,7 @@ class BasicStructure: ...@@ -1117,7 +1118,7 @@ class BasicStructure:
if hasattr(self.list_method, 'method_name'): if hasattr(self.list_method, 'method_name'):
if self.list_method.method_name == 'ObjectValues': if self.list_method.method_name == 'ObjectValues':
# list_method is available # list_method is available
self.list_method = self.here.objectValues self.list_method = self.context.objectValues
kw = copy(self.params) kw = copy(self.params)
else: else:
# building a complex query so we should not pass too many variables # building a complex query so we should not pass too many variables
...@@ -1137,7 +1138,7 @@ class BasicStructure: ...@@ -1137,7 +1138,7 @@ class BasicStructure:
kw[cname] = self.params[cname] kw[cname] = self.params[cname]
# try to get the method through acquisition # try to get the method through acquisition
try: try:
self.list_method = getattr(self.here, self.list_method.method_name) self.list_method = getattr(self.context, self.list_method.method_name)
except (AttributeError, KeyError): except (AttributeError, KeyError):
pass pass
elif self.list_method in (None,''): elif self.list_method in (None,''):
...@@ -1148,7 +1149,7 @@ class BasicStructure: ...@@ -1148,7 +1149,7 @@ class BasicStructure:
############## DEFINING STAT METHOD ############## ############## DEFINING STAT METHOD ##############
################################################## ##################################################
stat_method = self.field.get_value('stat_method') stat_method = self.field.get_value('stat_method')
stat_method = getattr(self.here,stat_method, None) stat_method = getattr(self.context, stat_method, None)
if stat_method is None: if stat_method is None:
show_stat = 0 show_stat = 0
else: else:
...@@ -1188,7 +1189,7 @@ class BasicStructure: ...@@ -1188,7 +1189,7 @@ class BasicStructure:
selection_report_current = self.selection.getReportList() selection_report_current = self.selection.getReportList()
# building report_tree_list # building report_tree_list
report_tree_list = makeTreeList(here=self.here, form=self.form, report_tree_list = makeTreeList(here=self.context, form=self.form,
root_dict=None, root_dict=None,
report_path=self.selection_report_path, report_path=self.selection_report_path,
base_category=None, depth=0, base_category=None, depth=0,
...@@ -1245,7 +1246,7 @@ class BasicStructure: ...@@ -1245,7 +1246,7 @@ class BasicStructure:
# getting list of statistic blocks # getting list of statistic blocks
stat_list = stat_method(selection=self.selection, stat_list = stat_method(selection=self.selection,
list_method=self.list_method, list_method=self.list_method,
selection_context=self.here, selection_context=self.context,
report_tree_list=report_tree_list, report_tree_list=report_tree_list,
object_tree_line=object_tree_line, object_tree_line=object_tree_line,
REQUEST=self.REQUEST, field=self.field) REQUEST=self.REQUEST, field=self.field)
...@@ -1272,7 +1273,7 @@ class BasicStructure: ...@@ -1272,7 +1273,7 @@ class BasicStructure:
self.selection.edit(exception_uid_list= \ self.selection.edit(exception_uid_list= \
object_tree_line.getExceptionUidList()) object_tree_line.getExceptionUidList())
object_list = self.selection(method = self.list_method, object_list = self.selection(method = self.list_method,
context=self.here, REQUEST=self.REQUEST) context=self.context, REQUEST=self.REQUEST)
else: else:
# no list_method found # no list_method found
# XXX seems to be buggy : # XXX seems to be buggy :
...@@ -1412,7 +1413,7 @@ class BasicStructure: ...@@ -1412,7 +1413,7 @@ class BasicStructure:
################################################## ##################################################
if self.list_method is not None and self.render_format != 'list': if self.list_method is not None and self.render_format != 'list':
self.selection.edit(params = self.params) self.selection.edit(params = self.params)
self.here.portal_selections.setSelectionFor(self.selection_name, self.context.portal_selections.setSelectionFor(self.selection_name,
self.selection, self.selection,
REQUEST = self.REQUEST) REQUEST = self.REQUEST)
...@@ -2137,7 +2138,7 @@ class PlanningStructure: ...@@ -2137,7 +2138,7 @@ class PlanningStructure:
axis_start = self.secondary_axis.start axis_start = self.secondary_axis.start
# XXX Isn't field enough ? # XXX Isn't field enough ?
axis_script=getattr(basic_structure.here, axis_script=getattr(basic_structure.context,
basic_structure.field.get_value('sec_axis_script'),None) basic_structure.field.get_value('sec_axis_script'),None)
if axis_script is None: if axis_script is None:
# ERROR # ERROR
...@@ -3115,6 +3116,22 @@ class PlanningBox(ZMIField): ...@@ -3115,6 +3116,22 @@ class PlanningBox(ZMIField):
def render_css(self, value=None, REQUEST=None): def render_css(self, value=None, REQUEST=None):
return self.widget.render_css(self, '', value, REQUEST) return self.widget.render_css(self, '', value, REQUEST)
# XXX Copy paste from listbox
def getContext(field, REQUEST):
"""
Return the context of rendering this PlanningBox.
"""
value = REQUEST.get('here')
if value is None:
value = getForm(field).aq_parent
return value
# XXX Copy paste from listbox
def getForm(field):
"""Return the form which contains the PlanningBox.
"""
return field.aq_parent
# Allow classes in ZMI # Allow classes in ZMI
for klass in (PlanningBoxWidget, BasicStructure, BasicGroup, for klass in (PlanningBoxWidget, BasicStructure, BasicGroup,
BasicActivity, PlanningStructure, Activity, BasicActivity, PlanningStructure, Activity,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment