def weekly_reports(): # this should get called every hour by celery now = datetime.utcnow() reps = DailyReportNotification.view("reports/weekly_notifications", key=[now.weekday(), now.hour], include_docs=True).all() _run_reports(reps)
def add_scheduled_report(request, domain, couch_user_id): if request.method == "POST": report_type = request.POST["report_type"] hour = request.POST["hour"] day = request.POST["day"] if day=="all": report = DailyReportNotification() else: report = WeeklyReportNotification() report.day_of_week = int(day) report.hours = int(hour) report.domain = domain report.report_slug = report_type report.user_ids = [couch_user_id] report.save() messages.success(request, "New scheduled report added!") return HttpResponseRedirect(reverse("user_account", args=(domain, couch_user_id ))) context = _users_context(request, domain) context.update({"hours": [(val, "%s:00" % val) for val in range(24)], "days": [(val, calendar.day_name[val]) for val in range(7)], "reports": dict([(key, value) for (key, value) in ScheduledReportFactory.get_reports(domain).items() if value.auth(request)])}) return render_to_response(request, "users/add_scheduled_report.html", context)
def daily_reports(): # this should get called every hour by celery reps = DailyReportNotification.view("reports/daily_notifications", key=datetime.utcnow().hour, include_docs=True).all() _run_reports(reps)