Skip to content

Commit c8a7ee8

Browse files
committed
First version of application moved into github
1 parent 1bac8cc commit c8a7ee8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1387
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# Backup files
132+
*.bak

LocalLibrary/__init__.py

Whitespace-only changes.

LocalLibrary/asgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for LocalLibrary project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'LocalLibrary.settings')
15+
16+
application = get_asgi_application()

LocalLibrary/settings.py

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
"""
2+
Django settings for LocalLibrary project.
3+
4+
Generated by 'django-admin startproject' using Django 3.1.3.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/3.1/ref/settings/
11+
"""
12+
import os
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
# SECRET_KEY = 'y*z_*&qi^sv%4j)e#oi))e=wp9p5fq+v%w!5mevnbrt%%6ri)l'
24+
SECRET_KEY = os.environ.get('DJANGO_SECRET','y*z_*&qi^sv%4j)e#oi))e=wp9p5fq+v%w!5mevnbrt%%6ri)l')
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
#DEBUG = True
27+
DEBUG = os.environ.get('DJANGO_DEBUG','')!='False'
28+
29+
ALLOWED_HOSTS = []
30+
31+
32+
# Application definition
33+
34+
INSTALLED_APPS = [
35+
'django.contrib.admin',
36+
'django.contrib.auth',
37+
'django.contrib.contenttypes',
38+
'django.contrib.sessions',
39+
'django.contrib.messages',
40+
'django.contrib.staticfiles',
41+
'catalog.apps.CatalogConfig',
42+
]
43+
44+
MIDDLEWARE = [
45+
'django.middleware.security.SecurityMiddleware',
46+
'django.contrib.sessions.middleware.SessionMiddleware',
47+
'django.middleware.common.CommonMiddleware',
48+
'django.middleware.csrf.CsrfViewMiddleware',
49+
'django.contrib.auth.middleware.AuthenticationMiddleware',
50+
'django.contrib.messages.middleware.MessageMiddleware',
51+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
52+
]
53+
54+
ROOT_URLCONF = 'LocalLibrary.urls'
55+
56+
TEMPLATES = [
57+
{
58+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
59+
'DIRS': [os.path.join(BASE_DIR, 'templates')],
60+
'APP_DIRS': True,
61+
'OPTIONS': {
62+
'context_processors': [
63+
'django.template.context_processors.debug',
64+
'django.template.context_processors.request',
65+
'django.contrib.auth.context_processors.auth',
66+
'django.contrib.messages.context_processors.messages',
67+
],
68+
},
69+
},
70+
]
71+
72+
WSGI_APPLICATION = 'LocalLibrary.wsgi.application'
73+
74+
75+
# Database
76+
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
77+
78+
DATABASES = {
79+
'default': {
80+
'ENGINE': 'django.db.backends.sqlite3',
81+
'NAME': BASE_DIR / 'db.sqlite3',
82+
}
83+
}
84+
85+
86+
# Password validation
87+
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
88+
89+
AUTH_PASSWORD_VALIDATORS = [
90+
{
91+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
92+
},
93+
{
94+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
95+
},
96+
{
97+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
98+
},
99+
{
100+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
101+
},
102+
]
103+
104+
105+
# Internationalization
106+
# https://docs.djangoproject.com/en/3.1/topics/i18n/
107+
108+
LANGUAGE_CODE = 'en-us'
109+
110+
TIME_ZONE = 'Asia/Tokyo'
111+
112+
USE_I18N = True
113+
114+
USE_L10N = True
115+
116+
USE_TZ = True
117+
118+
119+
# Static files (CSS, JavaScript, Images)
120+
# https://docs.djangoproject.com/en/3.1/howto/static-files/
121+
122+
STATIC_URL = '/static/'
123+
124+
# Redirect to home URL after login (Default redirects to /accounts/profile/)
125+
LOGIN_REDIRECT_URL = '/'
126+
127+
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

LocalLibrary/urls.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""LocalLibrary URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/3.1/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: path('', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.contrib import admin
17+
from django.urls import path, include
18+
from django.views.generic import RedirectView
19+
from django.conf import settings
20+
from django.conf.urls.static import static
21+
22+
23+
urlpatterns = [
24+
path('admin/', admin.site.urls),
25+
path('catalog/', include('catalog.urls')),
26+
path('',RedirectView.as_view(url='/catalog/', permanent=True)),
27+
path('accounts/', include('django.contrib.auth.urls')),
28+
]
29+
30+
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

LocalLibrary/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for LocalLibrary project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'LocalLibrary.settings')
15+
16+
application = get_wsgi_application()

catalog/.DS_Store

6 KB
Binary file not shown.

catalog/__init__.py

Whitespace-only changes.

catalog/admin.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from django.contrib import admin
2+
from .models import Book, BookInstance, Author, Genre, Language
3+
4+
class BookInline(admin.TabularInline):
5+
model=Book
6+
7+
class AuthorAdmin(admin.ModelAdmin):
8+
list_display=('last_name', 'first_name', 'date_of_birth', 'date_of_death')
9+
fields = ('first_name', 'last_name', ('date_of_birth', 'date_of_death'))
10+
inlines=[BookInline]
11+
# Register your models here.
12+
admin.site.register(Author, AuthorAdmin)
13+
14+
class BookInstanceInline(admin.TabularInline):
15+
model=BookInstance
16+
17+
@admin.register(Book)
18+
class BookAdmin(admin.ModelAdmin):
19+
list_display = ('title', 'author', 'display_genre')
20+
inlines = [BookInstanceInline]
21+
22+
@admin.register(BookInstance)
23+
class BookInstanceAdmin(admin.ModelAdmin):
24+
list_display = ('book','status','borrower','due_back','id')
25+
list_filter = ('status', 'due_back')
26+
27+
fieldsets = (
28+
(None, {
29+
'fields':('book', 'imprint', 'id')
30+
}),
31+
('Availability', {
32+
'fields':('status', 'due_back','borrower')
33+
}),
34+
)
35+
36+
@admin.register(Genre)
37+
class GenreAdmin(admin.ModelAdmin):
38+
pass
39+
40+
@admin.register(Language)
41+
class LanguageAdmin(admin.ModelAdmin):
42+
pass
43+
44+
#admin.site.register(models.Author)
45+
#admin.site.register(models.Book)
46+
#admin.site.register(models.BookInstance)
47+
#admin.site.register(models.Genre)
48+
#admin.site.register(models.Language)

catalog/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class CatalogConfig(AppConfig):
5+
name = 'catalog'

catalog/forms.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import datetime
2+
3+
from django import forms
4+
from django.forms import ModelForm
5+
from django.core.exceptions import ValidationError
6+
from django.utils.translation import ugettext_lazy as _
7+
8+
from catalog.models import BookInstance
9+
10+
class RenewBookForm(forms.Form):
11+
renewal_date = forms.DateField(help_text='Enter a date between now and 4 weeks (default 3).')
12+
13+
def clean_renewal_date(self):
14+
data = self.cleaned_data['renewal_date']
15+
16+
if data < datetime.date.today():
17+
raise ValidationError(_('Invalid date - renewal in past'))
18+
19+
if data > datetime.date.today() + datetime.timedelta(weeks = 4):
20+
raise ValidationError(_('Invalid date - renewal more than 4 weeks ahead'))
21+
22+
return data
23+
24+
class RenewBookModelForm(forms.ModelForm):
25+
def clean_due_back(self):
26+
data = self.cleaned_data['due_back']
27+
28+
# Check if date is not in the past
29+
if data < datetime.date.today():
30+
raise ValidationError(_('Invalid date - renewal in past'))
31+
32+
#Check if date is in the allowed range:
33+
if data > datetime.date.today() + datetime.timedelta(weeks=4):
34+
raise ValidationError(_('Invalid date - renewal more than 4 weeks ahead'))
35+
36+
#Remember always to return the cleaned data:
37+
return data
38+
class Meta:
39+
model = BookInstance
40+
fields = ['due_back']
41+
labels = {'due_back': _('New renewal date')}
42+
help_texts = {'due_back': _('Enter a date between now and 4 weeks (default 3).')}

catalog/migrations/0001_initial.py

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Generated by Django 3.1.3 on 2021-03-07 12:27
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
import uuid
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
initial = True
11+
12+
dependencies = [
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='Author',
18+
fields=[
19+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('first_name', models.CharField(max_length=100)),
21+
('last_name', models.CharField(max_length=100)),
22+
('date_of_birth', models.DateField(blank=True, null=True)),
23+
('date_of_death', models.DateField(blank=True, null=True, verbose_name='Died')),
24+
],
25+
options={
26+
'ordering': ['last_name', 'first_name'],
27+
},
28+
),
29+
migrations.CreateModel(
30+
name='Book',
31+
fields=[
32+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
33+
('title', models.CharField(max_length=200)),
34+
('summary', models.TextField(help_text='Enter a brief description of the book', max_length=1000)),
35+
('isbn', models.CharField(help_text='13 Character <a href="https://www.isbn-international.org/content/what-isbn">ISBN number</a>', max_length=13, unique=True)),
36+
('author', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='catalog.author')),
37+
],
38+
),
39+
migrations.CreateModel(
40+
name='Genre',
41+
fields=[
42+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
43+
('name', models.CharField(help_text='Enter a book genre (e.g. Science fiction)', max_length=200)),
44+
],
45+
),
46+
migrations.CreateModel(
47+
name='Language',
48+
fields=[
49+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
50+
('name', models.CharField(help_text="Enter the book's natural language (e.g. English, French, Japanese etc.)", max_length=200)),
51+
],
52+
),
53+
migrations.CreateModel(
54+
name='BookInstance',
55+
fields=[
56+
('id', models.UUIDField(default=uuid.uuid4, help_text='Unique ID for this particular book across whole library', primary_key=True, serialize=False)),
57+
('imprint', models.CharField(max_length=200)),
58+
('due_back', models.DateField(blank=True, null=True)),
59+
('status', models.CharField(blank=True, choices=[('m', 'Maintenance'), ('o', 'On loan'), ('a', 'Available'), ('r', 'Reserved')], default='m', help_text='Book availability', max_length=1)),
60+
('book', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='catalog.book')),
61+
],
62+
options={
63+
'ordering': ['due_back'],
64+
},
65+
),
66+
migrations.AddField(
67+
model_name='book',
68+
name='genre',
69+
field=models.ManyToManyField(help_text='Select a genre for this book', to='catalog.Genre'),
70+
),
71+
migrations.AddField(
72+
model_name='book',
73+
name='language',
74+
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='catalog.language'),
75+
),
76+
]

0 commit comments

Comments
 (0)