~replaceafill/ubuntu/trusty/schooltool/2.8_custom-css

« back to all changes in this revision

Viewing changes to src/schooltool/app/app.py

  • Committer: Gediminas Paulauskas
  • Date: 2013-10-17 14:10:50 UTC
  • mfrom: (1.1.28)
  • Revision ID: menesis@pov.lt-20131017141050-85s11mf1icfobyc2
Tags: 1:2.6.0.1-0ubuntu1
* New upstream micro release
  - Synchronize timezone set in preferences with timetables and schedules
    (LP: #1239468)
  - Set initial timezone from /etc/timezone (LP: #1030211)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
SchoolTool application
20
20
"""
21
21
import calendar
 
22
import os
 
23
import pytz
22
24
 
23
25
from persistent import Persistent
24
26
from persistent.dict import PersistentDict
199
201
 
200
202
    timezone = 'UTC'
201
203
 
 
204
    # XXX: initialize from locale
202
205
    dateformat = '%Y-%m-%d'
203
 
 
204
206
    timeformat = '%H:%M'
205
 
 
206
207
    weekstart = calendar.MONDAY
207
208
 
208
209
    frontPageCalendar = True
211
212
 
212
213
    name_sorting = 'last_name'
213
214
 
 
215
    def __init__(self):
 
216
        self.timezone = self._get_localzone()
 
217
 
 
218
    def _get_localzone(self):
 
219
        """Tries to find the local timezone configuration.
 
220
 
 
221
        Taken from https://github.com/regebro/tzlocal/
 
222
        only the part needed for Ubuntu.
 
223
        """
 
224
        tzpath = '/etc/timezone'
 
225
        if os.path.exists(tzpath):
 
226
            with open(tzpath, 'rb') as tzfile:
 
227
                data = tzfile.read()
 
228
                if data[:5] != 'TZif2':
 
229
                    etctz = data.strip().decode()
 
230
                    # Get rid of host definitions and comments:
 
231
                    if ' ' in etctz:
 
232
                        etctz, dummy = etctz.split(' ', 1)
 
233
                    if '#' in etctz:
 
234
                        etctz, dummy = etctz.split('#', 1)
 
235
                    try:
 
236
                        pytz.timezone(etctz)
 
237
                        return etctz
 
238
                    except pytz.UnknownTimeZoneError:
 
239
                        pass
 
240
 
 
241
        return 'UTC'
 
242
 
214
243
 
215
244
class ApplicationTabs(PersistentDict):
216
245
    """Object for storing application tab preferences.