Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ground observations data #1

Merged
merged 17 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .run/Run Server.run.xml

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
],
"django": true,
"justMyCode": true,
"env": {
"DJANGO_SETTINGS_MODULE": "core.settings.dev"
}
},
{
"command": "npm run serve",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"label": "React: Install dependencies",
"type": "shell",
"command": "npm install",
"command": "npm install --legacy-peer-deps",
"options": {
"cwd": "${workspaceFolder}/django_project/frontend"
},
Expand Down
29 changes: 27 additions & 2 deletions deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,24 @@ volumes:
x-common-django:
&default-common-django
image: kartoza/${COMPOSE_PROJECT_NAME:-django_project}:${DJANGO_TAG:-1.0.0}
env_file:
- .env
environment:
- DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE:-core.settings.dev}

- ADMIN_USERNAME=${ADMIN_USERNAME:-admin}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin}
- ADMIN_EMAIL=${ADMIN_EMAIL:-admin@example.com}

- DATABASE_NAME=${DATABASE_NAME:-django}
- DATABASE_USERNAME=${DATABASE_USERNAME:-docker}
- DATABASE_PASSWORD=${DATABASE_PASSWORD:-docker}
- DATABASE_HOST=${DATABASE_HOST:-db}
- DATABASE_PORT=${DATABASE_PORT:-5432}
- REDIS_HOST=${REDIS_HOST:-redis}
- REDIS_PASSWORD=${REDIS_PASSWORD:-redis_password}

- RABBITMQ_HOST=${RABBITMQ_HOST:-rabbitmq}
- SENTRY_DSN=${SENTRY_DSN:-}
- SECRET_KEY=SECRET_KEY
volumes:
- static-data:/home/web/static
- media-data:/home/web/media
Expand All @@ -36,6 +52,15 @@ services:
- POSTGRES_USER=${DATABASE_USERNAME:-docker}
- POSTGRES_PASS=${DATABASE_PASSWORD:-docker}

dbbackups:
image: kartoza/postgis:14-3.3
volumes:
- data-volume:/backups
environment:
- POSTGRES_DBNAME=${DATABASE_NAME:-django}
- POSTGRES_USER=${DATABASE_USERNAME:-docker}
- POSTGRES_PASS=${DATABASE_PASSWORD:-docker}

django:
<<: *default-common-django
command: 'uwsgi --ini /uwsgi.conf'
Expand Down
Empty file.
30 changes: 30 additions & 0 deletions django_project/core/models/general.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# coding=utf-8
"""
Tomorrow Now GAP.

.. note:: General models
"""

from django.db import models


class Definition(models.Model):
"""Abstract model for Model that has name and description.

Attributes:
name (str): Name of object.
description (str): Description of object.
"""

name = models.CharField(
max_length=512
)
description = models.TextField(
null=True, blank=True
)

def __str__(self):
return self.name

class Meta: # noqa: D106
abstract = True
8 changes: 2 additions & 6 deletions django_project/core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
'django.contrib.staticfiles',
'django.contrib.gis',
'django.contrib.messages',
'ground_observations',
)

SITE_ID = 1
Expand All @@ -143,9 +144,4 @@
LOGIN_URL = '/account/login/'
LOGIN_REDIRECT_URL = '/'

try:
SECRET_KEY = os.environ['SECRET_KEY']
if SECRET_KEY in ['', "''"]:
raise Exception('SECRET_KEY is required in env.')
except KeyError:
raise Exception('SECRET_KEY is required in env.')
from .secret import SECRET_KEY # noqa
1 change: 0 additions & 1 deletion django_project/core/settings/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
'django.contrib.auth.backends.ModelBackend', # default
'guardian.backends.ObjectPermissionBackend',
)
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
CELERY_RESULT_BACKEND = 'django-db'

TEMPLATES[0]['OPTIONS']['context_processors'] += [
Expand Down
2 changes: 2 additions & 0 deletions django_project/core/settings/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@
TEMPLATES[0]['DIRS'] += [
absolute_path('frontend', 'templates'),
]

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
3 changes: 2 additions & 1 deletion django_project/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"clean-webpack-plugin": "^4.0.0",
"css-loader": "^6.7.3",
"sass": "^1.60.0",
"ts-loader": "^9.4.2"
"ts-loader": "^9.4.2",
"webpack-dev-server": "^4.9.0"
}
}
Empty file.
63 changes: 63 additions & 0 deletions django_project/ground_observations/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# coding=utf-8
"""
Tomorrow Now GAP.

.. note:: Admins
"""
from django.contrib import admin

from .models import (
Attribute, Country, Provider, Measurement, Station
)


@admin.register(Attribute)
class AttributeAdmin(admin.ModelAdmin):
"""Attribute admin."""

list_display = (
'name', 'description'
)
search_fields = ('name',)


@admin.register(Country)
class CountryAdmin(admin.ModelAdmin):
"""Country admin."""

list_display = (
'name', 'description'
)
search_fields = ('name',)


@admin.register(Provider)
class ProviderAdmin(admin.ModelAdmin):
"""Provider admin."""

list_display = (
'name', 'description'
)
search_fields = ('name',)


@admin.register(Measurement)
class MeasurementAdmin(admin.ModelAdmin):
"""Measurement admin."""

list_display = (
'station', 'attribute', 'date', 'value'
)
list_filter = ('station', 'attribute')
search_fields = ('name',)


@admin.register(Station)
class StationAdmin(admin.ModelAdmin):
"""Station admin."""

list_display = (
'name', 'country', 'provider'
)
list_filter = ('country',)
search_fields = ('name',)
16 changes: 16 additions & 0 deletions django_project/ground_observations/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# coding=utf-8
"""
Tomorrow Now GAP.

.. note:: App Config
"""

from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _


class GroundObservationsConfig(AppConfig):
"""App Config for GroundObservations."""

name = 'ground_observations'
verbose_name = _('Ground Observations')
51 changes: 51 additions & 0 deletions django_project/ground_observations/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ground_observations/factories.py
import factory
from factory.django import DjangoModelFactory
from ground_observations.models import Provider, Attribute, Country, Station, Measurement
from django.contrib.gis.geos import Point, MultiPolygon
import uuid

class ProviderFactory(DjangoModelFactory):
class Meta:
model = Provider

provider = factory.LazyFunction(uuid.uuid4)
name = factory.Faker('company')
description = factory.Faker('text')

class AttributeFactory(DjangoModelFactory):
class Meta:
model = Attribute

attribute = factory.LazyFunction(uuid.uuid4)
name = factory.Faker('word')
description = factory.Faker('text')

class CountryFactory(DjangoModelFactory):
class Meta:
model = Country

name = factory.Faker('country')
iso_a3 = factory.Faker('country_code')
geometry = MultiPolygon([factory.LazyFunction(lambda: MultiPolygon(Point(0, 0)))])
description = factory.Faker('text')

class StationFactory(DjangoModelFactory):
class Meta:
model = Station

station = factory.LazyFunction(uuid.uuid4)
name = factory.Faker('word')
country = factory.SubFactory(CountryFactory)
geometry = factory.LazyFunction(lambda: Point(0, 0))
provider = factory.SubFactory(ProviderFactory)
description = factory.Faker('text')

class MeasurementFactory(DjangoModelFactory):
class Meta:
model = Measurement

station = factory.SubFactory(StationFactory)
attribute = factory.SubFactory(AttributeFactory)
date = factory.Faker('date')
value = factory.Faker('random_float')
75 changes: 75 additions & 0 deletions django_project/ground_observations/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Generated by Django 4.2.7 on 2024-06-21 02:55

import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Attribute',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=512)),
('description', models.TextField(blank=True, null=True)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Country',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=512)),
('description', models.TextField(blank=True, null=True)),
('iso_a3', models.TextField(unique=True)),
('geometry', django.contrib.gis.db.models.fields.MultiPolygonField(srid=4326)),
],
options={
'verbose_name_plural': 'countries',
},
),
migrations.CreateModel(
name='Provider',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=512)),
('description', models.TextField(blank=True, null=True)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Station',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=512)),
('description', models.TextField(blank=True, null=True)),
('geometry', django.contrib.gis.db.models.fields.PointField(srid=4326)),
('country', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ground_observations.country')),
('provider', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ground_observations.provider')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Measurement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateField()),
('value', models.FloatField()),
('attribute', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ground_observations.attribute')),
('station', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ground_observations.station')),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2024-06-23 21:46
danangmassandy marked this conversation as resolved.
Show resolved Hide resolved

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('ground_observations', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='station',
name='name',
field=models.TextField(),
),
]
Empty file.
Loading