Ejemplo n.º 1
0
 def create_trigger(self, device):
     trigger = Trigger(device=device,
                       trigger_type='MAGNETOMETER',
                       name=self.trigger_name,
                       desc="desc_test")
     db_session.add(device)
     db_session.commit()
     return device
Ejemplo n.º 2
0
 def create_device(self, user):
     device = Device(user=user,
                     device_code="device_code_test",
                     name=self.device_name,
                     desc="desc_test")
     db_session.add(device)
     db_session.commit()
     return device
def gen_panel():
    # CREATE DEVICE CREATE FORM
    form = CreateDeviceForm()
    # CHECK IF VALID DEVICE CREATE REQUEST
    if request.method == 'POST' and form.validate_on_submit():
        # CREATE NEW DEVICE
        new_device = Device(
            user=current_user,
            device_code=form.device_code.data,
            name=form.name.data,
            desc=form.desc.data
        )
        db_session.add(new_device)
        db_session.commit()
        return redirect(url_for('management.gen_panel'))
    return render_template('panel.html', form=form)
def signup():
    # create signup form
    form = SignUpForm()
    # CHECK IF USER IS ALL READY SIGNED IN
    if current_user.is_authenticated:
        return redirect(url_for('management.gen_panel'))

    # check if valid creation request
    if request.method == 'POST' and form.validate_on_submit():
        new_user = User(email=form.email.data, password=form.password.data)
        db_session.add(new_user)
        db_session.commit()
        # create new session
        login_user(new_user)
        # REDIRECT AUTHED USER TO GENERAL PANEL
        return redirect(url_for('management.gen_panel'))
    # RETURN THE SIGNUP HTML PAGE
    return render_template('signup.html', form=form)
def device_panel(device_id):
    # GET THE DEVICE REQUESTED
    device = db_session.query(Device).get(device_id)
    # CHECK IF CURRENT USER IS OWNER
    if device == None or device.user != current_user:
        return abort(401)
    # CREATE FORM FOR CREATING TRIGGER
    form = CreateTriggerForm()
    # CHECK IF VALID TIRGGER CREATION REQUEST
    if request.method == 'POST' and form.validate_on_submit():
        # CREATE NEW TRIGGER
        new_trigger = Trigger(
            device=device,
            trigger_type=Trigger_Types(int(form.trigger_type.data)).name,
            name=form.name.data,
            desc=form.desc.data
        )
        db_session.add(new_trigger)
        db_session.commit()
        return redirect(url_for('management.device_panel', device_id=device_id))
    return render_template('device_panel.html', form=form, device=device)
Ejemplo n.º 6
0
 def create_user(self):
     user = User(email=self.user_email, password=self.user_password)
     db_session.add(user)
     db_session.commit()
     return user