示例#1
0
def add_stats():
    # remember: url_for('add', username=session.get('username'))
    form = StatsForm()
    if form.validate_on_submit():
        # Create new stats object
        user_key_str = session.get('user_key_str')

        if user_key_str is None:
            flask.flash("You are not current logged in.", 'warning')
            return flask.redirect(flask.url_for('index'))

        stats = create_stats(form, user_key=ndb.Key(urlsafe=user_key_str))
        stats_dict = stats_to_dict(stats)
        session['stats'] = stats_dict

        user = get_current_user()

        if user is None:
            flask.flash("You are not current logged in.", 'warning')
            return flask.redirect(flask.url_for('index'))

        if user.starting_stats is None:
            user.starting_stats = stats
        user.current_stats = stats
        user.put()


        flask.flash("Successfully updated your stats.")
        return flask.redirect(flask.url_for('index'))
    return flask.render_template('basic_form.html', header='Update your stats', form=form)
示例#2
0
def add_stats():
    # remember: url_for('add', username=session.get('username'))
    form = StatsForm()
    if form.validate_on_submit():
        # Create new stats object
        user_key_str = session.get('user_key_str')

        if user_key_str is None:
            flask.flash("You are not current logged in.", 'warning')
            return flask.redirect(flask.url_for('index'))

        stats = create_stats(form, user_key=ndb.Key(urlsafe=user_key_str))
        stats_dict = stats_to_dict(stats)
        session['stats'] = stats_dict

        user = get_current_user()

        if user is None:
            flask.flash("You are not current logged in.", 'warning')
            return flask.redirect(flask.url_for('index'))

        if user.starting_stats is None:
            user.starting_stats = stats
        user.current_stats = stats
        user.put()

        flask.flash("Successfully updated your stats.")
        return flask.redirect(flask.url_for('index'))
    return flask.render_template('basic_form.html',
                                 header='Update your stats',
                                 form=form)
示例#3
0
def get_stats(request):
    c = StatsForm(data=request.GET)
    if c.is_valid():
        i = c.cleaned_data.get('start').strftime('%Y-%m-%d')
        e = c.cleaned_data.get('end').strftime('%Y-%m-%d')
        result = {}

        # total pedidios
        t = Order.stats.total(i, e)
        result['total_facturat'] = t[0][0]
        result['total_orders'] = t[0][1]

        # facturas dia
        result['facturas_dia'] = Order.stats.facturas_dia(i, e)
        # pedidos dia
        result['pedidos_dia'] = Order.stats.pedidos_dia(i, e)
        # rendiment producte
        result['rendiment_producte'] = Order.stats.rendiment_producte(i, e)
        # productes dies
        result['productes_per_dia'] = Order.stats.productes_per_dia(i, e)

        data = json.dumps(result, default=dthandler)
        res = HttpResponse(data)
        return res
    else:
        print c
        return HttpResponse('invalid_form')
示例#4
0
def get_stats(request):
    c = StatsForm(data=request.GET)
    if c.is_valid():
        i = c.cleaned_data.get("start").strftime("%Y-%m-%d")
        e = c.cleaned_data.get("end").strftime("%Y-%m-%d")
        result = {}

        # total pedidios
        t = Order.stats.total(i, e)
        result["total_facturat"] = t[0][0]
        result["total_orders"] = t[0][1]

        # facturas dia
        result["facturas_dia"] = Order.stats.facturas_dia(i, e)
        # pedidos dia
        result["pedidos_dia"] = Order.stats.pedidos_dia(i, e)
        # rendiment producte
        result["rendiment_producte"] = Order.stats.rendiment_producte(i, e)
        # productes dies
        result["productes_per_dia"] = Order.stats.productes_per_dia(i, e)

        data = json.dumps(result, default=dthandler)
        res = HttpResponse(data)
        return res
    else:
        print c
        return HttpResponse("invalid_form")
示例#5
0
def new_company():
  form = StatsForm(request.form)

  if request.method == "POST" and form.validate():
    stats = Stats()
    save_changes(stats, form, new=True)
    flash("Company created!")
    return redirect("/")
  return render_template("new_company.html", form=form)
示例#6
0
def add(chart):
    form = StatsForm()
    chart_ref = db.collection(current_user.brand).document(chart) # get the chart object
    if form.is_submitted():
        result = form.category.data
        chart_ref.update({'stats': firestore.ArrayUnion([result])})
        return redirect(url_for('chart', chart_name=chart))
    chart = chart_ref.get().to_dict() # get it as dict
    stats = chart['stats']
    return render_template('add.html', form=form, stats=stats)
示例#7
0
def character(username, cid):
    if not current_user.is_authenticated:
        return redirect(url_for('.root'))
    if current_user.username != username or cid not in [
            str(x.cid) for x in current_user.characters
    ]:
        return redirect(url_for('.user', username=current_user.username))
    char = Character.query.get(int(cid))
    return render_template('character.html',
                           title='Character Page',
                           char=char,
                           statsform=StatsForm(char))
示例#8
0
def stats(cid):
    if current_user.is_authenticated:
        for c in [c for c in current_user.characters if str(c.cid) == cid]:
            form = StatsForm(c)
            if form.validate_on_submit:
                c.spell_mod = form.spell_attack_rol.data
                c.spell_dc = form.spell_dc.data
                c.cantrip_lvl = form.cantrip_lvl.data
                for lvl in ['cantrip'] + [str(i) for i in range(1, 11)]:
                    setattr(c, 'spell_slots_' + lvl,
                            getattr(form, 'spell_slots_' + lvl).data)
                db.session.commit()
                return "Stats updated", 200
        return "Validation error", 400
    else:
        return "User not logged in", 400