Exemplo n.º 1
0
def save():
    # app.logger.debug(request.data)
    jsonData = json.loads(request.data)

    if 'Event-Name' in request.headers:
        save_event_data(request)
        if 'optOut' in jsonData and jsonData['optOut']:
            return get_entities()

    entity = None
    data = jsonData['entity']
    data["ip"] = request.remote_addr
    data["edit_type"] = None

    if data['id']:
        entity = Entity.query.get(data['id'])
    elif data['name']:
        data["edit_type"] = "create"
        entity = Entity(data['name'])
        db.add(entity)
        db.commit()

    if entity:
        if not data["edit_type"]:
            data["edit_type"] = "update"
        update(entity, data)

    return get_entities()
Exemplo n.º 2
0
def update_partnership(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("partnership/view.html", **data)

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

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

    item.name = data["name"]
    item.description = data["description"]
    item = api.update(Partnership, item)
    
    if not item:
        Alert.bad(api.error)
        return render_template("partnership/view.html", **data)
    
    Alert.good("Partnership <strong>{}</strong> {}".format(item.name, "created" if create else "updated"))
    return redirect("/partnerships/{}".format(item.id))
Exemplo n.º 3
0
def update_event_type(id):
    data = {
        "name": querystring_get("name"),
        "description": querystring_get("description"),
        "defaultchargetype": querystring_get("defaultchargetype")
    }

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

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

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

    item.name = data["name"]
    item.description = data["description"]
    item.default_charge_type_id = data["defaultchargetype"]
    item = api.update(EventType, item)
    
    if not item:
        Alert.bad(api.error)
        return render_template("event_type/view.html", **data)
    
    Alert.good("Event Type <strong>{}</strong> {}".format(item.name, "created" if create else "updated"))
    return redirect("/eventtypes/{}".format(item.id))
Exemplo n.º 4
0
def save():
    jsonData = json.loads(request.data)
    app.logger.debug(jsonData)
    if 'Event-Name' in request.headers:
        save_event_data(request)
        if 'optOut' in jsonData and jsonData['optOut']:
            return get_entities(request)
    entity = None
    data = jsonData['entity']
    data["ip"] = request.remote_addr
    data["edit_type"] = None
    if data['id']:
        entity = Entity.query.get(data['id'])
    elif data['name']:
        data["edit_type"] = "create"
        entity = Entity(data['name'])
        db.add(entity)
        db.commit()
    if entity:
        if not data["edit_type"]:
            data["edit_type"] = "update"
        update(entity, data)
        cache.clear()
    return get_entities()
Exemplo n.º 5
0
def save():
    app.logger.debug('SAVING')
    app.logger.debug(request.data)
    entity = None
    data = json.loads(request.data)['entity']
    data["ip"] = request.remote_addr
    data["edit_type"] = None
    if data['id']:
        entity = Entity.query.get(data['id'])
    elif data['name']:
        app.logger.debug('ADDING NEW ENTITY ' + data['name'])
        data["edit_type"] = "create"
        entity = Entity(data['name'])
        db.add(entity)
        db.commit()
    if entity:
        if not data["edit_type"]:
            data["edit_type"] = "update"
        app.logger.debug('UPDATING ENTITY ' + entity.name)
        update(entity, data)
        cache.clear()
    else:
        app.logger.debug('NO UPDATE')
    return get_entities()
Exemplo n.º 6
0
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))
Exemplo n.º 7
0
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))