def __init__(self, rh, target, params): WPCategoryDisplayBase.__init__(self, rh, target.getCategory()) self._task = target self._params = params if len(self._target.getSubCategoryList()) == 0: tzUtil = DisplayTZ(self._getAW(), None, useServerTZ=1) self._locTZ = tzUtil.getDisplayTZ()
def __init__( self, rh, target, params ): WPCategoryDisplayBase.__init__( self, rh, target.getCategory() ) self._task = target self._params = params if len(self._target.getSubCategoryList())==0: tzUtil = DisplayTZ(self._getAW(),None,useServerTZ=1) self._locTZ = tzUtil.getDisplayTZ()
def getStartDate(self, aw): tzUtil = DisplayTZ(aw,self.getConference()) locTZ = tzUtil.getDisplayTZ() if self._startDate: return self._startDate.astimezone(timezone(locTZ)) else: return None
def __init__( self, rh, target, filter="", order="1" ): WPCategoryDisplayBase.__init__( self, rh, target ) self._taskFilter = filter self._listOrder = order if len(self._target.getSubCategoryList())==0: tzUtil = DisplayTZ(self._getAW(),None,useServerTZ=1) self._locTZ = tzUtil.getDisplayTZ()
def __init__(self, rh, target, filter="", order="1"): WPCategoryDisplayBase.__init__(self, rh, target) self._taskFilter = filter self._listOrder = order if len(self._target.getSubCategoryList()) == 0: tzUtil = DisplayTZ(self._getAW(), None, useServerTZ=1) self._locTZ = tzUtil.getDisplayTZ()
def getEndDate(self, aw): tzUtil = DisplayTZ(aw,self.getConference()) locTZ = tzUtil.getDisplayTZ() if self.getTarget(): return self.getTarget().getEndDate().astimezone(timezone(locTZ)) else: return None
def __init__(self, aw, conf): self._conf = conf self._aw = aw WHeader.__init__(self, self._aw, prot_obj=self._conf, tpl_name='EventHeader') tzUtil = DisplayTZ(self._aw, self._conf) self._locTZ = tzUtil.getDisplayTZ()
def _getCommentsList(self, task): keys = task.getCommentHistory().keys() keys.sort() #raise "%s"%keys out = _(""" <table width="100%"> <tr> <td width="22%"><span class="titleCellFormat"> _("Date")</span></td> <td width="50%"><span class="titleCellFormat"> _("Text")</span></td> <td width="28%"><span class="titleCellFormat"> _("Author")</span></td> </tr>""") html = [] for k in keys: c = task.getCommentHistory()[k] tz = DisplayTZ(self._aw, None, useServerTZ=1).getDisplayTZ() date = "%s" % c.getCreationDate().astimezone(timezone(tz)) text = """ <tr> <td width="2%%">%s</td> <td width="50%%">%s</td> <td width="28%%"> %s</td> </tr>""" % (date[0:16], c.getCommentText(), c.getCommentAuthor()) html.append(text) return out + """ """.join(html) + """
def format_datetime(dt, format='medium', locale=None, timezone=None, server_tz=False, keep_tz=False): """ Basically a wrapper around Babel's own format_datetime """ inject_unicode = True if format == 'code': format = 'dd/MM/yyyy HH:mm' inject_unicode = False if not locale: locale = get_current_locale() if keep_tz: assert timezone is None timezone = dt.tzinfo elif not timezone and dt.tzinfo: timezone = DisplayTZ().getDisplayTZ() elif server_tz: timezone = Config.getInstance().getDefaultTimezone() rv = _format_datetime(dt, format=format, locale=locale, tzinfo=timezone) return inject_unicode_debug( rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
def _checkParams(self, params): categIdList = self._normaliseListParam(params.get("selCateg", [])) self._categList = [] cm = conference.CategoryManager() for id in categIdList: try: self._categList.append(cm.getById(id)) except KeyError: continue self._target = self._categList if not self._categList: cm = conference.CategoryManager() self._categList.append(cm.getRoot()) tz = DisplayTZ(self._aw).getDisplayTZ() months = params.get("months", 3) columns = params.get("columns", 3) month = int( params.get("month", (nowutc() - relativedelta(months=1)).astimezone( timezone(tz)).month)) year = int(params.get("year", nowutc().astimezone(timezone(tz)).year)) sdate = timezone(tz).localize(datetime(year, month, 1)) self._cal = wcalendar.MonthCalendar( self._aw, \ sdate, \ months, \ columns, \ self._categList ) self._categ = self._categList[0]
def tzinfo(self): """The tzinfo of the user's current timezone. This should only be used in places where no other timezone such as from an event or category is available. """ return DisplayTZ().getDisplayTZ(as_timezone=True)
def __init__(self, aw, categList=[]): self._detailLevel = "conference" self._categList = categList self._tz = DisplayTZ(aw).getDisplayTZ() self._date = nowutc().astimezone(timezone(self._tz)) self._aw = aw self._cal = None
def event_to_utc(dt, event): """Converts a datetime of an event to UTC. :param dt: A naive :class:`datetime.datetime` object in UTC :param event: An :class:`.Conference` object from which to take the timezone """ timezone = DisplayTZ(conf=event).getDisplayTZ() return get_timezone(timezone).localize(dt).astimezone(pytz.utc)
def _process(self): tz = timezone(DisplayTZ(session.user, self._conf).getDisplayTZ()) return self.view_class.render_template( 'display/contribution_list.html', self._conf, event=self.event_new, timezone=tz, **self.reporter.get_contrib_report_kwargs())
def _processData(self): data = "" tz = DisplayTZ(self._aw).getDisplayTZ() data += self._getRSS(tz) cfg = Config.getInstance() mimetype = cfg.getFileTypeMimeType("RSS") self._req.content_type = """%s""" % (mimetype) return data
def timezone(self): if self._timezone: return self._timezone form = self.get_form() if form and hasattr(self, 'timezone'): return form.timezone session_tz = DisplayTZ().getDisplayTZ() return session_tz
def _process(self): reminders = EventReminder.find(event_id=self.event.id).order_by( EventReminder.scheduled_dt.desc()).all() tz = get_timezone(DisplayTZ(conf=self.event).getDisplayTZ()) return WPReminders.render_template('reminders.html', self.event, event=self.event, reminders=reminders, timezone=tz)
def _process(self): if redis_write_client: suggestions.schedule_check(self.user) tz = timezone(DisplayTZ().getDisplayTZ()) hours, minutes = timedelta_split(tz.utcoffset(datetime.now()))[:2] return WPUserDashboard.render_template('dashboard.html', redis_enabled=bool(redis_client), timezone=unicode(tz), offset='{:+03d}:{:02d}'.format(hours, minutes), user=self.user, categories=get_related_categories(self.user), suggested_categories=get_suggested_categories(self.user))
def getData(self): categ_ids = tuple(int(cat.id) for cat in self._categList) tz = timezone(DisplayTZ(session.user, None, useServerTZ=True).getDisplayTZ()) self._data = get_category_timetable(categ_ids, self.getStartDate(), self.getEndDate() + timedelta(days=1) - timedelta(seconds=1), detail_level=self.getDetailLevel(), tz=tz, from_categ=self._categList[0]) return self._data
def _get_defaults(self): reminder = self.reminder if reminder.is_relative: defaults_kwargs = {'schedule_type': 'relative', 'relative_delta': reminder.event_start_delta} else: # Use the user's preferred event timezone tz = get_timezone(DisplayTZ(conf=self.event).getDisplayTZ()) dt = reminder.scheduled_dt.astimezone(tz) defaults_kwargs = {'schedule_type': 'absolute', 'absolute_date': dt.date(), 'absolute_time': dt.time()} return FormDefaults(reminder, **defaults_kwargs)
def render_contribution_list(self): """Render the contribution list template components. :return: dict containing the list's entries, the fragment of displayed entries and whether the contrib passed is displayed in the results. """ contrib_list_kwargs = self.get_list_kwargs() total_entries = contrib_list_kwargs.pop('total_entries') contribs = contrib_list_kwargs['contribs'] tpl = get_template_module('events/contributions/display/_contribution_list.html') tpl_lists = get_template_module('events/management/_lists.html') tz = timezone(DisplayTZ(session.user, self.list_event.as_legacy).getDisplayTZ()) return {'html': tpl.render_contribution_list(self.list_event, tz, contribs), 'counter': tpl_lists.render_displayed_entries_fragment(len(contribs), total_entries)}
def _process(self): ical_params = get_base_ical_parameters(session.user, self.event_new, 'sessions', self.session) tz = timezone(DisplayTZ(session.user, self._conf).getDisplayTZ()) contributions_strategy = subqueryload('contributions') _contrib_tte_strategy = contributions_strategy.joinedload('timetable_entry') _contrib_tte_strategy.lazyload('*') contributions_strategy.joinedload('person_links') blocks_strategy = joinedload('blocks') blocks_strategy.joinedload('person_links') _block_tte_strategy = blocks_strategy.joinedload('timetable_entry') _block_tte_strategy.lazyload('*') _block_tte_strategy.joinedload('children') sess = (Session.query .filter_by(id=self.session.id) .options(contributions_strategy, blocks_strategy) .one()) return self.view_class.render_template('display/session_display.html', self._conf, sess=sess, event=self.event_new, timezone=tz, **ical_params)
def _checkParams(self, params): # month/year indicates which month should be displayed in the calendar # date indicates if a day should be highlighted in the calendar tz = DisplayTZ(self._aw).getDisplayTZ() if params.has_key("month") and params.get("month") == "": del params["month"] if params.has_key("year") and params.get("year") == "": del params["year"] self._month = int( params.get("month", nowutc().astimezone(timezone(tz)).month)) self._year = int( params.get("year", nowutc().astimezone(timezone(tz)).year)) if params.get('date', '') == '--' or params.get('date', '') == '': self._date = '%s-%s-%s' % ('01', self._month, self._year) else: self._date = "" self._form = int(params.get('form', 0))
def format_time(t, format='short', locale=None, timezone=None, server_tz=False): """ Basically a wrapper around Babel's own format_time """ if not locale: locale = get_current_locale() if not timezone and t.tzinfo: timezone = DisplayTZ().getDisplayTZ() elif server_tz: timezone = HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone() if timezone: timezone = get_timezone(timezone) return _format_time(t, format=format, locale=locale, tzinfo=timezone).encode('utf-8')
def _checkParams(self, params): categIdList = self._normaliseListParam(params.get("selCateg", [])) self._categList = [] cm = conference.CategoryManager() for id in categIdList: self._categList.append(cm.getById(id)) tz = DisplayTZ(self._aw).getDisplayTZ() sdate = timezone(tz).localize(datetime(int(params.get("sDate", "")[0:4]),\ int(params.get("sDate", "")[5:7]),\ int(params.get("sDate", "")[8:]))) months = params.get("months", 6) self._cal = wcalendar.MonthCalendar( self._aw, \ sdate, \ months, \ 3, \ self._categList ) xs = self._normaliseListParam(params.get("xs", [])) self._expanded = [] for id in xs: self._expanded.append(cm.getById(id))
def _checkParams( self, params ): id = params.get("selCateg", "") if id != "" and not params.has_key("categId"): params["categId"] = id RHCategDisplayBase._checkParams( self, params ) if not self._target: raise MaKaCError( _("wrong category identifier")) tz = DisplayTZ(self._aw).getDisplayTZ() month = int( params.get("month", nowutc().astimezone(timezone(tz)).month) ) year = int( params.get("year", nowutc().astimezone(timezone(tz)).year) ) day = int( params.get("day", nowutc().astimezone(timezone(tz)).day) ) sd = timezone(tz).localize(datetime( year, month, day )) period = params.get("period", "day") if period == "month": self._cal = wcalendar.MonthOverview( self._aw, sd, [self._target] ) elif period == "week": self._cal = wcalendar.WeekOverview( self._aw, sd, [self._target] ) else: self._cal = wcalendar.Overview( self._aw, sd, [self._target] ) self._cal.setDetailLevel( params.get("detail", "conference") )
def format_datetime(dt, format='medium', locale=None, timezone=None, server_tz=False, keep_tz=False): """ Basically a wrapper around Babel's own format_datetime """ if not locale: locale = get_current_locale() if keep_tz: assert timezone is None timezone = dt.tzinfo elif not timezone and dt.tzinfo: timezone = DisplayTZ().getDisplayTZ() elif server_tz: timezone = HelperMaKaCInfo.getMaKaCInfoInstance().getTimezone() return _format_datetime(dt, format=format, locale=locale, tzinfo=timezone).encode('utf-8')
def _getTaskList(self): html = [] taskList = self._target.getTaskList()[:] if self._listOrder == "1": taskList.sort(task.Task.cmpTaskId) if self._listOrder == "2": taskList.sort(task.Task.cmpTaskTitle) if self._listOrder == "3": taskList.sort(task.Task.cmpTaskCurrentStatus) if self._listOrder == "4": taskList.sort(task.Task.cmpTaskCreationDate) for t in taskList: if self._taskFilter == "" or self._taskFilter == t.getCurrentStatus( ).getStatusName(): urlDetails = urlHandlers.UHTaskDetails.getURL(self._target) urlDetails.addParam("taskId", t.getId()) urlComment = urlHandlers.UHTaskCommentNew.getURL(self._target) urlComment.addParam("taskId", t.getId()) tz = DisplayTZ(self._aw, None, useServerTZ=1).getDisplayTZ() creationDate = "%s" % t.getCreationDate().astimezone( timezone(tz)) text = _(""" <tr> <td> %s</td> <td> <a href="%s">%s</a></td> <td> %s</td> <td> %s</td> <td align="center"> %s</td> <td align="center"><a href="%s"> _("comment")</a></td> </tr> """) % (t.getId(), urlDetails, t.getTitle(), _(t.getCurrentStatus().getStatusName()), creationDate[0:16], t.getCommentHistorySize(), urlComment) html.append(text) return """ """.join(html)
def _process(self): self.user.settings.set('suggest_categories', True) tz = timezone(DisplayTZ().getDisplayTZ()) hours, minutes = timedelta_split(tz.utcoffset(datetime.now()))[:2] categories = get_related_categories(self.user) categories_events = [] if categories: category_ids = {c['categ'].id for c in categories.itervalues()} today = now_utc(False).astimezone(session.tzinfo).date() query = (Event.query.filter( ~Event.is_deleted, Event.category_chain_overlaps(category_ids), Event.start_dt.astimezone(session.tzinfo) >= today).options( joinedload('category').load_only('id', 'title'), joinedload('series'), subqueryload('acl_entries'), load_only('id', 'category_id', 'start_dt', 'end_dt', 'title', 'access_key', 'protection_mode', 'series_id', 'series_pos', 'series_count')).order_by( Event.start_dt, Event.id)) categories_events = get_n_matching( query, 10, lambda x: x.can_access(self.user)) from_dt = now_utc(False) - relativedelta( weeks=1, hour=0, minute=0, second=0) linked_events = [(event, { 'management': bool(roles & self.management_roles), 'reviewing': bool(roles & self.reviewer_roles), 'attendance': bool(roles & self.attendance_roles) }) for event, roles in get_linked_events( self.user, from_dt, 10).iteritems()] return WPUserDashboard.render_template( 'dashboard.html', 'dashboard', timezone=unicode(tz), offset='{:+03d}:{:02d}'.format(hours, minutes), user=self.user, categories=categories, categories_events=categories_events, suggested_categories=get_suggested_categories(self.user), linked_events=linked_events)
class WConfModifChat(wcomponents.WTemplated): def __init__(self, conference, activeTab, tabNames, aw): self._conf = conference self._activeTab = activeTab self._tabNames = tabNames self._aw = aw self._user = aw.getUser() def getVars(self): vars = WTemplated.getVars(self) vars["Conference"] = self._conf try: chatrooms = list(DBHelpers.getChatroomList(self._conf)) vars["Chatrooms"] = fossilize(chatrooms) if len(vars['Chatrooms']) is 0: vars['Chatrooms'] = None except Exception, e: vars["Chatrooms"] = None chatrooms = {} links = {} for cr in chatrooms: crinfo = links[cr.getId()] = {} crinfo['custom'] = generateCustomLinks(cr) crinfo['logs'] = generateLogLink(cr, self._conf) vars['links'] = links vars['DefaultServer'] = PluginFieldsWrapper( 'InstantMessaging', 'XMPP').getOption('chatServerHost') vars["EventDate"] = formatDateTime( getAdjustedDate(nowutc(), self._conf)) vars["User"] = self._user vars["tz"] = DisplayTZ(self._aw, self._conf).getDisplayTZ() vars["MaterialUrl"] = RHMaterialsShow._uh().getURL( self._conf).__str__() vars["ShowLogsLink"] = XMPPLogsActivated() return vars
def _getStatusList(self, task): out = _(""" <table width="100%"> <tr> <td width="22%"><span class="titleCellFormat"> _("Date")</span></td> <td width="50%"><span class="titleCellFormat"> _("Status")</span></td> <td width="28%"><span class="titleCellFormat"> _("Changed by")</span></td> </tr>""") html = [] for s in task.getStatusHistoryEntries(): tz = DisplayTZ(self._aw, None, useServerTZ=1).getDisplayTZ() date = "%s" % s.getSettingDate().astimezone(timezone(tz)) text = """ <tr> <td>%s</td> <td> %s</td> <td> %s</td> </tr> """ % (date[0:16], _( s.getStatusName()), s.getUserWhoSet().getFullName()) html.append(text) return out + """ """.join(html) + """
def format_time(t, format='short', locale=None, timezone=None, server_tz=False): """ Basically a wrapper around Babel's own format_time """ inject_unicode = True if format == 'code': format = 'HH:mm' inject_unicode = False if not locale: locale = get_current_locale() if not timezone and t.tzinfo: timezone = DisplayTZ().getDisplayTZ() elif server_tz: timezone = Config.getInstance().getDefaultTimezone() if timezone: timezone = get_timezone(timezone) rv = _format_time(t, format=format, locale=locale, tzinfo=timezone) return inject_unicode_debug( rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
def __init__(self, aw, conf): self._conf = conf self._aw=aw WHeader.__init__(self, self._aw, prot_obj=self._conf, tpl_name='EventHeader') tzUtil = DisplayTZ(self._aw,self._conf) self._locTZ = tzUtil.getDisplayTZ()