def save(self, obj): data = self.form.cleaned_data org = self.request.org if 'partner_id' in self.kwargs: partner = Partner.get_all(org).get(pk=self.kwargs['partner_id']) else: partner = data.get('partner', None) full_name = data['full_name'] role = data.get('role', None) password = data['password'] change_password = data['change_password'] self.object = User.create(org, partner, role, full_name, obj.email, password, change_password)
def save(self, obj): data = self.form.cleaned_data org = self.request.org if 'partner_id' in self.kwargs: partner = Partner.get_all(org).get( pk=self.kwargs['partner_id']) else: partner = data.get('partner', None) full_name = data['full_name'] role = data.get('role', None) password = data['password'] change_password = data['change_password'] self.object = User.create(org, partner, role, full_name, obj.email, password, change_password)
def render_book(self, book): if self.type == self.TYPE_LABEL: sheet = book.add_sheet(six.text_type(_("Incoming Messages"))) labels = list(Label.get_all(self.org).order_by('name')) # get each label's day counts and organise by label and day totals_by_label = {} for label in labels: totals = DailyCount.get_by_label([label], DailyCount.TYPE_INCOMING, self.since, self.until).day_totals() totals_by_label[label] = {t[0]: t[1] for t in totals} self.write_row(sheet, 0, ["Date"] + [l.name for l in labels]) row = 1 for day in date_range(self.since, self.until): totals = [totals_by_label.get(l, {}).get(day, 0) for l in labels] self.write_row(sheet, row, [day] + totals) row += 1 elif self.type == self.TYPE_PARTNER: sheet = book.add_sheet(six.text_type(_("Replies Sent"))) partners = list(Partner.get_all(self.org).order_by('name')) # get each partner's day counts and organise by partner and day totals_by_partner = {} for partner in partners: totals = DailyCount.get_by_partner([partner], DailyCount.TYPE_REPLIES, self.since, self.until).day_totals() totals_by_partner[partner] = {t[0]: t[1] for t in totals} self.write_row(sheet, 0, ["Date"] + [p.name for p in partners]) row = 1 for day in date_range(self.since, self.until): totals = [totals_by_partner.get(l, {}).get(day, 0) for l in partners] self.write_row(sheet, row, [day] + totals) row += 1
def __init__(self, *args, **kwargs): super(OrgUserForm, self).__init__(*args, **kwargs) self.fields["partner"].queryset = Partner.get_all( self.org).order_by("name")
def render_book(self, book): if self.type == self.TYPE_LABEL: sheet = book.add_sheet(six.text_type(_("Incoming Messages"))) labels = list(Label.get_all(self.org).order_by('name')) # get each label's day counts and organise by label and day totals_by_label = {} for label in labels: totals = DailyCount.get_by_label([label], DailyCount.TYPE_INCOMING, self.since, self.until).day_totals() totals_by_label[label] = {t[0]: t[1] for t in totals} self.write_row(sheet, 0, ["Date"] + [l.name for l in labels]) row = 1 for day in date_range(self.since, self.until): totals = [totals_by_label.get(l, {}).get(day, 0) for l in labels] self.write_row(sheet, row, [day] + totals) row += 1 elif self.type == self.TYPE_USER: replies_sheet = book.add_sheet(six.text_type(_("Replies Sent"))) cases_opened_sheet = book.add_sheet(six.text_type(_("Cases Opened"))) cases_closed_sheet = book.add_sheet(six.text_type(_("Cases Closed"))) users = self.org.get_org_users().order_by('profile__full_name') replies_totals_by_user = {} cases_opened_by_user = {} cases_closed_by_user = {} for user in users: replies_totals = DailyCount.get_by_user( self.org, [user], DailyCount.TYPE_REPLIES, self.since, self.until).day_totals() cases_opened_totals = DailyCount.get_by_user( self.org, [user], DailyCount.TYPE_CASE_OPENED, self.since, self.until).day_totals() cases_closed_totals = DailyCount.get_by_user( self.org, [user], DailyCount.TYPE_CASE_CLOSED, self.since, self.until).day_totals() replies_totals_by_user[user] = {t[0]: t[1] for t in replies_totals} cases_opened_by_user[user] = {t[0]: t[1] for t in cases_opened_totals} cases_closed_by_user[user] = {t[0]: t[1] for t in cases_closed_totals} self.write_row(replies_sheet, 0, ["Date"] + [u.get_full_name() for u in users]) self.write_row(cases_opened_sheet, 0, ["Date"] + [u.get_full_name() for u in users]) self.write_row(cases_closed_sheet, 0, ["Date"] + [u.get_full_name() for u in users]) row = 1 for day in date_range(self.since, self.until): replies_totals = [replies_totals_by_user.get(u, {}).get(day, 0) for u in users] cases_opened_totals = [cases_opened_by_user.get(u, {}).get(day, 0) for u in users] cases_closed_totals = [cases_closed_by_user.get(u, {}).get(day, 0) for u in users] self.write_row(replies_sheet, row, [day] + replies_totals) self.write_row(cases_opened_sheet, row, [day] + cases_opened_totals) self.write_row(cases_closed_sheet, row, [day] + cases_closed_totals) row += 1 elif self.type == self.TYPE_PARTNER: replies_sheet = book.add_sheet(six.text_type(_("Replies Sent"))) ave_sheet = book.add_sheet(six.text_type(_("Average Reply Time"))) ave_closed_sheet = book.add_sheet(six.text_type(_("Average Closed Time"))) cases_opened_sheet = book.add_sheet(six.text_type(_("Cases Opened"))) cases_closed_sheet = book.add_sheet(six.text_type(_("Cases Closed"))) partners = list(Partner.get_all(self.org).order_by('name')) # get each partner's day counts and organise by partner and day replies_totals_by_partner = {} cases_opened_by_partner = {} cases_closed_by_partner = {} replied_averages_by_partner = {} closed_averages_by_partner = {} for partner in partners: replies_totals = DailyCount.get_by_partner([partner], DailyCount.TYPE_REPLIES, self.since, self.until).day_totals() cases_opened_totals = DailyCount.get_by_partner([partner], DailyCount.TYPE_CASE_OPENED, self.since, self.until).day_totals() cases_closed_totals = DailyCount.get_by_partner([partner], DailyCount.TYPE_CASE_CLOSED, self.since, self.until).day_totals() replies_totals_by_partner[partner] = {t[0]: t[1] for t in replies_totals} cases_opened_by_partner[partner] = {t[0]: t[1] for t in cases_opened_totals} cases_closed_by_partner[partner] = {t[0]: t[1] for t in cases_closed_totals} replied_second_totals = DailySecondTotalCount.get_by_partner([partner], DailySecondTotalCount.TYPE_TILL_REPLIED, self.since, self.until).day_totals() replied_averages_by_partner[partner] = {t[0]: (float(t[2]) / t[1]) for t in replied_second_totals} closed_second_totals = DailySecondTotalCount.get_by_partner([partner], DailySecondTotalCount.TYPE_TILL_CLOSED, self.since, self.until).day_totals() closed_averages_by_partner[partner] = {t[0]: (float(t[2]) / t[1]) for t in closed_second_totals} self.write_row(replies_sheet, 0, ["Date"] + [p.name for p in partners]) self.write_row(cases_opened_sheet, 0, ["Date"] + [p.name for p in partners]) self.write_row(cases_closed_sheet, 0, ["Date"] + [p.name for p in partners]) self.write_row(ave_sheet, 0, ["Date"] + [p.name for p in partners]) self.write_row(ave_closed_sheet, 0, ["Date"] + [p.name for p in partners]) row = 1 for day in date_range(self.since, self.until): replies_totals = [replies_totals_by_partner.get(l, {}).get(day, 0) for l in partners] cases_opened_totals = [cases_opened_by_partner.get(l, {}).get(day, 0) for l in partners] cases_closed_totals = [cases_closed_by_partner.get(l, {}).get(day, 0) for l in partners] replied_averages = [replied_averages_by_partner.get(l, {}).get(day, 0) for l in partners] closed_averages = [closed_averages_by_partner.get(l, {}).get(day, 0) for l in partners] self.write_row(replies_sheet, row, [day] + replies_totals) self.write_row(cases_opened_sheet, row, [day] + cases_opened_totals) self.write_row(cases_closed_sheet, row, [day] + cases_closed_totals) self.write_row(ave_sheet, row, [day] + replied_averages) self.write_row(ave_closed_sheet, row, [day] + closed_averages) row += 1
def __init__(self, *args, **kwargs): self.org = kwargs.pop('org') super(UserForm, self).__init__(*args, **kwargs) self.fields['partner'].queryset = Partner.get_all(self.org)
def get_partner(self): return Partner.get_all( self.request.org).get(pk=self.kwargs["partner_id"])
def render_book(self, book): if self.type == self.TYPE_LABEL: sheet = book.add_sheet(str(_("Incoming Messages"))) labels = list(Label.get_all(self.org).order_by("name")) # get each label's day counts and organise by label and day totals_by_label = {} for label in labels: totals = DailyCount.get_by_label([label], DailyCount.TYPE_INCOMING, self.since, self.until).day_totals() totals_by_label[label] = {t[0]: t[1] for t in totals} self.write_row(sheet, 0, ["Date"] + [l.name for l in labels]) row = 1 for day in date_range(self.since, self.until): totals = [ totals_by_label.get(l, {}).get(day, 0) for l in labels ] self.write_row(sheet, row, [day] + totals) row += 1 elif self.type == self.TYPE_USER: replies_sheet = book.add_sheet(str(_("Replies Sent"))) cases_opened_sheet = book.add_sheet(str(_("Cases Opened"))) cases_closed_sheet = book.add_sheet(str(_("Cases Closed"))) users = self.org.get_org_users().order_by("profile__full_name") replies_totals_by_user = {} cases_opened_by_user = {} cases_closed_by_user = {} for user in users: replies_totals = DailyCount.get_by_user( self.org, [user], DailyCount.TYPE_REPLIES, self.since, self.until).day_totals() cases_opened_totals = DailyCount.get_by_user( self.org, [user], DailyCount.TYPE_CASE_OPENED, self.since, self.until).day_totals() cases_closed_totals = DailyCount.get_by_user( self.org, [user], DailyCount.TYPE_CASE_CLOSED, self.since, self.until).day_totals() replies_totals_by_user[user] = { t[0]: t[1] for t in replies_totals } cases_opened_by_user[user] = { t[0]: t[1] for t in cases_opened_totals } cases_closed_by_user[user] = { t[0]: t[1] for t in cases_closed_totals } self.write_row(replies_sheet, 0, ["Date"] + [u.get_full_name() for u in users]) self.write_row(cases_opened_sheet, 0, ["Date"] + [u.get_full_name() for u in users]) self.write_row(cases_closed_sheet, 0, ["Date"] + [u.get_full_name() for u in users]) row = 1 for day in date_range(self.since, self.until): replies_totals = [ replies_totals_by_user.get(u, {}).get(day, 0) for u in users ] cases_opened_totals = [ cases_opened_by_user.get(u, {}).get(day, 0) for u in users ] cases_closed_totals = [ cases_closed_by_user.get(u, {}).get(day, 0) for u in users ] self.write_row(replies_sheet, row, [day] + replies_totals) self.write_row(cases_opened_sheet, row, [day] + cases_opened_totals) self.write_row(cases_closed_sheet, row, [day] + cases_closed_totals) row += 1 elif self.type == self.TYPE_PARTNER: replies_sheet = book.add_sheet(str(_("Replies Sent"))) ave_sheet = book.add_sheet(str(_("Average Reply Time"))) ave_closed_sheet = book.add_sheet(str(_("Average Closed Time"))) cases_opened_sheet = book.add_sheet(str(_("Cases Opened"))) cases_closed_sheet = book.add_sheet(str(_("Cases Closed"))) partners = list(Partner.get_all(self.org).order_by("name")) # get each partner's day counts and organise by partner and day replies_totals_by_partner = {} cases_opened_by_partner = {} cases_closed_by_partner = {} replied_averages_by_partner = {} closed_averages_by_partner = {} for partner in partners: replies_totals = DailyCount.get_by_partner( [partner], DailyCount.TYPE_REPLIES, self.since, self.until).day_totals() cases_opened_totals = DailyCount.get_by_partner( [partner], DailyCount.TYPE_CASE_OPENED, self.since, self.until).day_totals() cases_closed_totals = DailyCount.get_by_partner( [partner], DailyCount.TYPE_CASE_CLOSED, self.since, self.until).day_totals() replies_totals_by_partner[partner] = { t[0]: t[1] for t in replies_totals } cases_opened_by_partner[partner] = { t[0]: t[1] for t in cases_opened_totals } cases_closed_by_partner[partner] = { t[0]: t[1] for t in cases_closed_totals } replied_second_totals = DailySecondTotalCount.get_by_partner( [partner], DailySecondTotalCount.TYPE_TILL_REPLIED, self.since, self.until).day_totals() replied_averages_by_partner[partner] = { t[0]: (float(t[2]) / t[1]) for t in replied_second_totals } closed_second_totals = DailySecondTotalCount.get_by_partner( [partner], DailySecondTotalCount.TYPE_TILL_CLOSED, self.since, self.until).day_totals() closed_averages_by_partner[partner] = { t[0]: (float(t[2]) / t[1]) for t in closed_second_totals } self.write_row(replies_sheet, 0, ["Date"] + [p.name for p in partners]) self.write_row(cases_opened_sheet, 0, ["Date"] + [p.name for p in partners]) self.write_row(cases_closed_sheet, 0, ["Date"] + [p.name for p in partners]) self.write_row(ave_sheet, 0, ["Date"] + [p.name for p in partners]) self.write_row(ave_closed_sheet, 0, ["Date"] + [p.name for p in partners]) row = 1 for day in date_range(self.since, self.until): replies_totals = [ replies_totals_by_partner.get(l, {}).get(day, 0) for l in partners ] cases_opened_totals = [ cases_opened_by_partner.get(l, {}).get(day, 0) for l in partners ] cases_closed_totals = [ cases_closed_by_partner.get(l, {}).get(day, 0) for l in partners ] replied_averages = [ replied_averages_by_partner.get(l, {}).get(day, 0) for l in partners ] closed_averages = [ closed_averages_by_partner.get(l, {}).get(day, 0) for l in partners ] self.write_row(replies_sheet, row, [day] + replies_totals) self.write_row(cases_opened_sheet, row, [day] + cases_opened_totals) self.write_row(cases_closed_sheet, row, [day] + cases_closed_totals) self.write_row(ave_sheet, row, [day] + replied_averages) self.write_row(ave_closed_sheet, row, [day] + closed_averages) row += 1
def __init__(self, *args, **kwargs): super(OrgUserForm, self).__init__(*args, **kwargs) self.fields['partner'].queryset = Partner.get_all(self.org).order_by('name')