• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nansencenter / django-geo-spaas / 18780741707

24 Oct 2025 01:08PM UTC coverage: 89.524% (-6.5%) from 95.979%
18780741707

Pull #183

github

aperrin66
add todo on tag unique constaint
Pull Request #183: Data model rework

77 of 77 new or added lines in 9 files covered. (100.0%)

33 existing lines in 2 files now uncovered.

282 of 315 relevant lines covered (89.52%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.92
/geospaas/base_viewer/views.py
1
from django.core.paginator import Paginator
1✔
2
from django.core.serializers import serialize
1✔
3
from django.http import HttpResponse
1✔
4
from django.shortcuts import render
1✔
5
from django.views.generic import View
1✔
6
from django.conf import settings
1✔
7

8
from geospaas.base_viewer.forms import BaseSearchForm
1✔
9
from geospaas.catalog.models import Dataset
1✔
10

11
# def get_geometry_geojson(request, pk, *args, **kwargs):
12
#     """ Get GeographicLocation.Geometry as GeoJSON
13

14
#     Parameters
15
#     ----------
16
#     pk : int
17
#         primary key of GeographicLocation object
18

19
#     Returns
20
#     -------
21
#     response : HttpResponse
22
#         GeoJSON with geometry of GeographicLocation
23

24
#     """
25
#     gl = GeographicLocation.objects.filter(pk=pk)
26
#     if gl.count() == 0:
27
#         geojson = '{}'
28
#     else:
29
#         geojson = serialize('geojson', gl)
30
#     return HttpResponse(geojson)
31

32

33
class IndexView(View):
1✔
34
    """ The class-based view for processing both GET and POST methods of basic version of viewer """
35
    form_class = BaseSearchForm
1✔
36
    main_template = 'base_viewer/ds_info.html'
1✔
37
    viewname = 'index'
1✔
38
    paginate_by = 20
1✔
39

40
    @classmethod
1✔
41
    def get_all_datasets(cls):
1✔
42
        """ Retrieve all dataset(s) from the database"""
UNCOV
43
        return Dataset.objects.order_by('time_coverage_start').exclude(geographic_location__isnull=True)
×
44

45
    @classmethod
1✔
46
    def get_filtered_datasets(cls, form):
1✔
47
        """ Retrieve filtered list of dataset(s) based on form inputs """
UNCOV
48
        ds = cls.get_all_datasets()
×
UNCOV
49
        return form.filter(ds)
×
50

51
    @classmethod
1✔
52
    def paginate(cls, ds, request):
1✔
53
        """ Paginate datasets and return paginator at current page"""
UNCOV
54
        paginator = Paginator(ds, cls.paginate_by)
×
UNCOV
55
        page_number = request.POST.get('page', 1)
×
UNCOV
56
        page_obj = paginator.get_page(page_number)
×
UNCOV
57
        return page_obj
×
58

59
    @classmethod
1✔
60
    def set_context(cls, form, page_obj):
1✔
61
        """ Prepare all context for rendering """
UNCOV
62
        context = {}
×
UNCOV
63
        context['form'] = form
×
UNCOV
64
        context['page_obj'] = page_obj
×
UNCOV
65
        context['show_local_address'] = getattr(settings, 'SHOW_LOCAL_ADDRESS', False)
×
UNCOV
66
        context['local_file_service'] = LOCAL_FILE_SERVICE
×
UNCOV
67
        return context
×
68

69
    def get(self, request, *args, **kwargs):
1✔
70
        """ Render page if no data is given """
UNCOV
71
        form = self.form_class()
×
UNCOV
72
        form.is_valid()
×
UNCOV
73
        ds = self.get_all_datasets()
×
UNCOV
74
        page_obj = self.paginate(ds, request)
×
UNCOV
75
        context = self.set_context(form, page_obj)
×
UNCOV
76
        return render(request, self.main_template, context)
×
77

78
    def post(self, request, *args, **kwargs):
1✔
79
        """ Render page when user submits search request """
UNCOV
80
        form = self.form_class(request.POST)
×
UNCOV
81
        form.is_valid()
×
UNCOV
82
        ds = self.get_filtered_datasets(form)
×
UNCOV
83
        page_obj = self.paginate(ds, request)
×
UNCOV
84
        context = self.set_context(form, page_obj)
×
UNCOV
85
        return render(request, self.main_template, context)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc