mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-07 06:37:50 +02:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
e7d34ce8e0
|
|||
19eb70c492 | |||
4428b8c11d | |||
8400a5acd3
|
|||
7dadf23f5f
|
|||
4a12201d22
|
|||
830da80302 | |||
416ca5bbc6
|
|||
03fc82c38d
|
|||
ec8684dbc0
|
|||
7ec8baf733
|
Submodule arduino/CommandStation-EX updated: 2db2b0ecc6...3b162996ad
@@ -1,6 +1,7 @@
|
|||||||
# Generated by Django 4.2.5 on 2023-10-01 20:16
|
# 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
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
import uuid
|
import uuid
|
||||||
@@ -47,7 +48,8 @@ class Migration(migrations.Migration):
|
|||||||
("ISBN", models.CharField(max_length=13, unique=True)),
|
("ISBN", models.CharField(max_length=13, unique=True)),
|
||||||
("publication_year", models.SmallIntegerField(blank=True, null=True)),
|
("publication_year", models.SmallIntegerField(blank=True, null=True)),
|
||||||
("purchase_date", models.DateField(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)),
|
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||||
("updated_time", models.DateTimeField(auto_now=True)),
|
("updated_time", models.DateTimeField(auto_now=True)),
|
||||||
("authors", models.ManyToManyField(to="bookshelf.author")),
|
("authors", models.ManyToManyField(to="bookshelf.author")),
|
||||||
|
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 uuid import uuid4
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django_countries.fields import CountryField
|
from django_countries.fields import CountryField
|
||||||
|
|
||||||
from ckeditor_uploader.fields import RichTextUploadingField
|
from tinymce import models as tinymce
|
||||||
|
|
||||||
from metadata.models import Tag
|
from metadata.models import Tag
|
||||||
from ram.utils import DeduplicatedStorage
|
from ram.utils import DeduplicatedStorage
|
||||||
@@ -54,7 +56,7 @@ class Book(models.Model):
|
|||||||
tags = models.ManyToManyField(
|
tags = models.ManyToManyField(
|
||||||
Tag, related_name="bookshelf", blank=True
|
Tag, related_name="bookshelf", blank=True
|
||||||
)
|
)
|
||||||
notes = RichTextUploadingField(blank=True)
|
notes = tinymce.HTMLField(blank=True)
|
||||||
creation_time = models.DateTimeField(auto_now_add=True)
|
creation_time = models.DateTimeField(auto_now_add=True)
|
||||||
updated_time = models.DateTimeField(auto_now=True)
|
updated_time = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
@@ -70,16 +72,32 @@ class Book(models.Model):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("book", kwargs={"uuid": self.uuid})
|
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):
|
class BookImage(Image):
|
||||||
book = models.ForeignKey(
|
book = models.ForeignKey(
|
||||||
Book, on_delete=models.CASCADE, related_name="image"
|
Book, on_delete=models.CASCADE, related_name="image"
|
||||||
)
|
)
|
||||||
image = models.ImageField(
|
image = models.ImageField(
|
||||||
upload_to="images/books/", # FIXME, find a better way to replace this
|
upload_to=book_image_upload,
|
||||||
storage=DeduplicatedStorage,
|
storage=DeduplicatedStorage,
|
||||||
null=True,
|
|
||||||
blank=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
# Generated by Django 4.1 on 2022-08-23 15:54
|
# 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
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
@@ -11,9 +12,9 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterField(
|
# migrations.AlterField(
|
||||||
model_name="consist",
|
# model_name="consist",
|
||||||
name="notes",
|
# name="notes",
|
||||||
field=ckeditor_uploader.fields.RichTextUploadingField(blank=True),
|
# 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 uuid import uuid4
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from ckeditor_uploader.fields import RichTextUploadingField
|
from tinymce import models as tinymce
|
||||||
|
|
||||||
from ram.utils import DeduplicatedStorage
|
from ram.utils import DeduplicatedStorage
|
||||||
from metadata.models import Company, Tag
|
from metadata.models import Company, Tag
|
||||||
@@ -19,9 +21,12 @@ class Consist(models.Model):
|
|||||||
company = models.ForeignKey(Company, on_delete=models.CASCADE)
|
company = models.ForeignKey(Company, on_delete=models.CASCADE)
|
||||||
era = models.CharField(max_length=32, blank=True)
|
era = models.CharField(max_length=32, blank=True)
|
||||||
image = models.ImageField(
|
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)
|
creation_time = models.DateTimeField(auto_now_add=True)
|
||||||
updated_time = models.DateTimeField(auto_now=True)
|
updated_time = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
@@ -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.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -28,7 +29,10 @@ class Manufacturer(models.Model):
|
|||||||
)
|
)
|
||||||
website = models.URLField(blank=True)
|
website = models.URLField(blank=True)
|
||||||
logo = models.ImageField(
|
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:
|
class Meta:
|
||||||
@@ -58,7 +62,10 @@ class Company(models.Model):
|
|||||||
country = CountryField()
|
country = CountryField()
|
||||||
freelance = models.BooleanField(default=False)
|
freelance = models.BooleanField(default=False)
|
||||||
logo = models.ImageField(
|
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:
|
class Meta:
|
||||||
@@ -95,7 +102,10 @@ class Decoder(models.Model):
|
|||||||
version = models.CharField(max_length=64, blank=True)
|
version = models.CharField(max_length=64, blank=True)
|
||||||
sound = models.BooleanField(default=False)
|
sound = models.BooleanField(default=False)
|
||||||
image = models.ImageField(
|
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):
|
class Meta(object):
|
||||||
|
@@ -6,6 +6,7 @@ from portal.models import SiteConfiguration, Flatpage
|
|||||||
|
|
||||||
@admin.register(SiteConfiguration)
|
@admin.register(SiteConfiguration)
|
||||||
class SiteConfigurationAdmin(SingletonModelAdmin):
|
class SiteConfigurationAdmin(SingletonModelAdmin):
|
||||||
|
readonly_fields = ("site_name",)
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(
|
(
|
||||||
None,
|
None,
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
# Generated by Django 4.1 on 2022-08-23 15:54
|
# Generated by Django 4.1 on 2022-08-23 15:54
|
||||||
|
|
||||||
import ckeditor.fields
|
# ckeditor dependency removal
|
||||||
import ckeditor_uploader.fields
|
# import ckeditor.fields
|
||||||
|
# import ckeditor_uploader.fields
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
@@ -12,24 +13,24 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterField(
|
# migrations.AlterField(
|
||||||
model_name="flatpage",
|
# model_name="flatpage",
|
||||||
name="content",
|
# name="content",
|
||||||
field=ckeditor_uploader.fields.RichTextUploadingField(),
|
# field=ckeditor_uploader.fields.RichTextUploadingField(),
|
||||||
),
|
# ),
|
||||||
migrations.AlterField(
|
# migrations.AlterField(
|
||||||
model_name="siteconfiguration",
|
# model_name="siteconfiguration",
|
||||||
name="about",
|
# name="about",
|
||||||
field=ckeditor.fields.RichTextField(blank=True),
|
# field=ckeditor.fields.RichTextField(blank=True),
|
||||||
),
|
# ),
|
||||||
migrations.AlterField(
|
# migrations.AlterField(
|
||||||
model_name="siteconfiguration",
|
# model_name="siteconfiguration",
|
||||||
name="footer",
|
# name="footer",
|
||||||
field=ckeditor.fields.RichTextField(blank=True),
|
# field=ckeditor.fields.RichTextField(blank=True),
|
||||||
),
|
# ),
|
||||||
migrations.AlterField(
|
# migrations.AlterField(
|
||||||
model_name="siteconfiguration",
|
# model_name="siteconfiguration",
|
||||||
name="footer_extended",
|
# name="footer_extended",
|
||||||
field=ckeditor.fields.RichTextField(blank=True),
|
# 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
|
import django
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.conf import settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.dispatch.dispatcher import receiver
|
from django.dispatch.dispatcher import receiver
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from solo.models import SingletonModel
|
from solo.models import SingletonModel
|
||||||
|
|
||||||
from ckeditor.fields import RichTextField
|
from tinymce import models as tinymce
|
||||||
from ckeditor_uploader.fields import RichTextUploadingField
|
|
||||||
|
|
||||||
from ram import __version__ as app_version
|
from ram import __version__ as app_version
|
||||||
from ram.utils import slugify
|
from ram.utils import slugify
|
||||||
|
|
||||||
|
|
||||||
class SiteConfiguration(SingletonModel):
|
class SiteConfiguration(SingletonModel):
|
||||||
site_name = models.CharField(
|
|
||||||
max_length=256, default="Railroad Assets Manager"
|
|
||||||
)
|
|
||||||
site_author = models.CharField(max_length=256, blank=True)
|
site_author = models.CharField(max_length=256, blank=True)
|
||||||
about = RichTextField(blank=True)
|
about = tinymce.HTMLField(blank=True)
|
||||||
items_per_page = models.CharField(
|
items_per_page = models.CharField(
|
||||||
max_length=2,
|
max_length=2,
|
||||||
choices=[(str(x * 3), str(x * 3)) for x in range(2, 11)],
|
choices=[(str(x * 3), str(x * 3)) for x in range(2, 11)],
|
||||||
@@ -32,8 +29,8 @@ class SiteConfiguration(SingletonModel):
|
|||||||
],
|
],
|
||||||
default="type",
|
default="type",
|
||||||
)
|
)
|
||||||
footer = RichTextField(blank=True)
|
footer = tinymce.HTMLField(blank=True)
|
||||||
footer_extended = RichTextField(blank=True)
|
footer_extended = tinymce.HTMLField(blank=True)
|
||||||
show_version = models.BooleanField(default=True)
|
show_version = models.BooleanField(default=True)
|
||||||
use_cdn = models.BooleanField(default=True)
|
use_cdn = models.BooleanField(default=True)
|
||||||
extra_head = models.TextField(blank=True)
|
extra_head = models.TextField(blank=True)
|
||||||
@@ -44,6 +41,9 @@ class SiteConfiguration(SingletonModel):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Site Configuration"
|
return "Site Configuration"
|
||||||
|
|
||||||
|
def site_name(self):
|
||||||
|
return settings.SITE_NAME
|
||||||
|
|
||||||
def version(self):
|
def version(self):
|
||||||
return app_version
|
return app_version
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ class Flatpage(models.Model):
|
|||||||
name = models.CharField(max_length=256, unique=True)
|
name = models.CharField(max_length=256, unique=True)
|
||||||
path = models.CharField(max_length=256, unique=True)
|
path = models.CharField(max_length=256, unique=True)
|
||||||
published = models.BooleanField(default=False)
|
published = models.BooleanField(default=False)
|
||||||
content = RichTextUploadingField()
|
content = tinymce.HTMLField()
|
||||||
creation_time = models.DateTimeField(auto_now_add=True)
|
creation_time = models.DateTimeField(auto_now_add=True)
|
||||||
updated_time = models.DateTimeField(auto_now=True)
|
updated_time = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
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,19 +115,19 @@
|
|||||||
})
|
})
|
||||||
})()
|
})()
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
var selectElement = document.getElementById('tabSelector');
|
var selectElement = document.getElementById('tabSelector');
|
||||||
selectElement.addEventListener('change', function () {
|
selectElement.addEventListener('change', function () {
|
||||||
var selectedTabId = this.value;
|
var selectedTabId = this.value;
|
||||||
var tabs = document.querySelectorAll('.tab-pane');
|
var tabs = document.querySelectorAll('.tab-pane');
|
||||||
tabs.forEach(function (tab) {
|
tabs.forEach(function (tab) {
|
||||||
tab.classList.remove('show', 'active');
|
tab.classList.remove('show', 'active');
|
||||||
});
|
});
|
||||||
document.getElementById(selectedTabId).classList.add('show', 'active');
|
document.getElementById(selectedTabId).classList.add('show', 'active');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% block extra_head %}
|
{% block extra_head %}
|
||||||
{{ site_conf.extra_head | safe }}
|
{{ site_conf.extra_head | safe }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="card shadow-sm">
|
<div class="card shadow-sm">
|
||||||
{% if d.item.image.exists %}
|
{% 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 }}"></a>
|
<a href="{{d.item.get_absolute_url}}"><img class="card-img-top" src="{{ d.item.image.first.image.url }}" alt="{{ d.item }}"></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p class="card-text" style="position: relative;">
|
<p class="card-text" style="position: relative;">
|
||||||
|
@@ -2,10 +2,10 @@
|
|||||||
<div class="card shadow-sm">
|
<div class="card shadow-sm">
|
||||||
<a href="{{ d.item.get_absolute_url }}">
|
<a href="{{ d.item.get_absolute_url }}">
|
||||||
{% if d.item.image %}
|
{% if d.item.image %}
|
||||||
<img class="card-img-top" src="{{ d.item.image.url }}" alt="{{ d }}">
|
<img class="card-img-top" src="{{ d.item.image.url }}" alt="{{ d.item }}">
|
||||||
{% else %}
|
{% else %}
|
||||||
{% with d.item.consist_item.first.rolling_stock as r %}
|
{% with d.item.consist_item.first.rolling_stock as r %}
|
||||||
<img class="card-img-top" src="{{ r.image.first.image.url }}" alt="{{ d }}">
|
<img class="card-img-top" src="{{ r.image.first.image.url }}" alt="{{ d.item }}">
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
|
@@ -2,10 +2,10 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="card shadow-sm">
|
<div class="card shadow-sm">
|
||||||
{% if d.item.image.exists %}
|
{% 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 }}"></a>
|
<a href="{{d.item.get_absolute_url}}"><img class="card-img-top" src="{{ d.item.image.first.image.url }}" alt="{{ d.item }}"></a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<!-- Do not show the "Coming soon" image when running in a single card column mode (e.g. on mobile) -->
|
<!-- 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 }}"></a>
|
<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 %}
|
{% endif %}
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p class="card-text" style="position: relative;">
|
<p class="card-text" style="position: relative;">
|
||||||
|
@@ -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">
|
<div class="input-group has-validation">
|
||||||
<input class="form-control" type="search" list="datalistOptions" placeholder="Search" aria-label="Search" name="search" id="searchValidation" required>
|
<input class="form-control" type="search" list="datalistOptions" placeholder="Search" aria-label="Search" name="search" id="searchValidation" required>
|
||||||
<datalist id="datalistOptions">
|
<datalist id="datalistOptions">
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
from ram.utils import git_suffix
|
from ram.utils import git_suffix
|
||||||
|
|
||||||
__version__ = "0.9.2"
|
__version__ = "0.10.0"
|
||||||
__version__ += git_suffix(__file__)
|
__version__ += git_suffix(__file__)
|
||||||
|
@@ -1,10 +1,4 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.db.utils import OperationalError, ProgrammingError
|
from django.conf import settings
|
||||||
from portal.utils import get_site_conf
|
|
||||||
|
|
||||||
try:
|
admin.site.site_header = settings.SITE_NAME
|
||||||
site_name = get_site_conf().site_name
|
|
||||||
except (OperationalError, ProgrammingError):
|
|
||||||
site_name = "Train Assets Manager"
|
|
||||||
|
|
||||||
admin.site.site_header = site_name
|
|
||||||
|
@@ -11,8 +11,6 @@ class Document(models.Model):
|
|||||||
file = models.FileField(
|
file = models.FileField(
|
||||||
upload_to="files/",
|
upload_to="files/",
|
||||||
storage=DeduplicatedStorage(),
|
storage=DeduplicatedStorage(),
|
||||||
null=True,
|
|
||||||
blank=True,
|
|
||||||
)
|
)
|
||||||
private = models.BooleanField(default=False)
|
private = models.BooleanField(default=False)
|
||||||
|
|
||||||
@@ -34,7 +32,8 @@ class Document(models.Model):
|
|||||||
class Image(models.Model):
|
class Image(models.Model):
|
||||||
order = models.PositiveIntegerField(default=0, blank=False, null=False)
|
order = models.PositiveIntegerField(default=0, blank=False, null=False)
|
||||||
image = models.ImageField(
|
image = models.ImageField(
|
||||||
upload_to="images/", storage=DeduplicatedStorage, null=True, blank=True
|
upload_to="images/",
|
||||||
|
storage=DeduplicatedStorage,
|
||||||
)
|
)
|
||||||
|
|
||||||
def image_thumbnail(self):
|
def image_thumbnail(self):
|
||||||
|
@@ -44,12 +44,11 @@ INSTALLED_APPS = [
|
|||||||
"adminsortable2",
|
"adminsortable2",
|
||||||
"django_countries",
|
"django_countries",
|
||||||
"solo",
|
"solo",
|
||||||
"ckeditor",
|
"tinymce",
|
||||||
"ckeditor_uploader",
|
|
||||||
"rest_framework",
|
"rest_framework",
|
||||||
"ram",
|
"ram",
|
||||||
"portal",
|
"portal",
|
||||||
# "driver",
|
# "driver", # uncomment this to enable the "driver" API
|
||||||
"metadata",
|
"metadata",
|
||||||
"roster",
|
"roster",
|
||||||
"consist",
|
"consist",
|
||||||
@@ -60,7 +59,7 @@ MIDDLEWARE = [
|
|||||||
"django.middleware.security.SecurityMiddleware",
|
"django.middleware.security.SecurityMiddleware",
|
||||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
"django.middleware.common.CommonMiddleware",
|
"django.middleware.common.CommonMiddleware",
|
||||||
# 'django.middleware.csrf.CsrfViewMiddleware',
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||||
"django.contrib.messages.middleware.MessageMiddleware",
|
"django.contrib.messages.middleware.MessageMiddleware",
|
||||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
@@ -142,12 +141,31 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|||||||
|
|
||||||
MEDIA_URL = "media/"
|
MEDIA_URL = "media/"
|
||||||
MEDIA_ROOT = STORAGE_DIR / "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 = {
|
COUNTRIES_OVERRIDE = {
|
||||||
"ZZ": "Freelance",
|
"EU": "Europe",
|
||||||
|
"XX": "None",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SITE_NAME = "Railroad Assets Manger"
|
||||||
|
|
||||||
# Image used on cards without a custom image uploaded.
|
# Image used on cards without a custom image uploaded.
|
||||||
# The file must be placed in the root of the 'static' folder
|
# The file must be placed in the root of the 'static' folder
|
||||||
DEFAULT_CARD_IMAGE = "coming_soon.svg"
|
DEFAULT_CARD_IMAGE = "coming_soon.svg"
|
||||||
|
@@ -13,6 +13,7 @@ Including another URLconf
|
|||||||
1. Import the include() function: from django.urls import include, path
|
1. Import the include() function: from django.urls import include, path
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
@@ -20,9 +21,12 @@ from django.conf.urls.static import static
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
|
|
||||||
|
from ram.views import UploadImage
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", lambda r: redirect("portal/")),
|
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("portal/", include("portal.urls")),
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
path("api/v1/consist/", include("consist.urls")),
|
path("api/v1/consist/", include("consist.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
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
@@ -1,6 +1,7 @@
|
|||||||
# Generated by Django 4.1 on 2022-08-23 15:54
|
# 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
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
@@ -11,9 +12,9 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterField(
|
# migrations.AlterField(
|
||||||
model_name="rollingstock",
|
# model_name="rollingstock",
|
||||||
name="notes",
|
# name="notes",
|
||||||
field=ckeditor_uploader.fields.RichTextUploadingField(blank=True),
|
# field=ckeditor_uploader.fields.RichTextUploadingField(blank=True),
|
||||||
),
|
# ),
|
||||||
]
|
]
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
# Generated by Django 4.1 on 2022-08-27 12:43
|
# 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
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
|
||||||
@@ -25,7 +26,8 @@ class Migration(migrations.Migration):
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
("date", models.DateField()),
|
("date", models.DateField()),
|
||||||
("log", ckeditor_uploader.fields.RichTextUploadingField()),
|
# ("log", ckeditor_uploader.fields.RichTextUploadingField()),
|
||||||
|
("log", models.TextField()),
|
||||||
("private", models.BooleanField(default=False)),
|
("private", models.BooleanField(default=False)),
|
||||||
("creation_time", models.DateTimeField(auto_now_add=True)),
|
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||||
("updated_time", models.DateTimeField(auto_now=True)),
|
("updated_time", models.DateTimeField(auto_now=True)),
|
||||||
|
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 re
|
||||||
|
import shutil
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.dispatch import receiver
|
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.models import Document, Image, PropertyInstance
|
||||||
from ram.utils import get_image_preview
|
from ram.utils import DeduplicatedStorage
|
||||||
from metadata.models import (
|
from metadata.models import (
|
||||||
Scale,
|
Scale,
|
||||||
Manufacturer,
|
Manufacturer,
|
||||||
@@ -83,7 +85,7 @@ class RollingStock(models.Model):
|
|||||||
era = models.CharField(max_length=32, blank=True)
|
era = models.CharField(max_length=32, blank=True)
|
||||||
production_year = models.SmallIntegerField(null=True, blank=True)
|
production_year = models.SmallIntegerField(null=True, blank=True)
|
||||||
purchase_date = models.DateField(null=True, blank=True)
|
purchase_date = models.DateField(null=True, blank=True)
|
||||||
notes = RichTextUploadingField(blank=True)
|
notes = tinymce.HTMLField(blank=True)
|
||||||
tags = models.ManyToManyField(
|
tags = models.ManyToManyField(
|
||||||
Tag, related_name="rolling_stock", blank=True
|
Tag, related_name="rolling_stock", blank=True
|
||||||
)
|
)
|
||||||
@@ -106,6 +108,15 @@ class RollingStock(models.Model):
|
|||||||
def company(self):
|
def company(self):
|
||||||
return str(self.rolling_class.company)
|
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)
|
@receiver(models.signals.pre_save, sender=RollingStock)
|
||||||
def pre_save_running_number(sender, instance, *args, **kwargs):
|
def pre_save_running_number(sender, instance, *args, **kwargs):
|
||||||
@@ -126,10 +137,23 @@ class RollingStockDocument(Document):
|
|||||||
unique_together = ("rolling_stock", "file")
|
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):
|
class RollingStockImage(Image):
|
||||||
rolling_stock = models.ForeignKey(
|
rolling_stock = models.ForeignKey(
|
||||||
RollingStock, on_delete=models.CASCADE, related_name="image"
|
RollingStock, on_delete=models.CASCADE, related_name="image"
|
||||||
)
|
)
|
||||||
|
image = models.ImageField(
|
||||||
|
upload_to=rolling_stock_image_upload,
|
||||||
|
storage=DeduplicatedStorage,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RollingStockProperty(PropertyInstance):
|
class RollingStockProperty(PropertyInstance):
|
||||||
@@ -151,7 +175,7 @@ class RollingStockJournal(models.Model):
|
|||||||
blank=False,
|
blank=False,
|
||||||
)
|
)
|
||||||
date = models.DateField()
|
date = models.DateField()
|
||||||
log = RichTextUploadingField()
|
log = tinymce.HTMLField()
|
||||||
private = models.BooleanField(default=False)
|
private = models.BooleanField(default=False)
|
||||||
creation_time = models.DateTimeField(auto_now_add=True)
|
creation_time = models.DateTimeField(auto_now_add=True)
|
||||||
updated_time = models.DateTimeField(auto_now=True)
|
updated_time = models.DateTimeField(auto_now=True)
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
gunicorn
|
gunicorn
|
||||||
pylibmc
|
# Optional: # pylibmc
|
||||||
|
@@ -7,7 +7,7 @@ django-solo
|
|||||||
django-countries
|
django-countries
|
||||||
django-health-check
|
django-health-check
|
||||||
django-admin-sortable2
|
django-admin-sortable2
|
||||||
django-ckeditor
|
django-tinymce
|
||||||
# Optional: # psycopg2-binary
|
# Optional: # psycopg2-binary
|
||||||
# Optional: # pySerial
|
# Optional: # pySerial
|
||||||
# Required by django-countries and not always installed
|
# Required by django-countries and not always installed
|
||||||
|
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