class RHChatSeeLogs(RHChatModifBase): """For the conference modification""" def _checkParams(self, params): RHChatModifBase._checkParams(self, params) self._conf = ConferenceHolder().getById(params["confId"]) self._chatroom = DBHelpers.getChatroom(params["chatroom"]) self._sdate = params["sdate"] if params.has_key("sdate") else None self._edate = params["edate"] if params.has_key("edate") else None self._forEvent = bool(params["forEvent"]) if params.has_key("forEvent") else None self._getAll = not self._sdate and not self._edate and not self._forEvent def _process(self): if self._getAll: url = LogLinkGenerator(self._chatroom).generate() elif self._forEvent: url = LogLinkGenerator(self._chatroom).generate( str(self._conf.getStartDate().date()), str(self._conf.getEndDate().date()) ) else: url = LogLinkGenerator(self._chatroom).generate(self._sdate, self._edate) req = urllib2.Request(url, None, {"Accept-Charset": "utf-8"}) document = urllib2.urlopen(req).read() if document is "": raise MaKaCError("No logs were found for these dates") return document
class RHChatSeeLogs(RHChatModifBase): """ For the conference modification""" _url = wrapUH(UHConfModifChatSeeLogs) def _checkParams(self, params): RHChatModifBase._checkParams(self, params) self._conf = ConferenceHolder().getById(params['confId']) self._chatroom = DBHelpers.getChatroom(params['chatroom']) self._sdate = params['sdate'] if params.has_key('sdate') else None self._edate = params['edate'] if params.has_key('edate') else None self._forEvent = bool( params['forEvent']) if params.has_key('forEvent') else None self._getAll = not self._sdate and not self._edate and not self._forEvent def _process(self): if self._getAll: url = LogLinkGenerator(self._chatroom).generate() elif self._forEvent: url = LogLinkGenerator(self._chatroom).generate( str(self._conf.getStartDate().date()), str(self._conf.getEndDate().date())) else: url = LogLinkGenerator(self._chatroom).generate( self._sdate, self._edate) req = urllib2.Request(url, None, {'Accept-Charset': 'utf-8'}) document = urllib2.urlopen(req).read() if document is '': raise MaKaCError('No logs were found for these dates') return document
class PiwikReport(PiwikReportBase): fossilizes(IPiwikReportFossil) _defaultReportInterval = 14 def __init__(self, startDate, endDate, confId, contribId=None): """ Builds the map of generators to fill this object's variables before fossilization. """ PiwikReportBase.__init__(self) report = BaseReportGenerator self._conf = ConferenceHolder().getById(confId) self._confId = confId self._contribId = contribId self._buildDateRange(startDate, endDate) self._contributions = [] params = { 'startDate': self._startDate, 'endDate': self._endDate, 'confId': confId } if contribId: params['contribId'] = contribId # This report only has need for images and values, not for widgets. self._reportGenerators = { 'values': { 'visits': report(pq.PiwikQueryMetricConferenceVisits, params), 'uniqueVisits': report(pq.PiwikQueryMetricConferenceUniqueVisits, params), 'visitLength': report(pq.PiwikQueryMetricConferenceVisitLength, params), 'referrers': report(pq.PiwikQueryMetricConferenceReferrers, params), 'peakDate': report(pq.PiwikQueryMetricConferencePeakDateAndVisitors, params) } } self._buildReports() self._buildConferenceContributions() def _buildDateRange(self, startDate, endDate): """ If the default values are passed through, computes the appropriate date range based on whether today is before or after the conference end date. If after, end of period is set as conference end date. Start date is then calculated by the _defaultReportInterval difference. """ def getStartDate(): interval = datetime.timedelta(days=self._defaultReportInterval) adjustedStartDate = self._endDateTime - interval return str(adjustedStartDate.date()) def getEndDate(): today = nowutc() confEndDate = self._conf.getEndDate() self._endDateTime = confEndDate if today > confEndDate else today return str(self._endDateTime.date()) self._endDate = endDate if endDate else getEndDate() self._startDate = startDate if startDate else getStartDate() def _buildConferenceContributions(self): """ As this implementation permits the viewing of individual contributions, we make a list of tuples associating the uniqueId with the title (and start time) to be fossilized. """ contributions = self._conf.getContributionList() if contributions: self._contributions.append( ('None', str(_('Conference: ') + self._conf.getTitle()))) for ctrb in contributions: if not ctrb.isScheduled(): continue ctrbTime = str(ctrb.getStartDate().hour) + ':' + str( ctrb.getStartDate().minute) ctrbInfo = _( 'Contribution: ') + ctrb.getTitle() + ' (' + ctrbTime + ')' value = (ctrb.getUniqueId(), ctrbInfo) self._contributions.append(value) else: self._contributions = False def _getContributions(self): return self._contributions def getConferenceId(self): return self._confId def getContributionId(self): return self._contribId
class PiwikReport(PiwikReportBase): fossilizes(IPiwikReportFossil) _defaultReportInterval = 14 def __init__(self, startDate, endDate, confId, contribId=None): """ Builds the map of generators to fill this object's variables before fossilization. """ PiwikReportBase.__init__(self) report = BaseReportGenerator self._conf = ConferenceHolder().getById(confId) self._confId = confId self._contribId = contribId self._buildDateRange(startDate, endDate) self._contributions = [] params = {'startDate': self._startDate, 'endDate': self._endDate, 'confId': confId} if contribId: params['contribId'] = contribId # This report only has need for images and values, not for widgets. self._reportGenerators = { 'values': {'visits': report(pq.PiwikQueryMetricConferenceVisits, params), 'uniqueVisits': report(pq.PiwikQueryMetricConferenceUniqueVisits, params), 'visitLength': report(pq.PiwikQueryMetricConferenceVisitLength, params), 'referrers': report(pq.PiwikQueryMetricConferenceReferrers, params), 'peakDate': report(pq.PiwikQueryMetricConferencePeakDateAndVisitors, params)} } self._buildReports() self._buildConferenceContributions() def _buildDateRange(self, startDate, endDate): """ If the default values are passed through, computes the appropriate date range based on whether today is before or after the conference end date. If after, end of period is set as conference end date. Start date is then calculated by the _defaultReportInterval difference. """ def getStartDate(): interval = datetime.timedelta(days=self._defaultReportInterval) adjustedStartDate = self._endDateTime - interval return str(adjustedStartDate.date()) def getEndDate(): today = nowutc() confEndDate = self._conf.getEndDate() self._endDateTime = confEndDate if today > confEndDate else today return str(self._endDateTime.date()) self._endDate = endDate if endDate else getEndDate() self._startDate = startDate if startDate else getStartDate() def _buildConferenceContributions(self): """ As this implementation permits the viewing of individual contributions, we make a list of tuples associating the uniqueId with the title (and start time) to be fossilized. """ contributions = self._conf.getContributionList() if contributions: self._contributions.append(('None', str(_('Conference: ') + self._conf.getTitle()))) for ctrb in contributions: if not ctrb.isScheduled(): continue ctrbTime = str(ctrb.getStartDate().hour) + ':' + str(ctrb.getStartDate().minute) ctrbInfo = _('Contribution: ') + ctrb.getTitle() + ' (' + ctrbTime + ')' value = (ctrb.getUniqueId(), ctrbInfo) self._contributions.append(value) else: self._contributions = False def _getContributions(self): return self._contributions def getConferenceId(self): return self._confId def getContributionId(self): return self._contribId
class RHChatSeeLogs(RHChatModifBase): """ For the conference modification""" _url = wrapUH(UHConfModifChatSeeLogs) def _checkParams(self, params): RHChatModifBase._checkParams(self, params) self._conf = ConferenceHolder().getById(params['confId']) self._chatroom = DBHelpers.getChatroom(params['chatroom']) self._sdate = params['sdate'] if params.has_key('sdate') else None self._edate = params['edate'] if params.has_key('edate') else None self._forEvent = bool(params['forEvent']) if params.has_key('forEvent') else None self._getAll = not self._sdate and not self._edate and not self._forEvent def _process( self ): if self._getAll: url = LogLinkGenerator(self._chatroom).generate() elif self._forEvent: url = LogLinkGenerator(self._chatroom).generate(str(self._conf.getStartDate().date()), str(self._conf.getEndDate().date())) else: url = LogLinkGenerator(self._chatroom).generate(self._sdate, self._edate) req = urllib2.Request(url, None, {'Accept-Charset' : 'utf-8'}) document = urllib2.urlopen(req).read() if document is '': raise MaKaCError('No logs were found for these dates') return document