Back to index

plone3  3.1.7
Public Member Functions
plone.app.form.widgets.datecomponents.DateComponents Class Reference
Inheritance diagram for plone.app.form.widgets.datecomponents.DateComponents:
Inheritance graph
[legend]
Collaboration diagram for plone.app.form.widgets.datecomponents.DateComponents:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def result

Detailed Description

A view that provides some helper methods useful in date widgets.

Definition at line 26 of file datecomponents.py.


Member Function Documentation

def plone.app.form.widgets.datecomponents.DateComponents.result (   self,
  date = None,
  use_ampm = False,
  starting_year = None,
  ending_year = None,
  future_years = None,
  minute_step = 5 
)
Returns a dict with date information.

Definition at line 37 of file datecomponents.py.

00037 
00038                minute_step=5):
00039         """Returns a dict with date information.
00040         """
00041 
00042         ptool = getToolByName(self.context, 'portal_properties')
00043 
00044         site_props = ptool.site_properties
00045 
00046         # Get the date format from the locale
00047         context = aq_inner(self.context)
00048         portal_state = getMultiAdapter((context, self.request), name=u'plone_portal_state')
00049 
00050         locale = portal_state.locale()
00051         dates = portal_state.locale().dates
00052 
00053         timepattern = dates.getFormatter('time').getPattern()
00054         if 'a' in timepattern:
00055              use_ampm = True
00056         month_names = dates.getFormatter('date').calendar.months
00057 
00058         # 'id' is what shows up.  December for month 12. 
00059         # 'value' is the value for the form.
00060         # 'selected' is whether or not it is selected.
00061 
00062         default=0
00063         years=[]
00064         days=[]
00065         months=[]
00066         hours=[]
00067         minutes=[]
00068         ampm=[]
00069         now=DateTime()
00070 
00071         # This debacle is because the date that is usually passed in ends with GMT
00072         # and of course DateTime is too stupid to handle it.  So we strip it off.
00073 
00074         if isinstance(date, basestring):
00075             date=date.strip()
00076             if not date:
00077                 date=None
00078             elif date.split(' ')[-1].startswith('GMT'):
00079                 date=' '.join(date.split(' ')[:-1])
00080 
00081         if date is None:
00082             date=now
00083             default=1
00084         elif not isinstance(date, DateTime):
00085             try:
00086                 date=DateTime(date)
00087             except (TypeError, DateTimeError):
00088                 date=now
00089                 default=1
00090 
00091         # Anything above PLONE_CEILING should be PLONE_CEILING
00092         if date.greaterThan(PLONE_CEILING):
00093             date = PLONE_CEILING
00094 
00095         # Get portal year range
00096         if starting_year is None:
00097             min_year = site_props.getProperty('calendar_starting_year', 1999)
00098         else:
00099             min_year = int(starting_year)
00100         if ending_year is None:
00101             if future_years is None:
00102                 max_year = site_props.getProperty('calendar_future_years_available', 5) + now.year()
00103             else:
00104                 max_year = int(future_years) + now.year()
00105         else:
00106             max_year = int(ending_year)
00107 
00108         # keeps the existing date if it's out of range
00109         if not default:
00110             if min_year > date.year():
00111                 min_year = date.year()
00112             if max_year < date.year():
00113                 max_year = date.year()
00114 
00115         year=int(date.strftime('%Y'))
00116 
00117         if default:
00118             years.append({'id': '--', 'value': '0000', 'selected': 1})
00119         else:
00120             years.append({'id': '--', 'value': '0000', 'selected': None})
00121 
00122         for x in range(min_year, max_year+1):
00123             d={'id': x, 'value': x, 'selected': None}
00124             if x==year and not default:
00125                 d['selected']=1
00126             years.append(d)
00127 
00128         month=int(date.strftime('%m'))
00129 
00130         if default:
00131             months.append({'id': '--', 'value': '00', 'selected': 1, 'title': '--'})
00132         else:
00133             months.append({'id': '--', 'value': '00', 'selected': None, 'title': '--'})
00134 
00135         for x in range(1, 13):
00136             d={'id': ENGLISH_MONTH_NAMES[x], 'value': '%02d' % x, 'selected': None}
00137             if x==month and not default:
00138                 d['selected']=1
00139             d['title']=month_names[x][0]
00140             months.append(d)
00141 
00142         day=int(date.strftime('%d'))
00143 
00144         if default:
00145             days.append({'id': '--', 'value': '00', 'selected': 1})
00146         else:
00147             days.append({'id': '--', 'value': '00', 'selected': None})
00148 
00149         for x in range(1, 32):
00150             d={'id': x, 'value': '%02d' % x, 'selected': None}
00151             if x==day and not default:
00152                 d['selected']=1
00153             days.append(d)
00154 
00155         if use_ampm:
00156             hours_range=[12]+range(1,12)
00157             hour_default='12'
00158             hour=int(date.strftime('%I'))
00159         else:
00160             hours_range=range(0,24)
00161             hour_default='00'
00162             hour=int(date.strftime('%H'))
00163 
00164         if default:
00165             hours.append({'id': '--', 'value': hour_default, 'selected': 1})
00166         else:
00167             hours.append({'id': '--', 'value': hour_default, 'selected': None})
00168 
00169         for x in hours_range:
00170             d={'id': '%02d' % x, 'value': '%02d' % x, 'selected': None }
00171             if x==hour and not default:
00172                 d['selected']=1
00173             hours.append(d)
00174 
00175         minute=int(date.strftime('%M'))
00176 
00177         if default:
00178             minutes.append({'id': '--', 'value': '00', 'selected': 1})
00179         else:
00180             minutes.append({'id': '--', 'value': '00', 'selected': None})
00181 
00182         for x in range(0, 60, minute_step):
00183             d={'id': '%02d' % x, 'value': '%02d' % x, 'selected': None}
00184             if (x==minute or minute < x < minute+minute_step) and not default:
00185                 d['selected']=1
00186             minutes.append(d)
00187 
00188         if use_ampm:
00189             p=date.strftime('%p')
00190 
00191             if default:
00192                 ampm.append({'id': '--', 'value': 'AM', 'selected': 1})
00193             else:
00194                 ampm.append({'id': '--', 'value': 'AM', 'selected': None})
00195 
00196             for x in ('AM', 'PM'):
00197                 d={'id': x, 'value': x, 'selected': None}
00198                 if x==p and not default:
00199                     d['selected']=1
00200                 ampm.append(d)
00201 
00202         return {'years': years, 'months': months, 'days': days,
00203                 'hours': hours, 'minutes': minutes, 'ampm': ampm}

Here is the call graph for this function:


The documentation for this class was generated from the following file: