Пример #1
0
def service_add(request):
    info = ServiceInfo()
    box_select = QuickSelect(location=False,
                             room=False,
                             netbox=True,
                             netbox_multiple=False)
    if request.method == 'POST':
        choice_form = ServiceChoiceForm(request.POST)
        netbox_id = request.POST.get('netbox')
        try:
            netbox = Netbox.objects.get(pk=netbox_id)
        except Netbox.DoesNotExist:
            new_message(request, "Netbox does not exist in database",
                        Messages.ERROR)
        else:
            if choice_form.is_valid():
                property_form = ServicePropertyForm(
                    service_args=get_description(
                        choice_form.cleaned_data['service']))
                service_form = ServiceForm(
                    initial={
                        'netbox': netbox.pk,
                        'handler': choice_form.cleaned_data['service'],
                    })
                context = info.template_context
                context.update({
                    'service_form': service_form,
                    'property_form': property_form,
                    'sub_active': {
                        'add': True
                    },
                    'handler': choice_form.cleaned_data['service'],
                    'netbox': netbox,
                })
                return render_to_response('seeddb/service_property_form.html',
                                          context, RequestContext(request))
    else:
        choice_form = ServiceChoiceForm()

    context = info.template_context
    context.update({
        'box_select': box_select,
        'choice_form': choice_form,
        'sub_active': {
            'add': True
        },
    })
    return render_to_response('seeddb/service_netbox_form.html', context,
                              RequestContext(request))
Пример #2
0
def devicehistory_search(request):
    """Implements the device history landing page / search form"""
    device_quickselect = QuickSelect(**DEVICEQUICKSELECT_VIEW_HISTORY_KWARGS)

    if 'from_date' in request.GET:
        form = DeviceHistoryViewFilter(request.GET)
        if form.is_valid():
            return devicehistory_view(request)
    else:
        form = DeviceHistoryViewFilter()

    info_dict = {
        'active': {'device': True},
        'quickselect': device_quickselect,
        'navpath': [('Home', '/'), ('Device History', '')],
        'title': 'NAV - Device History',
        'form': form
    }
    return render(request, 'devicehistory/history_search.html', info_dict)
Пример #3
0
def error_form(request):
    """Implements the 'register error event' form"""
    device_quickselect = QuickSelect(**DEVICEQUICKSELECT_POST_ERROR_KWARGS)
    error_comment = request.POST.get('error_comment', "")

    return render_to_response(
        'devicehistory/register_error.html', {
            'active': {
                'error': True
            },
            'confirm': False,
            'quickselect': device_quickselect,
            'error_comment': error_comment,
            'title': 'NAV - Device History - Register error',
            'navpath': [
                ('Home', '/'),
                ('Register error event', ''),
            ]
        }, RequestContext(request))
Пример #4
0
Файл: views.py Проект: hmpf/nav
def edit(request, task_id=None, start_time=None, **_):
    account = get_account(request)
    quickselect = QuickSelect(service=True)
    component_trail = None
    component_keys = None
    task = None

    if task_id:
        task = get_object_or_404(MaintenanceTask, pk=task_id)
    task_form = MaintenanceTaskForm(
        initial=task_form_initial(task, start_time))

    if request.method == 'POST':
        component_keys = get_component_keys(request.POST)
    elif task:
        component_keys = {
            'service': [],
            'netbox': [],
            'room': [],
            'location': [],
            'netboxgroup': [],
        }
        for key, value in task.maintenancecomponent_set.values_list(
                'key', 'value'):
            if key in PRIMARY_KEY_INTEGER:
                value = int(value)
            component_keys[key].append(value)
    else:
        component_keys = get_component_keys(request.GET)

    if component_keys:
        component_data = components_for_keys(component_keys)
        components = structure_component_data(component_data)
        component_trail = task_component_trails(component_keys, components)

    if request.method == 'POST':
        if 'save' in request.POST:
            task_form = MaintenanceTaskForm(request.POST)
            if not any(component_data.values()):
                new_message(request, "No components selected.", Messages.ERROR)
            elif task_form.is_valid():
                start_time = task_form.cleaned_data['start_time']
                end_time = task_form.cleaned_data['end_time']
                no_end_time = task_form.cleaned_data['no_end_time']
                state = MaintenanceTask.STATE_SCHEDULED
                if (start_time < datetime.now() and end_time
                        and end_time <= datetime.now()):
                    state = MaintenanceTask.STATE_SCHEDULED

                new_task = MaintenanceTask()
                new_task.start_time = task_form.cleaned_data['start_time']
                if no_end_time:
                    new_task.end_time = INFINITY
                elif not no_end_time and end_time:
                    new_task.end_time = task_form.cleaned_data['end_time']
                new_task.description = task_form.cleaned_data['description']
                new_task.state = state
                new_task.author = account.login
                if task:
                    new_task.id = task.id
                new_task.save()

                if task:
                    cursor = connection.cursor()
                    sql = """DELETE FROM maint_component
                                WHERE maint_taskid = %s"""
                    cursor.execute(sql, (new_task.id, ))
                for key in component_data:
                    for component in component_data[key]:
                        task_component = MaintenanceComponent(
                            maintenance_task=new_task,
                            key=key,
                            value="%s" % component['id'],
                        )
                        task_component.save()
                new_message(request, "Saved task %s" % new_task.description,
                            Messages.SUCCESS)
                return HttpResponseRedirect(
                    reverse('maintenance-view', args=[new_task.id]))
        else:
            task_form = MaintenanceTaskForm(initial=request.POST)

    if task:
        navpath = NAVPATH + [('Edit', '')]
        heading = 'Editing "%s"' % task.description
        title = TITLE + " - " + heading
    else:
        navpath = NAVPATH + [('New', '')]
        heading = 'New task'
        title = TITLE + " - " + heading
    return render(
        request,
        'maintenance/new_task.html',
        {
            'active': {
                'new': True
            },
            'navpath': navpath,
            'title': title,
            'heading': heading,
            'task_form': task_form,
            'task_id': task_id,
            'quickselect': mark_safe(quickselect),
            'components': component_trail,
            'selected': component_keys,
        },
    )