Esempio n. 1
0
def edit_vehicle(request, vehicle_id, form_id):
    db_vehicle = get_object_or_404(Vehicle, id=vehicle_id)
    if request.method == 'POST':
        jsModel = jsonModel()

        vehicle_form = VehicleForm(instance=db_vehicle, data=request.POST, user=request.user)
        if vehicle_form.is_valid():

            db_exist_vehicle = Vehicle.objects.filter(organization=request.user.userprofil.organization,
                                                      radio_call_sign=request.POST.get('radio_call_sign', None))

            db_exist_vehicle = db_exist_vehicle.exclude(id=db_vehicle.id)

            if db_exist_vehicle.count() > 0:
                jsModel.set(result_code='error', result_message=MSG_VEHICLE_ADD_EXIS)
            else:
                vehicle_form.save()
                jsModel.set(result_code='success', result_message=MSG_VEHICLE_EDIT_SUCCESS)

        else:
            tmp_data = dict((k, v)
                            for (k, v) in vehicle_form.errors.items())

            jsModel.set(result_code='error', validation_errors=tmp_data)

        return HttpResponse(jsModel.json_dump(), mimetype='application/json')
    else:
        vehicle_form = VehicleForm(prefix=form_id, instance=db_vehicle, user=request.user)

    return render(request, 'fleets/vehicleForm.html',
                  {'formId': form_id, 'vehicleId': vehicle_id, 'vehicleForm': vehicle_form, 'add': True, 'object': db_vehicle})
Esempio n. 2
0
def edit_fleet(request, fleet_id, form_id):
    db_fleet = get_object_or_404(Fleet, id=fleet_id)

    if request.method == 'POST':
        fleet_form = FleetForm(instance=db_fleet, data=request.POST)

        js_model = jsonModel()

        if fleet_form.is_valid():
            db_exist_fleet = Fleet.objects.filter(organization=request.user.userprofil.organization,
                                                  name=request.POST.get('name', None))
            db_exist_fleet = db_exist_fleet.exclude(id = db_fleet.id)

            if db_exist_fleet.count() > 0:
                js_model.set(result_code='error', result_message=MSG_FLEET_ADD_EXIST)
            else:
                fleet_form.save()
                js_model.set(result_code='success', result_message=MSG_FLEET_EDIT_SUCCESS)
        else:
            tmp_data = dict((k, v)
                            for (k, v) in fleet_form.errors.items())

            js_model.set(result_code='error', validation_errors=tmp_data)

        return HttpResponse(js_model.json_dump(), mimetype='application/json')
    else:
        fleet_form = FleetForm(prefix=form_id, instance=db_fleet)

    return render(request,
                  'fleets/fleetForm.html',
        {'formId': form_id, 'fleetId': fleet_id, 'fleetForm': fleet_form, 'object': db_fleet})
Esempio n. 3
0
def add_vehicle(request, form_id):
    if request.method == 'POST':
        jsModel = jsonModel()

        vehicle_form = VehicleForm(user=request.user, data=request.POST)
        if vehicle_form.is_valid():

            db_exist_vehicle = Vehicle.objects.filter(organization=request.user.userprofil.organization,
                                                      radio_call_sign=request.POST.get('radio_call_sign', None))

            if db_exist_vehicle.count() > 0:
                jsModel.set(result_code='error', result_message=MSG_VEHICLE_ADD_EXIS)
            else:
                vehicle_form.save()
                jsModel.set(result_code='success', result_message=MSG_VEHICLE_ADD_SUCCESS)

        else:
            tmp_data = dict((k, v)
                            for (k, v) in vehicle_form.errors.items())

            jsModel.set(result_code='error', validation_errors=tmp_data)

        return HttpResponse(jsModel.json_dump(), mimetype='application/json')
    else:
        vehicle_form = VehicleForm(prefix=form_id, user=request.user)

    return render(request, 'fleets/vehicleForm.html',
                  {'formId': form_id, 'vehicleId': 0, 'vehicleForm': vehicle_form})
Esempio n. 4
0
def login(request, template_name="accounts/login.html"):
    jsModel = jsonModel()

    if request.method == "POST":
        form = AuthenticationForm(data=request.POST)

        if form.is_valid():
            username = request.POST.get("username", "").strip()
            password = request.POST.get("password", "").strip()
            if username and password:
                user = authenticate(username=username, password=password)

                if user is not None:
                    if user.is_active:
                        auth_login(request, user)

                        jsModel.set_result_code("success")

                    else:
                        jsModel.set(result_code="error", result_message="User is not active")

                else:
                    jsModel.set(result_code="error", result_message="Wrong Username and/or Password")
                return HttpResponse(jsModel.json_dump(), mimetype="application/json")
        else:

            data = dict((k, v) for (k, v) in form.errors.items())

            jsModel.set_validation_errors(data)

        return HttpResponse(jsModel.json_dump(), mimetype="application/json")
    else:
        form = AuthenticationForm()

        return render_to_response(template_name, {"form": form}, context_instance=RequestContext(request))
Esempio n. 5
0
def get_vehicle_max_crew(request, vehicle_id, form_id):
    db_vehicle = get_object_or_404(Vehicle, id=vehicle_id, organization=request.user.userprofil.organization)
    db_result = {}
    db_result['formId'] = form_id
    db_result['maxCrew'] = db_vehicle.max_crew

    js_model = jsonModel()
    js_model.set(data=db_result, result_code='success')

    return HttpResponse(js_model.json_dump(), mimetype='application/json')
Esempio n. 6
0
def get_vehicle_name(request, vehicle_id, form_id):
    if request.method == 'POST':
        db_vehicle = get_object_or_404(Vehicle, id=vehicle_id, organization=request.user.userprofil.organization)
        db_result = {}
        db_result['formId'] = form_id
        db_result['vehicleName'] = db_vehicle

        js_model = jsonModel()
        jsonModel.set(data=db_result, result_code='success')

        return HttpResponse(js_model.json_dump(), mimetype='application/json')
Esempio n. 7
0
def add_customer(request, form_id):
    if request.method == 'POST':
        json_model = jsonModel()
        customer_form = CustomerForm(prefix=form_id, data=request.POST,
                                     user=request.user)
        if customer_form.is_valid():
            db_exist_customer = Customer.objects.filter(
                organization=request.user.userprofil.organization,
                name=customer_form.instance.name)

            if db_exist_customer.count() > 0:
                json_model.set(result_code='error', result_message='Objekt schon in der Datenbank vorhanden')
            else:
                customer_form.save()
                json_model.set(result_code='success', result_message='Objekt wurde erfolgreich gespeoichert.')
        else:
            tmp_data = dict((k, v)
                            for (k, v) in customer_form.errors.items())
            json_model.set(result_code='error', validation_errors=tmp_data)

        return HttpResponse(json_model.json_dump(), mimetype='application/json')

    else:
        customer_form = CustomerForm(prefix=form_id, user=request.user)

    fieldsets = (
        {
            'tabname': 'Allgemeine Informationen:',
            'fieldsets': (
                {
                    'name': 'Anschrift:',
                    'fields': (
                        FieldSet(customer_form, 'name'),
                        FieldSet(customer_form, 'street'),
                        FieldSet(customer_form, 'zipcode'),
                        FieldSet(customer_form, 'city'),
                    ),
                },
                {
                    'name': 'Kontaktdaten:',
                    'fields': (
                        FieldSet(customer_form, 'phone_number'),
                        FieldSet(customer_form, 'fax_number'),
                    ),
                },
            ),
        },
    )
    return render(request, 'customers/customerForm.html',
        {'formId': form_id,
         'fieldsets': fieldsets,
         })
Esempio n. 8
0
def edit_operation_alarmed_over(request, operation_alarmed_over_id, form_id):
    db_operation_alarmed_over = get_object_or_404(OperationAlarmedOver, id=operation_alarmed_over_id)

    if request.method == 'POST':
        form_operation_alarmed_over = OperationAlarmedOverForm(instance=db_operation_alarmed_over,
                                                               data=request.POST,
                                                               user=request.user,
                                                               prefix=form_id)

        json_model = jsonModel()

        if form_operation_alarmed_over.is_valid():
            db_exist_operation_alarmed_over = OperationAlarmedOver.objects.filter(
                organization=request.user.userprofil.organization,
                name=request.POST.get('name', None))
            db_exist_operation_alarmed_over = db_exist_operation_alarmed_over.exclude(id=db_operation_alarmed_over.id)

            if db_exist_operation_alarmed_over.count() > 0:
                json_model.set(result_code='error', result_message=MSG_OPERATIONALARMEDOVER_ADD_EXIST)
            else:
                json_model.set(result_code='error', result_message='Ok')
                form_operation_alarmed_over.save()
        else:
            tmp_data = dict((k, v)
                            for (k, v) in form_operation_alarmed_over.errors.items())

            json_model.set(result_code='error', validation_errors=tmp_data)

        return HttpResponse(json_model.json_dump(), mimetype='application/json')
    else:
        form_operation_alarmed_over = OperationAlarmedOverForm(prefix=form_id, instance=db_operation_alarmed_over,
                                                               user=request.user)
    fieldsets = (
            {
                'tabname': 'Allgemeine Informationen',
                'fieldsets': (
                    {
                        'name': 'Informationen:',
                        'fields': (
                            FieldSet(form_operation_alarmed_over, 'name'),
                            FieldSet(form_operation_alarmed_over, 'description'),
                        ),
                    },
                ),
            },
        )
    return render(request,
                  'operations/operationAlarmedOverForm.html',
        {'formId': form_id,
         'fieldsets': fieldsets,
         'operationAlarmedOverId': int(operation_alarmed_over_id)})
Esempio n. 9
0
def edit_userprofil(request, user_id, form_id):
    user = get_object_or_404(User, id=user_id)
    user_profil = user.userprofil

    jsModel = jsonModel()

    if request.method == "POST":
        user_profil_form = UserProfilForm(instance=user_profil, data=request.POST)
        user_form = UserForm(instance=user, data=request.POST)

        if user_form.is_valid() and user_profil_form.is_valid():
            user_profil.user.save()
            user_profil.save()

            jsModel.set(result_code="success", result_message="Benutzerprofil wurde erfolgreich gespeicher.")

            return HttpResponse(jsModel.json_dump(), mimetype="application/json")
        else:
            tmp_data1 = dict((k, v) for (k, v) in user_form.errors.items())
            tmp_data2 = dict((k, v) for (k, v) in user_profil_form.errors.items())

            data = dict()
            data.update(tmp_data1)
            data.update(tmp_data2)

            jsModel.set(
                result_code="error",
                result_message="Benutzerprofil konnte nicht gespeichert werden. " "Bitte die Eingaben überprüfen",
                validation_errors=data,
            )

            return HttpResponse(jsModel.json_dump(), mimetype="application/json")
    else:
        user_profil_form = UserProfilForm(prefix=form_id, instance=user_profil)
        user_form = UserForm(prefix=form_id, instance=user_profil.user)

    return render_to_response(
        "accounts/user_profil_form.html",
        {
            "formId": form_id,
            "userId": user_id,
            "user_profil_form": user_profil_form,
            "user_form": user_form,
            "add": True,
        },
        context_instance=RequestContext(request),
    )
Esempio n. 10
0
def get_fleet(request):
    db_fleet = Fleet.objects.filter(organization=request.user.userprofil.organization)
    result = {}
    int = 1
    for item in db_fleet:
        db_result = {}
        db_result['id'] = item.pk
        db_result['name'] = item.name
        db_result['location'] = item.location
        db_result['create_user'] = item.create_user.first_name + " " + item.create_user.last_name
        result[int] = db_result
        int += 1

    js_model = jsonModel()
    js_model.set(result_code='success', data=result)

    return HttpResponse(js_model.json_dump(), mimetype='application/json')
Esempio n. 11
0
def get_vehicles(request):
    db_vehicles = Vehicle.objects.filter(organization=request.user.userprofil.organization)
    result = {}
    int = 1
    for item in db_vehicles:
        db_result = {
            'id' : item.pk,
            'name' : item.name,
            'radio_call_sign': item.radio_call_sign,
            'create_user': item.create_user.first_name + " " + item.create_user.last_name
        }
        result[int] = db_result
        int += 1
    js_model = jsonModel()
    js_model.set(result_code='success', data=result)

    return HttpResponse(js_model.json_dump(), mimetype='application/json')
Esempio n. 12
0
def add_operation_alarmed_by(request, form_id=None):
    if request.method == 'POST':
        json_model = jsonModel()
        form_operation_alarmed_by = OperationAlarmedByForm(prefix=form_id,
                                                           data=request.POST,
                                                           user=request.user)

        if form_operation_alarmed_by.is_valid():
            db_exist_operation_alarmed_by = OperationAlarmedBy.objects.filter(
                organization=request.user.userprofil.organization,
                name=form_operation_alarmed_by.instance.name)

            if db_exist_operation_alarmed_by.count() > 0:
                json_model.set(result_code='error', result_message='Objekt schon in der Datenbank vorhanden')
            else:
                form_operation_alarmed_by.save()
                json_model.set(result_code='success', result_message='Objekt wurde erfolgreich gespeichert.')
        else:
            tmp_data = dict((k, v)
                            for (k, v) in form_operation_alarmed_by.errors.items())
            json_model.set(result_code='error', validation_errors=tmp_data)

        return HttpResponse(json_model.json_dump(), mimetype='application/json')

    else:
        form_operation_alarmed_by = OperationAlarmedByForm(prefix=form_id, user=request.user)
        fieldsets = (
            {
                'tabname': 'Allgemeine Informationen',
                'fieldsets': (
                    {
                        'name': 'Sonstiges:',
                        'fields': (
                            FieldSet(form_operation_alarmed_by, 'name'),
                        ),
                    },
                ),
            },
        )

        return render(request, 'operations/operationAlarmedByForm.html',
            {'formOperationAlarmedBy': form_operation_alarmed_by,
             'fieldsets': fieldsets,
             'formId': form_id})
Esempio n. 13
0
def get_operation_alarmed_by(request):
    db_operation_alarmed_by = OperationAlarmedBy.objects.filter(
        organization=request.user.userprofil.organization,
    )
    result = {}
    i = 1
    for item in db_operation_alarmed_by:
        db_result = {
            'id': item.pk,
            'name': item.name,
            'create_users': item.create_user.first_name + " " + item.create_user.last_name
        }
        result[i] = db_result
        i += 1

    json_model = jsonModel()
    json_model.set(result_code='sucess', data=result)

    return HttpResponse(json_model.json_dump(), mimetype='application/json')