]> Johnzone git - stable.git/commitdiff
redo model -> database needs to be dropped!
authorJohn Janus <mail@johnzone.org>
Tue, 16 Apr 2019 22:22:22 +0000 (00:22 +0200)
committerJohn Janus <mail@johnzone.org>
Tue, 16 Apr 2019 22:22:22 +0000 (00:22 +0200)
- fix dynamic loading
- add eyecandy
- reorganize js

14 files changed:
core/admin.py
core/migrations/0001_initial.py
core/migrations/0002_auto_20190407_2011.py [deleted file]
core/migrations/0003_bay_name.py [deleted file]
core/migrations/0004_auto_20190409_2242.py [deleted file]
core/migrations/0005_auto_20190409_2256.py [deleted file]
core/migrations/0006_auto_20190409_2258.py [deleted file]
core/models.py
core/static/core/dynamic_card_load.js [new file with mode: 0644]
core/templates/core/stablepart_detail.html
core/templates/core/stablepart_list.html
static/base.css
static/base.js
templates/base.html

index 1b930ed1cc3bed8c42d4f0504d2a4291e0562d60..f87b7ca650284482e8e4515440fe9c00fe227233 100644 (file)
@@ -1,5 +1,5 @@
 from django.contrib import admin
-from core.models import StablePart, Bay, Horse, FodderPlan, Misc, IsInBay
+from core.models import StablePart, Bay, Horse, FodderPlan, Misc, IsInBay, HasFodderPlan, HasMisc
 
 # Register your models here.
 admin.site.register(StablePart)
@@ -8,3 +8,5 @@ admin.site.register(Horse)
 admin.site.register(FodderPlan)
 admin.site.register(Misc)
 admin.site.register(IsInBay)
+admin.site.register(HasFodderPlan)
+admin.site.register(HasMisc)
index 6edecb3f26c4d55c1e4ab06635bdb34a5da877b4..0dd7d89863ef8454c798779dabcdc09af8ca5caa 100644 (file)
@@ -1,4 +1,4 @@
-# Generated by Django 2.2 on 2019-04-06 22:06
+# Generated by Django 2.2 on 2019-04-16 21:29
 
 from django.db import migrations, models
 import django.db.models.deletion
@@ -16,6 +16,7 @@ class Migration(migrations.Migration):
             name='Bay',
             fields=[
                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('name', models.CharField(blank=True, max_length=120, null=True)),
                 ('bay_number', models.IntegerField()),
             ],
         ),
@@ -24,15 +25,38 @@ class Migration(migrations.Migration):
             fields=[
                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                 ('fodder', models.TextField()),
-                ('valid_since', models.DateTimeField()),
-                ('valid_until', models.DateTimeField()),
             ],
         ),
+        migrations.CreateModel(
+            name='HasFodderPlan',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('valid_since', models.DateField()),
+                ('valid_until', models.DateField()),
+                ('fodderplan', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.FodderPlan')),
+            ],
+            options={
+                'abstract': False,
+            },
+        ),
+        migrations.CreateModel(
+            name='HasMisc',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('valid_since', models.DateField()),
+                ('valid_until', models.DateField()),
+            ],
+            options={
+                'abstract': False,
+            },
+        ),
         migrations.CreateModel(
             name='Horse',
             fields=[
                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                 ('name', models.CharField(max_length=180)),
+                ('colour', models.CharField(blank=True, max_length=120, null=True)),
+                ('markings', models.CharField(blank=True, max_length=120, null=True)),
             ],
         ),
         migrations.CreateModel(
@@ -40,8 +64,6 @@ class Migration(migrations.Migration):
             fields=[
                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                 ('value', models.TextField()),
-                ('valid_since', models.DateTimeField()),
-                ('valid_until', models.DateTimeField()),
             ],
         ),
         migrations.CreateModel(
@@ -55,30 +77,48 @@ class Migration(migrations.Migration):
             name='IsInBay',
             fields=[
                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
-                ('in_bay_since', models.DateField()),
-                ('in_bay_until', models.DateField()),
+                ('valid_since', models.DateField()),
+                ('valid_until', models.DateField()),
                 ('bay', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Bay')),
                 ('horse', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Horse')),
             ],
+            options={
+                'abstract': False,
+            },
         ),
         migrations.AddField(
             model_name='horse',
             name='bay',
-            field=models.ManyToManyField(blank=True, null=True, through='core.IsInBay', to='core.Bay'),
+            field=models.ManyToManyField(blank=True, related_name='horses', through='core.IsInBay', to='core.Bay'),
         ),
         migrations.AddField(
             model_name='horse',
             name='fodder',
-            field=models.ManyToManyField(blank=True, null=True, to='core.FodderPlan'),
+            field=models.ManyToManyField(blank=True, related_name='horses', through='core.HasFodderPlan', to='core.FodderPlan'),
         ),
         migrations.AddField(
             model_name='horse',
             name='misc_remarks',
-            field=models.ManyToManyField(blank=True, null=True, to='core.Misc'),
+            field=models.ManyToManyField(blank=True, related_name='horses', through='core.HasMisc', to='core.Misc'),
+        ),
+        migrations.AddField(
+            model_name='hasmisc',
+            name='horse',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Horse'),
+        ),
+        migrations.AddField(
+            model_name='hasmisc',
+            name='misc',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Misc'),
+        ),
+        migrations.AddField(
+            model_name='hasfodderplan',
+            name='horse',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Horse'),
         ),
         migrations.AddField(
             model_name='bay',
             name='located_in',
-            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.StablePart'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bays', to='core.StablePart'),
         ),
     ]
diff --git a/core/migrations/0002_auto_20190407_2011.py b/core/migrations/0002_auto_20190407_2011.py
deleted file mode 100644 (file)
index 3c0de7d..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-# Generated by Django 2.2 on 2019-04-07 20:11
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('core', '0001_initial'),
-    ]
-
-    operations = [
-        migrations.AddField(
-            model_name='horse',
-            name='colour',
-            field=models.CharField(blank=True, max_length=120, null=True),
-        ),
-        migrations.AddField(
-            model_name='horse',
-            name='markings',
-            field=models.CharField(blank=True, max_length=120, null=True),
-        ),
-        migrations.AlterField(
-            model_name='horse',
-            name='bay',
-            field=models.ManyToManyField(blank=True, through='core.IsInBay', to='core.Bay'),
-        ),
-        migrations.AlterField(
-            model_name='horse',
-            name='fodder',
-            field=models.ManyToManyField(blank=True, to='core.FodderPlan'),
-        ),
-        migrations.AlterField(
-            model_name='horse',
-            name='misc_remarks',
-            field=models.ManyToManyField(blank=True, to='core.Misc'),
-        ),
-    ]
diff --git a/core/migrations/0003_bay_name.py b/core/migrations/0003_bay_name.py
deleted file mode 100644 (file)
index beec7a0..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-# Generated by Django 2.2 on 2019-04-07 20:56
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('core', '0002_auto_20190407_2011'),
-    ]
-
-    operations = [
-        migrations.AddField(
-            model_name='bay',
-            name='name',
-            field=models.CharField(blank=True, max_length=120, null=True),
-        ),
-    ]
diff --git a/core/migrations/0004_auto_20190409_2242.py b/core/migrations/0004_auto_20190409_2242.py
deleted file mode 100644 (file)
index a49076a..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-# Generated by Django 2.2 on 2019-04-09 22:42
-
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('core', '0003_bay_name'),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name='bay',
-            name='located_in',
-            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bays', to='core.StablePart'),
-        ),
-    ]
diff --git a/core/migrations/0005_auto_20190409_2256.py b/core/migrations/0005_auto_20190409_2256.py
deleted file mode 100644 (file)
index a0061be..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-# Generated by Django 2.2 on 2019-04-09 22:56
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('core', '0004_auto_20190409_2242'),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name='horse',
-            name='bay',
-            field=models.ManyToManyField(blank=True, related_name='in_bay', through='core.IsInBay', to='core.Bay'),
-        ),
-    ]
diff --git a/core/migrations/0006_auto_20190409_2258.py b/core/migrations/0006_auto_20190409_2258.py
deleted file mode 100644 (file)
index c8b4184..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-# Generated by Django 2.2 on 2019-04-09 22:58
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('core', '0005_auto_20190409_2256'),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name='horse',
-            name='bay',
-            field=models.ManyToManyField(blank=True, related_name='horses', through='core.IsInBay', to='core.Bay'),
-        ),
-    ]
index 5e024af7cae8060c338fe285a9782bce7e99a49c..9953bdcab0a13a77df4f8858c7d3e9ba10b26d3e 100644 (file)
@@ -5,7 +5,7 @@ from django.db import models
 
 class StablePart(models.Model):
     name = models.CharField(max_length=140)
-    
+
     def __str__(self):
         return 'Stable Part ' + self.name
 
@@ -13,7 +13,8 @@ class StablePart(models.Model):
 class Bay(models.Model):
     name = models.CharField(max_length=120, null=True, blank=True)
     bay_number = models.IntegerField()
-    located_in = models.ForeignKey(StablePart, on_delete=models.CASCADE, related_name='bays')
+    located_in = models.ForeignKey(
+        StablePart, on_delete=models.CASCADE, related_name='bays')
 
     def __str__(self):
         return (self.name if self.name is not None else '')\
@@ -22,33 +23,45 @@ class Bay(models.Model):
 
 class FodderPlan(models.Model):
     fodder = models.TextField()
-    valid_since = models.DateTimeField()
-    valid_until = models.DateTimeField()
-    
-    def __str__(self):
-        return self.valid_since + ' - ' + self.valid_until
 
 
 class Misc(models.Model):
     value = models.TextField()
-    valid_since = models.DateTimeField()
-    valid_until = models.DateTimeField()
 
 
 class Horse(models.Model):
     name = models.CharField(max_length=180)
     colour = models.CharField(max_length=120, null=True, blank=True)
     markings = models.CharField(max_length=120, null=True, blank=True)
-    bay = models.ManyToManyField(Bay,  through='IsInBay',   blank=True, related_name='horses')
-    fodder = models.ManyToManyField(FodderPlan,  blank=True)
-    misc_remarks = models.ManyToManyField(Misc,   blank=True)
-    
+    bay = models.ManyToManyField(
+        Bay,  through='IsInBay',   blank=True, related_name='horses')
+    fodder = models.ManyToManyField(
+        FodderPlan, through='HasFodderPlan', blank=True, related_name='horses')
+    misc_remarks = models.ManyToManyField(
+        Misc, through='HasMisc', blank=True, related_name='horses')
+
     def __str__(self):
         return self.name
 
 
-class IsInBay(models.Model):
+class IntervalBasedRelation(models.Model):
+    valid_since = models.DateField()
+    valid_until = models.DateField()
+
+    class Meta:
+        abstract = True
+
+
+class IsInBay(IntervalBasedRelation):
     horse = models.ForeignKey(Horse,  on_delete=models.CASCADE)
     bay = models.ForeignKey(Bay,  on_delete=models.CASCADE)
-    in_bay_since = models.DateField()
-    in_bay_until = models.DateField()
+
+
+class HasFodderPlan(IntervalBasedRelation):
+    fodderplan = models.ForeignKey(FodderPlan, on_delete=models.CASCADE)
+    horse = models.ForeignKey(Horse, on_delete=models.CASCADE)
+
+
+class HasMisc(IntervalBasedRelation):
+    misc = models.ForeignKey(Misc, on_delete=models.CASCADE)
+    horse = models.ForeignKey(Horse, on_delete=models.CASCADE)
diff --git a/core/static/core/dynamic_card_load.js b/core/static/core/dynamic_card_load.js
new file mode 100644 (file)
index 0000000..96f43c6
--- /dev/null
@@ -0,0 +1,21 @@
+// var cards;
+var idToUse;
+
+function generateCards() {
+    // console.log(this.response);
+    // cards += this.response;
+    document.getElementById(idToUse).innerHTML = this.response;
+    // console.log(cards);
+}
+
+function getBayCards(id, stablepartId) {
+    // console.log(bayIds);
+    // cards = '';
+    idToUse = id;
+    const xhr = new XMLHttpRequest();
+    // console.log('loading bay', bay);
+    xhr.open('GET', '/stablepart/'.concat(stablepartId));
+    xhr.addEventListener('load', generateCards);
+    xhr.send();
+
+}
index 3ef8b7f78f650b6e59bcd8a30efc4f09beddb2bf..4826a734097e3c487c8f00bc9ffe5c2bce018327 100644 (file)
@@ -1,18 +1,16 @@
-{% extends 'base.html' %}
-
-{% block title %}{{ object.name }} - {{ block.super }}{% endblock %}
-
-{% block main %}
+<div class="card"><h2>{{ object }}</h2>
+<div>
+{% for bay in object.bays.all %}
 <div class="card">
-  <h3>{{ object.name }}</h3>
+  <h3>{{ bay }} </h3>
   <div>
-    <ul>
-    {% for bay in object.bays.all %}
-    <li><a href="/bay/{{ bay.id }}">{{ bay }}</a></li>
-    {% empty %}
-    <li>EMPTY</li>
+    {% for inbay in bay.isinbay_set.all %}
+      <div class="card"><h4><button class="text">{{ inbay.horse }}</button></h4>
+        <div>{{ inbay.valid_since }} bis {{ inbay.valid_until }}</div>
+      </div>
     {% endfor %}
-    </ul>
   </div>
 </div>
-{% endblock %}
+{% endfor %}
+</div>
+</div>
index 40625a3eae30a426e738b23a9a034e1f5614683c..4d50e2bf7314d55ce6f65cb053c6b9588a9984b8 100644 (file)
@@ -6,11 +6,14 @@
 <div id="bays"></div>
 {% endblock %}
 {% block nav %}
-<ul>
+{% load static %}
+<script src="{% static 'core/dynamic_card_load.js' %}"></script>
   {% for sp in object_list %}
-  <li><button onclick="getBayCards('bays', [{% for bay in sp.bays.all %} {{bay.id}}, {% endfor %}])">{{ sp }}</button></li>
+  {% if forloop.first %}
+  <script>getBayCards('bays', {{ sp.pk }});</script>
+  {% endif %}
+  <button class="block" onclick="getBayCards('bays', {{sp.pk}})">{{ sp }}</button>
   {% empty %}
-  <li>No Stable yet</li>
+  No Stable yet
   {% endfor %}
-</ul>
 {% endblock %}
index 1342f8492e0a25f72f17fac30ef6141b84c2d52c..9405e2cb8c54c3681695f82f469b838b137f1122 100644 (file)
@@ -9,7 +9,7 @@ html {
 body {
     display: grid;
     grid-template-columns: 15em 1fr;
-    grid-template-rows: 1fr 6fr 1fr;
+    grid-template-rows: 1fr 6fr 2fr;
     grid-template-areas:
         "header header"
         "nav main"
@@ -20,28 +20,43 @@ body {
 
 div#header {
     grid-area: header;
-    border: 1px solid red;
+    /* border: 1px solid red; */
+    display: flex;
+    flex-direction: row;
+    justify-content: space-between;
+    background: rebeccapurple;
+    color: lightgrey;
+}
+
+div#header > div#headertitle {
+    font-size: xx-large;
+    font-weight: bolder;
+    vertical-align: middle;
+    /* background: magenta; */
+    text-align: center;
 }
 
 div#nav {
     grid-area: nav;
-    border: 1px solid red;
+    /* border: 1px solid red; */
 }
 
 div#main {
     grid-area: main;
-    border: 1px solid red;
+    overflow-y: auto;
+    /* border: 1px solid red; */
 }
 
 div#footer {
-    grid-area: footer
-    border: 1px solid red;
+    grid-area: footer;
+    border-top: 2px solid darkgrey;
 }
 
 div.card {
     box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
     transition: 0.3s;
     border-radius: 5px;
+    margin: 5px 0;
 }
 
 div.card:hover {
@@ -60,3 +75,61 @@ div.card > h1,h2,h3,h4 {
     margin: 0;
     border-bottom: 1px solid lightgrey;
 }
+
+button.block {
+    display: block;
+    width: 100%;
+    border: none;
+    background-color: darkcyan;
+    padding: 10px 20px;
+    cursor: pointer;
+    text-align: center;
+    color: white;
+    margin: 5px 0;
+}
+
+button.block:hover {
+    background-color: darkslategrey;
+}
+
+button.text {
+    border: none;
+    background-color: inherit;
+    padding: 10px 20px;
+    cursor: pointer;
+    display: inline-block;
+    color: black;
+    font-size: inherit;
+    font-style: inherit;
+    font-weight: inherit;
+}
+
+button.text:hover {
+    background: #eee;
+}
+
+button {
+    transition-duration: 0.4s;
+    overflow: hidden;
+    cursor: pointer;
+}
+
+button:after {
+    content: "";
+    background: #a00;
+    /* display: block; */
+    /* position: absolute; */
+    padding-top: 300%;
+    /* padding-left: 350%; */
+    /* margin-left: -20px!important; */
+    /* margin-top: -120%; */
+    opacity: 0;
+    transition: all 0.8s;
+}
+
+button:active:after {
+    padding: 0;
+    /* margin: 0; */
+    opacity: 1;
+    transition: 0s;
+}
index 7845bff463d06fccec440489fe2e9cfe78fe37f0..1c6cb41a15beb54de9c3468678d46e0ae90cc1f3 100644 (file)
@@ -1,9 +1,4 @@
-function setMainCards( id, cards ) {
-    document.getElementById(id).innerHTML = cards;
-    
-}
-
-function generateCard( title, content ) {
+function generateCard(title, content) {
     return '<div class="card"><h3>'.concat(title).concat('</h3><div>').concat(content).concat('</div></div>');
 }
 
@@ -11,22 +6,4 @@ function generateCardFromObject(card) {
     return generateCard(card.title, card.content);
 }
 
-function generateCards() {
-    // console.log(this.response);
-    cards += this.response;
-    document.getElementById('bays').innerHTML = cards;
-    // console.log(cards);
-}
-var cards;
-function getBayCards(id, bayIds) {
-    // console.log(bayIds);
-    cards = '';
-    
-    for (const bay of bayIds) {
-        const xhr = new XMLHttpRequest();
-        // console.log('loading bay', bay);
-        xhr.open('GET', '/bay/'.concat(bay));
-        xhr.addEventListener('load', generateCards);
-        xhr.send();
-    }
-}
+
index 0c9c994a10fcad4bbff886be8e3351846f688382..0bce0485b0821b028ca70d1946e75dba75eb3445 100644 (file)
@@ -9,7 +9,7 @@
     <title>{% block title %} Stable Management {% endblock %}</title>
   </head>
   <body>
-    <div id="header">{% block header %}<div class="card"><h1>Stable Management</h1><div>content</div></div>{% endblock %}</div>
+    <div id="header">{% block header %}<div id="headertitle">Stable Management</div>{% endblock %}</div>
     <div id="nav">{% block nav %}nav{% endblock %}</div>
     <div id="main">{% block main %}{% endblock %}</div>
     <div id="footer">{%block footer %}footer{% endblock %}</div>