def tracker_add(request, id): c = tools.default_context(request) tracker = Tracker() rfc = ChangeRequest.objects.get(id=id) c['rfc'] = rfc c['title'] = "Add Tracker" if request.method == "POST": _direction = request.POST.get('direction', 1) _amount = request.POST.get('amount', 0) _any_route = request.POST.get('any_route', False) _route = request.POST.get('route', None) try: tracker.rfc = rfc tracker.direction = int(_direction) tracker.count = int(_amount) if bool(_any_route): tracker.route = None else: tracker.route = _route tracker.save() logger.log_action(request.user, rfc, logger.ACTION_ADD_TRACKER) return redirect('/detail/%s/' % id) except ValueError: for key in request.POST.dict().keys(): c[key] = request.POST.get(key) c['error_code'] = 1 return render_to_response("add_tracker.html", c)
def rfc_confirm(request, id): if not tools.has_access(request, ["managers", "tech team"]): return permission_denied(request) _rfc = ChangeRequest.objects.get(id=id) _rfc.cur_state = 2 logger.log_action(user=request.user, action=logger.ACTION_CONFIRM_TRAFFIC, rfc=_rfc) _rfc.save() return redirect('/detail/' + id + '/')
def rfc_reject(request, id): if not tools.has_access(request, "tech team"): return permission_denied(request) rfc = ChangeRequest.objects.get(id=id) rfc.cur_state = 5 rfc.save() logger.log_action(request.user, rfc, logger.ACTION_REJECT) return redirect('/detail/' + id + '/')
def user_logout(request): c = tools.default_context(request) c['title'] = "Log Out" logger.log_action(user=request.user, action=logger.ACTION_LOG_OUT) logout(request) c['warning'] = "You were logged out." c['is_user'] = False return render_to_response('logout.html', c)
def add_rfc(request, rfc_to_edit=None): c = tools.default_context(request) if not tools.has_access(request, "managers"): return permission_denied(request) new_rfc = None c['title'] = "Add RFC" c['new_added'] = True c['oper_our'] = Operator.objects.filter(isDirect=True).order_by('fineName') c['oper_foreign'] = Operator.objects.all().order_by('fineName') # c['priorities'] = dict(ChangeRequest.PRIO_CHOICE) if request.method == "POST": _author = request.user _dt = tools.date_parse_input(request.POST['rfc_date']).date() if _dt < date.today(): return permission_denied(request) _comments = request.POST['comments'] _prio = request.POST['prio'] _peer_hub = request.POST['peer_hub'] _oper_our = request.POST['oper_our'] _oper_foreign = request.POST['oper_foreign'] _towards = request.POST['towards'] _backwards = request.POST['backwards'] new_rfc = ChangeRequest( author=_author, dt=_dt, comments=_comments, prio=_prio, peer_hub=_peer_hub, oper_our=Operator.objects.get(_id=int(_oper_our)), oper_foreign=Operator.objects.get(_id=int(_oper_foreign)), direction=1 * int(_towards) + 2 * int(_backwards), ) new_rfc.save() logger.log_action(user=_author, action=logger.ACTION_ADD_RFC, rfc=new_rfc) c['saved'] = "Saved: " + new_rfc.__str__() c['link'] = new_rfc.id c['new_added'] = False c['peer_hub'] = _peer_hub c['oper_our_previous'] = Operator.objects.get(_id=int(_oper_our)) c['oper_foreign_previous'] = Operator.objects.get(_id=int(_oper_foreign)) c['towards'] = int(_towards) c['backwards'] = int(_backwards) c['override'] = override.find_overriden(new_rfc) if rfc_to_edit is not None: # then delete old RFC and create another c['title'] = "Edit RFC" c['rfc_date'] = rfc_to_edit.dt c['oper_our_previous'] = rfc_to_edit.oper_our c['oper_foreign_previous'] = rfc_to_edit.oper_foreign c['peer_hub'] = rfc_to_edit.peer_hub c['comments'] = rfc_to_edit.comments c['backwards'] = rfc_to_edit.direction // 2 c['towards'] = rfc_to_edit.direction % 2 c['new_added'] = False rfc_to_edit.delete() if isinstance(new_rfc, ChangeRequest): return redirect('/detail/' + str(new_rfc.id)) return render_to_response('addRFC.html', c)
def rfc_override(request, id): try: rfc = ChangeRequest.objects.get(id=id) rfc.cur_state = 4 rfc.save(force_update=True) logger.log_action(request.user, rfc, logger.ACTION_OVERRIDE) return HttpResponse(status=200) except ChangeRequest.DoesNotExist: return HttpResponse(status=500)
def rfc_apply(request, id): if not tools.has_access(request, "tech team"): return permission_denied(request) _rfc = ChangeRequest.objects.get(id=id) if _rfc.cur_state == 0: _rfc.cur_state = 1 logger.log_action(user=request.user, action=logger.ACTION_CONFIRM_ROUTE, rfc=_rfc) _rfc.save() return redirect('/detail/' + id + '/')
def rfc_delete(request, id): try: _rfc = ChangeRequest.objects.get(id=id) except ChangeRequest.DoesNotExist: return page_not_found(request) if not (tools.has_access(request, ["managers"]) and _rfc.cur_state == 0): return permission_denied(request) logger.log_action(user=request.user, action=logger.ACTION_REMOVE_RFC, rfc=_rfc) _rfc.delete() return redirect('/list/')
def oper_sync(request): c = tools.default_context(request) if not tools.has_access(request, "tech team"): return permission_denied(request) c['title'] = "Manage Operators" if request.method == "POST": c['result'] = sync.sync()[1] logger.log_action(request.user, action=logger.ACTION_SYNC_OPERATORS) c['opers'] = Operator.objects.all() return render_to_response('sync.html', c)
def untrack_rfc(request, id): if not tools.has_access(request, "tech team"): return permission_denied(request) rfc = ChangeRequest.objects.get(id=id) trackers = Tracker.objects.filter(rfc=rfc) rfc.cur_state = 3 rfc.save(force_update=True) for tracker in trackers: tracker.delete() logger.log_action(request.user, rfc, logger.ACTION_MARK_UNTRACKABLE) return redirect('/detail/' + id + '/')
def user_login(request): c = tools.default_context(request) if request.user.is_authenticated(): c['title'] = "Main Page" else: c['title'] = "Log In" if request.method == "POST": _user = request.POST['user'] _pass = request.POST['pass'] user = authenticate(username=_user, password=_pass) if user is not None: if user.is_active: login(request, user) logger.log_action(user=user, action=logger.ACTION_LOG_IN) return redirect(request.GET.get("next", "/")) else: c['warning'] = "User is inactive." else: c['warning'] = "The username or password were incorrect." # from django.conf import settings # print settings.DATABASES return render_to_response('login.html', c)
def main() -> None: """ Main entrypoint for the bot """ # bot must be global for function decorators global bot global reddit_client global pasta_subs # get arguments and create clients args = get_args() bot = get_discord_bot() reddit_client = get_reddit_client(args) pasta_subs = reddit_client.subreddit(args.subreddits) # output logging header logger.set_basic_logger(filename=logger.get_log_filename(args)) logger.log_action("bot started") # define async callback functions and run the bot create_bot_callbacks() bot.run(args.discord_bot_token) # stop logging logger.log_action("bot shutdown")
def tracker_unbind(request, id): tracker = Tracker.objects.get(id=id) rfc_id = str(tracker.rfc.id) tracker.delete() logger.log_action(request.user, tracker.rfc, logger.ACTION_REMOVE_TRACKER) return redirect('/detail/' + rfc_id + '/')
def add_rfc(request, rfc_to_edit=None): c = tools.default_context(request) if not tools.has_access(request, "managers"): return permission_denied(request) new_rfc = None c['title'] = "Add RFC" c['new_added'] = True c['oper_our'] = Operator.objects.filter(isDirect=True).order_by('fineName') c['oper_foreign'] = Operator.objects.all().order_by('fineName') # c['priorities'] = dict(ChangeRequest.PRIO_CHOICE) if request.method == "POST": _author = request.user _dt = tools.date_parse_input(request.POST['rfc_date']).date() if _dt < date.today(): return permission_denied(request) _comments = request.POST['comments'] _prio = request.POST['prio'] _peer_hub = request.POST['peer_hub'] _oper_our = request.POST['oper_our'] _oper_foreign = request.POST['oper_foreign'] _towards = request.POST['towards'] _backwards = request.POST['backwards'] new_rfc = ChangeRequest( author=_author, dt=_dt, comments=_comments, prio=_prio, peer_hub=_peer_hub, oper_our=Operator.objects.get(_id=int(_oper_our)), oper_foreign=Operator.objects.get(_id=int(_oper_foreign)), direction=1 * int(_towards) + 2 * int(_backwards), ) new_rfc.save() logger.log_action(user=_author, action=logger.ACTION_ADD_RFC, rfc=new_rfc) c['saved'] = "Saved: " + new_rfc.__str__() c['link'] = new_rfc.id c['new_added'] = False c['peer_hub'] = _peer_hub c['oper_our_previous'] = Operator.objects.get(_id=int(_oper_our)) c['oper_foreign_previous'] = Operator.objects.get( _id=int(_oper_foreign)) c['towards'] = int(_towards) c['backwards'] = int(_backwards) c['override'] = override.find_overriden(new_rfc) if rfc_to_edit is not None: # then delete old RFC and create another c['title'] = "Edit RFC" c['rfc_date'] = rfc_to_edit.dt c['oper_our_previous'] = rfc_to_edit.oper_our c['oper_foreign_previous'] = rfc_to_edit.oper_foreign c['peer_hub'] = rfc_to_edit.peer_hub c['comments'] = rfc_to_edit.comments c['backwards'] = rfc_to_edit.direction // 2 c['towards'] = rfc_to_edit.direction % 2 c['new_added'] = False rfc_to_edit.delete() if isinstance(new_rfc, ChangeRequest): return redirect('/detail/' + str(new_rfc.id)) return render_to_response('addRFC.html', c)