mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Add Catalogs views, but still need to fix templates (use books for now)
This commit is contained in:
@@ -139,4 +139,4 @@ class CatalogAdmin(SortableAdminBase, admin.ModelAdmin):
|
||||
|
||||
@admin.display(description="Scales")
|
||||
def get_scales(self, obj):
|
||||
return ", ".join(s.scale for s in obj.scales.all())
|
||||
return "/".join(s.scale for s in obj.scales.all())
|
||||
|
@@ -54,9 +54,6 @@ class BaseBook(BaseModel):
|
||||
Tag, related_name="bookshelf", blank=True
|
||||
)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("book", kwargs={"uuid": self.uuid})
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
shutil.rmtree(
|
||||
os.path.join(
|
||||
@@ -110,6 +107,9 @@ class Book(BaseBook):
|
||||
def publisher_name(self):
|
||||
return self.publisher.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("book", kwargs={"uuid": self.uuid})
|
||||
|
||||
|
||||
class Catalog(BaseBook):
|
||||
manufacturer = models.ForeignKey(
|
||||
@@ -127,3 +127,6 @@ class Catalog(BaseBook):
|
||||
def __str__(self):
|
||||
scales = "/".join([s.scale for s in self.scales.all()])
|
||||
return "%s %s %s" % (self.manufacturer.name, self.years, scales)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("catalog", kwargs={"uuid": self.uuid})
|
||||
|
@@ -5,6 +5,7 @@
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="bookshelfDropdownMenuLink">
|
||||
<li><a class="dropdown-item" href="{% url 'books' %}">Books</a></li>
|
||||
<li><a class="dropdown-item" href="{% url 'catalogs' %}">Catalogs</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
@@ -1,13 +1,15 @@
|
||||
from django import template
|
||||
from portal.models import Flatpage
|
||||
from bookshelf.models import Book
|
||||
from bookshelf.models import Book, Catalog
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.inclusion_tag('bookshelf/bookshelf_menu.html')
|
||||
def show_bookshelf_menu():
|
||||
return {"bookshelf_menu": Book.objects.exists()}
|
||||
return {
|
||||
"bookshelf_menu": (Book.objects.exists() or Catalog.objects.exists())
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag('flatpages/flatpages_menu.html')
|
||||
|
@@ -15,6 +15,8 @@ from portal.views import (
|
||||
Types,
|
||||
Books,
|
||||
GetBook,
|
||||
Catalogs,
|
||||
GetCatalog,
|
||||
SearchObjects,
|
||||
)
|
||||
|
||||
@@ -98,6 +100,21 @@ urlpatterns = [
|
||||
name="books_pagination"
|
||||
),
|
||||
path("bookshelf/book/<uuid:uuid>", GetBook.as_view(), name="book"),
|
||||
path(
|
||||
"bookshelf/catalogs",
|
||||
Catalogs.as_view(template="bookshelf/books.html"),
|
||||
name="catalogs"
|
||||
),
|
||||
path(
|
||||
"bookshelf/catalogs/page/<int:page>",
|
||||
Catalogs.as_view(template="bookshelf/books.html"),
|
||||
name="catalogs_pagination"
|
||||
),
|
||||
path(
|
||||
"bookshelf/catalog/<uuid:uuid>",
|
||||
GetCatalog.as_view(),
|
||||
name="catalog"
|
||||
),
|
||||
path(
|
||||
"search",
|
||||
SearchObjects.as_view(http_method_names=["post"]),
|
||||
|
@@ -15,7 +15,7 @@ from portal.utils import get_site_conf
|
||||
from portal.models import Flatpage
|
||||
from roster.models import RollingStock
|
||||
from consist.models import Consist
|
||||
from bookshelf.models import Book
|
||||
from bookshelf.models import Book, Catalog
|
||||
from metadata.models import (
|
||||
Company,
|
||||
Manufacturer,
|
||||
@@ -536,6 +536,34 @@ class GetBook(View):
|
||||
)
|
||||
|
||||
|
||||
class Catalogs(GetData):
|
||||
title = "Catalogs"
|
||||
item_type = "book"
|
||||
|
||||
def get_data(self, request):
|
||||
return Catalog.objects.get_published(request.user).all()
|
||||
|
||||
|
||||
class GetCatalog(View):
|
||||
def get(self, request, uuid):
|
||||
try:
|
||||
catalog = Catalog.objects.get_published(request.user).get(uuid=uuid)
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404
|
||||
|
||||
catalog_properties = catalog.property.get_public(request.user)
|
||||
return render(
|
||||
request,
|
||||
"bookshelf/book.html",
|
||||
{
|
||||
"title": catalog,
|
||||
"catalog_properties": catalog_properties,
|
||||
"book": catalog,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
||||
class GetFlatpage(View):
|
||||
def get(self, request, flatpage):
|
||||
try:
|
||||
|
Reference in New Issue
Block a user