Пример #1
0
    def _title(self):
        """This is required for the site calendar views to work.

        Calendar views expect that their underlying objects (calendar
        parents) have an attribute named `title`.
        """
        return IApplicationPreferences(self).title
Пример #2
0
    def build(self, timetables, context):
        # XXX: what if timezone is broken or outdated?
        if self.timezone is None:
            timezone = IApplicationPreferences(context.app).timezone
        else:
            timezone = self.timezone

        first, last = context.schoolyear.first, context.schoolyear.last

        timetable = Timetable(
            first, last,
            title=self.title,
            timezone=timezone)
        timetables[self.__name__] = timetable
        timetable.__parent__ = timetables

        built_periods = self.periods.build(
            timetable, context(timetables=timetables))
        built_time_slots = self.time_slots.build(
            timetable, context(timetables=timetables))
        built_exceptions = self.exceptions.build(
            timetable, context(timetables=timetables,
                               period_map=built_periods.period_map))

        if self.set_default:
            timetables.default = timetable

        return BuildContext(timetable=timetable,
                            schema_id=self.__name__,
                            period_map=built_periods.period_map)
Пример #3
0
def datetime_formatter(value, item, formatter):
    if value is None:
        return ''
    app = ISchoolToolApplication(None)
    preferences = IApplicationPreferences(app)
    preferred_datetime_format = '%s %s' % (preferences.dateformat,
                                           preferences.timeformat)
    app_timezone = pytz.timezone(preferences.timezone)
    local_dt = value.astimezone(app_timezone)
    return local_dt.strftime(preferred_datetime_format)
Пример #4
0
    def preferences(self):
        """Return ApplicationPreferences for the SchoolToolApplication.

        Sample usage in a page template:

          <div tal:define="preferences context/schooltool:preferences">
            <b tal:content="preferences/title"></b>
          </div>

        """
        return IApplicationPreferences(self.app)
Пример #5
0
    def createTimetable(self):
        session = self.getSessionData()
        app = ISchoolToolApplication(None)
        tzname = IApplicationPreferences(app).timezone

        # XXX: quick fix for date range
        owner = IHaveTimetables(self.context)
        first, last = owner.first, owner.last

        timetable = Timetable(first,
                              last,
                              title=session['title'],
                              timezone=tzname)
        return timetable
Пример #6
0
    def header_extra_subtitles(self):
        extra_subtitles = {
            'fontSize': 12,
            'margin': Box(1, 0, 1, 0),
            'content': self.slots.subtitles_right,
        }

        if not self.slots.subtitles_right:
            prefs = IApplicationPreferences(ISchoolToolApplication(None))
            extra_subtitles['content'] = prefs.title

        doc_w, doc_h = self.manager.page_size
        top = self.top_bar['y'] - self.header_padding_top
        right = doc_w - self.manager.margin.right
        extra_subtitles['height'], extra_subtitles['lines'] = self.lines(
            extra_subtitles, top, right)
        return extra_subtitles
Пример #7
0
    def __init__(self, request):
        try:
            app = ISchoolToolApplication(None)
            prefs = IApplicationPreferences(app)
        except (ValueError, TypeError):
            prefs = None

        if prefs is not None:
            self.dateformat = prefs.dateformat
            self.timeformat = prefs.timeformat
            self.first_day_of_week = prefs.weekstart
            self.timezone = timezone(prefs.timezone)
        else:
            # no user, no application - test environment
            self.dateformat = '%Y-%m-%d'
            self.timeformat = '%H:%M'
            self.first_day_of_week = calendar.MONDAY
            self.timezone = timezone('UTC')
Пример #8
0
 def importAllTimetables(self):
     if not self.shouldImportAllTimetables():
         return
     oldTimetables = ITimetableContainer(self.activeSchoolyear)
     newTimetables = ITimetableContainer(self.newSchoolyear)
     chooser = INameChooser(newTimetables)
     app = ISchoolToolApplication(None)
     tzname = IApplicationPreferences(app).timezone
     for schooltt in oldTimetables.values():
         newSchooltt = Timetable(self.newSchoolyear.first,
                                 self.newSchoolyear.last,
                                 title=schooltt.title,
                                 timezone=tzname)
         name = chooser.chooseName(schooltt.__name__, newSchooltt)
         newTimetables[name] = newSchooltt
         self.setUpTimetable(newSchooltt, schooltt)
         if (oldTimetables.default is not None
                 and sameProxiedObjects(oldTimetables.default, schooltt)):
             newTimetables.default = newSchooltt
Пример #9
0
    def header_school_logo(self):
        if self.slots.subtitles_right:
            return None

        prefs = IApplicationPreferences(ISchoolToolApplication(None))
        if prefs.logo is None:
            return None

        padding = Box(4, 4, 0, 4)

        # XXX: need a better way to get image size
        logo_file = prefs.logo.open()
        image = Image.open(logo_file)
        logo_file.close()

        doc_w, doc_h = self.manager.page_size
        top = self.top_bar['y'] - self.header_padding_top
        right = doc_w - self.manager.margin.right

        extra_subtitles = self.header_extra_subtitles
        height = max(
            self.header_title['height'] + self.header_subtitles['height'],
            (extra_subtitles['fontSize'] + extra_subtitles['margin'].top +
             extra_subtitles['margin'].bottom) * self.min_header_lines)
        height += self.header_padding_top + self.header_padding_bottom
        height -= extra_subtitles['height'] + padding.top + padding.bottom
        ratio = image.size and float(image.size[0]) / image.size[1] or 1
        width = height * ratio

        logo_data = getMultiAdapter((prefs.logo, self.request),
                                    name='data_uri')

        logo = {
            'x': right - width - padding.right,
            'y': top - extra_subtitles['height'] - height - padding.top,
            'width': width,
            'height': height,
            'logo_data': logo_data,
        }
        return logo
Пример #10
0
 def __init__(self, request):
     self.request = request
     app = ISchoolToolApplication(None)
     self.tzinfo = pytz.timezone(IApplicationPreferences(app).timezone)
Пример #11
0
 def today(self):
     app = ISchoolToolApplication(None)
     tzinfo = pytz.timezone(IApplicationPreferences(app).timezone)
     dt = pytz.utc.localize(datetime.utcnow())
     return dt.astimezone(tzinfo).date()
Пример #12
0
 def name_sorting(self):
     app = ISchoolToolApplication(None)
     preferences = IApplicationPreferences(app)
     return preferences.name_sorting
Пример #13
0
def get_application_preferences():
    app = ISchoolToolApplication(None)
    return IApplicationPreferences(app)
Пример #14
0
def to_application_timezone(dt):
    app = ISchoolToolApplication(None)
    app_timezone = pytz.timezone(IApplicationPreferences(app).timezone)
    return dt.astimezone(app_timezone)
Пример #15
0
 def getApplicationTimezone(self):
     app = ISchoolToolApplication(None)
     return pytz.timezone(IApplicationPreferences(app).timezone)
Пример #16
0
 def title(self):
     preferences = IApplicationPreferences(ISchoolToolApplication(None))
     return preferences.title