def do_add(request): if request.method == 'POST': data = request.POST if data.has_key('main'): new = Schedule() new.name = data['name'] if data['is_model'] == 'true': new.is_model = True new.save() return HttpResponse('{"status": "ok", "new_id": %s}' % new.id) elif data.has_key('schedule_id'): s = get_object_or_404(Schedule, pk=int(data['schedule_id'])) try: run = Run() run.schedule = s run.level = BackupLevel.objects.get(id=int(data['level_id'])) run.kind = BackupKind.objects.get(id=int(data['kind_id'])) run.hour = data['hour'] run.minute = data['minute'] run.day = int(data['day_num']) run.save() return HttpResponse('{"status": "ok"}') except: s.delete() return HttpResponse('{"status": "error"}')
def do_edit(request): if request.method == 'POST': data = request.POST if data.has_key('main'): s = get_object_or_404(Schedule, pk=int(data['id'])) s.name = data['name'] s.save() return HttpResponse('{"status": "ok", "new_id": %s}' % s.id) elif data.has_key('schedule_id'): s = get_object_or_404(Schedule, pk=int(data['schedule_id'])) if data['status'] == 'deleted': r = get_object_or_404(Run, pk=int(data['id'])) r.delete() try: if data['status'] == 'new': run = Run() run.schedule = s run.level = BackupLevel.objects.get( id=int(data['level_id'])) run.kind = BackupKind.objects.get(id=int(data['kind_id'])) run.hour = data['hour'] run.minute = data['minute'] run.day = int(data['day_num']) run.save() return HttpResponse('{"status": "ok"}') except: return HttpResponse('{"status": "error"}')
def do_edit(request): if request.method == 'POST': data = request.POST if data.has_key('main'): s = get_object_or_404(Schedule, pk=int(data['id'])) s.name = data['name'] s.save() return HttpResponse('{"status": "ok", "new_id": %s}' % s.id) elif data.has_key('schedule_id'): s = get_object_or_404(Schedule, pk=int(data['schedule_id'])) if data['status'] == 'deleted': r = get_object_or_404(Run, pk=int(data['id'])) r.delete() try: if data['status'] == 'new': run = Run() run.schedule = s run.level = BackupLevel.objects.get(id=int(data['level_id'])) run.kind = BackupKind.objects.get(id=int(data['kind_id'])) run.hour = data['hour'] run.minute = data['minute'] run.day = int(data['day_num']) run.save() return HttpResponse('{"status": "ok"}') except: return HttpResponse('{"status": "error"}')
def do_delete(request, schedule_id): s = get_object_or_404(Schedule, pk=schedule_id) if s.is_model: for procedure in s.procedures.all(): new_schedule = Schedule() new_schedule.name = 'Agendamentos de %s' % procedure.name new_schedule.is_model = False new_schedule.save() for run in s.runs.all(): new_run = Run() new_run.schedule = new_schedule new_run.level = run.level new_run.kind = run.kind new_run.day = run.day new_run.hour = run.hour new_run.minute = run.minute new_run.save() procedure.schedule = new_schedule procedure.save() name = s.name s.delete() call_reload_baculadir() messages.success( request, u"Perfil de agendamento '%s' removido com sucesso." % name) return redirect('/procedures/profile/list')
def do_edit(request): if request.method == "POST": data = request.POST if data.has_key("main"): s = get_object_or_404(Schedule, pk=int(data["id"])) s.name = data["name"] s.save() return HttpResponse('{"status": "ok", "new_id": %s}' % s.id) elif data.has_key("schedule_id"): s = get_object_or_404(Schedule, pk=int(data["schedule_id"])) if data["status"] == "deleted": r = get_object_or_404(Run, pk=int(data["id"])) r.delete() try: if data["status"] == "new": run = Run() run.schedule = s run.level = BackupLevel.objects.get(id=int(data["level_id"])) run.kind = BackupKind.objects.get(id=int(data["kind_id"])) run.hour = data["hour"] run.minute = data["minute"] run.day = int(data["day_num"]) run.save() call_reload_baculadir() return HttpResponse('{"status": "ok"}') except: return HttpResponse('{"status": "error"}')
def do_add(request): if request.method == "POST": data = request.POST if data.has_key("main"): new = Schedule() new.name = data["name"] if data["is_model"] == "true": new.is_model = True new.save() return HttpResponse('{"status": "ok", "new_id": %s}' % new.id) elif data.has_key("schedule_id"): s = get_object_or_404(Schedule, pk=int(data["schedule_id"])) try: run = Run() run.schedule = s run.level = BackupLevel.objects.get(id=int(data["level_id"])) run.kind = BackupKind.objects.get(id=int(data["kind_id"])) run.hour = data["hour"] run.minute = data["minute"] run.day = int(data["day_num"]) run.save() return HttpResponse('{"status": "ok"}') except: s.delete() return HttpResponse('{"status": "error"}')
def do_delete(request, schedule_id): s = get_object_or_404(Schedule, pk=schedule_id) if s.is_model: for procedure in s.procedures.all(): new_schedule = Schedule() new_schedule.name = 'Agendamentos de %s' % procedure.name new_schedule.is_model = False new_schedule.save() for run in s.runs.all(): new_run = Run() new_run.schedule = new_schedule new_run.level = run.level new_run.kind = run.kind new_run.day = run.day new_run.hour = run.hour new_run.minute = run.minute new_run.save() procedure.schedule = new_schedule procedure.save() name = s.name s.delete() messages.success(request, u"Perfil de agendamento '%s' removido com sucesso." % name) return redirect('/procedures/profile/list')