예제 #1
0
def register():
    form = RegisterForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        new_user = User.create(username=form.username.data,
                        email=form.email.data,
                        password=form.password.data,
                        active=True)
        flash("Thank you for registering. You can now log in.", 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('public/register.html', form=form)
예제 #2
0
def all():
    fields = [{'field': 'alarm_status', 'label' : 'Alarm Status', 'default' : 1},
                {'field': 'alarm_minutes', 'label' : 'Alarm Minutes', 'default' : 0},
                {'field': 'alarm_hours', 'label' : 'Alarm Hours', 'default' : 6},
                {'field': 'snooze_minutes', 'label' : 'Snooze Minutes', 'default' : 10},
                {'field': 'alarm_text', 'label' : 'Alarm Text', 'default' : 'ALARM!'}]
    settings = []
    default = {} 
    for field in fields:
        setting = field
        setting['model'] = AlarmSetting()
        setting['data'] = setting['model'].get_pair(setting['field'])
        if setting['data']:
            setting['default'] = setting['data'].value
        default[setting['field']] = setting['default']
        settings.append(setting)

    form = AllSettings(request.form, alarm_status=default['alarm_status'], alarm_hours=default['alarm_hours'],
                            snooze_minutes=default['snooze_minutes'], alarm_text=default['alarm_text'],
                            alarm_minutes=default['alarm_minutes'], csrf_enabled=False)

    form.alarm_hours.choices=range(0,24)
    for v in form.alarm_hours.choices:
        form.alarm_hours.choices[v] = (str(v), str(v))
    
    form.alarm_minutes.choices=range(0,60)
    for v in form.alarm_minutes.choices:
        form.alarm_minutes.choices[v] = (str(v), str(v))

    form.snooze_minutes.choices=range(0,60)
    for v in form.snooze_minutes.choices:
        form.snooze_minutes.choices[v] = (str(v), str(v))
    
    if form.validate_on_submit():
        for setting in settings:
            if not setting['data']:
                setting['data'] = setting['model'].create(name=setting['field'],
                                    label=setting['label'],
                                    value=form[setting['field']].data)
            else:
                setting['data'] = setting['data'].update(value=form[setting['field']].data)

        from kraken.helpers.Skynet import Skynet
        skynet = Skynet()
        devices = skynet.search_devices({'name' : 'KrakenAlarm'});
        if devices:
            skynet.send_message(devices, { 'request' : 'update_settings' })
        flash("Settings Saved!", 'success')
        return redirect(url_for('setting.all'))
    else:
        flash_errors(form)
    return render_template("settings/all.html", form=form)
예제 #3
0
def home():
    skynet = Skynet()
    messages = []
    data = skynet.get_my_events()
    if data and 'events' in data:
        for event in data['events']:
            if event and 'message' in event:
                print("MESSAGE :: %s " % event['message'])
                messages.append(event['message'])
    form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash("You are logged in.", 'success')
            redirect_url = request.args.get("next") or url_for("user.members")
            return redirect(redirect_url)
        else:
            flash_errors(form)
    grades = Grade.get_recent(100, "created_at DESC");
    return render_template("public/home.html", form=form, grades = grades, messages=messages)