def helptext_edit(request, id): if not check_user_is_admin(request): return HttpResponseRedirect('/notadmin/') user = request.session.get('user') if request.method == 'POST': form = HelpTextForm(data=request.POST) if form.is_valid(): title = form.cleaned_data['title'] category = form.cleaned_data['category'] abstract = form.cleaned_data['abstract'] content = form.cleaned_data['content'] AdminService().editHelpText(id, title, category, abstract, content) return HttpResponseRedirect('/admin/') else: helptext = AdminService().getHelpText(id) if helptext: form = HelpTextForm(initial= {'title': helptext.title, 'category':helptext.category, 'abstract':helptext.abstract, 'content':helptext.content }) else: form = HelpTextForm() page_title=ugettext('Edit Help Text') form_action_url='/admin/helptext/edit/' + id page_module='Admin' return render_to_response('common_add_edit.html', {'page_title':page_title, 'form_action_url': form_action_url, 'form': form, 'user':user, 'page_module' : page_module })
def moneyiosystype_edit(request, id): if not check_user_is_admin(request): return HttpResponseRedirect('/notadmin/') user = request.session.get('user') if request.method == 'POST': form = MoneyIOSysTypeForm(data=request.POST) if form.is_valid(): name = form.cleaned_data['name'] isio = int(form.cleaned_data['isio']) AdminService().editMoneyIOSysType(id, name, isio) return HttpResponseRedirect('/admin/') else: moneyiosystype = MoneyService().getMoneyIOSysType(id) if moneyiosystype: form = MoneyIOSysTypeForm(initial= {'name': moneyiosystype.name, 'isio':moneyiosystype.isio }) else: form = MoneyIOSysTypeForm() page_title=ugettext('Edit Money Income and Expense System Type') form_action_url='/admin/moneyiosystype/edit/' + id page_module='Admin' return render_to_response('common_add_edit.html', {'page_title':page_title, 'form_action_url': form_action_url, 'form': form, 'user':user, 'page_module' : page_module })
def accounttype_edit(request, id): if not check_user_is_admin(request): return HttpResponseRedirect('/notadmin/') user = request.session.get('user') if request.method == 'POST': form = AccountTypeForm(data=request.POST) if form.is_valid(): name = form.cleaned_data['name'] canadvance = form.cleaned_data['canadvance'] AdminService().editAccountType(id, name, canadvance) return HttpResponseRedirect('/admin/') else: accounttype = AccountService().getAccountType(id) if accounttype: form = AccountTypeForm(initial= {'name': accounttype.name, 'canadvance':accounttype.canadvance }) else: form = AccountTypeForm() page_title=ugettext('Edit Account Type') form_action_url='/admin/accounttype/edit/' + id page_module='Admin' return render_to_response('common_add_edit.html', {'page_title':page_title, 'form_action_url': form_action_url, 'form': form, 'user':user, 'page_module' : page_module })
def currency_edit(request, id): if not check_user_is_admin(request): return HttpResponseRedirect('/notadmin/') user = request.session.get('user') if request.method == 'POST': form = CurrencyForm(data=request.POST) if form.is_valid(): name = form.cleaned_data['name'] symbol = form.cleaned_data['symbol'] AdminService().editCurrency(id, name, symbol) return HttpResponseRedirect('/admin/') else: currency = AccountService().getCurrency(id) if currency: form = CurrencyForm(initial= {'name': currency.name, 'symbol':currency.symbol }) else: form = CurrencyForm() page_title=ugettext('Edit Currency') form_action_url='/admin/currency/edit/' + id page_module='Admin' return render_to_response('common_add_edit.html', {'page_title':page_title, 'form_action_url': form_action_url, 'form': form, 'user':user, 'page_module' : page_module })
def season_admin(): next_season_name = None curr_season_name = None season_info = AdminService().get_season_info() try: curr_season_name = season_info[1] next_season_name = season_info[3] except: flash('Cannot retrieve season info', 'danger') return render_template('season_admin.html', next_season=next_season_name, curr_season=curr_season_name)
def challenges(): if request.method == 'POST': num_challenges = random.randint(1, 3) challenges_sql = AdminService().roll_challenges(num_challenges) selected_challenges = [challenge[0] for challenge in challenges_sql] challenge_dict = { "num": num_challenges, "challenges": selected_challenges } season_info = AdminService().get_season_info() curr_season_name = season_info[1] or None next_season_name = season_info[3] or None return render_template('season_admin.html', next_season=next_season_name, curr_season=curr_season_name, challenge_dict=challenge_dict ) else: return redirect(url_for('season_admin'))
def index(request): if not check_user_is_admin(request): return HttpResponseRedirect('/notadmin/') page_title = ugettext('Admin') user = request.session.get('user') page_module='Admin' currency_list = AdminService().getCurrencyList() accounttype_list = AdminService().getAccountTypeList() moneyiosystype_list = AdminService().getMoneyIOSysTypeList() helptext_list = AdminService().getHelpTextList() '''helptext_list_json = JSONEncoder().encode(AdminService().encode(helptext_list))''' return render_to_response('admin.html', {'currency_list': currency_list, 'accounttype_list': accounttype_list, 'moneyiosystype_list': moneyiosystype_list, 'helptext_list': helptext_list, 'user':user, 'page_title': page_title, 'page_module': page_module, })
def start_season(): if request.method == 'POST': # end season placeholder new_season = AdminService().start_season() if new_season: fmsg = 'New Season Started' state = 'success' us = update_standings() if not us: flash('Standings update failed', 'danger') elif new_season == 0: fmsg = 'Season cannot be started without games!' \ ' Add games and try again. ' state = 'danger' else: fmsg = 'Season cannot be started! ' state = 'danger' flash(fmsg, state) return redirect(url_for('season_admin'))
def add_games_to_season(): # redirects from add games form in season_admin season_number = request.form['add-season-games'].strip().lower() season_name = f'Season {season_number}' games = [] gl = request.form['games-list'].strip().split('\r\n') for line in gl: line = line.split(',') flex = False if line[2].lower().strip() == 'yes': flex = True game = { "game_num": int(line[0].strip()), "budget": int(line[1].strip()), "flex": flex, "theme": line[3].strip() } games.append(game) num_games = len(games) params = { "season_name": season_name, "games": games } add = AdminService().add_games_to_season(params) if add == num_games: fmsg = f'{num_games} games added to {season_name}. ' state = 'success' elif add != num_games: fmsg = f'Partial success. Only added {add} to {season_name}. ' state = 'warning' else: fmsg = 'Failed to add games. ' state = 'danger' flash(fmsg, state) return redirect(url_for('season_admin'))
def create_season(): # redirects from create season form in season_admin params = { "season-name": request.form['season-name'], "num-games": int(request.form['num-games']), "start-date": request.form['start-date'] } # Protecting myself from my own stupid data entry mistakes if 'season' not in params['season-name'].lower() \ and len(params['season-name'] == 1): params['season-name'] = f"Season {params['season-name']}" create = AdminService().create_season(params) if create: fmsg = f"{params['season-name']} created. " state = 'success' else: fmsg = f"{params['season-name']} either already exists " \ "or failed to create. " state = 'danger' flash(fmsg, state) return redirect(url_for('season_admin'))
def currency_delete(request, id): if not check_user_is_admin(request): return HttpResponseRedirect('/notadmin/') AdminService().deleteCurrency(id) return HttpResponseRedirect('/admin/')
def helptext_delete(request, id): if not check_user_is_admin(request): return HttpResponseRedirect('/notadmin/') AdminService().deleteHelpText(id) return HttpResponseRedirect('/admin/')
def moneyiosystype_delete(request, id): if not check_user_is_admin(request): return HttpResponseRedirect('/notadmin/') moneyiosystype_list = AdminService().getMoneyIOSysTypeList() return HttpResponseRedirect('/admin/')
def accounttype_delete(request, id): if not check_user_is_admin(request): return HttpResponseRedirect('/notadmin/') AdminService().deleteAccountType(id) return HttpResponseRedirect('/admin/')