Skip to content

Commit c74736c

Browse files
committed
Updates
1 parent 0dc11ac commit c74736c

File tree

5 files changed

+59
-10
lines changed

5 files changed

+59
-10
lines changed

Diff for: Ebog/models.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from sortedm2m.fields import SortedManyToManyField
55
from sorl.thumbnail import ImageField
66
from taggit.managers import TaggableManager
7+
from django.core.urlresolvers import reverse
78

89
# Create your models here.
910

@@ -51,4 +52,7 @@ class Book(models.Model):
5152
author = models.ForeignKey(User)
5253

5354
created_at = models.DateTimeField(auto_now_add=True)
54-
updated_at = models.DateTimeField(auto_now=True)
55+
updated_at = models.DateTimeField(auto_now=True)
56+
57+
def get_absolute_url(self):
58+
reverse("ebook:detail", self.slug);

Diff for: Ebog/urls.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from .views import *
44

55
urlpatterns = [
6-
url(r'^list/(?:page-(?P<page>\d+)/)?$', Book.List.as_view(), name="list"),
7-
url(r'^create/$', Book.Create.as_view(), name="create"),
8-
url(r'^section/create$', Section.Create.as_view(), name="create_section"),
9-
url(r'^section/page/create/$', Page.Create.as_view(), name="create_page"),
6+
url(r'^list/(?:page-(?P<page>\d+)/)?$', BookView.List.as_view(), name="list"),
7+
url(r'^create/$', BookView.Create.as_view(), name="create"),
8+
url(r'^(?P<slug>[\w-]+)', BookView.Detail.as_view()),
9+
url(r'^section/create$', SectionView.Create.as_view(), name="create_section"),
10+
url(r'^section/page/create/$', PageView.Create.as_view(), name="create_page"),
1011
]

Diff for: Ebog/views.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Create your views here.
88

99

10-
class Book:
10+
class BookView:
1111
class List(generic.ListView):
1212
template_name = "book_list.html"
1313
model = Book
@@ -24,7 +24,10 @@ class Create(generic.CreateView):
2424
form_class = BookFormCreate
2525
success_url = reverse_lazy('ebook:list')
2626

27-
27+
def form_valid(self, form):
28+
form.instance.author = self.request.user
29+
form.instance.slug = self.title
30+
return super(BookView.Create, self).form_valid(form)
2831

2932
class Edit(generic.UpdateView):
3033
model = Book
@@ -34,13 +37,14 @@ class Delete(generic.DeleteView):
3437
model = Book
3538

3639

37-
class Section:
40+
class SectionView:
3841
class Detail(generic.DetailView):
3942
model = Book
4043
template_name = "Ebog/detail.html"
4144

4245
class Create(generic.CreateView):
4346
model = Book
47+
template_name = "form.html"
4448
form_class = BookFormCreate
4549

4650
class Edit(generic.UpdateView):
@@ -51,7 +55,7 @@ class Delete(generic.DeleteView):
5155
model = Book
5256

5357

54-
class Page:
58+
class PageView:
5559
class Detail(generic.DetailView):
5660
model = Book
5761
template_name = "Ebog/detail.html"

Diff for: bookprofile/templates/login.html

+39
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
11
{% extends "base.html" %}
22
{% block content %}
3+
{% load crispy_forms_tags %}
34

5+
{% if form.non_field_errors %}
6+
{% for error in form.non_field_errors %}
7+
<p class="errornote">
8+
{{ error }}
9+
</p>
10+
{% endfor %}
11+
{% endif %}
12+
13+
<div class="center">
14+
15+
{% if user.is_authenticated %}
16+
<p class="errornote">
17+
You are authenticated as {{ user.username }}, Would you like to login to a different account?
18+
</p>
19+
{% endif %}
20+
21+
<form action="{{ app_path }}" method="post" id="login-form">{% csrf_token %}
22+
<div class="form-group">
23+
{{ form.username.errors }}
24+
<label for="exampleInputEmail1">Email address</label>
25+
{{ form.username.label_tag }} {{ form.username }}
26+
</div>
27+
<div class="form-group">
28+
{{ form.password.errors }}
29+
{{ form.password.label_tag }} {{ form.password }}
30+
<input type="hidden" name="next" value="{{ next }}" />
31+
</div>
32+
{% url 'admin_password_reset' as password_reset_url %}
33+
{% if password_reset_url %}
34+
<div class="password-reset-link">
35+
<a href="{{ password_reset_url }}">Forgotten your password or username?</a>
36+
</div>
37+
{% endif %}
38+
<div class="submit-row">
39+
<label>&nbsp;</label><input type="submit" value="Log in" />
40+
</div>
41+
</form>
42+
</div>
443
{% endblock %}

Diff for: requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ django-easy-select2
66
django-crispy-forms
77
django-sortedm2m
88
sorl-thumbnail
9-
pillow
9+
pillow
10+
django-filter

0 commit comments

Comments
 (0)