Skip to content

Commit eef4d15

Browse files
committed
Books updates.
1 parent 0f48ae3 commit eef4d15

File tree

8 files changed

+86
-30
lines changed

8 files changed

+86
-30
lines changed

files.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ def serve_book_file(book_format):
4747
response = StreamingHttpResponse(FileWrapper(open(file_path, 'rb'), 8192),
4848
content_type=files.guess_mime(book_format.filename))
4949
response['Content-Length'] = os.path.getsize(file_path)
50-
response['Content-Disposition'] = 'attachment; filename="{0}{1}"'.format(slugify(filename), extension)
50+
response['Content-Disposition'] = 'attachment;' \
51+
' filename="{0}{1}"'.format(
52+
slugify(book_format.book.full_title()),
53+
extension
54+
)
5155

5256
return response
5357
else:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.20 on 2019-06-24 11:19
3+
from __future__ import unicode_literals
4+
5+
import django.core.files.storage
6+
from django.db import migrations, models
7+
import plugins.books.models
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
dependencies = [
13+
('books', '0004_auto_20170905_1757'),
14+
]
15+
16+
operations = [
17+
migrations.AddField(
18+
model_name='book',
19+
name='is_open_access',
20+
field=models.BooleanField(default=True),
21+
),
22+
migrations.AlterField(
23+
model_name='book',
24+
name='cover',
25+
field=models.FileField(blank=True, null=True, storage=django.core.files.storage.FileSystemStorage(location='/vol/janeway/src/media'), upload_to=plugins.books.models.cover_images_upload_path),
26+
),
27+
]

models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Book(models.Model):
2929
pages = models.PositiveIntegerField()
3030

3131
is_edited_volume = models.BooleanField(default=False)
32+
is_open_access = models.BooleanField(default=True)
3233
date_published = models.DateField(blank=True, null=True)
3334

3435
publisher_name = models.CharField(max_length=100)
@@ -85,7 +86,6 @@ def cover_width(self):
8586
return width
8687

8788

88-
8989
class Contributor(models.Model):
9090
book = models.ForeignKey(Book)
9191
first_name = models.CharField(max_length=100)

templates/books/admin.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ <h2>Books</h2>
1919
<table id="books">
2020
<thead>
2121
<tr>
22+
<th>ID</th>
2223
<th>Title</th>
24+
<th>Subtile</th>
2325
<th>First Author</th>
2426
<th>ISBN</th>
2527
<th>DOI</th>
@@ -29,7 +31,9 @@ <h2>Books</h2>
2931
<tbody>
3032
{% for book in books %}
3133
<tr>
34+
<td>{{ book.pk }}</td>
3235
<td><a href="{% url 'books_edit_book' book.pk %}">{{ book.title }}</a></td>
36+
<td>{{ book.subtitle }}</td>
3337
<td>{{ book.first_contributor }}</td>
3438
<td>{{ book.isbn }}</td>
3539
<td>{{ book.doi }}</td>

templates/books/book.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% extends "press/core/base.html" %}
1+
{% extends "core/base.html" %}
22

33
{% block title %}{{ book.title }}{% endblock %}
44

templates/books/book_detail.html

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
1+
{% load static from staticfiles %}
12
<div class="large-12 columns">
23
<div class="content clearfix">
3-
<div class="large-2 columns">
4+
<div class="large-3 columns">
45
<img src="{% if book.cover %}{{ book.cover.url }}{% endif %}" alt="">
6+
{% if book.is_open_access %}
7+
<img src="{% static 'media/books/oa.png' %}" alt="Open Access Logo" style="padding: 30px; padding-bottom: 0;">
8+
{% endif %}
59
{% if not books %}<p><a href="{% url 'books_index' %}"><i class="fa fa-arrow-left">&nbsp;</i>Back to Listing</a></p>{% endif %}
610
</div>
7-
<div class="large-7 columns">
8-
<a href="{% url 'books_book' book.pk %}"><h2>{{ book.full_title }}</h2></a>
9-
<h6>{% for contributor in book.contributor_set.all %}{% if not forloop.first and not forloop.last %},
10-
{% elif forloop.last and not forloop.first %} & {% endif %}{{ contributor }}{% endfor %}</h6>
11-
{{ book.description|safe|linebreaksbr }}
12-
</div>
13-
<div class="large-3 columns">
14-
<h6>About this Book</h6>
15-
<strong>Published</strong> {{ book.date_published }}<br/><br/>
16-
<strong>Published by</strong> {{ book.publisher_name }}<br/><br/>
17-
{% if book.pages %}<strong>Pages</strong> {{ book.pages }}<br/><br/>{% endif %}
18-
{% if book.isbn %}<strong>ISBN</strong> {{ book.isbn }}<br/><br/>{% endif %}
19-
{% if book.doi %}<strong>DOI</strong> <a href="https://doi.org/{{ book.doi }}">{{ book.doi }}</a><br/>
20-
<br/>{% endif %}
21-
{% if book.format_set.all %}
22-
<h6>Downloads</h6>
23-
{% endif %}
11+
<div class="large-9 columns">
12+
<h2>{% if books %}<a href="{% url 'books_book' book.pk %}">{% endif %}{{ book.full_title }}{% if books %}</a>{% endif %}</h2>
13+
<h6><em>{% for contributor in book.contributor_set.all %}{% if not forloop.first and not forloop.last %},
14+
{% elif forloop.last and not forloop.first %} & {% endif %}{{ contributor }}{% endfor %}</em></h6>
15+
2416
{% for format in book.format_set.all %}
25-
<a href="{% url 'books_download_format' book.pk format.pk %}" class="button">{{ format.title }}</a>
17+
<a href="{% url 'books_download_format' book.pk format.pk %}" class="button"><i class="fa fa-download">&nbsp;</i> Download {{ format.title }}</a>
2618
{% endfor %}
27-
{% if book.purchase_url %}
28-
<h6>Purchase</h6>
29-
<a href="{{ book.purchase_url }}" class="button" target="_blank">Buy this Book</a>
30-
{% endif %}
19+
{% if book.purchase_url %}<a href="{{ book.purchase_url }}" class="button" target="_blank"><i class="fa fa-external-link"></i>&nbsp;Buy this Book</a>{% endif %}
20+
21+
<table class="table" style="margin-bottom: 0;">
22+
<tr>
23+
<th>Description</th>
24+
</tr>
25+
<tr>
26+
<td>{{ book.description|safe }}</td>
27+
</tr>
28+
</table>
29+
30+
<table class="table">
31+
<tr>
32+
<th>Published</th>
33+
<th>Published By</th>
34+
<th>Pages</th>
35+
{% if book.isbn %}<th>ISBN</th>{% endif %}
36+
{% if book.doi %}<th>DOI</th>{% endif %}
37+
</tr>
38+
<tr>
39+
<td>{{ book.date_published }}</td>
40+
<td>{{ book.publisher_name }}</td>
41+
<td>{{ book.pages }}</td>
42+
{% if book.isbn %}<td>{{ book.isbn }}</td>{% endif %}
43+
{% if book.doi %}<td>{{ book.doi }}</td>{% endif %}
44+
</tr>
45+
</table>
46+
3147
</div>
3248
</div>
33-
</div>
49+
</div>

templates/books/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% extends "press/core/base.html" %}
1+
{% extends "core/base.html" %}
22

33
{% block title %}Books{% endblock %}
44

@@ -13,6 +13,7 @@ <h4>Published Books</h4>
1313
{% include "books/book_detail.html" with book=book %}
1414
</div>
1515
</div>
16+
<hr />
1617
{% empty %}
1718
<p>There are no published books to display.</p>
1819
{% endfor %}

views.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import csv
22

33
from django.shortcuts import render, get_object_or_404, redirect, HttpResponse
4-
from django.core.urlresolvers import reverse
4+
from django.urls import reverse
55
from django.contrib.admin.views.decorators import staff_member_required
66
from django.contrib import messages
77

@@ -10,7 +10,11 @@
1010

1111

1212
def index(request):
13-
books = models.Book.objects.filter(date_published__isnull=False)
13+
books = models.Book.objects.filter(
14+
date_published__isnull=False,
15+
).order_by(
16+
'-date_published',
17+
)
1418

1519
template = 'books/index.html'
1620
context = {

0 commit comments

Comments
 (0)