Skip to content

Commit

Permalink
Web bookshelf first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
daniviga committed Oct 2, 2023
1 parent 3f90587 commit 996ddd6
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ram/bookshelf/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BookAdmin(SortableAdminBase, admin.ModelAdmin):
"get_authors",
"get_publisher",
"publication_year",
"numbers_of_pages"
"number_of_pages"
)
search_fields = ("title", "publisher__name", "authors__last_name")
list_filter = ("publisher__name", "authors")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.5 on 2023-10-02 20:38

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("bookshelf", "0003_bookimage"),
]

operations = [
migrations.RenameField(
model_name="book",
old_name="numbers_of_pages",
new_name="number_of_pages",
),
]
5 changes: 3 additions & 2 deletions ram/bookshelf/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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
Expand Down Expand Up @@ -41,7 +42,7 @@ class Book(models.Model):
choices=settings.LANGUAGES,
default='en'
)
numbers_of_pages = models.SmallIntegerField(null=True, blank=True)
number_of_pages = models.SmallIntegerField(null=True, blank=True)
publication_year = models.SmallIntegerField(null=True, blank=True)
purchase_date = models.DateField(null=True, blank=True)
tags = models.ManyToManyField(
Expand All @@ -58,7 +59,7 @@ def publisher_name(self):
return self.publisher.name

# def get_absolute_url(self):
# return reverse("rolling_stock", kwargs={"uuid": self.uuid})
# return reverse("books", kwargs={"uuid": self.uuid})


class BookImage(Image):
Expand Down
104 changes: 104 additions & 0 deletions ram/portal/templates/books.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{% extends "cards.html" %}

{% block cards %}
{% for d in data %}
<div class="col">
<div class="card shadow-sm">
{% if d.image.all %}
{# FIXME <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 %}
{# FIXME </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 }}</td>
</tr>
<tr>
<th scope="row">Year</th>
<td>{{ d.publication_year }}</td>
</tr>
</tbody>
</table>
<div class="d-grid gap-2 mb-1 d-md-block">
{# FIXME <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">
<ul class="pagination justify-content-center mt-4 mb-0">
{% if data.has_previous %}
<li class="page-item">
<a class="page-link" href="{% url 'books_pagination' page=data.previous_page_number %}#rolling-stock" tabindex="-1">Previous</a>
</li>
{% else %}
<li class="page-item disabled">
<span class="page-link">Previous</span>
</li>
{% endif %}
{% for i in page_range %}
{% if data.number == i %}
<li class="page-item active">
<span class="page-link">{{ i }}</span>
</li>
{% else %}
{% 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 'books_pagination' page=i %}#rolling-stock">{{ i }}</a></li>
{% endif %}
{% endif %}
{% endfor %}
{% if data.has_next %}
<li class="page-item">
<a class="page-link" href="{% url 'books_pagination' page=data.next_page_number %}#rolling-stock" tabindex="-1">Next</a>
</li>
{% else %}
<li class="page-item disabled">
<span class="page-link">Next</span>
</li>
{% endif %}
</ul>
</nav>
{% endif %}
{% endblock %}
3 changes: 3 additions & 0 deletions ram/portal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Manufacturers,
Scales,
Types,
Books,
SearchRoster,
)

Expand Down Expand Up @@ -54,6 +55,8 @@
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("books", Books.as_view(), name="books"),
path("books/<int:page>", Books.as_view(), name="books_pagination"),
path(
"search",
SearchRoster.as_view(http_method_names=["post"]),
Expand Down
8 changes: 8 additions & 0 deletions ram/portal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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


Expand Down Expand Up @@ -340,6 +341,13 @@ def __init__(self):
self.data = RollingStockType.objects.all()


class Books(GetData):
def __init__(self):
self.title = "Books"
self.template = "books.html"
self.data = Book.objects.all()


class GetFlatpage(View):
def get(self, request, flatpage):
try:
Expand Down

0 comments on commit 996ddd6

Please sign in to comment.