-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example survey models, streamline config
- Loading branch information
Showing
8 changed files
with
181 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,16 @@ | ||
import wq from './wq.js'; | ||
import config from './data/config.js'; | ||
import version from './data/version.js'; | ||
// import config from '/config.js'; // Load directly from wq.db | ||
|
||
wq.use({ | ||
context() { | ||
return { version }; | ||
} | ||
}); | ||
|
||
wq.init({ | ||
...config, | ||
router: { | ||
'base_url': '' | ||
}, | ||
store: { | ||
'service': '', | ||
'defaults': {'format': 'json'} | ||
}, | ||
material: { | ||
theme: { | ||
primary: '#7500ae', | ||
secondary: '#0088bd' | ||
} | ||
}, | ||
map: { | ||
bounds: [[-93.6, 44.7], [-92.8, 45.2]] | ||
async function init() { | ||
await wq.init(config); | ||
await wq.prefetchAll(); | ||
if (config.debug) { | ||
window.wq = wq; | ||
} | ||
}).then(() => { | ||
wq.prefetchAll(); | ||
}); | ||
|
||
if (config.debug) { | ||
window.wq = wq; | ||
} | ||
|
||
init(); | ||
|
||
navigator.serviceWorker.register('/service-worker.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django.conf import settings{% if with_gis %} | ||
import django.contrib.gis.db.models.fields{% endif %} | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Category', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255)), | ||
('description', models.TextField(blank=True, null=True)), | ||
], | ||
options={ | ||
'verbose_name_plural': 'categories', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Observation', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('date', models.DateField(blank=True, help_text='The date when the observation was taken', null=True, verbose_name='Date')),{% if with_gis %} | ||
('geometry', django.contrib.gis.db.models.fields.PointField(help_text='The location of the observation', srid=4326, verbose_name='Location')),{% endif %} | ||
('photo', models.ImageField(blank=True, help_text='Photo of the observation', null=True, upload_to='observations', verbose_name='Photo')), | ||
('notes', models.TextField(blank=True, help_text='Field observations and notes', null=True, verbose_name='Notes')), | ||
('category', models.ForeignKey(blank=True, help_text='Observation type', null=True, on_delete=django.db.models.deletion.PROTECT, to='{{ project_name }}_survey.category', verbose_name='Category')), | ||
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='submitted by')), | ||
], | ||
options={ | ||
'verbose_name_plural': 'observations', | ||
'ordering': ['-date'], | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{% if with_gis %}from django.contrib.gis.db import models | ||
{% else %}from django.db import models | ||
{% endif %}from wq.db.patterns.models import LabelModel | ||
from django.conf import settings | ||
|
||
|
||
""" | ||
Example survey app for {{ project_name }}. The models below are examples, and | ||
are not required for wq to work. Feel free to modify, rewrite, or delete and | ||
replace this folder with a completely new Django app. | ||
https://wq.io/guides/describe-your-data-model | ||
""" | ||
|
||
|
||
class Category(LabelModel): | ||
name = models.CharField(max_length=255) | ||
description = models.TextField(null=True, blank=True) | ||
|
||
wq_label_template = "{% templatetag openvariable %}name{% templatetag closevariable %}" | ||
|
||
class Meta: | ||
verbose_name_plural = "categories" | ||
|
||
|
||
class Observation(LabelModel): | ||
user = models.ForeignKey( | ||
settings.AUTH_USER_MODEL, | ||
on_delete=models.PROTECT, | ||
null=True, | ||
blank=True, | ||
verbose_name="submitted by", | ||
) | ||
date = models.DateField( | ||
null=True, | ||
blank=True, | ||
verbose_name="Date", | ||
help_text="The date when the observation was taken", | ||
) | ||
category = models.ForeignKey( | ||
Category, | ||
on_delete=models.PROTECT, | ||
null=True, | ||
blank=True, | ||
verbose_name="Category", | ||
help_text="Observation type", | ||
){% if with_gis %} | ||
geometry = models.PointField( | ||
srid=4326, | ||
verbose_name="Location", | ||
help_text="The location of the observation", | ||
){% endif %} | ||
photo = models.ImageField( | ||
upload_to="observations", | ||
null=True, | ||
blank=True, | ||
verbose_name="Photo", | ||
help_text="Photo of the observation", | ||
) | ||
notes = models.TextField( | ||
null=True, | ||
blank=True, | ||
verbose_name="Notes", | ||
help_text="Field observations and notes", | ||
) | ||
|
||
wq_label_template = "{% templatetag openvariable %}date{% templatetag closevariable %}" | ||
|
||
class Meta: | ||
verbose_name_plural = "observations" | ||
ordering = ['-date'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from wq.db import rest | ||
from .models import Category, Observation | ||
from .serializers import ObservationSerializer | ||
|
||
|
||
rest.router.register_model( | ||
Category, | ||
fields="__all__", | ||
cache="all", | ||
background_sync=False, | ||
) | ||
|
||
rest.router.register_model( | ||
Observation, | ||
serializer=ObservationSerializer, | ||
cache="first_page", | ||
background_sync=True,{% if with_gis %} | ||
map=[{ | ||
'mode': 'list', | ||
'autoLayers': True, | ||
'layers': [], | ||
}, { | ||
'mode': 'detail', | ||
'autoLayers': True, | ||
'layers': [], | ||
}, { | ||
'mode': 'edit', | ||
'layers': [], | ||
}], | ||
{% endif %} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from wq.db.rest.serializers import ModelSerializer | ||
from rest_framework import serializers | ||
from .models import Observation | ||
|
||
|
||
class ObservationSerializer(ModelSerializer): | ||
user = serializers.HiddenField( | ||
default=serializers.CurrentUserDefault() | ||
) | ||
|
||
class Meta: | ||
fields = "__all__" | ||
model = Observation | ||
wq_field_config = { | ||
"notes": {"multiline": True}, | ||
} |