示例#1
0
def garbage_can_list():
    try:
        search = False
        q = request.args.get('q')
        if q:
            search = True
        try:
            page = int(request.args.get('page', 1))
        except ValueError:
            page = 1

        can_count = GarbageCan.can_count()
        pagination = Pagination(page=page,
                                per_page=15,
                                total=can_count,
                                css_framework='bootstrap3',
                                search=search,
                                record_name='cans')

        can_datas = []

        cans = GarbageCan.get_garbage_cans(current_user, page, per_page=15)
        for o in cans:
            data = {}
            data['id'] = o.id
            data['bottom_height'] = o.bottom_height
            data['top_height'] = o.top_height
            data['type'] = o.type
            can_datas.append(data)

        return render_template('garbage_can/garbage_can_list.html',
                               can_datas=can_datas,
                               pagination=pagination)
    except TemplateNotFound:
        abort(404)
示例#2
0
def garbage_can_list():
    try:
        search = False
        q = request.args.get('q')
        if q:
            search = True
        try:
            page = int(request.args.get('page', 1))
        except ValueError:
            page = 1

        can_count = GarbageCan.can_count()
        pagination = Pagination(page=page, per_page=15, total=can_count, css_framework='bootstrap3',
                                search=search, record_name='cans')

        can_datas = []

        cans = GarbageCan.get_garbage_cans(current_user, page, per_page=15)
        for o in cans:
            data = {}
            data['id'] = o.id
            data['bottom_height'] = o.bottom_height
            data['top_height'] = o.top_height
            data['type'] = o.type
            can_datas.append(data)

        return render_template('garbage_can/garbage_can_list.html', can_datas=can_datas, pagination=pagination)
    except TemplateNotFound:
        abort(404)
示例#3
0
def garbage_can_profile(can_id):
    form = GarbageCanForm(request.form)
    can = GarbageCan.get(can_id)
    if can is None:
        can = GarbageCan()
    if request.method == 'POST' and form.validate_on_submit():
        try:
            if int(form.bottom_height.data) <= int(form.top_height.data):
                flash(u'垃圾桶底部高度应该大于顶部高度', category='error')
                return render_template('garbage_can/garbage_can_profile.html',
                                       form=form,
                                       can=can)
            form.save_form(can)
        except TypeError as e:
            flash(u'数据类型错误', category='error')
            return render_template('garbage_can/garbage_can_profile.html',
                                   form=form,
                                   can=can)
        flash(u'保存成功', category='success')
        return redirect(url_for('garbage_can.garbage_can_list'))

    return render_template('garbage_can/garbage_can_profile.html',
                           form=form,
                           can=can)
示例#4
0
 def save_form(self, device):
     if isinstance(device, Device):
         device.user_id = current_user.id
         device.mac = self.mac.data.upper()
         device.eui = self.eui.data
         garbage_can_id = int(self.garbage_can.data)
         if garbage_can_id > 0:
             device.garbage_can_id = garbage_can_id
         garbage_can = GarbageCan.get(garbage_can_id)
         if garbage_can:
             device.garbage_can = garbage_can.type
         device.longitude = float(self.longitude.data)
         device.latitude = float(self.latitude.data)
         device.save()
     else:
         raise ValueError()
示例#5
0
def garbage_can_profile(can_id):
    form = GarbageCanForm(request.form)
    can = GarbageCan.get(can_id)
    if can is None:
        can = GarbageCan()
    if request.method == 'POST' and form.validate_on_submit():
        try:
            if int(form.bottom_height.data) <= int(form.top_height.data):
                flash(u'垃圾桶底部高度应该大于顶部高度', category='error')
                return render_template('garbage_can/garbage_can_profile.html', form=form, can=can)
            form.save_form(can)
        except TypeError as e:
            flash(u'数据类型错误', category='error')
            return render_template('garbage_can/garbage_can_profile.html', form=form, can=can)
        flash(u'保存成功', category='success')
        return redirect(url_for('garbage_can.garbage_can_list'))

    return render_template('garbage_can/garbage_can_profile.html', form=form, can=can)