Beispiel #1
0
    def test_location_name_too_many_chars(self):
        """test for max length"""

        # get object
        form = LocationForm(data={'location_name': 'l' * 51})
        # compare
        self.assertFalse(form.is_valid())
Beispiel #2
0
    def test_location_name_form_filled(self):
        """test minimum form requirements / VALID"""

        # get object
        form = LocationForm(data={'location_name': 'location_1'})
        # compare
        self.assertTrue(form.is_valid())
Beispiel #3
0
    def test_location_name_proper_chars(self):
        """test for max length"""

        # get object
        form = LocationForm(data={'location_name': 'l' * 50})
        # compare
        self.assertTrue(form.is_valid())
Beispiel #4
0
    def test_location_form_empty(self):
        """test minimum form requirements / INVALID"""

        # get object
        form = LocationForm(data={})
        # compare
        self.assertFalse(form.is_valid())
Beispiel #5
0
    def test_location_note_form_filled(self):
        """ test additional form content """

        # get object
        form = LocationForm(data={
            'location_name': 'location_1',
            'location_note': 'lorem ipsum',
        })
        # compare
        self.assertTrue(form.is_valid())
Beispiel #6
0
    def test_location_name_form_label(self):
        """test form label"""

        # get object
        form = LocationForm()
        # compare
        self.assertEqual(form.fields['location_name'].label, 'Location name (*)')
Beispiel #7
0
def locations_add_popup(request):
    if request.method == 'POST':
        form = LocationForm(request.POST)
        if form.is_valid():
            location = form.save(commit=False)
            location.save()
            location.logger(str(request.user), " LOCATION_ADD_POPUP_EXECUTED")
            messages.success(request, 'Location added')
            return HttpResponse('<script type="text/javascript">window.close();</script>')
    else:
        form = LocationForm()
        debug_logger(str(request.user), " LOCATION_ADD_POPUP_ENTERED")
    return render(request, 'dfirtrack_main/location/locations_add_popup.html', {'form': form})
Beispiel #8
0
def locations_add(request):
    if request.method == 'POST':
        form = LocationForm(request.POST)
        if form.is_valid():
            location = form.save(commit=False)
            location.save()
            location.logger(str(request.user), " LOCATION_ADD_EXECUTED")
            messages.success(request, 'Location added')
            return redirect('/locations')
    else:
        form = LocationForm()
        debug_logger(str(request.user), " LOCATION_ADD_ENTERED")
    return render(request, 'dfirtrack_main/location/locations_add.html', {'form': form})
Beispiel #9
0
def locations_edit(request, pk):
    location = get_object_or_404(Location, pk=pk)
    if request.method == 'POST':
        form = LocationForm(request.POST, instance=location)
        if form.is_valid():
            location = form.save(commit=False)
            location.save()
            location.logger(str(request.user), " LOCATION_EDIT_EXECUTED")
            messages.success(request, 'Location edited')
            return redirect('/locations')
    else:
        form = LocationForm(instance=location)
        location.logger(str(request.user), " LOCATION_EDIT_ENTERED")
    return render(request, 'dfirtrack_main/location/locations_edit.html', {'form': form})