コード例 #1
0
def update_charge_type(id):
    data = {
        "name": querystring_get("name"),
        "description": querystring_get("description")
    }

    if not data["name"]:
        Alert.bad("The <strong>name</strong> field is required")
        return render_template("charge_type/view.html", **data)

    create = str(id).lower() == "create"

    item = None
    if create:
        item = ChargeType()
    else:   
        item = api.get(ChargeType, id)
        if not item:
            Alert.bad("Could not find <strong>Charge Type</strong> {}; {}".format(id, api.error))
            return render_template("charge_type/view.html", **data)

    item.name = data["name"]
    item.description = data["description"]
    item = api.update(ChargeType, item)
    
    if not item:
        Alert.bad(api.error)
        return render_template("charge_type/view.html", **data)
    
    Alert.good("Charge Type <strong>{}</strong> {}".format(item.name, "created" if create else "updated"))
    return redirect("/chargetypes/{}".format(item.id))
コード例 #2
0
def delete_charge_type_post(id):
    item = api.get(ChargeType, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/chargetypes/")

    deleted = api.delete(ChargeType, item)

    if not deleted:
        Alert.bad(api.error)
        return redirect("/chargetypes/{}/".format(id))

    Alert.good("Deleted <strong>Charge Type</strong> '{}'".format(item.name))
    return redirect("/chargetypes/")
コード例 #3
0
ファイル: event_role.gen.py プロジェクト: jack0x539/cycleng
def delete_event_role_post(id):
    item = api.get(EventRole, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/eventroles/")

    deleted = api.delete(EventRole, item)

    if not deleted:
        Alert.bad(api.error)
        return redirect("/eventroles/{}/".format(id))

    Alert.good("Deleted <strong>Event Role</strong> '{}'".format(item.name))
    return redirect("/eventroles/")
コード例 #4
0
def restore_charge_type(id):
    item = api.get(ChargeType, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/chargetypes/")

    restored = api.restore(ChargeType, item)

    if not restored:
        Alert.bad(api.error)
        return redirect("/chargetypes/")

    Alert.good("Restored <strong>Charge Type</strong> with name <strong>{}</strong>".format(item.name))
    return redirect("/chargetypes/")
コード例 #5
0
ファイル: user.py プロジェクト: jack0x539/cycleng
def delete_user_post(id):
    item = api.get(User, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/users/")

    deleted = api.delete(User, item)

    if not deleted:
        Alert.bad(api.error)
        return redirect("/users/{}/".format(id))

    Alert.good("Deleted <strong>User</strong> '{}'".format(item.name))
    return redirect("/users/")
コード例 #6
0
ファイル: events.py プロジェクト: jack0x539/cycleng
def restore_event(id):
    item = api.get(Event, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/events/")

    restored = api.restore(Event, item)

    if not restored:
        Alert.bad(api.error)
        return redirect("/events/")

    Alert.good("Restored <strong>Event</strong> with name <strong>{}</strong>".format(item.name))
    return redirect("/events/")
コード例 #7
0
ファイル: location.py プロジェクト: jack0x539/cycleng
def delete_location_post(id):
    item = api.get(EventLocation, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/locations/")

    deleted = api.delete(EventLocation, item)

    if not deleted:
        Alert.bad(api.error)
        return redirect("/locations/{}/".format(id))

    Alert.good("Deleted <strong>Location</strong> '{}'".format(item.name))
    return redirect("/locations/")
コード例 #8
0
ファイル: partnership.gen.py プロジェクト: jack0x539/cycleng
def delete_partnership_post(id):
    item = api.get(Partnership, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/partnerships/")

    deleted = api.delete(Partnership, item)

    if not deleted:
        Alert.bad(api.error)
        return redirect("/partnerships/{}/".format(id))

    Alert.good("Deleted <strong>Partnership</strong> '{}'".format(item.name))
    return redirect("/partnerships/")
コード例 #9
0
ファイル: partnership.gen.py プロジェクト: jack0x539/cycleng
def restore_partnership(id):
    item = api.get(Partnership, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/partnerships/")

    restored = api.restore(Partnership, item)

    if not restored:
        Alert.bad(api.error)
        return redirect("/partnerships/")

    Alert.good("Restored <strong>Partnership</strong> with name <strong>{}</strong>".format(item.name))
    return redirect("/partnerships/")
コード例 #10
0
def restore_location(id):
    item = api.get(EventLocation, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/locations/")

    restored = api.restore(EventLocation, item)

    if not restored:
        Alert.bad(api.error)
        return redirect("/locations/")

    Alert.good("Restored <strong>Location</strong> with name <strong>{}</strong>".format(item.name))
    return redirect("/locations/")
コード例 #11
0
def delete_weather_post(id):
    item = api.get(WeatherCondition, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/weather/")

    deleted = api.delete(WeatherCondition, item)

    if not deleted:
        Alert.bad(api.error)
        return redirect("/weather/{}/".format(id))

    Alert.good("Deleted <strong>Weather Condition</strong> '{}'".format(
        item.name))
    return redirect("/weather/")
コード例 #12
0
def restore_weather(id):
    item = api.get(WeatherCondition, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/weather/")

    restored = api.restore(WeatherCondition, item)

    if not restored:
        Alert.bad(api.error)
        return redirect("/weather/")

    Alert.good(
        "Restored <strong>Weather Condition</strong> with name <strong>{}</strong>"
        .format(item.name))
    return redirect("/weather/")
コード例 #13
0
ファイル: user.py プロジェクト: jack0x539/cycleng
def restore_user(id):
    item = api.get(User, id)

    if not item:
        Alert.bad(api.error)
        return redirect("/users/")

    restored = api.restore(User, item)

    if not restored:
        Alert.bad(api.error)
        return redirect("/users/")

    Alert.good(
        "Restored <strong>User</strong> with name <strong>{}</strong>".format(
            item.name))
    return redirect("/users/")
コード例 #14
0
ファイル: location.py プロジェクト: jack0x539/cycleng
def update_location(id):
    data = {
        "name": querystring_get("name"),
        "description": querystring_get("description"),
        "address1": querystring_get("address1"),
        "address2": querystring_get("address2"),
        "address3": querystring_get("address3"),
        "county": querystring_get("county"),
        "postcode": querystring_get("postcode"),
        "contactname": querystring_get("contactname"),
        "contactemail": querystring_get("contactemail"),
        "contactphone1": querystring_get("contactphone1"),
        "contactphone2": querystring_get("contactphone2"),
    }

    if not data["name"]:
        Alert.bad("The <strong>Name</strong> field is required")
        return render_template("location/view.html", **data)

    if not data["address1"]:
        Alert.bad("The <strong>Address 1</strong> field is required")
        return render_template("location/view.html", **data)

    if not data["postcode"]:
        Alert.bad("The <strong>Post Code</strong> field is required")
        return render_template("location/view.html", **data)

    create = str(id).lower() == "create"

    item = None
    if create:
        item = EventLocation()
    else:
        item = api.get(EventLocation, id)
        if not item:
            Alert.bad("Could not find <strong>Location</strong> {}; {}".format(
                id, api.error))
            return render_template("location/view.html", **data)

    address = None
    if create or not item.address:
        address = Address()
    else:
        address = item.address

    address.line1 = data["address1"]
    address.line2 = data["address2"]
    address.line3 = data["address3"]
    address.county = data["county"]
    address.postcode = data["postcode"]

    if create or not item.address:
        address = api.create(Address, address)
        if not address:
            Alert.bad("Failed to create <strong>Address</strong>; {}".format(
                api.error))
            return render_template("location/view.html", **data)
    else:
        address = api.update(Address, address)
        if not address:
            Alert.bad("Failed to update <strong>Address</strong>; {}".format(
                api.error))
            return render_template("location/view.html", **data)

    item.name = data["name"]
    item.description = data["description"]
    item.contact_name = data["contactname"]
    item.contact_email_address = data["contactemail"]
    item.contact_telephone1 = data["contactphone1"]
    item.contact_telephone2 = data["contactphone2"]
    item.address = address

    item = api.update(EventLocation, item)

    if not item:
        Alert.bad("Failed to create <strong>Address</strong>; {}".format(
            api.error))
        return render_template("location/view.html", **data)

    Alert.good("Location <strong>{}</strong> {}".format(
        item.name, "created" if create else "updated"))
    return redirect("/locations/{}".format(item.id))
コード例 #15
0
ファイル: user.py プロジェクト: jack0x539/cycleng
def update_user(id):
    data = {
        "username": querystring_get("username"),
        "forename": querystring_get("forename"),
        "surname": querystring_get("surname"),
        "email": querystring_get("email"),
        "dob": querystring_get("dob"),
        "address1": querystring_get("address1"),
        "address2": querystring_get("address2"),
        "address3": querystring_get("address3"),
        "county": querystring_get("county"),
        "postcode": querystring_get("postcode")
    }

    if not data["username"]:
        Alert.bad("The <strong>username</strong> field is required")
        return render_template("user/view.html", **data)

    if not data["forename"]:
        Alert.bad("The <strong>forename</strong> field is required")
        return render_template("user/view.html", **data)

    if not data["surname"]:
        Alert.bad("The <strong>surname</strong> field is required")
        return render_template("user/view.html", **data)

    if not data["address1"]:
        Alert.bad("The <strong>Address 1</strong> field is required")
        return render_template("user/view.html", **data)

    if not data["postcode"]:
        Alert.bad("The <strong>Post Code</strong> field is required")
        return render_template("user/view.html", **data)

    create = str(id).lower() == "create"

    item = None
    if create:
        item = User()
    else:
        item = api.get(User, id)
        if not item:
            Alert.bad("Could not find <strong>User</strong> {}; {}".format(
                id, api.error))
            return render_template("user/view.html", **data)

    address = None
    if create or not item.address:
        address = Address()
    else:
        address = item.address

    address.line1 = data["address1"]
    address.line2 = data["address2"]
    address.line3 = data["address3"]
    address.county = data["county"]
    address.postcode = data["postcode"]

    if create or not item.address:
        address = api.create(Address, address)
        if not address:
            Alert.bad("Failed to create <strong>Address</strong>; {}".format(
                api.error))
            return render_template("user/view.html", **data)
    else:
        address = api.update(Address, address)
        if not address:
            Alert.bad("Failed to update <strong>Address</strong>; {}".format(
                api.error))
            return render_template("user/view.html", **data)

    item.username = data["username"]
    item.forename = data["forename"]
    item.surname = data["surname"]
    item.email_address = data["email"]
    item.dob = data["dob"]
    item.address = address
    item = api.update(User, item)

    if not item:
        Alert.bad(api.error)
        return render_template("user/view.html", **data)

    Alert.good("User <strong>{}</strong> {}".format(
        item.name, "created" if create else "updated"))
    return redirect("/users/{}".format(item.id))