Ejemplo n.º 1
0
def getFrontendContent(**params):

    if 'area' not in params.keys() and request.args.get('area', '') != '':
        params['area'] = request.args.get('area')

    if 'area' in params.keys() and params['area'] in ['west', 'east'
                                                      ]:  # small area view
        return render_template(
            'frontend.locations_smallarea.html',
            cities=City.getCities(),
            alarmobjects=AlarmObject.getAlarmObjects(),
            alarmobjecttypes=AlarmObjectType.getAlarmObjectTypes(),
            frontendarea=params['area'])
    return ""
Ejemplo n.º 2
0
def getAdminContent(self, **params):
    """
    Deliver admin content of module alarmobjects

    :param params: use given parameters of request
    :return: rendered template as string
    """
    module = request.view_args['module'].split('/')

    def chunks(l, n):
        return [l[i:i + n] for i in range(0, len(l), n)]

    if len(module) > 1:  # type definition
        if module[1] == 'types':
            if request.method == 'POST':
                if request.form.get(
                        'action') == 'createalarmobjecttype':  # add type
                    params.update({'alarmobjecttype': AlarmObjectType('', '')})
                    return render_template(
                        'admin.alarmobjects.types_action.html', **params)

                elif request.form.get(
                        'action') == 'savealarmobjecttype':  # save type
                    if request.form.get(
                            'alarmobjecttype_id') == 'None':  # add new type
                        alarmobjecttype = AlarmObjectType('', '')
                        db.session.add(alarmobjecttype)
                    else:  # update existing
                        alarmobjecttype = AlarmObjectType.getAlarmObjectTypes(
                            id=int(request.form.get('alarmobjecttype_id')))
                    alarmobjecttype.name = request.form.get(
                        'alarmobjecttype_name')
                    alarmobjecttype.remark = request.form.get(
                        'alarmobjecttype_remark')
                    db.session.commit()

                elif request.form.get('action').startswith(
                        'detailobjecttype'):  # edit type
                    alarmobjecttype = AlarmObjectType.getAlarmObjectTypes(
                        id=int(request.form.get('action').split('_')[-1]))
                    params.update({'alarmobjecttype': alarmobjecttype})
                    return render_template(
                        'admin.alarmobjects.types_action.html', **params)

                elif request.form.get('action').startswith(
                        'deleteobjecttype_'):  # delete type
                    db.session.delete(
                        AlarmObjectType.getAlarmObjectTypes(
                            id=int(request.form.get('action').split('_')[-1])))
                    db.session.commit()

            params.update(
                {'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes()})
            return render_template('admin.alarmobjects.types.html', **params)

        elif module[1] == 'fields':
            if request.method == 'POST':
                if request.form.get(
                        'action') == 'updatefield':  # update fields
                    Settings.set('alarmobjectfields', [
                        i for i in chunks(request.form.getlist('fieldname'), 2)
                        if i[0] != ''
                    ])
                    db.session.commit()

            params.update({'fields': Settings.get('alarmobjectfields', [])})
            return render_template('admin.alarmobjects.fields.html', **params)

    else:  # base view
        if request.method == 'POST':
            streets = Street.getStreets()
            if request.form.get(
                    'action') == 'createalarmobject':  # add alarmobject
                params.update({
                    'alarmobject':
                    AlarmObject('', 0, '', Settings.get('defaultLat'),
                                Settings.get('defaultLng'),
                                Settings.get('defaultZoom'), '', '', '', 0, 0),
                    'streets':
                    streets,
                    'selectedstreet':
                    '',
                    'map':
                    Map.getDefaultMap(),
                    'alarmobjecttypes':
                    AlarmObjectType.getAlarmObjectTypes()
                })
                return render_template('admin.alarmobjects_actions.html',
                                       **params)

            elif request.form.get('action') == 'savealarmobject':  # save
                if request.form.get('alarmobject_id') == 'None':  # add new
                    alarmobject = AlarmObject('', 0, '', 0, 0, 0, '', '', '',
                                              0, 0)
                    db.session.add(alarmobject)
                else:  # update existing
                    alarmobject = AlarmObject.getAlarmObjects(
                        id=request.form.get('alarmobject_id'))
                alarmobject.name = request.form.get('edit_name')
                alarmobject._streetid = request.form.get('streetid')
                alarmobject._objecttype = int(
                    request.form.get('edit_objecttype'))
                alarmobject.remark = request.form.get('edit_remark')
                if request.form.get('edit_position') == '1':
                    alarmobject.lat = request.form.get('edit_lat')
                    alarmobject.lng = request.form.get('edit_lng')
                    alarmobject.zoom = request.form.get('edit_zoom')
                alarmobject.streetno = request.form.get('edit_streetno')
                alarmobject.alarmplan = request.form.get('edit_alarmplan')
                alarmobject.bma = request.form.get('edit_bma')
                alarmobject.active = int(request.form.get('edit_active', '0'))
                db.session.commit()

            elif request.form.get(
                    'action'
            ) == 'savealarmobjectattributes':  # save attributes
                alarmobject = AlarmObject.getAlarmObjects(
                    id=request.form.get('alarmobject_id'))
                for field in Settings.get('alarmobjectfields',
                                          []):  # store attributes
                    if 'edit_%s' % field[0] in request.form:
                        alarmobject.set(field[0],
                                        request.form.get('edit_%s' % field[0]))
                db.session.commit()

            elif request.form.get(
                    'action') == 'savealarmobjectaao':  # save aao
                alarmobject = AlarmObject.getAlarmObjects(
                    id=request.form.get('alarmobject_id'))
                if alarmobject:
                    alarmobject.set('cars1', [
                        c for c in request.form.get('cars1').split(';')
                        if c != ''
                    ])
                    alarmobject.set('cars2', [
                        c for c in request.form.get('cars2').split(';')
                        if c != ''
                    ])
                    alarmobject.set('material', [
                        c for c in request.form.get('material').split(';')
                        if c != ''
                    ])
                    db.session.commit()

            elif request.form.get('action').startswith(
                    'editalarmobject_'):  # edit alarmobject
                alarmobject = AlarmObject.getAlarmObjects(
                    id=int(request.form.get('action').split('_')[-1]))
                params.update({
                    'alarmobject':
                    alarmobject,
                    'streets':
                    streets,
                    'selectedstreet':
                    '%s (%s)' %
                    (alarmobject.street.name, alarmobject.street.city.name),
                    'map':
                    Map.getDefaultMap(),
                    'alarmobjecttypes':
                    AlarmObjectType.getAlarmObjectTypes(),
                    'fields':
                    Settings.get('alarmobjectfields', []),
                    'cars':
                    Car.getCars(deptid=Department.getDefaultDepartment().id)
                })
                return render_template('admin.alarmobjects_actions.html',
                                       **params)

            elif request.form.get('action').startswith(
                    'deletealarmobject_'):  # delete alarmobject
                db.session.delete(
                    AlarmObject.getAlarmObjects(
                        id=int(request.form.get('action').split('_')[-1])))
                db.session.commit()

        params.update({
            'alarmobjects': AlarmObject.getAlarmObjects(active=0),
            'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes()
        })
        return render_template('admin.alarmobjects.html', **params)
def getFrontendContent(**params):

    if 'area' not in params.keys() and request.args.get('area', '') != '':
        params['area'] = request.args.get('area')

    if 'area' in params.keys() and params['area'] in ['west', 'east']:  # small area view
        return render_template('frontend.locations_smallarea.html', cities=City.getCities(), alarmobjects=AlarmObject.getAlarmObjects(), alarmobjecttypes=AlarmObjectType.getAlarmObjectTypes(), frontendarea=params['area'])
    return ""
def getAdminContent(self, **params):
    """
    Deliver admin content of module alarmobjects

    :param params: use given parameters of request
    :return: rendered template as string
    """
    module = request.view_args['module'].split('/')

    def chunks(l, n):
        return [l[i:i + n] for i in range(0, len(l), n)]

    if len(module) > 1:  # type definition
        if module[1] == 'types':
            if request.method == 'POST':
                if request.form.get('action') == 'createalarmobjecttype':  # add type
                    params.update({'alarmobjecttype': AlarmObjectType('', '')})
                    return render_template('admin.alarmobjects.types_action.html', **params)

                elif request.form.get('action') == 'savealarmobjecttype':  # save type
                    if request.form.get('alarmobjecttype_id') == 'None':  # add new type
                        alarmobjecttype = AlarmObjectType('', '')
                        db.session.add(alarmobjecttype)
                    else:  # update existing
                        alarmobjecttype = AlarmObjectType.getAlarmObjectTypes(id=int(request.form.get('alarmobjecttype_id')))
                    alarmobjecttype.name = request.form.get('alarmobjecttype_name')
                    alarmobjecttype.remark = request.form.get('alarmobjecttype_remark')
                    db.session.commit()

                elif request.form.get('action').startswith('detailobjecttype'):  # edit type
                    alarmobjecttype = AlarmObjectType.getAlarmObjectTypes(id=int(request.form.get('action').split('_')[-1]))
                    params.update({'alarmobjecttype': alarmobjecttype})
                    return render_template('admin.alarmobjects.types_action.html', **params)

                elif request.form.get('action').startswith('deleteobjecttype_'):  # delete type
                    db.session.delete(AlarmObjectType.getAlarmObjectTypes(id=int(request.form.get('action').split('_')[-1])))
                    db.session.commit()

            params.update({'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes()})
            return render_template('admin.alarmobjects.types.html', **params)

        elif module[1] == 'fields':
            if request.method == 'POST':
                if request.form.get('action') == 'updatefield':  # update fields
                    Settings.set('alarmobjectfields', [i for i in chunks(request.form.getlist('fieldname'), 2) if i[0] != ''])
                    db.session.commit()

            params.update({'fields': Settings.get('alarmobjectfields', [])})
            return render_template('admin.alarmobjects.fields.html', **params)

    else:  # base view
        if request.method == 'POST':
            streets = Street.getStreets()
            if request.form.get('action') == 'createalarmobject':  # add alarmobject
                params.update({'alarmobject': AlarmObject('', 0, '', Settings.get('defaultLat'), Settings.get('defaultLng'), Settings.get('defaultZoom'), '', '', '', 0, 0), 'streets': streets, 'selectedstreet': '', 'map': Map.getDefaultMap(), 'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes()})
                return render_template('admin.alarmobjects_actions.html', **params)

            elif request.form.get('action') == 'savealarmobject':  # save
                if request.form.get('alarmobject_id') == 'None':  # add new
                    alarmobject = AlarmObject('', 0, '', 0, 0, 0, '', '', '', 0, 0)
                    db.session.add(alarmobject)
                else:  # update existing
                    alarmobject = AlarmObject.getAlarmObjects(id=request.form.get('alarmobject_id'))
                alarmobject.name = request.form.get('edit_name')
                alarmobject._streetid = request.form.get('streetid')
                alarmobject._objecttype = int(request.form.get('edit_objecttype'))
                alarmobject.remark = request.form.get('edit_remark')
                if request.form.get('edit_position') == '1':
                    alarmobject.lat = request.form.get('edit_lat')
                    alarmobject.lng = request.form.get('edit_lng')
                    alarmobject.zoom = request.form.get('edit_zoom')
                alarmobject.streetno = request.form.get('edit_streetno')
                alarmobject.alarmplan = request.form.get('edit_alarmplan')
                alarmobject.bma = request.form.get('edit_bma')
                alarmobject.active = int(request.form.get('edit_active', '0'))
                db.session.commit()

            elif request.form.get('action') == 'savealarmobjectattributes':  # save attributes
                alarmobject = AlarmObject.getAlarmObjects(id=request.form.get('alarmobject_id'))
                for field in Settings.get('alarmobjectfields', []):  # store attributes
                    if 'edit_%s' % field[0] in request.form:
                        alarmobject.set(field[0], request.form.get('edit_%s' % field[0]))
                db.session.commit()

            elif request.form.get('action') == 'savealarmobjectaao':  # save aao
                alarmobject = AlarmObject.getAlarmObjects(id=request.form.get('alarmobject_id'))
                if alarmobject:
                    alarmobject.set('cars1', [c for c in request.form.get('cars1').split(';') if c != ''])
                    alarmobject.set('cars2', [c for c in request.form.get('cars2').split(';') if c != ''])
                    alarmobject.set('material', [c for c in request.form.get('material').split(';') if c != ''])
                    db.session.commit()

            elif request.form.get('action').startswith('editalarmobject_'):  # edit alarmobject
                alarmobject = AlarmObject.getAlarmObjects(id=int(request.form.get('action').split('_')[-1]))
                params.update({'alarmobject': alarmobject, 'streets': streets, 'selectedstreet': '%s (%s)' % (alarmobject.street.name, alarmobject.street.city.name), 'map': Map.getDefaultMap(), 'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes(), 'fields': Settings.get('alarmobjectfields', []), 'cars': Car.getCars(deptid=Department.getDefaultDepartment().id)})
                return render_template('admin.alarmobjects_actions.html', **params)

            elif request.form.get('action').startswith('deletealarmobject_'):  # delete alarmobject
                db.session.delete(AlarmObject.getAlarmObjects(id=int(request.form.get('action').split('_')[-1])))
                db.session.commit()

        params.update({'alarmobjects': AlarmObject.getAlarmObjects(active=0), 'alarmobjecttypes': AlarmObjectType.getAlarmObjectTypes()})
        return render_template('admin.alarmobjects.html', **params)