Skip to content

Commit

Permalink
#1: Added default None in search model, created migration, and update…
Browse files Browse the repository at this point in the history
…d search in viewer.views.IndexView.render
  • Loading branch information
mortenwh committed Feb 5, 2019
1 parent 78d0ca1 commit 3e44f5b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
28 changes: 28 additions & 0 deletions geospaas/viewer/migrations/0007_auto_20190205_1546.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.1.5 on 2019-02-05 15:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('viewer', '0006_auto_20190204_1345'),
]

operations = [
migrations.AlterField(
model_name='search',
name='instrument',
field=models.ManyToManyField(blank=True, default=None, to='vocabularies.Instrument'),
),
migrations.AlterField(
model_name='search',
name='parameter',
field=models.ManyToManyField(blank=True, default=None, to='vocabularies.Parameter'),
),
migrations.AlterField(
model_name='search',
name='platform',
field=models.ManyToManyField(blank=True, default=None, to='vocabularies.Platform'),
),
]
6 changes: 3 additions & 3 deletions geospaas/viewer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class Search(geomodels.Model):
sdate = models.DateTimeField() # when was search
date0 = models.DateField()
date1 = models.DateField()
platform = models.ManyToManyField(Platform, blank=True)
instrument = models.ManyToManyField(Instrument, blank=True)
parameter = models.ManyToManyField(Parameter, blank=True)
platform = models.ManyToManyField(Platform, blank=True, default=None)
instrument = models.ManyToManyField(Instrument, blank=True, default=None)
parameter = models.ManyToManyField(Parameter, blank=True, default=None)

# GeoDjango-specific: a geometry field (PolygonField), and
# overriding the default manager with a GeoManager instance.
Expand Down
12 changes: 6 additions & 6 deletions geospaas/viewer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ def render(self, request):
datasets = datasets.order_by('time_coverage_start')
if self.form.cleaned_data['platform'] is not None and \
len(self.form.cleaned_data['platform'])>0:
src = self.form.cleaned_data['platform']
datasets = datasets.filter(sources__platform__in=src)
platform = self.form.cleaned_data['platform'][0]
datasets = datasets.filter(sources__platform=platform)
if self.form.cleaned_data['instrument'] is not None and \
len(self.form.cleaned_data['instrument'])>0:
src = self.form.cleaned_data['instrument']
datasets = datasets.filter(sources__instrument__in=src)
instr = self.form.cleaned_data['instrument'][0]
datasets = datasets.filter(sources__instrument=instr)
if self.form.cleaned_data['parameter'] is not None and \
len(self.form.cleaned_data['parameter'])>0:
src = self.form.cleaned_data['parameter']
datasets = datasets.filter(parameters__in=src)
par = self.form.cleaned_data['parameter'][0]
datasets = datasets.filter(parameters=par)
t0 = self.form.cleaned_data['date0']
t1 = self.form.cleaned_data['date1'] + timezone.timedelta(hours=24)
datasets = datasets.filter(
Expand Down

0 comments on commit 3e44f5b

Please sign in to comment.