:return: a dictionary of {calenderid, TrumbaCalendar}
             None if error, {} if not exists
545324
def _load_calendar(campus, resp_fragment, calendar_dict, parent):
    
    for record in resp_fragment:
        if re.match(r'Internal Event Actions', record['Name']) or\
                re.match(r'Migrated .*', record['Name']):
            continue
        trumba_cal = TrumbaCalendar()
        trumba_cal.calendarid = record['ID']
        trumba_cal.campus = campus
        if parent is None:
            trumba_cal.name = record['Name']
        else:
            trumba_cal.name = "%s >> %s" % (parent, record['Name'])

        if not _is_valid_calendarid(record['ID']):
            logger.warn(
                "InvalidCalendarId %s, entry skipped!" % trumba_cal)
            continue

        calendar_dict[trumba_cal.calendarid] = trumba_cal
        if record['ChildCalendars'] is not None and\
                len(record['ChildCalendars']) > 0:
            _load_calendar(campus,
                           record['ChildCalendars'],
                           calendar_dict,
                           trumba_cal.name)
627258
def get_or_create_calendar_for_object(self, obj, distinction='', name=None):
        
        try:
            return self.get_calendar_for_object(obj, distinction)
        except Calendar.DoesNotExist:
            if name is None:
                calendar = self.model(name=str(obj))
            else:
                calendar = self.model(name=name)
            calendar.slug = slugify(calendar.name)
            calendar.save()
            calendar.create_relation(obj, distinction)
            return calendar
456063
def to_dict(self):
        

        return {
            'id': self.id,
            'type': str(self.type.ver_type),
            'controller': canon_ref(self.did, self.controller),
            **self.type.specification(self.value)
        }
558184
def get_urls(self):
        
        from django.conf.urls import patterns, url
        urls = super(EventAdmin, self).get_urls()
        my_urls = patterns(
            '',
            url(
                r'^calendar/$',
                self.admin_site.admin_view(self.calendar),
                name='icekit_events_eventbase_calendar'
            ),
            url(
                r'^calendar_data/$',
                self.admin_site.admin_view(self.calendar_data),
                name='icekit_events_eventbase_calendar_data'
            ),
        )
        return my_urls + urls
1293305
def _getEventsByWeek(self, request, year, month):
        """"""
        return getAllEventsByWeek(request, year, month, home=self)
133152
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'intent') and self.intent is not None:
            _dict['intent'] = self.intent
        if hasattr(self, 'description') and self.description is not None:
            _dict['description'] = self.description
        if hasattr(self, 'created') and self.created is not None:
            _dict['created'] = datetime_to_string(self.created)
        if hasattr(self, 'updated') and self.updated is not None:
            _dict['updated'] = datetime_to_string(self.updated)
        if hasattr(self, 'examples') and self.examples is not None:
            _dict['examples'] = [x._to_dict() for x in self.examples]
        return _dict
143591
def _getEventsByDay(self, request, firstDay, lastDay):
        
        return getAllEventsByDay(request, firstDay, lastDay, home=self)
1253220
def to_reminders(self, ical, label=None, priority=None, tags=None,
                     tail=None, sep=" ", postdate=None, posttime=None):
        """"""
        if not hasattr(ical, 'vevent_list'):
            return ''

        reminders = [self.to_remind(vevent, label, priority, tags, tail, sep,
                                    postdate, posttime)
                     for vevent in ical.vevent_list]
        return ''.join(reminders)
220877
def get_day_name(self) -> str:
        
        weekday = self.value.isoweekday() - 1
        return calendar.day_name[weekday]
1320504
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'type' in _dict:
            args['type'] = _dict.get('type')
        if 'credential_id' in _dict:
            args['credential_id'] = _dict.get('credential_id')
        if 'schedule' in _dict:
            args['schedule'] = SourceSchedule._from_dict(_dict.get('schedule'))
        if 'options' in _dict:
            args['options'] = SourceOptions._from_dict(_dict.get('options'))
        return cls(**args)
160669
def get_events_map():
    
    from nefertari import events
    set_keys = ('create', 'update', 'replace', 'update_many', 'register')
    before_events = events.BEFORE_EVENTS.copy()
    before_events['set'] = [before_events[key] for key in set_keys]
    after_events = events.AFTER_EVENTS.copy()
    after_events['set'] = [after_events[key] for key in set_keys]
    return {
        'before': before_events,
        'after': after_events,
    }
166419
def list_calendar_events(self, all_events=None, context_codes=None, end_date=None, excludes=None, start_date=None, type=None, undated=None):
        
        path = {}
        data = {}
        params = {}

        # OPTIONAL - type
        """Defaults to "event""""
        if type is not None:
            self._validate_enum(type, ["event", "assignment"])
            params["type"] = type

        # OPTIONAL - start_date
        """Only return events since the start_date (inclusive).
        Defaults to today. The value should be formatted as: yyyy-mm-dd or ISO 8601 YYYY-MM-DDTHH:MM:SSZ."""
        if start_date is not None:
            params["start_date"] = start_date

        # OPTIONAL - end_date
        """Only return events before the end_date (inclusive).
        Defaults to start_date. The value should be formatted as: yyyy-mm-dd or ISO 8601 YYYY-MM-DDTHH:MM:SSZ.
        If end_date is the same as start_date, then only events on that day are
        returned."""
        if end_date is not None:
            params["end_date"] = end_date

        # OPTIONAL - undated
        """Defaults to false (dated events only).
        If true, only return undated events and ignore start_date and end_date."""
        if undated is not None:
            params["undated"] = undated

        # OPTIONAL - all_events
        """Defaults to false (uses start_date, end_date, and undated criteria).
        If true, all events are returned, ignoring start_date, end_date, and undated criteria."""
        if all_events is not None:
            params["all_events"] = all_events

        # OPTIONAL - context_codes
        """List of context codes of courses/groups/users whose events you want to see.
        If not specified, defaults to the current user (i.e personal calendar,
        no course/group events). Limited to 10 context codes, additional ones are
        ignored. The format of this field is the context type, followed by an
        underscore, followed by the context id. For example: course_42"""
        if context_codes is not None:
            params["context_codes"] = context_codes

        # OPTIONAL - excludes
        """Array of attributes to exclude. Possible values are "description", "child_events" and "assignment""""
        if excludes is not None:
            params["excludes"] = excludes

        self.logger.debug("GET /api/v1/calendar_events with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("GET", "/api/v1/calendar_events".format(**path), data=data, params=params, all_pages=True)
1040301
def to_json(self):
        """"""
        return {
            'st_month': self.st_month,
            'st_day': self.st_day,
            'st_hour': self.st_hour,
            'end_month': self.end_month,
            'end_day': self.end_day,
            'end_hour': self.end_hour,
            'timestep': self.timestep,
            'is_leap_year': self.is_leap_year
        }
239940
def todict(self):
        
        return {'index': self.index,
                'seed': hb_encode(self.seed),
                'n': self.n,
                'root': hb_encode(self.root),
                'hmac': hb_encode(self.hmac),
                'timestamp': self.timestamp}
703907
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'text') and self.text is not None:
            _dict['text'] = self.text
        if hasattr(self, 'created') and self.created is not None:
            _dict['created'] = datetime_to_string(self.created)
        if hasattr(self, 'updated') and self.updated is not None:
            _dict['updated'] = datetime_to_string(self.updated)
        return _dict
335594
def check_calendar_dates(
    feed: "Feed", *, as_df: bool = False, include_warnings: bool = False
) -> List:
    
    table = "calendar_dates"
    problems = []

    # Preliminary checks
    if feed.calendar_dates is None:
        return problems

    f = feed.calendar_dates.copy()
    problems = check_for_required_columns(problems, table, f)
    if problems:
        return format_problems(problems, as_df=as_df)

    if include_warnings:
        problems = check_for_invalid_columns(problems, table, f)

    # Check service_id
    problems = check_column(problems, table, f, "service_id", valid_str)

    # Check date
    problems = check_column(problems, table, f, "date", valid_date)

    # No duplicate (service_id, date) pairs allowed
    cond = f[["service_id", "date"]].duplicated()
    problems = check_table(
        problems, table, f, cond, "Repeated pair (service_id, date)"
    )

    # Check exception_type
    v = lambda x: x in [1, 2]
    problems = check_column(problems, table, f, "exception_type", v)

    return format_problems(problems, as_df=as_df)
1139975
def serialize(self):
        
        return {'syear': self.syear, 'smon': self.smon, 'smday': self.smday,
                'swday': self.swday, 'swday_offset': self.swday_offset,
                'eyear': self.eyear, 'emon': self.emon, 'emday': self.emday,
                'ewday': self.ewday, 'ewday_offset': self.ewday_offset,
                'skip_interval': self.skip_interval, 'other': self.other,
                'timeranges': [t.serialize() for t in self.timeranges]}