Skip to content

Commit

Permalink
Merge branch 'master' into feature/6/django_forms
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii73 committed Jun 16, 2018
2 parents 47a790c + 24d545b commit 2770e75
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
# Note: .db, .p, and .pkl files are associated
# with the python modules ``pickle``, ``dbm.*``,
# ``shelve``, ``marshal``, ``anydbm``, & ``bsddb``
# (among others).
# (among others).
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,7 @@ fabric.properties
.idea/sonarlint


# End of https://www.gitignore.io/api/django,pycharm
# End of https://www.gitignore.io/api/django,pycharm

# Add all idea files
.idea/
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
hooks:
- id: check-ast
- id: check-yaml
- id: check-merge-conflict
- id: check-docstring-first
- id: debug-statements
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: flake8
- id: name-tests-test
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: git://github.com/chewse/pre-commit-mirrors-pydocstyle
sha: v2.1.1
hooks:
- id: pydocstyle
exclude: blog/migrations
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: python
python: 3.6
cache: pip
before_install: pip install -U pre-commit
script: pre-commit run --all-files
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[![Build Status](https://travis-ci.com/kpi-web-guild/django-girls-blog-serhii73.svg?branch=master)](https://travis-ci.com/kpi-web-guild/django-girls-blog-serhii73)
# django-girls-blog-serhii73
##### This is a simple blog based on the djangogirl's tutorial.
##### This is a simple blog based on the djangogirl's tutorial.
1 change: 1 addition & 0 deletions blog/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Settings for Blog app."""
5 changes: 4 additions & 1 deletion blog/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Configuration for admin Blog app."""

# Register your models here.
from django.contrib import admin
from .models import Post

admin.site.register(Post)
admin.site.register(Post)
3 changes: 3 additions & 0 deletions blog/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Blog app metadata."""
from django.apps import AppConfig


class BlogConfig(AppConfig):
"""Config for Blog app."""

name = 'blog'
15 changes: 11 additions & 4 deletions blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Post',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('id', models.AutoField(auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID')),
('title', models.CharField(max_length=200)),
('text', models.TextField()),
('created_date', models.DateTimeField(default=django.utils.timezone.now)),
('published_date', models.DateTimeField(blank=True, null=True)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('created_date', models.DateTimeField(
default=django.utils.timezone.now)),
('published_date',
models.DateTimeField(blank=True, null=True)),
('author', models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL)),
],
),
]
5 changes: 5 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""Models for Blog app."""
from django.db import models
from django.utils import timezone


class Post(models.Model):
"""Create Post model for Blog app."""

author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
title = models.CharField(max_length=200)
text = models.TextField()
Expand All @@ -12,8 +15,10 @@ class Post(models.Model):
blank=True, null=True)

def publish(self):
"""Publish date method."""
self.published_date = timezone.now()
self.save()

def __str__(self):
"""Return title in admin."""
return self.title
2 changes: 1 addition & 1 deletion blog/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.test import TestCase
"""Tests for Blog app."""

# Create your tests here.
9 changes: 7 additions & 2 deletions blog/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Views for the blog app."""
from django.shortcuts import render, get_object_or_404
from django.utils import timezone
from .models import Post
Expand All @@ -6,18 +7,21 @@


def post_list(request):
"""Display the list of posts on the web page."""
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by(
'-published_date')
return render(request, 'blog/post_list.html', {'posts': posts})


def post_detail(request, pk):
"""Show the full post on the web page."""
post = get_object_or_404(Post, pk=pk)
return render(request, 'blog/post_detail.html', {'post': post})


def post_new(request):
if request.method == "POST":
"""Create a new post."""
if request.method == 'POST':
form = PostForm(request.POST)
if form.is_valid():
post = form.save(commit=False)
Expand All @@ -31,8 +35,9 @@ def post_new(request):


def post_edit(request, pk):
"""Edit the post."""
post = get_object_or_404(Post, pk=pk)
if request.method == "POST":
if request.method == 'POST':
form = PostForm(request.POST, instance=post)
if form.is_valid():
post = form.save(commit=False)
Expand Down
9 changes: 5 additions & 4 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env python
"""Blog app manager."""
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
'available on your PYTHONPATH environment variable? Did you '
'forget to activate a virtual environment?'
) from exc
execute_from_command_line(sys.argv)
1 change: 1 addition & 0 deletions mysite/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Settings for Blog app."""
22 changes: 10 additions & 12 deletions mysite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 's_#$5r*&&pn-p+2@ofesbsgf3pr4ftfy7p#8%c2y=-du@u$6+z'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['127.0.0.1', 'serhii73.pythonanywhere.com']
DEBUG = False

ALLOWED_HOSTS = []

# Application definition

Expand Down Expand Up @@ -70,7 +68,6 @@

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

Expand All @@ -81,26 +78,28 @@
}
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
'NAME': 'django.contrib.auth.password_validation.'
'UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'NAME': 'django.contrib.auth.password_validation.'
'MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
'NAME': 'django.contrib.auth.password_validation.'
'CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
'NAME': 'django.contrib.auth.password_validation.'
'NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

Expand All @@ -114,7 +113,6 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

Expand Down
16 changes: 1 addition & 15 deletions mysite/urls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
"""mysite URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
"""mysite URL Configuration."""
from django.contrib import admin
from django.urls import path, include

Expand Down
2 changes: 1 addition & 1 deletion mysite/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')

application = get_wsgi_application()

0 comments on commit 2770e75

Please sign in to comment.