def send_signal(request, pk): error = Error.get(pk) if not error.create_signal_sent: error.create_signal_sent = True error.save() error_created.send(sender=error.__class__, instance=error) return render_plain("Signal sent") return render_plain("Signal not sent")
def notifications_send(request): log("Firing cron: notifications_send") notifications = Notification.all().filter("type = ", "Error").filter("tried = ", False) # batch up the notifications for the user holders = {} for notif in notifications: for user in notif.user_list(): key = str(user.key()) if key not in holders: holder = Holder() holder.user = user holders[key] = holder holders[key].objs.append(notif.notifier()) holders[key].notifs.append(notif) for user_id, holder in holders.items(): try: send_error_email(holder) for notification in holder.notifs: notification.tried = True notification.completed = True notification.save() except: info = sys.exc_info() data = "%s, %s" % (info[0], info[1]) for notification in holder.notifs: notification.tried = True notification.completed = True notification.error_msg = data notification.save() return render_plain("Cron job completed")
def post(request): """ Add in a post """ log("Processing email message") mailobj = mail.InboundEmailMessage(request.raw_post_data) to = mailobj.to if to in settings.ALLOWED_RECEIVING_ADDRESSES: key = settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER else: key = to.split("-", 1)[1].split("@")[0] if key != settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER: log("To address (%s, to %s) does not match account number (%s)" % (key, to, settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER)) return for content_type, body in mailobj.bodies("text/plain"): if mailobj.subject.find(" Broken ") > -1: log("Trying to parse body using 404 parser") result = parse_404(body, mailobj.subject) else: log("Trying to parse body using 500 parser") result = parse_500(body, mailobj.subject) err = Error() result["account"] = key populate(err, result) return render_plain("message parsed")
def notifications_send(request): log("Firing cron: notifications_send") notifications = Notification.all().filter("tried = ", False) # batch up the notifications for the user holders = {} for notif in notifications: for user in notif.user_list(): key = str(user.key()) if key not in holders: holder = Holder() holder.user = user holders[key] = holder holders[key].objs.append(notif.error) holders[key].notifs.append(notif) for user_id, holder in holders.items(): try: send_error_email(holder) for notification in holder.notifs: notification.tried = True notification.completed = True notification.save() except: info = sys.exc_info() data = "%s, %s" % (info[0], info[1]) for notification in holder.notifs: notification.tried = True notification.completed = True notification.error_msg = data notification.save() return render_plain("Cron job completed")
def post(request): """ Add in a post """ data = request.POST.copy() data["ip"] = request.META.get("REMOTE_ADDR", "") data["user_agent"] = request.META.get("HTTP_USER_AGENT", "") populate.delay(data) return render_plain("Error recorded")
def notifications_cleanup(request): log("Firing cron: notifications_cleanup") expired = datetime.today() - timedelta(days=7) queryset = Notification.all().filter("tried = ", True).filter("timestamp < ", expired) for notification in queryset: notification.delete() return render_plain("Cron job completed")
def notifications_cleanup(request): log("Firing cron: notifications_cleanup") expired = datetime.today() - timedelta(days=7) queryset = Notification.objects.filter(tried=True, timestamp__lt=expired) for notification in queryset: notification.delete() return render_plain("Cron job completed")
def post(request): """ Add in a post """ err = Error() err.ip = request.META.get("REMOTE_ADDR", "") err.user_agent = request.META.get("HTTP_USER_AGENT", "") populate(err, request.POST) return render_plain("Error recorded")
def notifications_cleanup(days=0): log("Firing cron: notifications_cleanup") expired = datetime.today() - timedelta(days=days) queryset = Notification.objects.filter(tried=True, timestamp__lt=expired) for notification in queryset: notification.delete() return render_plain("Cron job completed")
def get_action(request, action, pk): stats = Stats.get(pk) current = stats.get_stats() if action not in registered: raise ValueError, "Action: %s not registered" % action current[action] = registered[action](stats) stats.set_stats(current) stats.save() return render_plain("total done: %s" % current)
def post(request): """ Add in a post """ data = request.POST.copy() if "ip" not in data: data["ip"] = request.META.get("REMOTE_ADDR", "") if "user_agent" not in data: data["user_agent"] = request.META.get("HTTP_USER_AGENT", "") populate.delay(data) return render_plain("Error recorded")
def post(request): """ Add in a post """ log("Processing email message") mailobj = mail.InboundEmailMessage(request.raw_post_data) found = False for content_type, body in mailobj.bodies("text/plain"): found = parse(content_type, body) for content_type, body in mailobj.bodies("text/html"): found = parse(content_type, body) if not found: log("No contents found in the message.") return render_plain("message parsed")