Ejemplo n.º 1
0
 def get_value(self, name, language=None):
     if name in ('rrule_interval', 'rrule_byday', 'rrule_until'):
         f_name, kk, param = name.partition('_')
         property = self.metadata.get_property(f_name, language=language)
         if property:
             value = property.get_parameter(param)
             if param == 'byday' and value is not None:
                 bydays = []
                 for v in value:
                     bydays.append(DaysOfWeek.get_name_by_shortname(v))
                 return bydays
             return value
     proxy = super(Event, self)
     return proxy.get_value(name, language)
Ejemplo n.º 2
0
def get_dates(start, end, rrule):
    dates = set()
    days = range((end - start).days + 1)
    f = lambda date: dates.update([ date + timedelta(x) for x in days ])

    # Case 1: No recurrence rule
    if not rrule or not rrule.value:
        f(start)
        return dates

    # Case 2: Recurrence rule
    rrule_name = rrule.value
    rrule_interval = int(rrule.get_parameter('interval') or 1)
    bydays = rrule.get_parameter('byday')
    if bydays:
        bydays = [ int(DaysOfWeek.get_name_by_shortname(v))
                   for v in bydays ]

    until = rrule.get_parameter('until')
    if until:
        until += timedelta(1)
    else:
        until = max(start, date.today()) + MAX_DELTA

    next_date = rrules[rrule_name]
    while start < until:
        interval = rrule_interval
        if bydays:
            # Check any day of byday parameter
            for byday in bydays:
                # Skip previous byday values
                if start.isoweekday() > byday:
                    continue
                # Go ahead to current byday value
                while start.isoweekday() < byday:
                    start = next_day(start)
                if start >= until:
                    break
                # Add current day (== byday value)
                f(start)
        else:
            f(start)
        # Go to next date based on rrule value and interval
        while interval > 0:
            start = next_date(start)
            interval -= 1

    return dates
Ejemplo n.º 3
0
class RRule_Field(Select_Field):
    """Recurrence Rule
        - byday allowed on value 'weekly' only
        - default byday is MO,TU,WE,TH,FR,SA,SU
        - interval not allowed on value 'daily'
        - default interval is 1

        Examples:
            rrule;byday=MO,WE,FR;interval=1:weekly
            rrule;interval=2:monthly
    """
    datatype = RRule_Datatype
    parameters_schema = {'interval': RRuleInterval_Datatype,
                         'byday': DaysOfWeek(multiple=True),
                         'until': RRuleUntil_Datatype}
    widget = RRule_Widget
Ejemplo n.º 4
0
 def set_value(self, resource, context, name, form):
     if name in ('rrule_interval', 'rrule_byday', 'rrule_until', 'allday'):
         return False
     elif name == 'rrule':
         value = form.get(name, None)
         if value:
             kw = {
                 'interval': form.get('rrule_interval', None),
                 'until': form.get('rrule_until', None)}
             byday = form.get('rrule_byday', None)
             if value == 'weekly' and byday:
                 kw['byday'] = [ DaysOfWeek.get_shortname(v)
                                 for v in byday ]
             resource.set_value(name, value, **kw)
             return False
     proxy = super(Event_Edit, self)
     return proxy.set_value(resource, context, name, form)