コード例 #1
0
def add_data():
    if request.method == 'GET':
        #utente
        usr = User()
        usr.nome = "Luca"
        usr.cognome = "Puggioninu"
        usr.uuid = str(uuid.uuid4())
        usr.password = hashlib.sha1("ciaone").hexdigest()
        usr.email = "*****@*****.**"
        usr.targa = "GF6543"
        usr.tariffa = "Tariffa 1"
        usr.is_valid = True
        usr.put()

        #admin
        usr = User()
        usr.nome = "Claudio"
        usr.cognome = "Marche"
        usr.uuid = str(uuid.uuid4())
        usr.password = hashlib.sha1("ciaone").hexdigest()
        usr.email = "*****@*****.**"
        usr.tariffa = "Tariffa 1"
        usr.targa = "GF6543"
        usr.is_valid = True
        usr.has_superuser = True
        usr.put()

        #tariffa
        tar = Tariffa()
        tar.tariffa = 'Tariffa 1'
        tar.description = "La piu' bella gazz"
        tar.prezzo = 5.00
        tar.order = 1
        tar.visibilita = True
        tar.put()

        tar = Tariffa()
        tar.tariffa = 'Tariffa 2'
        tar.description = "La meno bella gazz"
        tar.order = 2
        tar.prezzo = 5.00
        tar.visibilita = False
        tar.put()

        #parcheggi
        state = ['Libero', 'Prenotato', 'Occupato', 'Fuori Servizio']
        for piano in ['A', 'B', 'C', 'D']:
            for i in range(1, 41):
                parking = Parking()
                parking.piano = piano
                parking.number = i
                parking.stato = state[randint(0, 3)]
                parking.put()
        flash("Dati Aggiunti")
        return redirect(url_for('auth.login'))
コード例 #2
0
def insert_user(form):
    try:
        check_user = User.query(User.email == form.email.data).fetch(1)
        if check_user > 0:
            u = User()
            u.uuid = str(uuid.uuid4())
            u.nome = form.nome.data
            u.cognome = form.cognome.data
            u.password = hashlib.sha1(form.password.data).hexdigest()
            u.email = form.email.data

            # insert tariffa
            tariffe = Tariffa.query(Tariffa.visibilita == True).order(
                Tariffa.order).fetch()
            for i, tar in enumerate(tariffe):
                if (i + 1) == int(form.tariffa.data):
                    u.tariffa = tar.tariffa

            u.targa = form.targa.data
            u.put()
            return True

        return False
    except:
        return False