def get_context_data(self, **kwargs): context = super(MonitorView, self).get_context_data(**kwargs) user = self.request.user year = int(self.kwargs.get("year", datetime.now().year)) month = int(self.kwargs.get("month", datetime.now().month)) ref_date = date(year, month, 1) period = ref_date.strftime("%B") next_month_date = ref_date + relativedelta(months=1) next_month_month = next_month_date.month next_month_year = next_month_date.year prev_month_date = ref_date + relativedelta(months=-1) prev_month_month = prev_month_date.month prev_month_year = prev_month_date.year table_data = service.get_friend_entries(user, "teacher", year, month) context["columns"] = json.dumps(table_data["columns"]) context["data"] = json.dumps(table_data["data"]) context["period"] = "%s %s" % (period, year) context["prev_month_month"] = prev_month_month context["prev_month_year"] = prev_month_year context["month"] = month context["year"] = year context["next_month_month"] = next_month_month context["next_month_year"] = next_month_year return context
def get(self, request, *args, **kwargs): user = self.request.user year = int(self.kwargs.get("year", datetime.now().year)) month = int(self.kwargs.get("month", datetime.now().month)) table_data = service.get_friend_entries(user, "teacher", year, month) data = {"data": table_data} return JsonResponse(data)
def get(self, request, *args, **kwargs): user = self.request.user year = int(self.kwargs.get("year", datetime.now().year)) month = int(self.kwargs.get("month", datetime.now().month)) table_data = service.get_friend_entries(user, "teacher", year, month) response = HttpResponse(content_type="text/csv") response["Content-Disposition"] = 'attachment; filename="list_%s_%s.csv"' % (year, month) writer = csv.writer(response) columns = [d["title"] for d in table_data["columns"]] writer.writerow(columns) for row in table_data["data"]: writer.writerow(row) return response