def _send_email(self): data = self._get_data() data["not_full_time_users"] = self._get_not_full_time_employees() data["quarters"] = "Q%s" % idate.quarter_number(self.start), "Q%s" % idate.quarter_number(self.end) data["months"] = self.months response = render("intranet3:templates/_email_reports/missed_hours.html", data, request=self.request) response = response.replace("\n", "").replace("\t", "") deferred = EmailSender.send_html(config["MANAGER_EMAIL"], self._(u"[Intranet2] Missed hours"), response) def on_success(result): LOG(u"Report with missed hours - sent") def on_error(err): EXCEPTION(u"Failed to sent report with missed hours") deferred.addCallbacks(on_success, on_error) return data
def action(self): today = datetime.date.today() data = self._annually_report(today.year) def on_success(result): LOG(u'Report with incorrect time records - sent') def on_error(err): EXCEPTION(u'Failed to sent report with incorrect time records') data['config'] = self.settings response = render('intranet3:templates/_email_reports/time_annually_report.html', data, request=self.request) response = response.replace('\n', '').replace('\t', '') deferred = EmailSender.send_html( config['MANAGER_EMAIL'], self._(u'[Intranet2] Wrong time record report'), response ) deferred.addCallbacks(on_success, on_error) return Response('ok')
def action(self): today = datetime.date.today() data = self._annually_report(today.year) def on_success(result): LOG(u"Report with incorrect time records - sent") def on_error(err): EXCEPTION(u"Failed to sent report with incorrect time records") data["config"] = self.settings response = render("intranet3:templates/_email_reports/time_annually_report.html", data, request=self.request) response = response.replace("\n", "").replace("\t", "") deferred = EmailSender.send_html( config["MANAGER_EMAIL"], self._(u"[Intranet2] Wrong time record report"), response ) deferred.addCallbacks(on_success, on_error) return Response("ok")
def _send_report(self, coordinator, email, bugs): def on_success(result): LOG(u'Monthly report with old bugs - sent') def on_error(err): EXCEPTION(u'Failed to sent Monthly report with old bugs') if coordinator in bugs: data = {'bugs': bugs[coordinator][1][:20], 'title': self._(u'Lista najstarszych niezamkniętych bugów\nw projektach w których jesteś koordynatorem')} response = render( 'intranet3:templates/_email_reports/old_bugs_report.html', data, request=self.request ) deferred = EmailSender.send_html( email, self._(u'[Intranet2] Old bugs report'), response ) deferred.addCallbacks(on_success, on_error)
def _send_email(self): data = self._get_data() data['not_full_time_users'] = self._get_not_full_time_employees() data['quarters'] = 'Q%s' % idate.quarter_number(self.start), 'Q%s' % idate.quarter_number(self.end) data['months'] = self.months response = render( 'intranet3:templates/_email_reports/missed_hours.html', data, request=self.request ) response = response.replace('\n', '').replace('\t', '') deferred = EmailSender.send_html( config['MANAGER_EMAIL'], self._(u'[Intranet2] Missed hours'), response ) def on_success(result): LOG(u'Report with missed hours - sent') def on_error(err): EXCEPTION(u'Failed to sent report with missed hours') deferred.addCallbacks(on_success, on_error) return data
def _send_report(self, coordinator_id, email, bugs): def on_success(result): LOG(u'Monthly report with old bugs - sent') def on_error(err): EXCEPTION(u'Failed to sent Monthly report with old bugs') # Bugs filtering & ordering # Coordinator gets bugs from his projects, manager gets bugs from # all projects if coordinator_id is None: # Manager bugs_filtered = sorted( bugs, key=lambda b: b.changeddate.replace(tzinfo=None), ) title = u'Lista najstarszych niezamkniętych bugów\nwe wszystkich projektach' else: # Coordinator bugs_filtered = sorted( [b for b in bugs if b.project.coordinator_id == coordinator_id], key=lambda b: b.changeddate.replace(tzinfo=None), ) title = u'Lista najstarszych niezamkniętych bugów\nw projektach w których jesteś koordynatorem' if bugs_filtered: data = { 'bugs': bugs_filtered[:20], 'title': self._(title), } response = render( 'intranet3:templates/_email_reports/old_bugs_report.html', data, request=self.request ) deferred = EmailSender.send_html( email, self._(u'[Intranet3] Old bugs report'), response ) deferred.addCallbacks(on_success, on_error)
def _send_report(self, coordinator_id, email, bugs): def on_success(result): LOG(u'Monthly report with old bugs - sent') def on_error(err): EXCEPTION(u'Failed to sent Monthly report with old bugs') # Bugs filtering & ordering # Coordinator gets bugs from his projects, manager gets bugs from # all projects if coordinator_id is None: # Manager bugs_filtered = sorted( bugs, key=lambda b: b.changeddate.replace(tzinfo=None), ) title = u'Lista najstarszych niezamkniętych bugów\nwe wszystkich projektach' else: # Coordinator bugs_filtered = sorted( [ b for b in bugs if b.project.coordinator_id == coordinator_id ], key=lambda b: b.changeddate.replace(tzinfo=None), ) title = u'Lista najstarszych niezamkniętych bugów\nw projektach w których jesteś koordynatorem' if bugs_filtered: data = { 'bugs': bugs_filtered[:20], 'title': self._(title), } response = render( 'intranet3:templates/_email_reports/old_bugs_report.html', data, request=self.request) deferred = EmailSender.send_html( email, self._(u'[Intranet3] Old bugs report'), response) deferred.addCallbacks(on_success, on_error)
def _send_report(self, coordinator, email, bugs): def on_success(result): LOG(u'Monthly report with old bugs - sent') def on_error(err): EXCEPTION(u'Failed to sent Monthly report with old bugs') if coordinator in bugs: data = { 'bugs': bugs[coordinator][1][:20], 'title': self. _(u'Lista najstarszych niezamkniętych bugów\nw projektach w których jesteś koordynatorem' ) } response = render( 'intranet3:templates/_email_reports/old_bugs_report.html', data, request=self.request) deferred = EmailSender.send_html( email, self._(u'[Intranet2] Old bugs report'), response) deferred.addCallbacks(on_success, on_error)
def _today_hours(self, date, projects, omit_users): time_entries = ( self.session.query( "user", "description", "time", "project", "client", "ticket_id", "tracker_id", "total_time" ) .from_statement( """ SELECT u.name as "user", t.description as "description", t.time as "time", p.name as "project", c.name as "client", t.ticket_id as "ticket_id", p.tracker_id as "tracker_id", ( SELECT SUM(te.time) FROM time_entry te WHERE te.ticket_id=t.ticket_id ) as "total_time" FROM time_entry as t, project as p, client as c, "user" as u WHERE t.deleted = False AND t.date = :date AND u.id = t.user_id AND p.id = t.project_id AND c.id = p.client_id AND p.id IN :projects AND u.id NOT IN :users ORDER BY u.name, c.name, p.name """ ) .params(date=date, projects=tuple(projects), users=tuple(omit_users)) .all() ) if not time_entries: s = u"No time entries for report with hours added on %s" % date LOG(s) return s output = [] total_sum = 0 user_sum = defaultdict(lambda: 0.0) user_entries = defaultdict(lambda: []) trackers = {} for (user, description, time, project, client, ticket_id, tracker_id, total_time) in time_entries: # Lazy dict filling if not tracker_id in trackers: trackers[tracker_id] = Tracker.query.get(tracker_id) tracker = trackers[tracker_id] ticket_url = tracker.get_bug_url(ticket_id) total_sum += time user_sum[user] += time user_entries[user].append((description, time, project, client, ticket_id, ticket_url, total_time)) output.append(self._(u"Daily hours report (${total_sum} h)", total_sum="%.2f" % total_sum)) user_entries = sorted(user_entries.iteritems(), key=lambda u: user_sum[u[0]], reverse=True) for user, entries in user_entries: entries = sorted(entries, key=itemgetter(1), reverse=True) output.append(u"") output.append(u"\t%s (%.2f h):" % (user, user_sum[user])) for (description, time, project, client, ticket_id, bug_url, total_time) in entries: if ticket_id: ticket_id = '[<a href="%s">%s</a>] ' % (bug_url, ticket_id) else: ticket_id = "" total_time = " (%.2fh)" % total_time if ticket_id else "" output.append( u"\t\t- %s / %s / %s%s - %.2fh%s" % (client, project, ticket_id, description, time, total_time) ) message = u"<br />\n".join(output).replace("\t", "  ") def on_success(result): LOG(u"Report with hours added on %s - sent" % (date,)) def on_error(err): EXCEPTION(u"Failed to sent Report with hours added on %s" % (date,)) topic = self._(u"[intranet] Daily hours report") deferred = EmailSender.send_html(config["MANAGER_EMAIL"], topic, message) deferred.addCallbacks(on_success, on_error) LOG(u"Report with hours on %s - started" % (date,)) return message