mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-07 14:47:49 +02:00
Compare commits
39 Commits
Author | SHA1 | Date | |
---|---|---|---|
e7d34ce8e0
|
|||
19eb70c492 | |||
4428b8c11d | |||
8400a5acd3
|
|||
7dadf23f5f
|
|||
4a12201d22
|
|||
830da80302 | |||
416ca5bbc6
|
|||
03fc82c38d
|
|||
ec8684dbc0
|
|||
7ec8baf733
|
|||
86589ad718
|
|||
98fed02a40
|
|||
9602f67e0e
|
|||
5bb6279095
|
|||
84cdee42a6
|
|||
168b424df7
|
|||
e1400fe720
|
|||
26dea2fb35
|
|||
ef767ec33d
|
|||
b23801dbf0
|
|||
c7fa54e90e
|
|||
9164ba494f
|
|||
97989c3384
|
|||
7865bf04f0
|
|||
e6f1480894
|
|||
8d8ede4c06
|
|||
87e1107156 | |||
448ecae070
|
|||
2b0fdc4487
|
|||
764240d67a
|
|||
424b17ae58
|
|||
c73efb01e4 | |||
a21baac10c
|
|||
4b0361acc1
|
|||
425eed3d83 | |||
2d48463474
|
|||
08226247c7
|
|||
4f52736d97
|
2
.github/workflows/django.yml
vendored
2
.github/workflows/django.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
strategy:
|
||||
max-parallel: 2
|
||||
matrix:
|
||||
python-version: ['3.9', '3.10', '3.11']
|
||||
python-version: ['3.9', '3.10', '3.11', '3.12']
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
Submodule arduino/CommandStation-EX updated: 2db2b0ecc6...3b162996ad
@@ -1,6 +1,7 @@
|
||||
# Generated by Django 4.2.5 on 2023-10-01 20:16
|
||||
|
||||
import ckeditor_uploader.fields
|
||||
# ckeditor removal
|
||||
# import ckeditor_uploader.fields
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
@@ -47,7 +48,8 @@ class Migration(migrations.Migration):
|
||||
("ISBN", models.CharField(max_length=13, unique=True)),
|
||||
("publication_year", models.SmallIntegerField(blank=True, null=True)),
|
||||
("purchase_date", models.DateField(blank=True, null=True)),
|
||||
("notes", ckeditor_uploader.fields.RichTextUploadingField(blank=True)),
|
||||
# ("notes", ckeditor_uploader.fields.RichTextUploadingField(blank=True)),
|
||||
("notes", models.TextField(blank=True)),
|
||||
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_time", models.DateTimeField(auto_now=True)),
|
||||
("authors", models.ManyToManyField(to="bookshelf.author")),
|
||||
|
@@ -12,9 +12,6 @@ class Migration(migrations.Migration):
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="book",
|
||||
options={
|
||||
"ordering": ["authors__last_name", "title"],
|
||||
"verbose_name_plural": "Rolling stock",
|
||||
},
|
||||
options={"ordering": ["authors__last_name", "title"]},
|
||||
),
|
||||
]
|
||||
|
18
ram/bookshelf/migrations/0006_alter_book_isbn.py
Normal file
18
ram/bookshelf/migrations/0006_alter_book_isbn.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.5 on 2023-10-03 20:43
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookshelf", "0005_alter_book_options"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="book",
|
||||
name="ISBN",
|
||||
field=models.CharField(blank=True, max_length=17),
|
||||
),
|
||||
]
|
17
ram/bookshelf/migrations/0007_alter_book_options.py
Normal file
17
ram/bookshelf/migrations/0007_alter_book_options.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 4.2.5 on 2023-10-03 21:07
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookshelf", "0006_alter_book_isbn"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="book",
|
||||
options={"ordering": ["title"]},
|
||||
),
|
||||
]
|
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 4.2.6 on 2023-10-09 21:08
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("bookshelf", "0007_alter_book_options"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="author",
|
||||
options={"ordering": ["last_name", "first_name"]},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name="publisher",
|
||||
options={"ordering": ["name"]},
|
||||
),
|
||||
]
|
49
ram/bookshelf/migrations/0009_alter_bookimage_image.py
Normal file
49
ram/bookshelf/migrations/0009_alter_bookimage_image.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# Generated by Django 4.2.6 on 2023-10-30 13:16
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import ram.utils
|
||||
import bookshelf.models
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def move_images(apps, schema_editor):
|
||||
sys.stdout.write("\n Processing files. Please await...")
|
||||
for r in bookshelf.models.BookImage.objects.all():
|
||||
fname = os.path.basename(r.image.path)
|
||||
new_image = bookshelf.models.book_image_upload(r, fname)
|
||||
new_path = os.path.join(settings.MEDIA_ROOT, new_image)
|
||||
os.makedirs(os.path.dirname(new_path), exist_ok=True)
|
||||
try:
|
||||
shutil.move(r.image.path, new_path)
|
||||
except FileNotFoundError:
|
||||
sys.stderr.write(" !! FileNotFoundError: {}\n".format(new_image))
|
||||
pass
|
||||
r.image.name = new_image
|
||||
r.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("bookshelf", "0008_alter_author_options_alter_publisher_options"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="bookimage",
|
||||
name="image",
|
||||
field=models.ImageField(
|
||||
blank=True,
|
||||
null=True,
|
||||
storage=ram.utils.DeduplicatedStorage,
|
||||
upload_to=bookshelf.models.book_image_upload,
|
||||
),
|
||||
),
|
||||
migrations.RunPython(
|
||||
move_images,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
22
ram/bookshelf/migrations/0010_alter_bookimage_image.py
Normal file
22
ram/bookshelf/migrations/0010_alter_bookimage_image.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 4.2.6 on 2023-11-04 22:53
|
||||
|
||||
import bookshelf.models
|
||||
from django.db import migrations, models
|
||||
import ram.utils
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("bookshelf", "0009_alter_bookimage_image"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="bookimage",
|
||||
name="image",
|
||||
field=models.ImageField(
|
||||
storage=ram.utils.DeduplicatedStorage,
|
||||
upload_to=bookshelf.models.book_image_upload,
|
||||
),
|
||||
),
|
||||
]
|
121
ram/bookshelf/migrations/0011_alter_book_language.py
Normal file
121
ram/bookshelf/migrations/0011_alter_book_language.py
Normal file
@@ -0,0 +1,121 @@
|
||||
# Generated by Django 5.0.1 on 2024-01-20 21:02
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("bookshelf", "0010_alter_bookimage_image"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="book",
|
||||
name="language",
|
||||
field=models.CharField(
|
||||
choices=[
|
||||
("af", "Afrikaans"),
|
||||
("ar", "Arabic"),
|
||||
("ar-dz", "Algerian Arabic"),
|
||||
("ast", "Asturian"),
|
||||
("az", "Azerbaijani"),
|
||||
("bg", "Bulgarian"),
|
||||
("be", "Belarusian"),
|
||||
("bn", "Bengali"),
|
||||
("br", "Breton"),
|
||||
("bs", "Bosnian"),
|
||||
("ca", "Catalan"),
|
||||
("ckb", "Central Kurdish (Sorani)"),
|
||||
("cs", "Czech"),
|
||||
("cy", "Welsh"),
|
||||
("da", "Danish"),
|
||||
("de", "German"),
|
||||
("dsb", "Lower Sorbian"),
|
||||
("el", "Greek"),
|
||||
("en", "English"),
|
||||
("en-au", "Australian English"),
|
||||
("en-gb", "British English"),
|
||||
("eo", "Esperanto"),
|
||||
("es", "Spanish"),
|
||||
("es-ar", "Argentinian Spanish"),
|
||||
("es-co", "Colombian Spanish"),
|
||||
("es-mx", "Mexican Spanish"),
|
||||
("es-ni", "Nicaraguan Spanish"),
|
||||
("es-ve", "Venezuelan Spanish"),
|
||||
("et", "Estonian"),
|
||||
("eu", "Basque"),
|
||||
("fa", "Persian"),
|
||||
("fi", "Finnish"),
|
||||
("fr", "French"),
|
||||
("fy", "Frisian"),
|
||||
("ga", "Irish"),
|
||||
("gd", "Scottish Gaelic"),
|
||||
("gl", "Galician"),
|
||||
("he", "Hebrew"),
|
||||
("hi", "Hindi"),
|
||||
("hr", "Croatian"),
|
||||
("hsb", "Upper Sorbian"),
|
||||
("hu", "Hungarian"),
|
||||
("hy", "Armenian"),
|
||||
("ia", "Interlingua"),
|
||||
("id", "Indonesian"),
|
||||
("ig", "Igbo"),
|
||||
("io", "Ido"),
|
||||
("is", "Icelandic"),
|
||||
("it", "Italian"),
|
||||
("ja", "Japanese"),
|
||||
("ka", "Georgian"),
|
||||
("kab", "Kabyle"),
|
||||
("kk", "Kazakh"),
|
||||
("km", "Khmer"),
|
||||
("kn", "Kannada"),
|
||||
("ko", "Korean"),
|
||||
("ky", "Kyrgyz"),
|
||||
("lb", "Luxembourgish"),
|
||||
("lt", "Lithuanian"),
|
||||
("lv", "Latvian"),
|
||||
("mk", "Macedonian"),
|
||||
("ml", "Malayalam"),
|
||||
("mn", "Mongolian"),
|
||||
("mr", "Marathi"),
|
||||
("ms", "Malay"),
|
||||
("my", "Burmese"),
|
||||
("nb", "Norwegian Bokmål"),
|
||||
("ne", "Nepali"),
|
||||
("nl", "Dutch"),
|
||||
("nn", "Norwegian Nynorsk"),
|
||||
("os", "Ossetic"),
|
||||
("pa", "Punjabi"),
|
||||
("pl", "Polish"),
|
||||
("pt", "Portuguese"),
|
||||
("pt-br", "Brazilian Portuguese"),
|
||||
("ro", "Romanian"),
|
||||
("ru", "Russian"),
|
||||
("sk", "Slovak"),
|
||||
("sl", "Slovenian"),
|
||||
("sq", "Albanian"),
|
||||
("sr", "Serbian"),
|
||||
("sr-latn", "Serbian Latin"),
|
||||
("sv", "Swedish"),
|
||||
("sw", "Swahili"),
|
||||
("ta", "Tamil"),
|
||||
("te", "Telugu"),
|
||||
("tg", "Tajik"),
|
||||
("th", "Thai"),
|
||||
("tk", "Turkmen"),
|
||||
("tr", "Turkish"),
|
||||
("tt", "Tatar"),
|
||||
("udm", "Udmurt"),
|
||||
("ug", "Uyghur"),
|
||||
("uk", "Ukrainian"),
|
||||
("ur", "Urdu"),
|
||||
("uz", "Uzbek"),
|
||||
("vi", "Vietnamese"),
|
||||
("zh-hans", "Simplified Chinese"),
|
||||
("zh-hant", "Traditional Chinese"),
|
||||
],
|
||||
default="en",
|
||||
max_length=7,
|
||||
),
|
||||
),
|
||||
]
|
19
ram/bookshelf/migrations/0012_alter_book_notes.py
Normal file
19
ram/bookshelf/migrations/0012_alter_book_notes.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.0.2 on 2024-02-17 12:19
|
||||
|
||||
import tinymce.models
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookshelf", "0011_alter_book_language"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="book",
|
||||
name="notes",
|
||||
field=tinymce.models.HTMLField(blank=True),
|
||||
),
|
||||
]
|
@@ -1,10 +1,12 @@
|
||||
import os
|
||||
import shutil
|
||||
from uuid import uuid4
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from django_countries.fields import CountryField
|
||||
|
||||
from ckeditor_uploader.fields import RichTextUploadingField
|
||||
from tinymce import models as tinymce
|
||||
|
||||
from metadata.models import Tag
|
||||
from ram.utils import DeduplicatedStorage
|
||||
@@ -16,6 +18,9 @@ class Publisher(models.Model):
|
||||
country = CountryField(blank=True)
|
||||
website = models.URLField(blank=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ["name"]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@@ -24,6 +29,9 @@ class Author(models.Model):
|
||||
first_name = models.CharField(max_length=100)
|
||||
last_name = models.CharField(max_length=100)
|
||||
|
||||
class Meta:
|
||||
ordering = ["last_name", "first_name"]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.last_name}, {self.first_name}"
|
||||
|
||||
@@ -36,7 +44,7 @@ class Book(models.Model):
|
||||
title = models.CharField(max_length=200)
|
||||
authors = models.ManyToManyField(Author)
|
||||
publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE)
|
||||
ISBN = models.CharField(max_length=13, blank=True)
|
||||
ISBN = models.CharField(max_length=17, blank=True) # 13 + dashes
|
||||
language = models.CharField(
|
||||
max_length=7,
|
||||
choices=settings.LANGUAGES,
|
||||
@@ -48,13 +56,12 @@ class Book(models.Model):
|
||||
tags = models.ManyToManyField(
|
||||
Tag, related_name="bookshelf", blank=True
|
||||
)
|
||||
notes = RichTextUploadingField(blank=True)
|
||||
notes = tinymce.HTMLField(blank=True)
|
||||
creation_time = models.DateTimeField(auto_now_add=True)
|
||||
updated_time = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ["authors__last_name", "title"]
|
||||
verbose_name_plural = "Rolling stock"
|
||||
ordering = ["title"]
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
@@ -65,16 +72,32 @@ class Book(models.Model):
|
||||
def get_absolute_url(self):
|
||||
return reverse("book", kwargs={"uuid": self.uuid})
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
shutil.rmtree(
|
||||
os.path.join(
|
||||
settings.MEDIA_ROOT, "images", "books", str(self.uuid)
|
||||
),
|
||||
ignore_errors=True
|
||||
)
|
||||
super(Book, self).delete(*args, **kwargs)
|
||||
|
||||
|
||||
def book_image_upload(instance, filename):
|
||||
return os.path.join(
|
||||
"images",
|
||||
"books",
|
||||
str(instance.book.uuid),
|
||||
filename
|
||||
)
|
||||
|
||||
|
||||
class BookImage(Image):
|
||||
book = models.ForeignKey(
|
||||
Book, on_delete=models.CASCADE, related_name="image"
|
||||
)
|
||||
image = models.ImageField(
|
||||
upload_to="images/books/", # FIXME, find a better way to replace this
|
||||
upload_to=book_image_upload,
|
||||
storage=DeduplicatedStorage,
|
||||
null=True,
|
||||
blank=True
|
||||
)
|
||||
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
# Generated by Django 4.1 on 2022-08-23 15:54
|
||||
|
||||
import ckeditor_uploader.fields
|
||||
# ckeditor removal
|
||||
# import ckeditor_uploader.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
@@ -11,9 +12,9 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="consist",
|
||||
name="notes",
|
||||
field=ckeditor_uploader.fields.RichTextUploadingField(blank=True),
|
||||
),
|
||||
# migrations.AlterField(
|
||||
# model_name="consist",
|
||||
# name="notes",
|
||||
# field=ckeditor_uploader.fields.RichTextUploadingField(blank=True),
|
||||
# ),
|
||||
]
|
||||
|
51
ram/consist/migrations/0009_alter_consist_image.py
Normal file
51
ram/consist/migrations/0009_alter_consist_image.py
Normal file
@@ -0,0 +1,51 @@
|
||||
# Generated by Django 4.2.6 on 2023-10-31 09:41
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import ram.utils
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def move_images(apps, schema_editor):
|
||||
sys.stdout.write("\n Processing files. Please await...")
|
||||
model = apps.get_model("consist", "Consist")
|
||||
for r in model.objects.all():
|
||||
if not r.image: # exit the loop if there's no image
|
||||
continue
|
||||
fname = os.path.basename(r.image.path)
|
||||
new_image = os.path.join("images", "consists", fname)
|
||||
new_path = os.path.join(settings.MEDIA_ROOT, new_image)
|
||||
os.makedirs(os.path.dirname(new_path), exist_ok=True)
|
||||
try:
|
||||
shutil.move(r.image.path, new_path)
|
||||
except FileNotFoundError:
|
||||
sys.stderr.write(" !! FileNotFoundError: {}\n".format(new_image))
|
||||
pass
|
||||
r.image.name = new_image
|
||||
r.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("consist", "0008_alter_consist_options"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="consist",
|
||||
name="image",
|
||||
field=models.ImageField(
|
||||
blank=True,
|
||||
null=True,
|
||||
storage=ram.utils.DeduplicatedStorage,
|
||||
upload_to="images/consists",
|
||||
),
|
||||
),
|
||||
migrations.RunPython(
|
||||
move_images,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
19
ram/consist/migrations/0010_alter_consist_notes.py
Normal file
19
ram/consist/migrations/0010_alter_consist_notes.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.0.2 on 2024-02-17 12:19
|
||||
|
||||
import tinymce.models
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("consist", "0009_alter_consist_image"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="consist",
|
||||
name="notes",
|
||||
field=tinymce.models.HTMLField(blank=True),
|
||||
),
|
||||
]
|
@@ -1,8 +1,10 @@
|
||||
import os
|
||||
|
||||
from uuid import uuid4
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
|
||||
from ckeditor_uploader.fields import RichTextUploadingField
|
||||
from tinymce import models as tinymce
|
||||
|
||||
from ram.utils import DeduplicatedStorage
|
||||
from metadata.models import Company, Tag
|
||||
@@ -19,9 +21,12 @@ class Consist(models.Model):
|
||||
company = models.ForeignKey(Company, on_delete=models.CASCADE)
|
||||
era = models.CharField(max_length=32, blank=True)
|
||||
image = models.ImageField(
|
||||
upload_to="images/", storage=DeduplicatedStorage, null=True, blank=True
|
||||
upload_to=os.path.join("images", "consists"),
|
||||
storage=DeduplicatedStorage,
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
notes = RichTextUploadingField(blank=True)
|
||||
notes = tinymce.HTMLField(blank=True)
|
||||
creation_time = models.DateTimeField(auto_now_add=True)
|
||||
updated_time = models.DateTimeField(auto_now=True)
|
||||
|
||||
|
@@ -15,6 +15,7 @@ from metadata.models import (
|
||||
|
||||
@admin.register(Property)
|
||||
class PropertyAdmin(admin.ModelAdmin):
|
||||
list_display = ("name", "private")
|
||||
search_fields = ("name",)
|
||||
|
||||
|
||||
|
18
ram/metadata/migrations/0013_decoderdocument_private.py
Normal file
18
ram/metadata/migrations/0013_decoderdocument_private.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.5 on 2023-10-06 19:48
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("metadata", "0012_alter_decoder_manufacturer_decoderdocument"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="decoderdocument",
|
||||
name="private",
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 4.2.6 on 2023-10-10 12:44
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("metadata", "0013_decoderdocument_private"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="decoder",
|
||||
options={"ordering": ["manufacturer", "name"]},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name="tag",
|
||||
options={"ordering": ["name"]},
|
||||
),
|
||||
]
|
@@ -0,0 +1,80 @@
|
||||
# Generated by Django 4.2.6 on 2023-10-30 13:16
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import ram.utils
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def move_images(apps, schema_editor):
|
||||
fields = {
|
||||
"Company": ["companies", "logo"],
|
||||
"Decoder": ["decoders", "image"],
|
||||
"Manufacturer": ["manufacturers", "logo"],
|
||||
}
|
||||
sys.stdout.write("\n Processing files. Please await...")
|
||||
for m in fields.items():
|
||||
model = apps.get_model("metadata", m[0])
|
||||
for r in model.objects.all():
|
||||
field = getattr(r, m[1][1])
|
||||
if not field: # exit the loop if there's no image
|
||||
continue
|
||||
fname = os.path.basename(field.path)
|
||||
new_image = os.path.join("images", m[1][0], fname)
|
||||
new_path = os.path.join(settings.MEDIA_ROOT, new_image)
|
||||
os.makedirs(os.path.dirname(new_path), exist_ok=True)
|
||||
try:
|
||||
shutil.move(field.path, new_path)
|
||||
except FileNotFoundError:
|
||||
sys.stderr.write(
|
||||
" !! FileNotFoundError: {}\n".format(new_image)
|
||||
)
|
||||
pass
|
||||
field.name = new_image
|
||||
r.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("metadata", "0014_alter_decoder_options_alter_tag_options"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="company",
|
||||
name="logo",
|
||||
field=models.ImageField(
|
||||
blank=True,
|
||||
null=True,
|
||||
storage=ram.utils.DeduplicatedStorage,
|
||||
upload_to="images/companies",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="decoder",
|
||||
name="image",
|
||||
field=models.ImageField(
|
||||
blank=True,
|
||||
null=True,
|
||||
storage=ram.utils.DeduplicatedStorage,
|
||||
upload_to="images/decoders",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="manufacturer",
|
||||
name="logo",
|
||||
field=models.ImageField(
|
||||
blank=True,
|
||||
null=True,
|
||||
storage=ram.utils.DeduplicatedStorage,
|
||||
upload_to="images/manufacturers",
|
||||
),
|
||||
),
|
||||
migrations.RunPython(
|
||||
move_images,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
20
ram/metadata/migrations/0016_alter_decoderdocument_file.py
Normal file
20
ram/metadata/migrations/0016_alter_decoderdocument_file.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 4.2.6 on 2023-11-04 22:53
|
||||
|
||||
from django.db import migrations, models
|
||||
import ram.utils
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("metadata", "0015_alter_company_logo_alter_decoder_image_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="decoderdocument",
|
||||
name="file",
|
||||
field=models.FileField(
|
||||
storage=ram.utils.DeduplicatedStorage(), upload_to="files/"
|
||||
),
|
||||
),
|
||||
]
|
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.conf import settings
|
||||
@@ -28,7 +29,10 @@ class Manufacturer(models.Model):
|
||||
)
|
||||
website = models.URLField(blank=True)
|
||||
logo = models.ImageField(
|
||||
upload_to="images/", storage=DeduplicatedStorage, null=True, blank=True
|
||||
upload_to=os.path.join("images", "manufacturers"),
|
||||
storage=DeduplicatedStorage,
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -58,7 +62,10 @@ class Company(models.Model):
|
||||
country = CountryField()
|
||||
freelance = models.BooleanField(default=False)
|
||||
logo = models.ImageField(
|
||||
upload_to="images/", storage=DeduplicatedStorage, null=True, blank=True
|
||||
upload_to=os.path.join("images", "companies"),
|
||||
storage=DeduplicatedStorage,
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@@ -76,6 +83,9 @@ class Company(models.Model):
|
||||
}
|
||||
)
|
||||
|
||||
def extended_name_pp(self):
|
||||
return "({})".format(self.extended_name) if self.extended_name else ""
|
||||
|
||||
def logo_thumbnail(self):
|
||||
return get_image_preview(self.logo.url)
|
||||
|
||||
@@ -92,9 +102,15 @@ class Decoder(models.Model):
|
||||
version = models.CharField(max_length=64, blank=True)
|
||||
sound = models.BooleanField(default=False)
|
||||
image = models.ImageField(
|
||||
upload_to="images/", storage=DeduplicatedStorage, null=True, blank=True
|
||||
upload_to=os.path.join("images", "decoders"),
|
||||
storage=DeduplicatedStorage,
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
class Meta(object):
|
||||
ordering = ["manufacturer", "name"]
|
||||
|
||||
def __str__(self):
|
||||
return "{0} - {1}".format(self.manufacturer, self.name)
|
||||
|
||||
@@ -163,6 +179,9 @@ class Tag(models.Model):
|
||||
name = models.CharField(max_length=128, unique=True)
|
||||
slug = models.CharField(max_length=128, unique=True)
|
||||
|
||||
class Meta(object):
|
||||
ordering = ["name"]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
@@ -6,6 +6,7 @@ from portal.models import SiteConfiguration, Flatpage
|
||||
|
||||
@admin.register(SiteConfiguration)
|
||||
class SiteConfigurationAdmin(SingletonModelAdmin):
|
||||
readonly_fields = ("site_name",)
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
|
@@ -1,7 +1,8 @@
|
||||
# Generated by Django 4.1 on 2022-08-23 15:54
|
||||
|
||||
import ckeditor.fields
|
||||
import ckeditor_uploader.fields
|
||||
# ckeditor dependency removal
|
||||
# import ckeditor.fields
|
||||
# import ckeditor_uploader.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
@@ -12,24 +13,24 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="flatpage",
|
||||
name="content",
|
||||
field=ckeditor_uploader.fields.RichTextUploadingField(),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="siteconfiguration",
|
||||
name="about",
|
||||
field=ckeditor.fields.RichTextField(blank=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="siteconfiguration",
|
||||
name="footer",
|
||||
field=ckeditor.fields.RichTextField(blank=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="siteconfiguration",
|
||||
name="footer_extended",
|
||||
field=ckeditor.fields.RichTextField(blank=True),
|
||||
),
|
||||
# migrations.AlterField(
|
||||
# model_name="flatpage",
|
||||
# name="content",
|
||||
# field=ckeditor_uploader.fields.RichTextUploadingField(),
|
||||
# ),
|
||||
# migrations.AlterField(
|
||||
# model_name="siteconfiguration",
|
||||
# name="about",
|
||||
# field=ckeditor.fields.RichTextField(blank=True),
|
||||
# ),
|
||||
# migrations.AlterField(
|
||||
# model_name="siteconfiguration",
|
||||
# name="footer",
|
||||
# field=ckeditor.fields.RichTextField(blank=True),
|
||||
# ),
|
||||
# migrations.AlterField(
|
||||
# model_name="siteconfiguration",
|
||||
# name="footer_extended",
|
||||
# field=ckeditor.fields.RichTextField(blank=True),
|
||||
# ),
|
||||
]
|
||||
|
@@ -0,0 +1,16 @@
|
||||
# Generated by Django 5.0.1 on 2024-01-20 21:02
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("portal", "0015_siteconfiguration_use_cdn"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name="siteconfiguration",
|
||||
name="site_name",
|
||||
),
|
||||
]
|
@@ -0,0 +1,34 @@
|
||||
# Generated by Django 5.0.2 on 2024-02-17 12:19
|
||||
|
||||
import tinymce.models
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("portal", "0016_remove_siteconfiguration_site_name"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="flatpage",
|
||||
name="content",
|
||||
field=tinymce.models.HTMLField(),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="siteconfiguration",
|
||||
name="about",
|
||||
field=tinymce.models.HTMLField(blank=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="siteconfiguration",
|
||||
name="footer",
|
||||
field=tinymce.models.HTMLField(blank=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="siteconfiguration",
|
||||
name="footer_extended",
|
||||
field=tinymce.models.HTMLField(blank=True),
|
||||
),
|
||||
]
|
@@ -1,23 +1,20 @@
|
||||
import django
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from django.dispatch.dispatcher import receiver
|
||||
from django.utils.safestring import mark_safe
|
||||
from solo.models import SingletonModel
|
||||
|
||||
from ckeditor.fields import RichTextField
|
||||
from ckeditor_uploader.fields import RichTextUploadingField
|
||||
from tinymce import models as tinymce
|
||||
|
||||
from ram import __version__ as app_version
|
||||
from ram.utils import slugify
|
||||
|
||||
|
||||
class SiteConfiguration(SingletonModel):
|
||||
site_name = models.CharField(
|
||||
max_length=256, default="Railroad Assets Manager"
|
||||
)
|
||||
site_author = models.CharField(max_length=256, blank=True)
|
||||
about = RichTextField(blank=True)
|
||||
about = tinymce.HTMLField(blank=True)
|
||||
items_per_page = models.CharField(
|
||||
max_length=2,
|
||||
choices=[(str(x * 3), str(x * 3)) for x in range(2, 11)],
|
||||
@@ -32,8 +29,8 @@ class SiteConfiguration(SingletonModel):
|
||||
],
|
||||
default="type",
|
||||
)
|
||||
footer = RichTextField(blank=True)
|
||||
footer_extended = RichTextField(blank=True)
|
||||
footer = tinymce.HTMLField(blank=True)
|
||||
footer_extended = tinymce.HTMLField(blank=True)
|
||||
show_version = models.BooleanField(default=True)
|
||||
use_cdn = models.BooleanField(default=True)
|
||||
extra_head = models.TextField(blank=True)
|
||||
@@ -44,6 +41,9 @@ class SiteConfiguration(SingletonModel):
|
||||
def __str__(self):
|
||||
return "Site Configuration"
|
||||
|
||||
def site_name(self):
|
||||
return settings.SITE_NAME
|
||||
|
||||
def version(self):
|
||||
return app_version
|
||||
|
||||
@@ -55,7 +55,7 @@ class Flatpage(models.Model):
|
||||
name = models.CharField(max_length=256, unique=True)
|
||||
path = models.CharField(max_length=256, unique=True)
|
||||
published = models.BooleanField(default=False)
|
||||
content = RichTextUploadingField()
|
||||
content = tinymce.HTMLField()
|
||||
creation_time = models.DateTimeField(auto_now_add=True)
|
||||
updated_time = models.DateTimeField(auto_now=True)
|
||||
|
||||
@@ -66,7 +66,6 @@ class Flatpage(models.Model):
|
||||
return reverse("flatpage", kwargs={"flatpage": self.path})
|
||||
|
||||
def get_link(self):
|
||||
if self.published:
|
||||
return mark_safe(
|
||||
'<a href="{0}" target="_blank">Link</a>'.format(
|
||||
self.get_absolute_url()
|
||||
|
@@ -46,12 +46,12 @@
|
||||
transform="rotate(-90)" />
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-weight:bold;font-size:0.444444px;line-height:1.25;font-family:'Noto Sans';-inkscape-font-specification:'Noto Sans Bold';letter-spacing:0px;word-spacing:0px;stroke-width:0.0138889"
|
||||
style="font-weight:bold;font-size:0.444444px;line-height:1.25;font-family:system-ui,-apple-system,'Segoe UI',Roboto,'Helvetica Neue','Noto Sans','Liberation Sans',Arial,sans-serif;-inkscape-font-specification:'Noto Sans Bold';letter-spacing:0px;word-spacing:0px;stroke-width:0.0138889"
|
||||
x="1.5366687"
|
||||
y="1.6798887"
|
||||
id="text1"><tspan
|
||||
id="tspan1"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:0.444444px;font-family:'Noto Sans';-inkscape-font-specification:'Noto Sans';fill:#dee2e6;fill-opacity:1;stroke-width:0.0138889"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:0.444444px;font-family:system-ui,-apple-system,'Segoe UI',Roboto,'Helvetica Neue','Noto Sans','Liberation Sans',Arial,sans-serif;-inkscape-font-specification:'Noto Sans';fill:#dee2e6;fill-opacity:1;stroke-width:0.0138889"
|
||||
x="1.5366687"
|
||||
y="1.6798887">Coming soon</tspan></text>
|
||||
</g>
|
||||
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2.0 KiB |
@@ -7,6 +7,16 @@ html[data-bs-theme='dark'] .navbar svg {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
td > img.logo {
|
||||
max-width: 200px;
|
||||
max-height: 48px;
|
||||
}
|
||||
|
||||
td > img.logo-xl {
|
||||
max-width: 400px;
|
||||
max-height: 96px;
|
||||
}
|
||||
|
||||
.btn > span {
|
||||
display: inline-block;
|
||||
}
|
||||
|
BIN
ram/portal/static/flags/xx.gif
Normal file
BIN
ram/portal/static/flags/xx.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 72 B |
@@ -115,13 +115,26 @@
|
||||
})
|
||||
})()
|
||||
</script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var selectElement = document.getElementById('tabSelector');
|
||||
selectElement.addEventListener('change', function () {
|
||||
var selectedTabId = this.value;
|
||||
var tabs = document.querySelectorAll('.tab-pane');
|
||||
tabs.forEach(function (tab) {
|
||||
tab.classList.remove('show', 'active');
|
||||
});
|
||||
document.getElementById(selectedTabId).classList.add('show', 'active');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% block extra_head %}
|
||||
{{ site_conf.extra_head | safe }}
|
||||
{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-lg bg-body-tertiary shadow-sm">
|
||||
<nav class="navbar navbar-expand-sm bg-body-tertiary shadow-sm">
|
||||
<div class="container d-flex">
|
||||
<div class="me-auto">
|
||||
<a href="{% url 'index' %}" class="navbar-brand d-flex align-items-center">
|
||||
@@ -146,33 +159,34 @@
|
||||
<nav class="navbar navbar-expand-lg">
|
||||
<div class="container-fluid g-0">
|
||||
<a class="navbar-brand" href="{% url 'index' %}">Home</a>
|
||||
<div class="navbar-collapse" id="navbarSupportedContent">
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="rosterDropdownMenu" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Roster
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="rosterDropdownMenu">
|
||||
<li><a class="dropdown-item" href="{% url 'roster' %}">Rolling stock</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'companies' %}">Companies</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'types' %}">Types</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'scales' %}">Scales</a></li>
|
||||
</ul>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'roster' %}">Roster</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'consists' %}">Consists</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="manufacturersDropdownMenu" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Manufacturers
|
||||
<a class="nav-link dropdown-toggle" href="#" id="filterDropdownMenu" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Search by
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="manufacturersDropdownMenu">
|
||||
<li><a class="dropdown-item" href="{% url 'manufacturers' category='model' %}">Models</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'manufacturers' category='real' %}">Real</a></li>
|
||||
<ul class="dropdown-menu" aria-labelledby="filterDropdownMenu">
|
||||
<li class="ps-2 text-secondary">Model</li>
|
||||
<li><a class="dropdown-item" href="{% url 'scales' %}">Scale</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'manufacturers' category='model' %}">Manufacturer</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li class="ps-2 text-secondary">Prototype</li>
|
||||
<li><a class="dropdown-item" href="{% url 'types' %}">Type</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'companies' %}">Company</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'manufacturers' category='real' %}">Manufacturer</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{% show_flatpages_menu %}
|
||||
{% show_bookshelf_menu %}
|
||||
{% show_flatpages_menu %}
|
||||
</ul>
|
||||
{% include 'includes/search.html' %}
|
||||
</div>
|
||||
|
@@ -43,14 +43,16 @@
|
||||
<section class="py-4 text-start container">
|
||||
<div class="row">
|
||||
<div class="mx-auto">
|
||||
<nav>
|
||||
<div class="nav nav-tabs" id="nav-tab" role="tablist">
|
||||
<nav class="nav nav-tabs d-none d-lg-flex flex-row mb-2" id="nav-tab" role="tablist">
|
||||
<button class="nav-link active" id="nav-summary-tab" data-bs-toggle="tab" data-bs-target="#nav-summary" type="button" role="tab" aria-controls="nav-summary" aria-selected="true">Summary</button>
|
||||
{% if book.notes %}<button class="nav-link" id="nav-notes-tab" data-bs-toggle="tab" data-bs-target="#nav-notes" type="button" role="tab" aria-controls="nav-notes" aria-selected="false">Notes</button>{% endif %}
|
||||
</div>
|
||||
</nav>
|
||||
<select class="form-select d-lg-none mb-2" id="tabSelector" aria-label="Tab selector">
|
||||
<option value="nav-summary" selected>Summary</option>
|
||||
{% if book.notes %}<option value="nav-notes">Notes</option>{% endif %}
|
||||
</select>
|
||||
<div class="tab-content" id="nav-tabContent">
|
||||
<div class="tab-pane fade show active" id="nav-summary" role="tabpanel" aria-labelledby="nav-summary-tab">
|
||||
<div class="tab-pane show active" id="nav-summary" role="tabpanel" aria-labelledby="nav-summary-tab">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -112,7 +114,7 @@
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="tab-pane fade" id="nav-notes" role="tabpanel" aria-labelledby="nav-notes-tab">
|
||||
<div class="tab-pane" id="nav-notes" role="tabpanel" aria-labelledby="nav-notes-tab">
|
||||
{{ book.notes | safe }}
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -1,68 +1,4 @@
|
||||
{% extends "cards.html" %}
|
||||
|
||||
{% block cards %}
|
||||
{% for d in data %}
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
{% if d.image.all %}
|
||||
<a href="{{ d.get_absolute_url }}">
|
||||
{% for r in d.image.all %}
|
||||
{% if forloop.first %}<img src="{{ r.image.url }}" alt="Card image cap">{% endif %}
|
||||
{% endfor %}
|
||||
</a>
|
||||
{% endif %}
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d }}</strong>
|
||||
<a class="stretched-link" href="{{ d.get_absolute_url }}"></a>
|
||||
</p>
|
||||
{% if d.tags.all %}
|
||||
<p class="card-text"><small>Tags:</small>
|
||||
{% for t in d.tags.all %}<a href="{% url 'filtered' _filter="tag" search=t.slug %}" class="badge rounded-pill bg-primary">
|
||||
{{ t.name }}</a>{# new line is required #}
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Book</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Authors</th>
|
||||
<td>
|
||||
<ul class="mb-0 list-unstyled">{% for a in d.authors.all %}<li>{{ a }}</li>{% endfor %}</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Publisher</th>
|
||||
<td>{{ d.publisher }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Language</th>
|
||||
<td>{{ d.get_language_display }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Pages</th>
|
||||
<td>{{ d.number_of_pages|default:"-" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Year</th>
|
||||
<td>{{ d.publication_year|default:"-" }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{ d.get_absolute_url }}">Show all data</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:bookshelf_book_change' d.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
{% block pagination %}
|
||||
{% if data.has_other_pages %}
|
||||
<nav aria-label="Page navigation example">
|
||||
|
@@ -4,7 +4,7 @@
|
||||
Bookshelf
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="bookshelfDropdownMenuLink">
|
||||
<li><a class="nav-link" href="{% url 'books' %}">Books</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'books' %}">Books</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
@@ -1,104 +1,26 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block header %}
|
||||
<p class="lead text-muted">Results found: {{ matches }}</p>
|
||||
{% endblock %}
|
||||
{% block cards_layout %}
|
||||
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
|
||||
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3">
|
||||
{% block cards %}
|
||||
{% for d in data %}
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
{% if d.image.count > 0 %}
|
||||
<a href="{{d.get_absolute_url}}"><img class="card-img-top" src="{{ d.image.first.image.url }}" alt="{{ d }}"></a>
|
||||
{% else %}
|
||||
<!-- Do not show the "Coming soon" image when running in a single card column mode (e.g. on mobile) -->
|
||||
<a href="{{d.get_absolute_url}}"><img class="card-img-top d-none d-sm-block" src="{% static DEFAULT_CARD_IMAGE %}" alt="{{ d }}"></a>
|
||||
{% if d.type == "rolling_stock" %}
|
||||
{% include "cards/roster.html" %}
|
||||
{% elif d.type == "company" %}
|
||||
{% include "cards/company.html" %}
|
||||
{% elif d.type == "rolling_stock_type" %}
|
||||
{% include "cards/rolling_stock_type.html" %}
|
||||
{% elif d.type == "scale" %}
|
||||
{% include "cards/scale.html" %}
|
||||
{% elif d.type == "consist" %}
|
||||
{% include "cards/consist.html" %}
|
||||
{% elif d.type == "manufacturer" %}
|
||||
{% include "cards/manufacturer.html" %}
|
||||
{% elif d.type == "book" %}
|
||||
{% include "cards/book.html" %}
|
||||
{% endif %}
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d }}</strong>
|
||||
<a class="stretched-link" href="{{ d.get_absolute_url }}"></a>
|
||||
</p>
|
||||
{% if d.tags.all %}
|
||||
<p class="card-text"><small>Tags:</small>
|
||||
{% for t in d.tags.all %}<a href="{% url 'filtered' _filter="tag" search=t.slug %}" class="badge rounded-pill bg-primary">
|
||||
{{ t.name }}</a>{# new line is required #}
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Data</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Type</th>
|
||||
<td>{{ d.rolling_class.type }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Company</th>
|
||||
<td>
|
||||
<a href="{% url 'filtered' _filter="company" search=d.rolling_class.company.slug %}"><abbr title="{{ d.rolling_class.company.extended_name }}">{{ d.rolling_class.company }}</abbr></a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Class</th>
|
||||
<td>{{ d.rolling_class.identifier }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Road number</th>
|
||||
<td>{{ d.road_number }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Era</th>
|
||||
<td>{{ d.era }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Manufacturer</th>
|
||||
<td>{%if d.manufacturer %}
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=d.manufacturer.slug %}">{{ d.manufacturer }}{% if d.manufacturer.website %}</a> <a href="{{ d.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
{% endif %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Scale</th>
|
||||
<td><a href="{% url 'filtered' _filter="scale" search=d.scale.slug %}"><abbr title="{{ d.scale.ratio }} - {{ d.scale.tracks }}">{{ d.scale }}</abbr></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Item number</th>
|
||||
<td>{{ d.item_number }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% if d.decoder %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">DCC data</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Decoder</th>
|
||||
<td>{{ d.decoder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Address</th>
|
||||
<td>{{ d.address }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{d.get_absolute_url}}">Show all data</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:roster_rollingstock_change' d.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
56
ram/portal/templates/cards/book.html
Normal file
56
ram/portal/templates/cards/book.html
Normal file
@@ -0,0 +1,56 @@
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
{% if d.item.image.exists %}
|
||||
<a href="{{d.item.get_absolute_url}}"><img class="card-img-top" src="{{ d.item.image.first.image.url }}" alt="{{ d.item }}"></a>
|
||||
{% endif %}
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d.item }}</strong>
|
||||
<a class="stretched-link" href="{{ d.item.get_absolute_url }}"></a>
|
||||
</p>
|
||||
{% if d.item.tags.all %}
|
||||
<p class="card-text"><small>Tags:</small>
|
||||
{% for t in d.item.tags.all %}<a href="{% url 'filtered' _filter="tag" search=t.slug %}" class="badge rounded-pill bg-primary">
|
||||
{{ t.name }}</a>{# new line is required #}
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Book</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Authors</th>
|
||||
<td>
|
||||
<ul class="mb-0 list-unstyled">{% for a in d.item.authors.all %}<li>{{ a }}</li>{% endfor %}</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Publisher</th>
|
||||
<td>{{ d.item.publisher }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Language</th>
|
||||
<td>{{ d.item.get_language_display }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Pages</th>
|
||||
<td>{{ d.item.number_of_pages|default:"-" }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Year</th>
|
||||
<td>{{ d.item.publication_year|default:"-" }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{ d.item.get_absolute_url }}">Show all data</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:bookshelf_book_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
46
ram/portal/templates/cards/company.html
Normal file
46
ram/portal/templates/cards/company.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d.item.name }}</strong>
|
||||
</p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Company</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if d.item.logo %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Logo</th>
|
||||
<td><img class="logo" src="{{ d.item.logo.url }}" alt="{{ d.item.name }} logo"></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Name</th>
|
||||
<td>{{ d.item.extended_name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Abbreviation</th>
|
||||
<td>{{ d.item.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Country</th>
|
||||
<td>{{ d.item.country.name }} <img src="{{ d.item.country.flag }}" alt="{{ d.item.country }}">
|
||||
</tr>
|
||||
{% if d.item.freelance %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Notes</th>
|
||||
<td>A <em>freelance</em> company</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{% url 'filtered' _filter="company" search=d.item.slug %}">Show all rolling stock</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_company_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
57
ram/portal/templates/cards/consist.html
Normal file
57
ram/portal/templates/cards/consist.html
Normal file
@@ -0,0 +1,57 @@
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<a href="{{ d.item.get_absolute_url }}">
|
||||
{% if d.item.image %}
|
||||
<img class="card-img-top" src="{{ d.item.image.url }}" alt="{{ d.item }}">
|
||||
{% else %}
|
||||
{% with d.item.consist_item.first.rolling_stock as r %}
|
||||
<img class="card-img-top" src="{{ r.image.first.image.url }}" alt="{{ d.item }}">
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
</a>
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d.item }}</strong>
|
||||
<a class="stretched-link" href="{{ d.item.get_absolute_url }}"></a>
|
||||
</p>
|
||||
{% if d.item.tags.all %}
|
||||
<p class="card-text"><small>Tags:</small>
|
||||
{% for t in d.item.tags.all %}<a href="{% url 'filtered' _filter="tag" search=t.slug %}" class="badge rounded-pill bg-primary">
|
||||
{{ t.name }}</a>{# new line is required #}
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Consist</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if d.item.address %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Address</th>
|
||||
<td>{{ d.item.address }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Company</th>
|
||||
<td><abbr title="{{ d.item.company.extended_name }}">{{ d.item.company }}</abbr></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Era</th>
|
||||
<td>{{ d.item.era }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Length</th>
|
||||
<td>{{ d.item.consist_item.count }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{ d.item.get_absolute_url }}">Show all data</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:consist_consist_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
39
ram/portal/templates/cards/manufacturer.html
Normal file
39
ram/portal/templates/cards/manufacturer.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d.item.name }}</strong>
|
||||
</p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Manufacturer</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if d.item.logo %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Logo</th>
|
||||
<td><img class="logo" src="{{ d.item.logo.url }}" alt="{{ d.item.name }} logo"></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if d.item.website %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Website</th>
|
||||
<td><a href="{{ d.item.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Category</th>
|
||||
<td>{{ d.item.category | title }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{% url 'filtered' _filter="manufacturer" search=d.item.slug %}">Show all rolling stock</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_manufacturer_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
29
ram/portal/templates/cards/rolling_stock_type.html
Normal file
29
ram/portal/templates/cards/rolling_stock_type.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="card-text"><strong>{{ d.item }}</strong></p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Type</th>
|
||||
<td>{{ d.item.type }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Category</th>
|
||||
<td>{{ d.item.category | title}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{% url 'filtered' _filter="type" search=d.item.slug %}">Show all rolling stock</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_scale_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
92
ram/portal/templates/cards/roster.html
Normal file
92
ram/portal/templates/cards/roster.html
Normal file
@@ -0,0 +1,92 @@
|
||||
{% load static %}
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
{% if d.item.image.exists %}
|
||||
<a href="{{d.item.get_absolute_url}}"><img class="card-img-top" src="{{ d.item.image.first.image.url }}" alt="{{ d.item }}"></a>
|
||||
{% else %}
|
||||
<!-- Do not show the "Coming soon" image when running in a single card column mode (e.g. on mobile) -->
|
||||
<a href="{{d.item.get_absolute_url}}"><img class="card-img-top d-none d-sm-block" src="{% static DEFAULT_CARD_IMAGE %}" alt="{{ d.item }}"></a>
|
||||
{% endif %}
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d.item }}</strong>
|
||||
<a class="stretched-link" href="{{ d.item.get_absolute_url }}"></a>
|
||||
</p>
|
||||
{% if d.item.tags.all %}
|
||||
<p class="card-text"><small>Tags:</small>
|
||||
{% for t in d.item.tags.all %}<a href="{% url 'filtered' _filter="tag" search=t.slug %}" class="badge rounded-pill bg-primary">
|
||||
{{ t.name }}</a>{# new line is required #}
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Rolling stock</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Type</th>
|
||||
<td>{{ d.item.rolling_class.type }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Company</th>
|
||||
<td>
|
||||
<a href="{% url 'filtered' _filter="company" search=d.item.rolling_class.company.slug %}"><abbr title="{{ d.item.rolling_class.company.extended_name }}">{{ d.item.rolling_class.company }}</abbr></a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Class</th>
|
||||
<td>{{ d.item.rolling_class.identifier }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Road number</th>
|
||||
<td>{{ d.item.road_number }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Era</th>
|
||||
<td>{{ d.item.era }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Manufacturer</th>
|
||||
<td>{%if d.item.manufacturer %}
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=d.item.manufacturer.slug %}">{{ d.item.manufacturer }}{% if d.item.manufacturer.website %}</a> <a href="{{ d.item.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
{% endif %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Scale</th>
|
||||
<td><a href="{% url 'filtered' _filter="scale" search=d.item.scale.slug %}"><abbr title="{{ d.item.scale.ratio }} - {{ d.item.scale.tracks }}">{{ d.item.scale }}</abbr></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Item number</th>
|
||||
<td>{{ d.item.item_number }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% if d.item.decoder %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">DCC data</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Decoder</th>
|
||||
<td>{{ d.item.decoder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Address</th>
|
||||
<td>{{ d.item.address }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{d.item.get_absolute_url}}">Show all data</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:roster_rollingstock_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
36
ram/portal/templates/cards/scale.html
Normal file
36
ram/portal/templates/cards/scale.html
Normal file
@@ -0,0 +1,36 @@
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="card-text"><strong>{{ d.item }}</strong></p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Scale</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Name</th>
|
||||
<td>{{ d.item.scale }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Ratio</th>
|
||||
<td>{{ d.item.ratio }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Gauge</th>
|
||||
<td>{{ d.item.gauge }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Tracks</th>
|
||||
<td>{{ d.item.tracks }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{% url 'filtered' _filter="scale" search=d.item.slug %}">Show all rolling stock</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_scale_change' d.item.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@@ -1,55 +1,4 @@
|
||||
{% extends "cards.html" %}
|
||||
|
||||
{% block cards %}
|
||||
{% for d in data %}
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d.name }}</strong>
|
||||
</p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Company</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if d.logo %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Logo</th>
|
||||
<td><img style="max-height: 48px" src="{{ d.logo.url }}" /></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Name</th>
|
||||
<td>{{ d.extended_name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Abbreviation</th>
|
||||
<td>{{ d.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Country</th>
|
||||
<td>{{ d.country.name }} <img src="{{ d.country.flag }}" alt="{{ d.country }}" />
|
||||
</tr>
|
||||
{% if d.freelance %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Notes</th>
|
||||
<td>A <em>freelance</em> company</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{% url 'filtered' _filter="company" search=d.slug %}">Show all rolling stock</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_company_change' d.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
{% block pagination %}
|
||||
{% if data.has_other_pages %}
|
||||
<nav aria-label="Page navigation example">
|
||||
|
@@ -16,7 +16,7 @@
|
||||
<div id="carouselControls" class="carousel carousel-dark slide" data-bs-ride="carousel">
|
||||
<div class="carousel-inner">
|
||||
<div class="carousel-item active">
|
||||
<img src="{{ consist.image.url }}" class="d-block w-100 rounded img-thumbnail" alt="...">
|
||||
<img src="{{ consist.image.url }}" class="d-block w-100 rounded img-thumbnail" alt="Consist cover">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -66,14 +66,16 @@
|
||||
<section class="py-4 text-start container">
|
||||
<div class="row">
|
||||
<div class="mx-auto">
|
||||
<nav>
|
||||
<div class="nav nav-tabs" id="nav-tab" role="tablist">
|
||||
<nav class="nav nav-tabs d-none d-lg-flex flex-row mb-2" id="nav-tab" role="tablist">
|
||||
<button class="nav-link active" id="nav-summary-tab" data-bs-toggle="tab" data-bs-target="#nav-summary" type="button" role="tab" aria-controls="nav-summary" aria-selected="true">Summary</button>
|
||||
{% if consist.notes %}<button class="nav-link" id="nav-notes-tab" data-bs-toggle="tab" data-bs-target="#nav-notes" type="button" role="tab" aria-controls="nav-notes" aria-selected="false">Notes</button>{% endif %}
|
||||
</div>
|
||||
</nav>
|
||||
<select class="form-select d-lg-none mb-2" id="tabSelector" aria-label="Tab selector">
|
||||
<option value="nav-summary" selected>Summary</option>
|
||||
{% if consist.notes %}<option value="nav-notes">Notes</option>{% endif %}
|
||||
</select>
|
||||
<div class="tab-content" id="nav-tabContent">
|
||||
<div class="tab-pane fade show active" id="nav-summary" role="tabpanel" aria-labelledby="nav-summary-tab">
|
||||
<div class="tab-pane show active" id="nav-summary" role="tabpanel" aria-labelledby="nav-summary-tab">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -83,7 +85,9 @@
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Company</th>
|
||||
<td><abbr title="{{ consist.company.extended_name }}">{{ consist.company }}</abbr></td>
|
||||
<td>
|
||||
<a href="{% url 'filtered' _filter="company" search=consist.company.slug %}">{{ consist.company }}</a> ({{ consist.company.extended_name }})
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Era</th>
|
||||
@@ -96,7 +100,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="nav-notes" role="tabpanel" aria-labelledby="nav-notes-tab">
|
||||
<div class="tab-pane" id="nav-notes" role="tabpanel" aria-labelledby="nav-notes-tab">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@@ -1,68 +1,4 @@
|
||||
{% extends "cards.html" %}
|
||||
|
||||
{% block cards %}
|
||||
{% for d in data %}
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<a href="{{ d.get_absolute_url }}">
|
||||
{% if d.image %}
|
||||
<img src="{{ d.image.url }}" alt="Card image cap">
|
||||
{% else %}
|
||||
{% with d.consist_item.first.rolling_stock as r %}
|
||||
{% for i in r.image.all %}
|
||||
{% if forloop.first %}<img src="{{ i.image.url }}" alt="Card image cap">{% endif %}
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
</a>
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d }}</strong>
|
||||
<a class="stretched-link" href="{{ d.get_absolute_url }}"></a>
|
||||
</p>
|
||||
{% if d.tags.all %}
|
||||
<p class="card-text"><small>Tags:</small>
|
||||
{% for t in d.tags.all %}<a href="{% url 'filtered' _filter="tag" search=t.slug %}" class="badge rounded-pill bg-primary">
|
||||
{{ t.name }}</a>{# new line is required #}
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Consist data</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if d.address %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Address</th>
|
||||
<td>{{ d.address }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Company</th>
|
||||
<td><abbr title="{{ d.company.extended_name }}">{{ d.company }}</abbr></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Era</th>
|
||||
<td>{{ d.era }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Length</th>
|
||||
<td>{{ d.consist_item.all | length }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{{ d.get_absolute_url }}">Show all data</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:consist_consist_change' d.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
{% block pagination %}
|
||||
{% if data.has_other_pages %}
|
||||
<nav aria-label="Page navigation example">
|
||||
|
@@ -1,5 +1,4 @@
|
||||
{% extends "cards.html" %}
|
||||
|
||||
{% block pagination %}
|
||||
{% if data.has_other_pages %}
|
||||
<nav aria-label="Page navigation example">
|
||||
|
@@ -1,4 +1,7 @@
|
||||
<div class="navbar-collapse justify-content-end" id="loginNavbar">
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#loginNavbar" aria-controls="loginNavbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="bi bi-person-fill-gear"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse justify-content-end" id="loginNavbar">
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item dropdown">
|
||||
{% if request.user.is_staff %}
|
||||
@@ -14,7 +17,6 @@
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item" href="{% url 'admin:index' %}">Admin</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'admin:portal_siteconfiguration_changelist' %}">Site configuration</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'admin:driver_driverconfiguration_changelist' %}">DCC configuration</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item text-danger" href="{% url 'admin:logout' %}?next={{ request.path }}">Logout</a></li>
|
||||
</ul>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<form class="d-flex needs-validation" action="{% url 'search' %}" method="post" novalidate>
|
||||
<form class="d-flex needs-validation" action="{% url 'search' %}" method="post" novalidate>{% csrf_token %}
|
||||
<div class="input-group has-validation">
|
||||
<input class="form-control" type="search" list="datalistOptions" placeholder="Search" aria-label="Search" name="search" id="searchValidation" required>
|
||||
<datalist id="datalistOptions">
|
||||
|
@@ -1,50 +1,7 @@
|
||||
{% extends "cards.html" %}
|
||||
|
||||
{% block cards %}
|
||||
{% for d in data %}
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="card-text" style="position: relative;">
|
||||
<strong>{{ d.name }}</strong>
|
||||
</p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Manufacturer</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if d.logo %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Logo</th>
|
||||
<td><img style="max-height: 48px" src="{{ d.logo.url }}" /></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if d.website %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Website</th>
|
||||
<td><a href="{{ d.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Category</th>
|
||||
<td>{{ d.category | title }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{% url 'filtered' _filter="manufacturer" search=d.slug %}">Show all rolling stock</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_manufacturer_change' d.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
{% block pagination %}
|
||||
{% if data.has_other_pages %}
|
||||
{% with data.0.category as c %}
|
||||
{% with data.0.item.category as c %}
|
||||
<nav aria-label="Page navigation example">
|
||||
<ul class="pagination justify-content-center mt-4 mb-0">
|
||||
{% if data.has_previous %}
|
||||
|
@@ -43,19 +43,31 @@
|
||||
<section class="py-4 text-start container">
|
||||
<div class="row">
|
||||
<div class="mx-auto">
|
||||
<nav>
|
||||
<div class="nav nav-tabs" id="nav-tab" role="tablist">
|
||||
<nav class="nav nav-tabs d-none d-lg-flex flex-row mb-2" id="nav-tab" role="tablist">
|
||||
<button class="nav-link active" id="nav-summary-tab" data-bs-toggle="tab" data-bs-target="#nav-summary" type="button" role="tab" aria-controls="nav-summary" aria-selected="true">Summary</button>
|
||||
<button class="nav-link" id="nav-model-tab" data-bs-toggle="tab" data-bs-target="#nav-model" type="button" role="tab" aria-controls="nav-model" aria-selected="false">Model data</button>
|
||||
<button class="nav-link" id="nav-class-tab" data-bs-toggle="tab" data-bs-target="#nav-class" type="button" role="tab" aria-controls="nav-class" aria-selected="false">Class data</button>
|
||||
<button class="nav-link" id="nav-model-tab" data-bs-toggle="tab" data-bs-target="#nav-model" type="button" role="tab" aria-controls="nav-model" aria-selected="false">Model</button>
|
||||
<button class="nav-link" id="nav-class-tab" data-bs-toggle="tab" data-bs-target="#nav-class" type="button" role="tab" aria-controls="nav-class" aria-selected="false">Class</button>
|
||||
<button class="nav-link" id="nav-company-tab" data-bs-toggle="tab" data-bs-target="#nav-company" type="button" role="tab" aria-controls="nav-company" aria-selected="false">Company</button>
|
||||
{% if rolling_stock.decoder %}<button class="nav-link" id="nav-dcc-tab" data-bs-toggle="tab" data-bs-target="#nav-dcc" type="button" role="tab" aria-controls="nav-dcc" aria-selected="false">DCC</button>{% endif %}
|
||||
{% if rolling_stock.document.count > 0 or rolling_stock.decoder.document.count > 0 %}<button class="nav-link" id="nav-documents-tab" data-bs-toggle="tab" data-bs-target="#nav-documents" type="button" role="tab" aria-controls="nav-documents" aria-selected="false">Documents</button>{% endif %}
|
||||
{% if rolling_stock_journal.count > 0 %}<button class="nav-link" id="nav-journal-tab" data-bs-toggle="tab" data-bs-target="#nav-journal" type="button" role="tab" aria-controls="nav-journal" aria-selected="false">Journal</button>{% endif %}
|
||||
{% if documents or decoder_documents %}<button class="nav-link" id="nav-documents-tab" data-bs-toggle="tab" data-bs-target="#nav-documents" type="button" role="tab" aria-controls="nav-documents" aria-selected="false">Documents</button>{% endif %}
|
||||
{% if journal %}<button class="nav-link" id="nav-journal-tab" data-bs-toggle="tab" data-bs-target="#nav-journal" type="button" role="tab" aria-controls="nav-journal" aria-selected="false">Journal</button>{% endif %}
|
||||
{% if rolling_stock.notes %}<button class="nav-link" id="nav-notes-tab" data-bs-toggle="tab" data-bs-target="#nav-notes" type="button" role="tab" aria-controls="nav-notes" aria-selected="false">Notes</button>{% endif %}
|
||||
</div>
|
||||
{% if consists %}<button class="nav-link" id="nav-consists-tab" data-bs-toggle="tab" data-bs-target="#nav-consists" type="button" role="tab" aria-controls="nav-consists" aria-selected="false">Consists</button>{% endif %}
|
||||
</nav>
|
||||
<select class="form-select d-lg-none mb-2" id="tabSelector" aria-label="Tab selector">
|
||||
<option value="nav-summary" selected>Summary</option>
|
||||
<option value="nav-model">Model</option>
|
||||
<option value="nav-class">Class</option>
|
||||
<option value="nav-company">Company</option>
|
||||
{% if rolling_stock.decoder %}<option value="nav-dcc">DCC</option>{% endif %}
|
||||
{% if documents or decoder_documents %}<option value="nav-documents">Documents</option>{% endif %}
|
||||
{% if journal %}<option value="nav-journal">Journal</option>{% endif %}
|
||||
{% if rolling_stock.notes %}<option value="nav-notes">Notes</option>{% endif %}
|
||||
{% if consists %}<option value="nav-consists">Consists</option>{% endif %}
|
||||
</select>
|
||||
{% with class=rolling_stock.rolling_class company=rolling_stock.rolling_class.company %}
|
||||
<div class="tab-content" id="nav-tabContent">
|
||||
<div class="tab-pane fade show active" id="nav-summary" role="tabpanel" aria-labelledby="nav-summary-tab">
|
||||
<div class="tab-pane show active" id="nav-summary" role="tabpanel" aria-labelledby="nav-summary-tab">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -65,17 +77,17 @@
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Type</th>
|
||||
<td>{{ rolling_stock.rolling_class.type }}</td>
|
||||
<td>{{ class.type }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Company</th>
|
||||
<td>
|
||||
<a href="{% url 'filtered' _filter="company" search=rolling_stock.rolling_class.company.slug %}"><abbr title="{{ rolling_stock.rolling_class.company.extended_name }}">{{ rolling_stock.rolling_class.company }}</abbr></a>
|
||||
<a href="{% url 'filtered' _filter="company" search=company.slug %}">{{ company }}</a> {{ company.extended_name_pp }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Class</th>
|
||||
<td>{{ rolling_stock.rolling_class.identifier }}</td>
|
||||
<td>{{ class.identifier }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Road number</th>
|
||||
@@ -97,7 +109,7 @@
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Manufacturer</th>
|
||||
<td>{%if rolling_stock.manufacturer %}
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=rolling_stock.manufacturer.slug %}">{{ rolling_stock.manufacturer }}{% if rolling_stock.manufacturer.website %}</a> <a href="{{ rolling_stock.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=rolling_stock.manufacturer.slug %}">{{ rolling_stock.manufacturer }}</a>{% if rolling_stock.manufacturer.website %} <a href="{{ rolling_stock.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
{% endif %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -136,7 +148,7 @@
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="tab-pane fade" id="nav-model" role="tabpanel" aria-labelledby="nav-model-tab">
|
||||
<div class="tab-pane" id="nav-model" role="tabpanel" aria-labelledby="nav-model-tab">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -146,9 +158,11 @@
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Manufacturer</th>
|
||||
<td>{%if rolling_stock.manufacturer %}
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=rolling_stock.manufacturer.slug %}">{{ rolling_stock.manufacturer }}{% if rolling_stock.manufacturer.website %}</a> <a href="{{ rolling_stock.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
{% endif %}</td>
|
||||
<td>
|
||||
{%if rolling_stock.manufacturer %}
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=rolling_stock.manufacturer.slug %}">{{ rolling_stock.manufacturer }}</a>{% if rolling_stock.manufacturer.website %} <a href="{{ rolling_stock.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
{% else %}-{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Scale</th>
|
||||
@@ -172,7 +186,7 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% if rolling_stock_properties %}
|
||||
{% if properties %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -180,7 +194,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% for p in rolling_stock_properties %}
|
||||
{% for p in properties %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">{{ p.property }}</th>
|
||||
<td>{{ p.value }}</td>
|
||||
@@ -190,7 +204,7 @@
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="tab-pane fade" id="nav-class" role="tabpanel" aria-labelledby="nav-class-tab">
|
||||
<div class="tab-pane" id="nav-class" role="tabpanel" aria-labelledby="nav-class-tab">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -200,27 +214,19 @@
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Class</th>
|
||||
<td>{{ rolling_stock.rolling_class.identifier }}</td>
|
||||
<td>{{ class.identifier }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Type</th>
|
||||
<td>{{ rolling_stock.rolling_class.type }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Company</th>
|
||||
<td>
|
||||
<a href="{% url 'filtered' _filter="company" search=rolling_stock.rolling_class.company.slug %}">{{ rolling_stock.rolling_class.company }}</a> ({{ rolling_stock.rolling_class.company.extended_name }})
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Country</th>
|
||||
<td>{{ rolling_stock.rolling_class.company.country.name }}</td>
|
||||
<td>{{ class.type }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Manufacturer</th>
|
||||
<td>{%if rolling_stock.rolling_class.manufacturer %}
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=rolling_stock.rolling_class.manufacturer.slug %}">{{ rolling_stock.rolling_class.manufacturer }}{% if rolling_stock.rolling_class.manufacturer.website %}</a> <a href="{{ rolling_stock.rolling_class.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
{% endif %}</td>
|
||||
<td>
|
||||
{%if class.manufacturer %}
|
||||
<a href="{% url 'filtered' _filter="manufacturer" search=class.manufacturer.slug %}">{{ class.manufacturer }}</a>{% if class.manufacturer.website %} <a href="{{ class.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||
{% else %}-{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -242,11 +248,42 @@
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="tab-pane fade" id="nav-dcc" role="tabpanel" aria-labelledby="nav-dcc-tab">
|
||||
<div class="tab-pane" id="nav-company" role="tabpanel" aria-labelledby="nav-company-tab">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">DCC data</th>
|
||||
<th colspan="2" scope="row">Company data</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% if company.logo %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Logo</th>
|
||||
<td><img class="logo-xl" src="{{ company.logo.url }}" alt="{{ company }} logo"></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Name</th>
|
||||
<td><a href="{% url 'filtered' _filter="company" search=company.slug %}">{{ company.name }}</a> {{ company.extended_name_pp }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Country</th>
|
||||
<td>{{ company.country.name }} <img src="{{ company.country.flag }}" alt="{{ company.country }}">
|
||||
</tr>
|
||||
{% if company.freelance %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Notes</th>
|
||||
<td>A <em>freelance</em> company</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="tab-pane" id="nav-dcc" role="tabpanel" aria-labelledby="nav-dcc-tab">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Decoder data</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
@@ -277,8 +314,8 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="nav-documents" role="tabpanel" aria-labelledby="nav-documents-tab">
|
||||
{% if rolling_stock.document.count > 0 %}
|
||||
<div class="tab-pane" id="nav-documents" role="tabpanel" aria-labelledby="nav-documents-tab">
|
||||
{% if documents %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -286,7 +323,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% for d in rolling_stock.document.all %}
|
||||
{% for d in documents.all %}
|
||||
<tr>
|
||||
<td class="w-33">{{ d.description }}</td>
|
||||
<td><a href="{{ d.file.url }}" target="_blank">{{ d.filename }}</a></td>
|
||||
@@ -296,7 +333,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% if rolling_stock.decoder.document.count > 0 %}
|
||||
{% if decoder_documents %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -304,7 +341,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% for d in rolling_stock.decoder.document.all %}
|
||||
{% for d in decoder_documents.all %}
|
||||
<tr>
|
||||
<td class="w-33">{{ d.description }}</td>
|
||||
<td><a href="{{ d.file.url }}" target="_blank">{{ d.filename }}</a></td>
|
||||
@@ -315,27 +352,35 @@
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="tab-pane fade" id="nav-journal" role="tabpanel" aria-labelledby="nav-journal-tab">
|
||||
<div class="tab-pane" id="nav-journal" role="tabpanel" aria-labelledby="nav-journal-tab">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3" scope="row">Journal</th>
|
||||
<th colspan="2" scope="row">Journal</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
{% for j in rolling_stock_journal %}
|
||||
{% for j in journal %}
|
||||
<tr>
|
||||
<th class="w-33" scope="row">{{ j.date }}</th>
|
||||
<td>{{ j.log | safe }}</a></td>
|
||||
<td>{{ j.log | safe }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="nav-notes" role="tabpanel" aria-labelledby="nav-notes-tab">
|
||||
<div class="tab-pane" id="nav-notes" role="tabpanel" aria-labelledby="nav-notes-tab">
|
||||
{{ rolling_stock.notes | safe }}
|
||||
</div>
|
||||
<div class="tab-pane" id="nav-consists" role="tabpanel" aria-labelledby="nav-cosists-tab">
|
||||
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3 mb-3">
|
||||
{% for d in consists %}
|
||||
{% include "cards/consist.html" %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endwith %}
|
||||
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:roster_rollingstock_change' rolling_stock.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
|
@@ -1,45 +1,4 @@
|
||||
{% extends "cards.html" %}
|
||||
|
||||
{% block cards %}
|
||||
{% for d in data %}
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="card-text"><strong>{{ d }}</strong></p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Scale</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Name</th>
|
||||
<td>{{ d.scale }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Ratio</th>
|
||||
<td>{{ d.ratio }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Gauge</th>
|
||||
<td>{{ d.gauge }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Tracks</th>
|
||||
<td>{{ d.tracks }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{% url 'filtered' _filter="scale" search=d.slug %}">Show all rolling stock</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_scale_change' d.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
{% block pagination %}
|
||||
{% if data.has_other_pages %}
|
||||
<nav aria-label="Page navigation example">
|
||||
|
@@ -1,44 +1,11 @@
|
||||
{% extends "cards.html" %}
|
||||
|
||||
{% block cards %}
|
||||
{% for d in data %}
|
||||
<div class="col">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="card-text"><strong>{{ d }}</strong></p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" scope="row">Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Type</th>
|
||||
<td>{{ d.type }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="w-33" scope="row">Category</th>
|
||||
<td>{{ d.category | title}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-grid gap-2 mb-1 d-md-block">
|
||||
<a class="btn btn-sm btn-outline-primary" href="{% url 'filtered' _filter="type" search=d.slug %}">Show all rolling stock</a>
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_scale_change' d.pk %}">Edit</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
{% block pagination %}
|
||||
{% if data.has_other_pages %}
|
||||
<nav aria-label="Page navigation example">
|
||||
<ul class="pagination justify-content-center mt-4 mb-0">
|
||||
{% if data.has_previous %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url 'scales_pagination' page=data.previous_page_number %}#main-content" tabindex="-1">Previous</a>
|
||||
<a class="page-link" href="{% url 'types_pagination' page=data.previous_page_number %}#main-content" tabindex="-1">Previous</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
@@ -54,13 +21,13 @@
|
||||
{% if i == data.paginator.ELLIPSIS %}
|
||||
<li class="page-item"><span class="page-link">{{ i }}</span></li>
|
||||
{% else %}
|
||||
<li class="page-item"><a class="page-link" href="{% url 'scales_pagination' page=i %}#main-content">{{ i }}</a></li>
|
||||
<li class="page-item"><a class="page-link" href="{% url 'types_pagination' page=i %}#main-content">{{ i }}</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if data.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{% url 'scales_pagination' page=data.next_page_number %}#main-content" tabindex="-1">Next</a>
|
||||
<a class="page-link" href="{% url 'types_pagination' page=data.next_page_number %}#main-content" tabindex="-1">Next</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
|
@@ -3,7 +3,7 @@ from django.urls import path
|
||||
from portal.views import (
|
||||
GetData,
|
||||
GetRoster,
|
||||
GetRosterFiltered,
|
||||
GetObjectsFiltered,
|
||||
GetFlatpage,
|
||||
GetRollingStock,
|
||||
GetConsist,
|
||||
@@ -14,11 +14,11 @@ from portal.views import (
|
||||
Types,
|
||||
Books,
|
||||
GetBook,
|
||||
SearchRoster,
|
||||
SearchObjects,
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path("", GetData.as_view(), name="index"),
|
||||
path("", GetData.as_view(template="home.html"), name="index"),
|
||||
path("roster", GetRoster.as_view(), name="roster"),
|
||||
path("roster/<int:page>", GetRoster.as_view(), name="roster_pagination"),
|
||||
path(
|
||||
@@ -26,9 +26,15 @@ urlpatterns = [
|
||||
GetFlatpage.as_view(),
|
||||
name="flatpage",
|
||||
),
|
||||
path("consists", Consists.as_view(), name="consists"),
|
||||
path(
|
||||
"consists/<int:page>", Consists.as_view(), name="consists_pagination"
|
||||
"consists",
|
||||
Consists.as_view(template="consists.html"),
|
||||
name="consists"
|
||||
),
|
||||
path(
|
||||
"consists/<int:page>",
|
||||
Consists.as_view(template="consists.html"),
|
||||
name="consists_pagination"
|
||||
),
|
||||
path("consist/<uuid:uuid>", GetConsist.as_view(), name="consist"),
|
||||
path(
|
||||
@@ -36,47 +42,75 @@ urlpatterns = [
|
||||
GetConsist.as_view(),
|
||||
name="consist_pagination",
|
||||
),
|
||||
path("companies", Companies.as_view(), name="companies"),
|
||||
path(
|
||||
"companies",
|
||||
Companies.as_view(template="companies.html"),
|
||||
name="companies"
|
||||
),
|
||||
path(
|
||||
"companies/<int:page>",
|
||||
Companies.as_view(),
|
||||
Companies.as_view(template="companies.html"),
|
||||
name="companies_pagination",
|
||||
),
|
||||
path(
|
||||
"manufacturers/<str:category>",
|
||||
Manufacturers.as_view(),
|
||||
Manufacturers.as_view(template="manufacturers.html"),
|
||||
name="manufacturers"
|
||||
),
|
||||
path(
|
||||
"manufacturers/<str:category>/<int:page>",
|
||||
Manufacturers.as_view(),
|
||||
Manufacturers.as_view(template="manufacturers.html"),
|
||||
name="manufacturers_pagination",
|
||||
),
|
||||
path("scales", Scales.as_view(), name="scales"),
|
||||
path("scales/<int:page>", Types.as_view(), name="scales_pagination"),
|
||||
path("types", Types.as_view(), name="types"),
|
||||
path("types/<int:page>", Types.as_view(), name="types_pagination"),
|
||||
path("bookshelf/books", Books.as_view(), name="books"),
|
||||
path("bookshelf/books/<int:page>", Books.as_view(), name="books_pagination"),
|
||||
path(
|
||||
"scales",
|
||||
Scales.as_view(template="scales.html"),
|
||||
name="scales"
|
||||
),
|
||||
path(
|
||||
"scales/<int:page>",
|
||||
Scales.as_view(template="scales.html"),
|
||||
name="scales_pagination"
|
||||
),
|
||||
path(
|
||||
"types",
|
||||
Types.as_view(template="types.html"),
|
||||
name="types"
|
||||
),
|
||||
path(
|
||||
"types/<int:page>",
|
||||
Types.as_view(template="types.html"),
|
||||
name="types_pagination"
|
||||
),
|
||||
path(
|
||||
"bookshelf/books",
|
||||
Books.as_view(template="bookshelf/books.html"),
|
||||
name="books"
|
||||
),
|
||||
path(
|
||||
"bookshelf/books/<int:page>",
|
||||
Books.as_view(template="bookshelf/books.html"),
|
||||
name="books_pagination"
|
||||
),
|
||||
path("bookshelf/book/<uuid:uuid>", GetBook.as_view(), name="book"),
|
||||
path(
|
||||
"search",
|
||||
SearchRoster.as_view(http_method_names=["post"]),
|
||||
SearchObjects.as_view(http_method_names=["post"]),
|
||||
name="search",
|
||||
),
|
||||
path(
|
||||
"search/<str:search>/<int:page>",
|
||||
SearchRoster.as_view(),
|
||||
SearchObjects.as_view(),
|
||||
name="search_pagination",
|
||||
),
|
||||
path(
|
||||
"<str:_filter>/<str:search>",
|
||||
GetRosterFiltered.as_view(),
|
||||
GetObjectsFiltered.as_view(),
|
||||
name="filtered",
|
||||
),
|
||||
path(
|
||||
"<str:_filter>/<str:search>/<int:page>",
|
||||
GetRosterFiltered.as_view(),
|
||||
GetObjectsFiltered.as_view(),
|
||||
name="filtered_pagination",
|
||||
),
|
||||
path("<uuid:uuid>", GetRollingStock.as_view(), name="rolling_stock"),
|
||||
|
@@ -5,6 +5,7 @@ from urllib.parse import unquote
|
||||
|
||||
from django.views import View
|
||||
from django.http import Http404, HttpResponseBadRequest
|
||||
from django.db.utils import OperationalError, ProgrammingError
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
@@ -15,11 +16,17 @@ from portal.models import Flatpage
|
||||
from roster.models import RollingStock
|
||||
from consist.models import Consist
|
||||
from bookshelf.models import Book
|
||||
from metadata.models import Company, Manufacturer, Scale, RollingStockType, Tag
|
||||
from metadata.models import (
|
||||
Company, Manufacturer, Scale, DecoderDocument, RollingStockType, Tag
|
||||
)
|
||||
|
||||
|
||||
def order_by_fields():
|
||||
try:
|
||||
order_by = get_site_conf().items_ordering
|
||||
except (OperationalError, ProgrammingError):
|
||||
order_by = "type"
|
||||
|
||||
fields = [
|
||||
"rolling_class__type",
|
||||
"rolling_class__company",
|
||||
@@ -36,15 +43,22 @@ def order_by_fields():
|
||||
|
||||
|
||||
class GetData(View):
|
||||
def __init__(self):
|
||||
self.title = "Home"
|
||||
self.template = "home.html"
|
||||
self.data = RollingStock.objects.order_by(*order_by_fields())
|
||||
title = "Home"
|
||||
template = "roster.html"
|
||||
item_type = "rolling_stock"
|
||||
queryset = RollingStock.objects.order_by(*order_by_fields())
|
||||
|
||||
def get(self, request, page=1):
|
||||
site_conf = get_site_conf()
|
||||
|
||||
paginator = Paginator(self.data, site_conf.items_per_page)
|
||||
data = []
|
||||
for item in self.queryset:
|
||||
data.append({
|
||||
"type": self.item_type,
|
||||
"item": item
|
||||
})
|
||||
|
||||
paginator = Paginator(data, site_conf.items_per_page)
|
||||
data = paginator.get_page(page)
|
||||
page_range = paginator.get_elided_page_range(
|
||||
data.number, on_each_side=2, on_ends=1
|
||||
@@ -55,6 +69,7 @@ class GetData(View):
|
||||
self.template,
|
||||
{
|
||||
"title": self.title,
|
||||
"type": self.item_type,
|
||||
"data": data,
|
||||
"matches": paginator.count,
|
||||
"page_range": page_range,
|
||||
@@ -63,13 +78,12 @@ class GetData(View):
|
||||
|
||||
|
||||
class GetRoster(GetData):
|
||||
def __init__(self):
|
||||
self.title = "Rolling stock"
|
||||
self.template = "roster.html"
|
||||
self.data = RollingStock.objects.order_by(*order_by_fields())
|
||||
title = "Roster"
|
||||
item_type = "rolling_stock"
|
||||
queryset = RollingStock.objects.order_by(*order_by_fields())
|
||||
|
||||
|
||||
class SearchRoster(View):
|
||||
class SearchObjects(View):
|
||||
def run_search(self, request, search, _filter, page=1):
|
||||
site_conf = get_site_conf()
|
||||
if _filter is None:
|
||||
@@ -111,20 +125,50 @@ class SearchRoster(View):
|
||||
else:
|
||||
raise Http404
|
||||
|
||||
# FIXME duplicated code!
|
||||
data = []
|
||||
rolling_stock = (
|
||||
RollingStock.objects.filter(query)
|
||||
.distinct()
|
||||
.order_by(*order_by_fields())
|
||||
)
|
||||
matches = rolling_stock.count()
|
||||
for item in rolling_stock:
|
||||
data.append({
|
||||
"type": "rolling_stock",
|
||||
"item": item
|
||||
})
|
||||
if _filter is None:
|
||||
consists = (
|
||||
Consist.objects.filter(
|
||||
Q(
|
||||
Q(identifier__icontains=search)
|
||||
| Q(company__name__icontains=search)
|
||||
)
|
||||
)
|
||||
.distinct()
|
||||
)
|
||||
for item in consists:
|
||||
data.append({
|
||||
"type": "consist",
|
||||
"item": item
|
||||
})
|
||||
books = (
|
||||
Book.objects.filter(title__icontains=search)
|
||||
.distinct()
|
||||
)
|
||||
for item in books:
|
||||
data.append({
|
||||
"type": "book",
|
||||
"item": item
|
||||
})
|
||||
|
||||
paginator = Paginator(rolling_stock, site_conf.items_per_page)
|
||||
rolling_stock = paginator.get_page(page)
|
||||
paginator = Paginator(data, site_conf.items_per_page)
|
||||
data = paginator.get_page(page)
|
||||
page_range = paginator.get_elided_page_range(
|
||||
rolling_stock.number, on_each_side=2, on_ends=1
|
||||
data.number, on_each_side=2, on_ends=1
|
||||
)
|
||||
|
||||
return rolling_stock, matches, page_range
|
||||
return data, paginator.count, page_range
|
||||
|
||||
def split_search(self, search):
|
||||
search = search.strip().split(":")
|
||||
@@ -149,7 +193,7 @@ class SearchRoster(View):
|
||||
encoded_search = base64.b64encode(
|
||||
search.encode()).decode()
|
||||
_filter, keyword = self.split_search(search)
|
||||
rolling_stock, matches, page_range = self.run_search(
|
||||
data, matches, page_range = self.run_search(
|
||||
request, keyword, _filter, page
|
||||
)
|
||||
|
||||
@@ -160,8 +204,8 @@ class SearchRoster(View):
|
||||
"title": "Search: \"{}\"".format(search),
|
||||
"search": search,
|
||||
"encoded_search": encoded_search,
|
||||
"data": data,
|
||||
"matches": matches,
|
||||
"data": rolling_stock,
|
||||
"page_range": page_range,
|
||||
},
|
||||
)
|
||||
@@ -171,15 +215,17 @@ class SearchRoster(View):
|
||||
return self.get(request, search, page)
|
||||
|
||||
|
||||
class GetRosterFiltered(View):
|
||||
class GetObjectsFiltered(View):
|
||||
def run_filter(self, request, search, _filter, page=1):
|
||||
site_conf = get_site_conf()
|
||||
|
||||
if _filter == "type":
|
||||
title = RollingStockType.objects.get(slug__iexact=search)
|
||||
title = get_object_or_404(RollingStockType, slug__iexact=search)
|
||||
query = Q(rolling_class__type__slug__iexact=search)
|
||||
elif _filter == "company":
|
||||
title = get_object_or_404(Company, slug__iexact=search)
|
||||
query = Q(rolling_class__company__slug__iexact=search)
|
||||
query_2nd = Q(company__slug__iexact=search)
|
||||
elif _filter == "manufacturer":
|
||||
title = get_object_or_404(Manufacturer, slug__iexact=search)
|
||||
query = Q(
|
||||
@@ -189,9 +235,13 @@ class GetRosterFiltered(View):
|
||||
elif _filter == "scale":
|
||||
title = get_object_or_404(Scale, slug__iexact=search)
|
||||
query = Q(scale__slug__iexact=search)
|
||||
query_2nd = Q(
|
||||
consist_item__rolling_stock__scale__slug__iexact=search
|
||||
)
|
||||
elif _filter == "tag":
|
||||
title = get_object_or_404(Tag, slug__iexact=search)
|
||||
query = Q(tags__slug__iexact=search)
|
||||
query_2nd = query # For tags the 2nd level query doesn't change
|
||||
else:
|
||||
raise Http404
|
||||
|
||||
@@ -200,15 +250,44 @@ class GetRosterFiltered(View):
|
||||
.distinct()
|
||||
.order_by(*order_by_fields())
|
||||
)
|
||||
matches = rolling_stock.count()
|
||||
|
||||
paginator = Paginator(rolling_stock, site_conf.items_per_page)
|
||||
rolling_stock = paginator.get_page(page)
|
||||
data = []
|
||||
for item in rolling_stock:
|
||||
data.append({
|
||||
"type": "rolling_stock",
|
||||
"item": item
|
||||
})
|
||||
|
||||
try: # Execute only if query_2nd is defined
|
||||
consists = (
|
||||
Consist.objects.filter(query_2nd)
|
||||
.distinct()
|
||||
)
|
||||
for item in consists:
|
||||
data.append({
|
||||
"type": "consist",
|
||||
"item": item
|
||||
})
|
||||
if _filter == "tag": # Books can be filtered only by tag
|
||||
books = (
|
||||
Book.objects.filter(query_2nd)
|
||||
.distinct()
|
||||
)
|
||||
for item in books:
|
||||
data.append({
|
||||
"type": "book",
|
||||
"item": item
|
||||
})
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
paginator = Paginator(data, site_conf.items_per_page)
|
||||
data = paginator.get_page(page)
|
||||
page_range = paginator.get_elided_page_range(
|
||||
rolling_stock.number, on_each_side=2, on_ends=1
|
||||
data.number, on_each_side=2, on_ends=1
|
||||
)
|
||||
|
||||
return rolling_stock, title, matches, page_range
|
||||
return data, title, paginator.count, page_range
|
||||
|
||||
def get(self, request, search, _filter, page=1):
|
||||
data, title, matches, page_range = self.run_filter(
|
||||
@@ -223,8 +302,8 @@ class GetRosterFiltered(View):
|
||||
_filter.capitalize(), title),
|
||||
"search": search,
|
||||
"filter": _filter,
|
||||
"matches": matches,
|
||||
"data": data,
|
||||
"matches": matches,
|
||||
"page_range": page_range,
|
||||
},
|
||||
)
|
||||
@@ -237,24 +316,36 @@ class GetRollingStock(View):
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404
|
||||
|
||||
class_properties = (
|
||||
rolling_stock.rolling_class.property.all()
|
||||
if request.user.is_authenticated
|
||||
else rolling_stock.rolling_class.property.filter(
|
||||
# FIXME there's likely a better and more efficient way of doing this
|
||||
# but keeping KISS for now
|
||||
decoder_documents = []
|
||||
if request.user.is_authenticated:
|
||||
class_properties = rolling_stock.rolling_class.property.all()
|
||||
properties = rolling_stock.property.all()
|
||||
documents = rolling_stock.document.all()
|
||||
journal = rolling_stock.journal.all()
|
||||
if rolling_stock.decoder:
|
||||
decoder_documents = rolling_stock.decoder.document.all()
|
||||
else:
|
||||
class_properties = rolling_stock.rolling_class.property.filter(
|
||||
property__private=False
|
||||
)
|
||||
properties = rolling_stock.property.filter(
|
||||
property__private=False
|
||||
)
|
||||
rolling_stock_properties = (
|
||||
rolling_stock.property.all()
|
||||
if request.user.is_authenticated
|
||||
else rolling_stock.property.filter(property__private=False)
|
||||
documents = rolling_stock.document.filter(private=False)
|
||||
journal = rolling_stock.journal.filter(private=False)
|
||||
if rolling_stock.decoder:
|
||||
decoder_documents = rolling_stock.decoder.document.filter(
|
||||
private=False
|
||||
)
|
||||
|
||||
rolling_stock_journal = (
|
||||
rolling_stock.journal.all()
|
||||
if request.user.is_authenticated
|
||||
else rolling_stock.journal.filter(private=False)
|
||||
)
|
||||
consists = [{
|
||||
"type": "consist",
|
||||
"item": c
|
||||
} for c in Consist.objects.filter(
|
||||
consist_item__rolling_stock=rolling_stock
|
||||
)] # A dict with "item" is required by the consists card
|
||||
|
||||
return render(
|
||||
request,
|
||||
@@ -263,17 +354,19 @@ class GetRollingStock(View):
|
||||
"title": rolling_stock,
|
||||
"rolling_stock": rolling_stock,
|
||||
"class_properties": class_properties,
|
||||
"rolling_stock_properties": rolling_stock_properties,
|
||||
"rolling_stock_journal": rolling_stock_journal,
|
||||
"properties": properties,
|
||||
"decoder_documents": decoder_documents,
|
||||
"documents": documents,
|
||||
"journal": journal,
|
||||
"consists": consists,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class Consists(GetData):
|
||||
def __init__(self):
|
||||
self.title = "Consists"
|
||||
self.template = "consists.html"
|
||||
self.data = Consist.objects.all()
|
||||
title = "Consists"
|
||||
item_type = "consist"
|
||||
queryset = Consist.objects.all()
|
||||
|
||||
|
||||
class GetConsist(View):
|
||||
@@ -283,15 +376,15 @@ class GetConsist(View):
|
||||
consist = Consist.objects.get(uuid=uuid)
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404
|
||||
rolling_stock = [
|
||||
RollingStock.objects.get(uuid=r.rolling_stock_id) for r in
|
||||
consist.consist_item.all()
|
||||
]
|
||||
data = [{
|
||||
"type": "rolling_stock",
|
||||
"item": RollingStock.objects.get(uuid=r.rolling_stock_id)
|
||||
} for r in consist.consist_item.all()]
|
||||
|
||||
paginator = Paginator(rolling_stock, site_conf.items_per_page)
|
||||
rolling_stock = paginator.get_page(page)
|
||||
paginator = Paginator(data, site_conf.items_per_page)
|
||||
data = paginator.get_page(page)
|
||||
page_range = paginator.get_elided_page_range(
|
||||
rolling_stock.number, on_each_side=2, on_ends=1
|
||||
data.number, on_each_side=2, on_ends=1
|
||||
)
|
||||
|
||||
return render(
|
||||
@@ -300,52 +393,47 @@ class GetConsist(View):
|
||||
{
|
||||
"title": consist,
|
||||
"consist": consist,
|
||||
"data": rolling_stock,
|
||||
"data": data,
|
||||
"page_range": page_range,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class Manufacturers(GetData):
|
||||
def __init__(self):
|
||||
self.title = "Manufacturers"
|
||||
self.template = "manufacturers.html"
|
||||
self.data = None # Set via method get
|
||||
title = "Manufacturers"
|
||||
item_type = "manufacturer"
|
||||
queryset = None # Set via method get
|
||||
|
||||
# overload get method to filter by category
|
||||
def get(self, request, category, page=1):
|
||||
if category not in ("real", "model"):
|
||||
raise Http404
|
||||
self.data = Manufacturer.objects.filter(category=category)
|
||||
self.queryset = Manufacturer.objects.filter(category=category)
|
||||
return super().get(request, page)
|
||||
|
||||
|
||||
class Companies(GetData):
|
||||
def __init__(self):
|
||||
self.title = "Companies"
|
||||
self.template = "companies.html"
|
||||
self.data = Company.objects.all()
|
||||
title = "Companies"
|
||||
item_type = "company"
|
||||
queryset = Company.objects.all()
|
||||
|
||||
|
||||
class Scales(GetData):
|
||||
def __init__(self):
|
||||
self.title = "Scales"
|
||||
self.template = "scales.html"
|
||||
self.data = Scale.objects.all()
|
||||
title = "Scales"
|
||||
item_type = "scale"
|
||||
queryset = Scale.objects.all()
|
||||
|
||||
|
||||
class Types(GetData):
|
||||
def __init__(self):
|
||||
self.title = "Types"
|
||||
self.template = "types.html"
|
||||
self.data = RollingStockType.objects.all()
|
||||
title = "Types"
|
||||
item_type = "rolling_stock_type"
|
||||
queryset = RollingStockType.objects.all()
|
||||
|
||||
|
||||
class Books(GetData):
|
||||
def __init__(self):
|
||||
self.title = "Books"
|
||||
self.template = "bookshelf/books.html"
|
||||
self.data = Book.objects.all()
|
||||
title = "Books"
|
||||
item_type = "book"
|
||||
queryset = Book.objects.all()
|
||||
|
||||
|
||||
class GetBook(View):
|
||||
@@ -373,10 +461,12 @@ class GetBook(View):
|
||||
|
||||
class GetFlatpage(View):
|
||||
def get(self, request, flatpage):
|
||||
_filter = Q(published=True) # Show only published pages
|
||||
if request.user.is_authenticated:
|
||||
_filter = Q() # Reset the filter if user is authenticated
|
||||
|
||||
try:
|
||||
flatpage = Flatpage.objects.get(
|
||||
Q(Q(path=flatpage) & Q(published=True))
|
||||
)
|
||||
flatpage = Flatpage.objects.filter(_filter).get(path=flatpage)
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from ram.utils import git_suffix
|
||||
|
||||
__version__ = "0.5.0"
|
||||
__version__ = "0.10.0"
|
||||
__version__ += git_suffix(__file__)
|
||||
|
@@ -1,10 +1,4 @@
|
||||
from django.contrib import admin
|
||||
from django.db.utils import OperationalError
|
||||
from portal.utils import get_site_conf
|
||||
from django.conf import settings
|
||||
|
||||
try:
|
||||
site_name = get_site_conf().site_name
|
||||
except OperationalError:
|
||||
site_name = "Train Assets Manager"
|
||||
|
||||
admin.site.site_header = site_name
|
||||
admin.site.site_header = settings.SITE_NAME
|
||||
|
14
ram/ram/apps.py
Normal file
14
ram/ram/apps.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from django.conf import settings
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class RamConfig(AppConfig):
|
||||
name = "ram"
|
||||
|
||||
def ready(self):
|
||||
cache_middleware = set([
|
||||
"django.middleware.cache.UpdateCacheMiddleware",
|
||||
"django.middleware.cache.FetchFromCacheMiddleware",
|
||||
])
|
||||
if cache_middleware.issubset(settings.MIDDLEWARE):
|
||||
from ram.signals import clear_cache # noqa: F401
|
@@ -1,7 +1,8 @@
|
||||
# vim: syntax=python
|
||||
from django.conf import settings
|
||||
|
||||
"""
|
||||
Django local_settings for ram project.
|
||||
Example of changes suitable for production
|
||||
"""
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
@@ -12,9 +13,23 @@ SECRET_KEY = (
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = False
|
||||
|
||||
# SECURITY WARNING: cache middlewares must be loaded before cookies one
|
||||
MIDDLEWARE = [
|
||||
"django.middleware.cache.UpdateCacheMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.cache.FetchFromCacheMiddleware",
|
||||
] + settings.MIDDLEWARE
|
||||
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.redis.RedisCache",
|
||||
"LOCATION": "redis://127.0.0.1:6379",
|
||||
}
|
||||
}
|
||||
|
||||
CACHE_MIDDLEWARE_SECONDS = 300
|
||||
STORAGE_DIR = BASE_DIR / "storage"
|
||||
ALLOWED_HOSTS = ["127.0.0.1"]
|
||||
ALLOWED_HOSTS = ["127.0.0.1", "myhost"]
|
||||
CSRF_TRUSTED_ORIGINS = ["https://myhost"]
|
||||
ROOT_URLCONF = "ram.urls"
|
||||
STATIC_URL = "static/"
|
||||
MEDIA_URL = "media/"
|
||||
|
@@ -11,9 +11,8 @@ class Document(models.Model):
|
||||
file = models.FileField(
|
||||
upload_to="files/",
|
||||
storage=DeduplicatedStorage(),
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
private = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
@@ -33,7 +32,8 @@ class Document(models.Model):
|
||||
class Image(models.Model):
|
||||
order = models.PositiveIntegerField(default=0, blank=False, null=False)
|
||||
image = models.ImageField(
|
||||
upload_to="images/", storage=DeduplicatedStorage, null=True, blank=True
|
||||
upload_to="images/",
|
||||
storage=DeduplicatedStorage,
|
||||
)
|
||||
|
||||
def image_thumbnail(self):
|
||||
|
@@ -41,17 +41,14 @@ INSTALLED_APPS = [
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"health_check",
|
||||
"health_check.db",
|
||||
"adminsortable2",
|
||||
"django_countries",
|
||||
"solo",
|
||||
"ckeditor",
|
||||
"ckeditor_uploader",
|
||||
"tinymce",
|
||||
"rest_framework",
|
||||
"ram",
|
||||
"portal",
|
||||
"driver",
|
||||
# "driver", # uncomment this to enable the "driver" API
|
||||
"metadata",
|
||||
"roster",
|
||||
"consist",
|
||||
@@ -62,7 +59,7 @@ MIDDLEWARE = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
# 'django.middleware.csrf.CsrfViewMiddleware',
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
@@ -144,12 +141,31 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
MEDIA_URL = "media/"
|
||||
MEDIA_ROOT = STORAGE_DIR / "media"
|
||||
CKEDITOR_UPLOAD_PATH = "uploads/"
|
||||
|
||||
TINYMCE_DEFAULT_CONFIG = {
|
||||
"height": "500px",
|
||||
"menubar": False,
|
||||
"plugins": "autolink lists link image charmap preview anchor "
|
||||
"searchreplace visualblocks code fullscreen insertdatetime media "
|
||||
"table paste code",
|
||||
"toolbar": "undo redo | "
|
||||
"bold italic underline strikethrough removeformat | "
|
||||
"fontsizeselect formatselect | "
|
||||
"alignleft aligncenter alignright alignjustify | "
|
||||
"outdent indent numlist bullist | "
|
||||
"insertfile image media pageembed template link anchor codesample | "
|
||||
"charmap | "
|
||||
"fullscreen preview code",
|
||||
"images_upload_url": "/tinymce/upload_image",
|
||||
}
|
||||
|
||||
COUNTRIES_OVERRIDE = {
|
||||
"ZZ": "Freelance",
|
||||
"EU": "Europe",
|
||||
"XX": "None",
|
||||
}
|
||||
|
||||
SITE_NAME = "Railroad Assets Manger"
|
||||
|
||||
# Image used on cards without a custom image uploaded.
|
||||
# The file must be placed in the root of the 'static' folder
|
||||
DEFAULT_CARD_IMAGE = "coming_soon.svg"
|
||||
|
8
ram/ram/signals.py
Normal file
8
ram/ram/signals.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.core.cache import cache
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
|
||||
@receiver(post_save)
|
||||
def clear_cache(sender, **kwargs):
|
||||
cache.clear()
|
@@ -13,24 +13,33 @@ Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.shortcuts import redirect
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
|
||||
from ram.views import UploadImage
|
||||
|
||||
urlpatterns = [
|
||||
path("", lambda r: redirect("portal/")),
|
||||
path("ckeditor/", include("ckeditor_uploader.urls")),
|
||||
path("tinymce/", include("tinymce.urls")),
|
||||
path("tinymce/upload_image", UploadImage.as_view(), name="upload_image"),
|
||||
path("portal/", include("portal.urls")),
|
||||
path("ht/", include("health_check.urls")),
|
||||
path("admin/", admin.site.urls),
|
||||
path("api/v1/consist/", include("consist.urls")),
|
||||
path("api/v1/roster/", include("roster.urls")),
|
||||
path("api/v1/dcc/", include("driver.urls")),
|
||||
path("api/v1/bookshelf/", include("bookshelf.urls")),
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
# Enable the "/dcc" routing only if the "driver" app is active
|
||||
if apps.is_installed("driver"):
|
||||
urlpatterns += [
|
||||
path("api/v1/dcc/", include("driver.urls")),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
from django.views.generic import TemplateView
|
||||
from rest_framework.schemas import get_schema_view
|
||||
@@ -54,3 +63,7 @@ if settings.DEBUG:
|
||||
name="openapi-schema",
|
||||
),
|
||||
]
|
||||
if apps.is_installed("debug_toolbar"):
|
||||
urlpatterns += [
|
||||
path("__debug__/", include("debug_toolbar.urls")),
|
||||
]
|
||||
|
62
ram/ram/views.py
Normal file
62
ram/ram/views.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import os
|
||||
import datetime
|
||||
import posixpath
|
||||
|
||||
from pathlib import Path
|
||||
from PIL import Image, UnidentifiedImageError
|
||||
|
||||
from django.views import View
|
||||
from django.conf import settings
|
||||
from django.http import (
|
||||
HttpResponseBadRequest,
|
||||
HttpResponseForbidden,
|
||||
JsonResponse,
|
||||
)
|
||||
from django.utils.text import slugify as slugify
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name="dispatch")
|
||||
class UploadImage(View):
|
||||
def post(self, request):
|
||||
if not request.user.is_authenticated:
|
||||
raise HttpResponseForbidden()
|
||||
|
||||
file_obj = request.FILES["file"]
|
||||
file_name, file_extension = os.path.splitext(file_obj.name)
|
||||
file_name = slugify(file_name) + file_extension
|
||||
|
||||
try:
|
||||
Image.open(file_obj)
|
||||
except UnidentifiedImageError:
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
today = datetime.date.today()
|
||||
container = (
|
||||
"uploads",
|
||||
today.strftime("%Y"),
|
||||
today.strftime("%m"),
|
||||
today.strftime("%d"),
|
||||
)
|
||||
|
||||
dir_path = os.path.join(settings.MEDIA_ROOT, *(p for p in container))
|
||||
file_path = os.path.normpath(os.path.join(dir_path, file_name))
|
||||
# even if we apply slugify to the file name, add more hardening
|
||||
# to avoid any path transversal risk
|
||||
if not file_path.startswith(str(settings.MEDIA_ROOT)):
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
Path(dir_path).mkdir(parents=True, exist_ok=True)
|
||||
with open(file_path, "wb+") as f:
|
||||
for chunk in file_obj.chunks():
|
||||
f.write(chunk)
|
||||
|
||||
return JsonResponse(
|
||||
{
|
||||
"message": "Image uploaded successfully",
|
||||
"location": posixpath.join(
|
||||
settings.MEDIA_URL, *(p for p in container), file_name
|
||||
),
|
||||
}
|
||||
)
|
@@ -28,6 +28,7 @@ class RollingClass(admin.ModelAdmin):
|
||||
"company__name",
|
||||
"type__type",
|
||||
)
|
||||
save_as = True
|
||||
|
||||
|
||||
class RollingStockDocInline(admin.TabularInline):
|
||||
@@ -64,6 +65,7 @@ class RollingStockDocumentAdmin(admin.ModelAdmin):
|
||||
"__str__",
|
||||
"rolling_stock",
|
||||
"description",
|
||||
"private",
|
||||
"download",
|
||||
)
|
||||
search_fields = (
|
||||
|
@@ -1,6 +1,7 @@
|
||||
# Generated by Django 4.1 on 2022-08-23 15:54
|
||||
|
||||
import ckeditor_uploader.fields
|
||||
# ckeditor removal
|
||||
# import ckeditor_uploader.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
@@ -11,9 +12,9 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="rollingstock",
|
||||
name="notes",
|
||||
field=ckeditor_uploader.fields.RichTextUploadingField(blank=True),
|
||||
),
|
||||
# migrations.AlterField(
|
||||
# model_name="rollingstock",
|
||||
# name="notes",
|
||||
# field=ckeditor_uploader.fields.RichTextUploadingField(blank=True),
|
||||
# ),
|
||||
]
|
||||
|
@@ -1,6 +1,7 @@
|
||||
# Generated by Django 4.1 on 2022-08-27 12:43
|
||||
|
||||
import ckeditor_uploader.fields
|
||||
# ckeditor removal
|
||||
# import ckeditor_uploader.fields
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
@@ -25,7 +26,8 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
),
|
||||
("date", models.DateField()),
|
||||
("log", ckeditor_uploader.fields.RichTextUploadingField()),
|
||||
# ("log", ckeditor_uploader.fields.RichTextUploadingField()),
|
||||
("log", models.TextField()),
|
||||
("private", models.BooleanField(default=False)),
|
||||
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_time", models.DateTimeField(auto_now=True)),
|
||||
|
18
ram/roster/migrations/0019_rollingstockdocument_private.py
Normal file
18
ram/roster/migrations/0019_rollingstockdocument_private.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.5 on 2023-10-06 19:48
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("roster", "0018_rename_sku_rollingstock_item_number"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="rollingstockdocument",
|
||||
name="private",
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
49
ram/roster/migrations/0020_alter_rollingstockimage_image.py
Normal file
49
ram/roster/migrations/0020_alter_rollingstockimage_image.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# Generated by Django 4.2.6 on 2023-10-30 13:16
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import ram.utils
|
||||
import roster.models
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def move_images(apps, schema_editor):
|
||||
sys.stdout.write("\n Processing files. Please await...")
|
||||
for r in roster.models.RollingStockImage.objects.all():
|
||||
fname = os.path.basename(r.image.path)
|
||||
new_image = roster.models.rolling_stock_image_upload(r, fname)
|
||||
new_path = os.path.join(settings.MEDIA_ROOT, new_image)
|
||||
os.makedirs(os.path.dirname(new_path), exist_ok=True)
|
||||
try:
|
||||
shutil.move(r.image.path, new_path)
|
||||
except FileNotFoundError:
|
||||
sys.stderr.write(" !! FileNotFoundError: {}\n".format(new_image))
|
||||
pass
|
||||
r.image.name = new_image
|
||||
r.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("roster", "0019_rollingstockdocument_private"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="rollingstockimage",
|
||||
name="image",
|
||||
field=models.ImageField(
|
||||
blank=True,
|
||||
null=True,
|
||||
storage=ram.utils.DeduplicatedStorage,
|
||||
upload_to=roster.models.rolling_stock_image_upload,
|
||||
),
|
||||
),
|
||||
migrations.RunPython(
|
||||
move_images,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 4.2.6 on 2023-11-04 22:53
|
||||
|
||||
from django.db import migrations, models
|
||||
import ram.utils
|
||||
import roster.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("roster", "0020_alter_rollingstockimage_image"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="rollingstockdocument",
|
||||
name="file",
|
||||
field=models.FileField(
|
||||
storage=ram.utils.DeduplicatedStorage(), upload_to="files/"
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="rollingstockimage",
|
||||
name="image",
|
||||
field=models.ImageField(
|
||||
storage=ram.utils.DeduplicatedStorage,
|
||||
upload_to=roster.models.rolling_stock_image_upload,
|
||||
),
|
||||
),
|
||||
]
|
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 5.0.2 on 2024-02-17 12:19
|
||||
|
||||
import tinymce.models
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("roster", "0021_alter_rollingstockdocument_file_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="rollingstock",
|
||||
name="notes",
|
||||
field=tinymce.models.HTMLField(blank=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="rollingstockjournal",
|
||||
name="log",
|
||||
field=tinymce.models.HTMLField(),
|
||||
),
|
||||
]
|
@@ -1,14 +1,16 @@
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
from uuid import uuid4
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.conf import settings
|
||||
from django.dispatch import receiver
|
||||
|
||||
from ckeditor_uploader.fields import RichTextUploadingField
|
||||
from tinymce import models as tinymce
|
||||
|
||||
from ram.models import Document, Image, PropertyInstance
|
||||
from ram.utils import get_image_preview
|
||||
from ram.utils import DeduplicatedStorage
|
||||
from metadata.models import (
|
||||
Scale,
|
||||
Manufacturer,
|
||||
@@ -83,7 +85,7 @@ class RollingStock(models.Model):
|
||||
era = models.CharField(max_length=32, blank=True)
|
||||
production_year = models.SmallIntegerField(null=True, blank=True)
|
||||
purchase_date = models.DateField(null=True, blank=True)
|
||||
notes = RichTextUploadingField(blank=True)
|
||||
notes = tinymce.HTMLField(blank=True)
|
||||
tags = models.ManyToManyField(
|
||||
Tag, related_name="rolling_stock", blank=True
|
||||
)
|
||||
@@ -106,6 +108,15 @@ class RollingStock(models.Model):
|
||||
def company(self):
|
||||
return str(self.rolling_class.company)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
shutil.rmtree(
|
||||
os.path.join(
|
||||
settings.MEDIA_ROOT, "images", "rollingstock", str(self.uuid)
|
||||
),
|
||||
ignore_errors=True
|
||||
)
|
||||
super(RollingStock, self).delete(*args, **kwargs)
|
||||
|
||||
|
||||
@receiver(models.signals.pre_save, sender=RollingStock)
|
||||
def pre_save_running_number(sender, instance, *args, **kwargs):
|
||||
@@ -126,10 +137,23 @@ class RollingStockDocument(Document):
|
||||
unique_together = ("rolling_stock", "file")
|
||||
|
||||
|
||||
def rolling_stock_image_upload(instance, filename):
|
||||
return os.path.join(
|
||||
"images",
|
||||
"rollingstock",
|
||||
str(instance.rolling_stock.uuid),
|
||||
filename
|
||||
)
|
||||
|
||||
|
||||
class RollingStockImage(Image):
|
||||
rolling_stock = models.ForeignKey(
|
||||
RollingStock, on_delete=models.CASCADE, related_name="image"
|
||||
)
|
||||
image = models.ImageField(
|
||||
upload_to=rolling_stock_image_upload,
|
||||
storage=DeduplicatedStorage,
|
||||
)
|
||||
|
||||
|
||||
class RollingStockProperty(PropertyInstance):
|
||||
@@ -151,7 +175,7 @@ class RollingStockJournal(models.Model):
|
||||
blank=False,
|
||||
)
|
||||
date = models.DateField()
|
||||
log = RichTextUploadingField()
|
||||
log = tinymce.HTMLField()
|
||||
private = models.BooleanField(default=False)
|
||||
creation_time = models.DateTimeField(auto_now_add=True)
|
||||
updated_time = models.DateTimeField(auto_now=True)
|
||||
|
@@ -1 +1,2 @@
|
||||
gunicorn
|
||||
# Optional: # pylibmc
|
||||
|
@@ -7,6 +7,9 @@ django-solo
|
||||
django-countries
|
||||
django-health-check
|
||||
django-admin-sortable2
|
||||
django-ckeditor
|
||||
# psycopg2-binary
|
||||
pySerial
|
||||
django-tinymce
|
||||
# Optional: # psycopg2-binary
|
||||
# Optional: # pySerial
|
||||
# Required by django-countries and not always installed
|
||||
# by default on modern venvs (like Python 3.12 on Fedora 39)
|
||||
setuptools
|
||||
|
BIN
sample_data/background.png
Normal file
BIN
sample_data/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Reference in New Issue
Block a user