From c488ad804bcc7c3febee3bea2089b86bbe419bbb Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 24 Jan 2020 10:10:09 +0000 Subject: Played about with CSS/templates and tinkered with admin --- ctrack/organisations/admin.py | 1 + .../migrations/0008_auto_20200123_1657.py | 29 +++++++++++++ ctrack/organisations/models.py | 21 ++++++--- .../organisations/organisation_detail.html | 50 ++++++++++++++++++++++ ctrack/organisations/urls.py | 2 +- ctrack/organisations/views.py | 19 ++++++++ ctrack/static/css/project.css | 47 +++++++++++++++++--- ctrack/static/css/project.css.map | 1 + ctrack/static/sass/project.scss | 38 ++++++++++++++++ ctrack/templates/account/login.html | 30 +++++++++++++ ctrack/templates/base.html | 24 +++++------ 11 files changed, 239 insertions(+), 23 deletions(-) create mode 100644 ctrack/organisations/migrations/0008_auto_20200123_1657.py create mode 100644 ctrack/organisations/templates/organisations/organisation_detail.html create mode 100644 ctrack/static/css/project.css.map (limited to 'ctrack') diff --git a/ctrack/organisations/admin.py b/ctrack/organisations/admin.py index 686cb30..f8ad2aa 100644 --- a/ctrack/organisations/admin.py +++ b/ctrack/organisations/admin.py @@ -15,6 +15,7 @@ class AddressInLine(admin.StackedInline): class OrganisationAdmin(admin.ModelAdmin): inlines = [AddressInLine,] + list_display = ('slug', 'name') # Register your models here. diff --git a/ctrack/organisations/migrations/0008_auto_20200123_1657.py b/ctrack/organisations/migrations/0008_auto_20200123_1657.py new file mode 100644 index 0000000..1b9f833 --- /dev/null +++ b/ctrack/organisations/migrations/0008_auto_20200123_1657.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2.9 on 2020-01-23 16:57 + +from django.db import migrations, models +import django.db.models.deletion +import django_extensions.db.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('organisations', '0007_auto_20200121_1806'), + ] + + operations = [ + migrations.AlterModelOptions( + name='address', + options={'verbose_name_plural': 'Addresses'}, + ), + migrations.AddField( + model_name='organisation', + name='slug', + field=django_extensions.db.fields.AutoSlugField(blank=True, editable=False, populate_from=['name']), + ), + migrations.AlterField( + model_name='address', + name='type', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='organisations.AddressType', verbose_name='Address Type'), + ), + ] diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py index 727ef58..0ecac94 100644 --- a/ctrack/organisations/models.py +++ b/ctrack/organisations/models.py @@ -2,22 +2,30 @@ from django.db import models # Create your models here. from django.urls import reverse +from django_extensions.db.fields import AutoSlugField from slugify import slugify class AddressType(models.Model): descriptor = models.CharField(max_length=50) + def __str__(self): + return self.descriptor + class Organisation(models.Model): name = models.CharField(max_length=255, blank=False) + slug = AutoSlugField(populate_from=['name']) def get_absolute_url(self): - return reverse("organisations:detail", kwargs={"name": self.slugify_name()}) + return reverse("organisations:detail", kwargs={"slug": self.slug}) def slugify_name(self): return slugify(self.name) + def __str__(self): + return self.name + class Address(models.Model): organisation = models.ForeignKey( @@ -27,13 +35,16 @@ class Address(models.Model): AddressType, verbose_name="Address Type", on_delete=models.CASCADE, blank=False ) line1 = models.CharField(max_length=255) - line2 = models.CharField(max_length=255) - line3 = models.CharField(max_length=255) + line2 = models.CharField(max_length=255, blank=True) + line3 = models.CharField(max_length=255, blank=True) city = models.CharField(max_length=100) - county = models.CharField(max_length=100) + county = models.CharField(max_length=100, blank=True) postcode = models.CharField(max_length=10) country = models.CharField(max_length=100) - other_details = models.CharField(max_length=255) + other_details = models.CharField(max_length=255, blank=True) + + def __str__(self): + return " ".join([self.organisation.name, self.line1]) class Meta: verbose_name_plural = "Addresses" diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html new file mode 100644 index 0000000..5302ef4 --- /dev/null +++ b/ctrack/organisations/templates/organisations/organisation_detail.html @@ -0,0 +1,50 @@ +{% extends "base.html" %} + +{% block content %} +

Organisation detail

+
+
+ {% if n_addr > 1 %} + {% for a in addr %} +
+
+
+
{{ object.name }}
+
{{ a.type }}
+

+ {{ a.line1 }}
+ {{ a.line2 }}
+ {{ a.line3 }}
+ {{ a.city }}
+ {{ a.county }}
+ {{ a.country}}
+

+

{{ a.other_details }}

+ Edit Details +
+
+
+ {% endfor %} + {% else %} +
+
+
+
{{ object.name }}
+
{{ addr.type }}
+

+ {{ addr.line1 }}
+ {{ addr.line2 }}
+ {{ addr.line3 }}
+ {{ addr.city }}
+ {{ addr.county }}
+ {{ addr.country}}
+

+

{{ addr.other_details }}

+ Edit Details +
+
+
+ {% endif %} +
+
+{% endblock %} diff --git a/ctrack/organisations/urls.py b/ctrack/organisations/urls.py index c6cc382..454d73f 100644 --- a/ctrack/organisations/urls.py +++ b/ctrack/organisations/urls.py @@ -5,5 +5,5 @@ from ctrack.organisations.views import OrganisationDetailView app_name = "organisations" urlpatterns = [ - path("/", view=OrganisationDetailView, name="detail") + path("/", view=OrganisationDetailView.as_view(), name="detail") ] diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py index 92bb134..1ec5469 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -1,8 +1,27 @@ +from typing import Any + from django.contrib.auth.mixins import LoginRequiredMixin +from django.http import HttpRequest +from django.http import HttpResponse from django.views.generic import DetailView +from typing import Dict from .models import Organisation class OrganisationDetailView(LoginRequiredMixin, DetailView): model = Organisation + + def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: + context = super().get_context_data() + org = kwargs['object'] + no_addr = org.addresses.count() + if no_addr > 1: + context['no_addr'] = no_addr + addr = org.addresses.all() + context['addr'] = addr + else: + context['no_addr'] = 1 + addr = org.addresses.first() + context['addr'] = addr + return context diff --git a/ctrack/static/css/project.css b/ctrack/static/css/project.css index f1d543d..dfcbc99 100644 --- a/ctrack/static/css/project.css +++ b/ctrack/static/css/project.css @@ -1,13 +1,50 @@ -/* These styles are generated from project.scss. */ - .alert-debug { - color: black; - background-color: white; + background-color: #fff; border-color: #d6e9c6; + color: #000; } .alert-error { - color: #b94a48; background-color: #f2dede; border-color: #eed3d7; + color: #b94a48; +} + +.bg-light { + background-color: green; +} + +.btn:hover { + background-color: red; + border-color: orange; +} + +.container a { + color: darkslategrey; + background-color: yellowgreen; + font-size: large; } + +#chunky { + border: 8px dashed yellowgreen; + border-radius: 10px; + box-shadow: 3px 10px 12px lightgray; +} + +.table-sm tr { + font-size: 0.75rem; + line-height: 10px; + min-height: 10px; +} + +.textinput { + background-color: lightgoldenrodyellow; + box-shadow: 2px 10px 15px lightgray; + height: 49px; +} + +#_title { + color: orangered; +} + +/*# sourceMappingURL=project.css.map */ diff --git a/ctrack/static/css/project.css.map b/ctrack/static/css/project.css.map new file mode 100644 index 0000000..cee13e7 --- /dev/null +++ b/ctrack/static/css/project.css.map @@ -0,0 +1 @@ +{"version":3,"sourceRoot":"","sources":["../sass/project.scss"],"names":[],"mappings":"AA2BA;EACE,kBAhBM;EAiBN,cAhBW;EAiBX,OAhBM;;;AAmBR;EACE,kBAnBK;EAoBL,cAnBU;EAoBV,OAnBI;;;AAsBN;EACE;;;AAGF;EACE;EACA;;;AAGF;EACE;EACA;EACA;;;AAGF;EACE;EACA;EACA;;;AAGF;EACE;EACA;EACA;;;AAGF;EACE;EACA;EACA,QAnDa;;;AAsDf;EACE","file":"project.css"} \ No newline at end of file diff --git a/ctrack/static/sass/project.scss b/ctrack/static/sass/project.scss index 3c8f261..5980b48 100644 --- a/ctrack/static/sass/project.scss +++ b/ctrack/static/sass/project.scss @@ -16,6 +16,7 @@ $black: #000; $pink: #f2dede; $dark-pink: #eed3d7; $red: #b94a48; +$input-height: 49px; //////////////////////////////// //Alerts// @@ -35,3 +36,40 @@ $red: #b94a48; border-color: $dark-pink; color: $red; } + +.bg-light { + background-color: green; +} + +.btn:hover { + background-color: red; + border-color: orange; +} + +.container a { + color: darkslategrey; + background-color: yellowgreen; + font-size: large; +} + +#chunky { + border: 8px dashed yellowgreen; + border-radius: 10px; + box-shadow: 3px 10px 12px lightgray; +} + +.table-sm tr { + font-size: 0.75rem; + line-height: 10px; + min-height: 10px; +} + +.textinput { + background-color: lightgoldenrodyellow; + box-shadow: 2px 10px 15px lightgray; + height: $input-height; +} + +#_title { + color: orangered; +} diff --git a/ctrack/templates/account/login.html b/ctrack/templates/account/login.html index 2cadea6..fbaa171 100644 --- a/ctrack/templates/account/login.html +++ b/ctrack/templates/account/login.html @@ -44,5 +44,35 @@ for a {{ site_name }} account and sign in below:{% endblocktrans %}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#FirstLastHandle
1MarkOtto@mdo
2JacobThornton@fat
3Larrythe Bird@twitter
{% endblock %} diff --git a/ctrack/templates/base.html b/ctrack/templates/base.html index fbe9d86..7ed25a7 100644 --- a/ctrack/templates/base.html +++ b/ctrack/templates/base.html @@ -16,18 +16,18 @@ {% block css %} - + - + - + - + - - + + {% endblock %} @@ -39,7 +39,7 @@ - ctrack + ctrack