def post(self, request, *args, **kwargs): login_form = self.get_form() if login_form.is_valid(): user_name = login_form.cleaned_data['username'] pass_word = login_form.cleaned_data['password'] next = request.POST.get('next', '') user = authenticate(username=user_name, password=pass_word) if user is not None: if user.is_active: login(request, user) if next: return HttpResponseRedirect(next) else: return HttpResponseRedirect(reverse('index')) else: return my_render(request, "login.html", {"msq": _(u"用户未激活,请联系管理!")}) else: return my_render(request, "login.html", {"msq": _(u"用户验证失败,请联系管理员!")}) else: return my_render(request, "login.html", { "msq": _(u"用户验证失败,请联系管理员!"), "login_form": login_form })
def post(self, request, *args, **kwargs): post_data = request.POST enabled_value = str(post_data.get("enabled")) == str(True) is_send_email_value = str(post_data.get("is_send_email")) == str(True) job_data = { "nice_name": post_data.get("nice_name", ''), "host": post_data.get("host", ''), "name": post_data.get("name", ''), "interval_id": post_data.get("interval", ''), "crontab_id": post_data.get("crontab", ''), "args": post_data.get("args", ''), "kwargs": post_data.get("kwargs", ''), "queue": post_data.get("queue", ''), "enabled": enabled_value, "run_status": True if enabled_value else False, "exchange": post_data.get("exchange", ''), "routing_key": post_data.get("routing_key", ''), "expires": None, "description": post_data.get("description", ''), "date_changed": datetime.now(), "email": post_data.get("email"), "is_send_email": is_send_email_value } if job_data['interval_id'] and job_data['crontab_id']: status = 2 return my_render(request, "task/job_edit.html", locals()) task_value = post_data.get("regtask") if task_value: job_data["task"] = task_value kwargs_vaule = job_data["kwargs"] args_value = job_data["args"] try: json.loads(kwargs_vaule) except: status = 2 return my_render(request, "task/job_edit.html", locals()) if args_value: try: json.loads(args_value) except: status = 2 return my_render(request, "task/job_edit.html", locals()) try: pre_save.send(sender=PeriodicTask, instance=TimedTask) self.get_queryset().update(**job_data) status = 1 except Exception as e: print e status = 2 return my_render(request, "task/job_edit.html", locals())
def post(self, request, *args, **kwargs): post_data = request.POST interval_data = { "every": post_data.get("every"), "period": post_data.get("period") } try: pre_save.send(sender=PeriodicTask, instance=TimedTask) self.get_queryset().update(**interval_data) status = 1 except: status = 2 return my_render(request, "task/interval_edit.html", locals())
def post(self, request): crontab_data = { "minute": request.POST.get("minute", ''), "hour": request.POST.get("hour", ''), "day_of_week": request.POST.get("day_of_week", ''), "day_of_month": request.POST.get("day_of_month", ''), "month_of_year": request.POST.get("month_of_year", '') } try: CrontabSchedule.objects.create(**crontab_data) msg = u"添加crontab成功!" except: error = u"添加crontab失败!" return my_render(request, "task/crontab_add.html", locals())
def post(self, request, id): crontab_data = { "minute": request.POST.get("minute", ''), "hour": request.POST.get("hour", ''), "day_of_week": request.POST.get("day_of_week", ''), "day_of_month": request.POST.get("day_of_month", ''), "month_of_year": request.POST.get("month_of_year", '') } try: pre_save.send(sender=PeriodicTask, instance=TimedTask) CrontabSchedule.objects.filter(pk=id).update(**crontab_data) status = 1 except: status = 2 return my_render(request, "task/crontab_edit.html", locals())
def post(self, request, *args, **kwargs): login_form = self.get_form() if login_form.is_valid(): user_name = login_form.cleaned_data['username'] pass_word = login_form.cleaned_data['password'] if User.objects.filter(username=user_name).exists(): next = request.POST.get('next', '') user = authenticate(username=user_name, password=pass_word) if user is not None: if user.is_active: login(request, user) request.session.clear_expired() if next: return HttpResponseRedirect(next) else: return HttpResponseRedirect(reverse('index')) else: return my_render(request, "login.html", {"msq": "用户未激活,请联系管理!"}) else: return my_render(request, "login.html", {"msq": "用户未激活或密码错误,请联系管理员!"}) else: return my_render(request, "login.html", {"msq": "用户不存在,请确定用户名后再次登录!"}) else: return my_render(request, "login.html", {"msq": "用户验证失败,请联系管理员!", "login_form": login_form})
def get(self, request): start_time = (datetime.datetime.now() - datetime.timedelta(days=30)).strftime('%Y-%m-%d %H:%M:%S') end_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') return my_render(request, 'histoty_records_periodictask.html', locals())
def get(self, request): start_time = (datetime.datetime.now() - datetime.timedelta(days=30)).strftime('%Y-%m-%d %H:%M:%S') end_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') return my_render(request, 'op_log.html', locals())
def get(self, request): return my_render(request, "index.html", locals())
def get(self, request): result_dict = {} left = [] right = [] first = False last = False left_has_more = False right_has_more = False is_paginated = True host_ip = request.GET.get('host', '') status = request.GET.get('status', '') kwargs = request.GET.get('kwargs', '') page = request.GET.get('page', 1) timedtask_obj = TimedTask.objects.all() result_list = TaskResult.objects.all() if host_ip and kwargs: result_dict['task_kwargs__contains'] = host_ip and kwargs elif host_ip: result_dict['task_kwargs__contains'] = host_ip elif kwargs: result_dict['task_kwargs__contains'] = kwargs if status: result_dict['status__contains'] = status if result_dict: result_list = TaskResult.objects.filter(**result_dict) total_result = result_list.count() page_number = int(page) paginator = Paginator(result_list, 10) # 获得分页后的总页数 total_pages = paginator.num_pages page_range = list(paginator.page_range) currentPage = int(page_number) try: result_list = paginator.page(page) except PageNotAnInteger: result_list = paginator.page(1) except EmptyPage: result_list = paginator.page(total_pages) if result_list and total_pages > 1: if page_number == 1: right = page_range[page_number:page_number + 2] if right[-1] < total_pages - 1: right_has_more = True if right[-1] < total_pages: last = True elif page_number == total_pages: left = page_range[( page_number - 3) if (page_number - 3) > 0 else 0:page_number - 1] if left[0] > 2: left_has_more = True if left[0] > 1: first = True else: left = page_range[( page_number - 3) if (page_number - 3) > 0 else 0:page_number - 1] right = page_range[page_number:page_number + 2] if right[-1] < total_pages - 1: right_has_more = True if right[-1] < total_pages: last = True if left[0] > 2: left_has_more = True if left[0] > 1: first = True else: is_paginated = False return my_render(request, "task/result_list.html", locals())
def get(self, request, id): status = 0 crontab_info = CrontabSchedule.objects.get(pk=id) return my_render(request, "task/crontab_edit.html", locals())
def get(self, request): return my_render(request, "task/crontab_add.html", locals())
def post(self, request, *args, **kwargs): post_data = request.POST enabled_value = str(post_data.get("enabled")) == str(True) is_send_email_value = str(post_data.get("is_send_email")) == str(True) job_data = { "nice_name": post_data.get("nice_name", ''), "host": post_data.get("host", ''), "name": post_data.get("name", ''), "task": post_data.get("regtask", ''), "interval_id": post_data.get("interval", ''), "crontab_id": post_data.get("crontab", ''), "args": post_data.get("args", ''), "kwargs": post_data.get("kwargs", ''), "queue": str(rabbitmq_queue), "exchange": rabbitmq_exchange, "routing_key": str(rabbitmq_routing_key), "expires": None, "enabled": enabled_value, "run_status": True if enabled_value else False, "description": post_data.get("description", ''), "email": post_data.get("email"), "is_send_email": is_send_email_value } print job_data if job_data['interval_id'] and job_data['crontab_id']: error = u"you can only choices one of interval or crontab!" interval_info = self.interval_info crontab_info = self.crontab_info self.celery_app.loader.import_default_modules() tasks = list( sorted(name for name in self.celery_app.tasks if not name.startswith('celery.'))) return my_render(request, "task/job_add.html", locals()) value = job_data["kwargs"] try: json.loads(value) except ValueError as exc: error = u"Unable to parse JSON: %s" % exc interval_info = self.interval_info crontab_info = self.crontab_info self.celery_app.loader.import_default_modules() tasks = list( sorted(name for name in self.celery_app.tasks if not name.startswith('celery.'))) return my_render(request, "task/job_add.html", locals()) if job_data['args']: try: json.loads(job_data['args']) except Exception as exc: error = u"Unable to parse JSON: %s" % exc interval_info = self.interval_info crontab_info = self.crontab_info self.celery_app.loader.import_default_modules() tasks = list( sorted(name for name in self.celery_app.tasks if not name.startswith('celery.'))) try: pre_save.send(sender=PeriodicTask, instance=TimedTask) TimedTask.objects.create(**job_data) msg = u"添加任务成功!" except Exception as e: error = u"添加任务失败!,{0}".format(e) interval_info = self.interval_info crontab_info = self.crontab_info self.celery_app.loader.import_default_modules() tasks = list( sorted(name for name in self.celery_app.tasks if not name.startswith('celery.'))) return my_render(request, "task/job_add.html", locals())