def new_do():
    description = local.request.form.get("description", u"")
    creditor = local.request.form.get("creditor", u"")
    amount = local.request.form.get("amount", u"")
    amount = parsenumber(amount)
    
    if amount == None:
        amount = 0

    debtors = []
    for name, weight in local.request.form.items():
        if not name.startswith("member_"):
            continue

        name = name[7:]
        weight = int(weight)
        
        if weight == 0:
            continue

        debtors.append([name, weight])
    
    username = local.session.get("uid")
    group = user.getgroup(local.session.get("uid"))
    entries.add(username, group, description, amount, creditor, debtors)

    redirect("index.index")
Beispiel #2
0
def create_do():
    if not authcheck():
        return
    form = local.request.form
    username = form.get("username")
    email = form.get("email")
    macaddrs_max = form.get("macaddrs_max")
    password0 = form.get("password0")
    password1 = form.get("password1")
    
    errors = set()
    if password0 != password1:
        errors.add("passwordmatch")

    try:
        macaddrs_max = int(macaddrs_max)
    except ValueError:
        errors.add("macaddrs_max_type")
    else:
        if not macaddrs_max >= 0:
            errors.add("macaddrs_max_range")
    if len(errors) > 0:
        redirect("user.create_form", errors=",".join(errors), username=username, email=email, macaddrs_max=macaddrs_max)
        return
    
    user.create(username=username, email=email, macaddrs_max=macaddrs_max, password=password0)
    redirect("user.list")
Beispiel #3
0
def rollback(filename):
    doc = Document.load("savedir/" + filename)
    doc.save("Rullede tilbage til version '%s'"
            % (filename.replace("save.beer.", ""), ), "savedir/save.beer")

    set_document(doc)

    redirect("version.browse")
Beispiel #4
0
def delete(product_id):
    try:
        product = inventory().get_product(product_id)
    except KeyError:
        return notfound()

    inventory().remove_product(product.id)
    document().save(u'Fjernede "%s"' % (product.name,))
    redirect("product.browse")
Beispiel #5
0
def purchase_delete(product_id, purchase_id):
    try:
        product = inventory().get_product(product_id)
        purchase = product.get_purchase(purchase_id)
    except KeyError:
        return notfound()

    product.remove_purchase(purchase.id)
    document().save(u'Fjernede indkøb "%s" fra produkt "%s"' % (product.name, purchase.name))
    redirect("product.edit", product_id=product_id)
Beispiel #6
0
def enter_title_do():
    title = local.request.form.get("title", u"")

    if len(title) == 0:
        return redirect("misc.enter_title_form")

    document().title = title
    document().save(u'Ændrede titel til "%s"' % (title,))

    redirect("index.index")
Beispiel #7
0
def login_do():
    password = local.request.form.get("password", u"")

    if adminauth(password):
        local.session["authed"] = True
        redirect("index")
        return

    redirect("admin.login_form")
    return
Beispiel #8
0
def login_do():
    password = local.request.form.get("password", u"")
    
    if adminauth(password):
        local.session["authed"] = True
        redirect("index")
        return

    redirect("admin.login_form")
    return
Beispiel #9
0
def login_do():
    username = local.request.form.get("username")
    password = local.request.form.get("password")

    uid = user.authenticate(username, password)

    if uid == None:
        redirect("netlogon.login_form", error="")
        return

    local.response = werkzeug.utils.redirect("http://www.dikulan.dk/", 307)
Beispiel #10
0
def adjust_cash():
    amount = parsenumber(local.request.form.get("amount", u""))

    if amount != None and amount != 0:
        document().cash_in_hand.add_transaction("Justerede kassebeholdning", amount)

        amount_str = formatcurrency(abs(amount))
        if amount < 0:
            document().save("Tog %s fra kassen." % (amount_str,))
        else:
            document().save("Lagde %s i kassen." % (amount_str,))
    redirect("misc.cashlog")
Beispiel #11
0
def create_do():
    name = local.request.form.get("name", u"")
    fixedprice = local.request.form.get("fixedprice", u"")
    if len(fixedprice) == 0:
        fixedprice = None
    else:
        fixedprice = parsenumber(fixedprice)

    product = Product(name=name, fixedprice=fixedprice)
    inventory().add_product(product)

    document().save(u"Tilføjede produkt '%s'" % (product.name, ))

    redirect("product.edit", product_id=product.id)
Beispiel #12
0
def purchase_do(product_id):
    try:
        product = inventory().get_product(product_id)
    except KeyError:
        return notfound()

    name = local.request.form.get("name", u"")
    quantity = int(local.request.form.get("quantity", u"0"))
    price = parsenumber(local.request.form.get("price", u"0"))

    purchase = Purchase(name, price, quantity)
    product.add_purchase(purchase)

    document().save(u"Tilføjede indkøb '%s' til '%s'" % (name, product.name))
    redirect("product.edit", product_id=product.id)
Beispiel #13
0
def edit_do(product_id):
    try:
        product = inventory().get_product(product_id)
    except KeyError:
        return notfound()

    name = local.request.form.get("name", u"")
    fixedprice = local.request.form.get("fixedprice", u"")
    if len(fixedprice) == 0:
        fixedprice = None
    else:
        fixedprice = parsenumber(fixedprice)

    product.name = name
    product.fixedprice = fixedprice

    document().save(u"Ændrede data for produkt '%s'" % (name,))

    redirect("product.edit", product_id=product_id)
def chpasswd_do():
    password0 = local.request.form.get("password0", u"")
    password1 = local.request.form.get("password1", u"")
    
    error = {}

    if len(password0) == 0 or len(password1) == 0:
        error["length"] = "yes"
    
    if len(error) == 0 and password0 != password1:
        error["match"] = "yes"
    
    if len(error) == 0:
        user.changepassword(local.session.get("uid"), password0)
        redirect("login.chpasswd_confirm")
        return
    
    redirect(
        "login.chpasswd_form",
        **error
    )
def authenticate():
    error = {}

    username = local.request.form.get("username", u"")
    password = local.request.form.get("password", u"")
    
    if len(username) == 0 or len(password) == 0:
        error["length"] = "yes"
    
    if len(error) == 0:
        uid = user.authenticate(username, password)
        if uid is None:
            error["invalid"] = "yes"
    
    if len(error) == 0:
        local.session["uid"] = uid
        
        if not user.haschangedpasswd(uid):
            redirect("login.chpasswd_form")
            return

        redirect("index.index")
        return

    redirect(
        "login.form",
        **error
    )
Beispiel #16
0
def save(id):
    name = local.request.form.get("name", "")
    phone = local.request.form.get("phone", "")
    email = local.request.form.get("email", "")
    year = local.request.form.get("year", "")
    rustur = local.request.form.get("rustur", "")

    if name == "":
        name = None
    if phone == "":
        phone = None
    if email == "":
        email = None
    if rustur == "":
        rustur = None
    try:
        year = int(year)
    except ValueError:
        year = None

    rus.update(id, name, phone, email, year, rustur)

    redirect("rus.edit", id=id)
Beispiel #17
0
def save(id):
    name = local.request.form.get("name", "")
    phone = local.request.form.get("phone", "")
    email = local.request.form.get("email", "")
    year = local.request.form.get("year", "")
    rustur = local.request.form.get("rustur", "")

    if name == "":
        name = None
    if phone == "":
        phone = None
    if email == "":
        email = None
    if rustur == "":
        rustur = None
    try:
        year = int(year)
    except ValueError:
        year = None

    rus.update(id, name, phone, email, year, rustur)

    redirect("rus.edit", id=id)
def logout():
    local.session["uid"] = None
    redirect("login.chpasswd_form")
Beispiel #19
0
def delete(uid):
    if not authcheck():
        return
    user.delete(uid)
    redirect("user.list")
Beispiel #20
0
def logout():
    if not authcheck():
        return
    local.session["authed"] = False
    redirect("admin.login_form")
Beispiel #21
0
def import_file():
    data = json.load(local.request.files.get("savefile"))
    new_doc = Document.create(data)
    new_doc.save("Importerede dokument", "savedir/save.beer")
    set_document(new_doc)
    redirect("version.browse")
def delete(id):
    entries.delete(local.session.get("uid"), id)
    redirect("index.index")
Beispiel #23
0
def new_form_do():
    update_usage_from_form()
    usage().commit()
    document().save(u"Afregning")

    redirect("account.browse")
Beispiel #24
0
def logout():
    if not authcheck():
        return
    local.session["authed"] = False
    redirect("admin.login_form")