Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
meomancer committed Jun 21, 2024
1 parent d420bdb commit e0adddb
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 133 deletions.
27 changes: 0 additions & 27 deletions .run/Run Server.run.xml

This file was deleted.

8 changes: 3 additions & 5 deletions deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@ 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:[email protected]}

- 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
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
11 changes: 1 addition & 10 deletions django_project/core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'core.wsgi.application'

# import SECRET_KEY into current namespace
# noinspection PyUnresolvedReferences
from core.settings.secret import SECRET_KEY # noqa

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
Expand Down Expand Up @@ -148,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
10 changes: 6 additions & 4 deletions django_project/core/settings/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'django',
'USER': 'docker',
'PASSWORD': 'docker',
'HOST': 'db',
'NAME': os.environ['DATABASE_NAME'],
'USER': os.environ['DATABASE_USERNAME'],
'PASSWORD': os.environ['DATABASE_PASSWORD'],
'HOST': os.environ['DATABASE_HOST'],
'PORT': 5432,
'TEST_NAME': 'unittests',
}
Expand All @@ -35,3 +35,5 @@
TEMPLATES[0]['DIRS'] += [
absolute_path('frontend', 'templates'),
]

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
62 changes: 61 additions & 1 deletion django_project/ground_observations/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
# coding=utf-8
"""
Tomorrow Now GAP.
.. note:: Admins
"""
from django.contrib import admin

# Register your models here.
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',)
12 changes: 11 additions & 1 deletion django_project/ground_observations/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +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):
default_auto_field = 'django.db.models.BigAutoField'
"""App Config for GroundObservations."""

name = 'ground_observations'
verbose_name = _('Ground Observations')
55 changes: 37 additions & 18 deletions django_project/ground_observations/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Generated by Django 4.2.7 on 2024-06-20 07:46
# 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
import uuid


class Migration(migrations.Migration):
Expand All @@ -17,40 +16,60 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Attribute',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('attribute_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('name', models.TextField()),
('description', models.TextField()),
('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.AutoField(primary_key=True, serialize=False)),
('provider_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('name', models.TextField()),
('description', models.TextField()),
('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.AutoField(primary_key=True, serialize=False)),
('station_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('name', models.TextField()),
('country_ISO_A3', models.TextField()),
('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)),
('provider_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ground_observations.provider', to_field='provider_id')),
('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.AutoField(primary_key=True, serialize=False)),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateField()),
('value', models.FloatField()),
('attribute_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ground_observations.attribute', to_field='attribute_id')),
('station_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ground_observations.station', to_field='station_id')),
('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')),
],
),
]
Loading

0 comments on commit e0adddb

Please sign in to comment.