commit
e953064b6d
32 changed files with 12295 additions and 0 deletions
@ -0,0 +1,16 @@
|
||||
""" |
||||
ASGI config for blog project. |
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``. |
||||
|
||||
For more information on this file, see |
||||
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/ |
||||
""" |
||||
|
||||
import os |
||||
|
||||
from django.core.asgi import get_asgi_application |
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings') |
||||
|
||||
application = get_asgi_application() |
@ -0,0 +1,130 @@
|
||||
""" |
||||
Django settings for blog project. |
||||
|
||||
Generated by 'django-admin startproject' using Django 4.0.3. |
||||
|
||||
For more information on this file, see |
||||
https://docs.djangoproject.com/en/4.0/topics/settings/ |
||||
|
||||
For the full list of settings and their values, see |
||||
https://docs.djangoproject.com/en/4.0/ref/settings/ |
||||
""" |
||||
|
||||
from pathlib import Path |
||||
import os |
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'. |
||||
BASE_DIR = Path(__file__).resolve().parent.parent |
||||
PROJECT_ROOT = os.path.dirname(__file__) |
||||
|
||||
# Quick-start development settings - unsuitable for production |
||||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ |
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret! |
||||
SECRET_KEY = "django-insecure-+-=x#$t4ympabt6#3#k=5t2w60%uiz7l6une62r+i6@sw9jds(" |
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production! |
||||
DEBUG = True |
||||
|
||||
ALLOWED_HOSTS = [] |
||||
|
||||
|
||||
# Application definition |
||||
|
||||
INSTALLED_APPS = [ |
||||
"django.contrib.admin", |
||||
"django.contrib.auth", |
||||
"django.contrib.contenttypes", |
||||
"django.contrib.sessions", |
||||
"django.contrib.messages", |
||||
"django.contrib.staticfiles", |
||||
"posts.apps.PostConfig", |
||||
"mainpage.apps.MainpageConfig", |
||||
] |
||||
|
||||
MIDDLEWARE = [ |
||||
"django.middleware.security.SecurityMiddleware", |
||||
"django.contrib.sessions.middleware.SessionMiddleware", |
||||
"django.middleware.common.CommonMiddleware", |
||||
"django.middleware.csrf.CsrfViewMiddleware", |
||||
"django.contrib.auth.middleware.AuthenticationMiddleware", |
||||
"django.contrib.messages.middleware.MessageMiddleware", |
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware", |
||||
] |
||||
|
||||
ROOT_URLCONF = "blog.urls" |
||||
|
||||
TEMPLATES = [ |
||||
{ |
||||
"BACKEND": "django.template.backends.django.DjangoTemplates", |
||||
"DIRS": [os.path.join(BASE_DIR, "templates")], |
||||
"APP_DIRS": True, |
||||
"OPTIONS": { |
||||
"context_processors": [ |
||||
"django.template.context_processors.debug", |
||||
"django.template.context_processors.request", |
||||
"django.contrib.auth.context_processors.auth", |
||||
"django.contrib.messages.context_processors.messages", |
||||
], |
||||
}, |
||||
}, |
||||
] |
||||
|
||||
WSGI_APPLICATION = "blog.wsgi.application" |
||||
|
||||
|
||||
# Database |
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases |
||||
|
||||
DATABASES = { |
||||
"default": { |
||||
"ENGINE": "django.db.backends.sqlite3", |
||||
"NAME": BASE_DIR / "db.sqlite3", |
||||
} |
||||
} |
||||
|
||||
|
||||
# Password validation |
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators |
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [ |
||||
{ |
||||
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", |
||||
}, |
||||
{ |
||||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", |
||||
}, |
||||
{ |
||||
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", |
||||
}, |
||||
{ |
||||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", |
||||
}, |
||||
] |
||||
|
||||
|
||||
# Internationalization |
||||
# https://docs.djangoproject.com/en/4.0/topics/i18n/ |
||||
|
||||
LANGUAGE_CODE = "en-us" |
||||
|
||||
TIME_ZONE = "UTC" |
||||
|
||||
USE_I18N = True |
||||
|
||||
USE_TZ = True |
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images) |
||||
# https://docs.djangoproject.com/en/4.0/howto/static-files/ |
||||
|
||||
STATIC_URL = "static/" |
||||
|
||||
# для того чтобы использовать общие статические файлы |
||||
STATICFILES_DIRS = [ |
||||
BASE_DIR / "static", |
||||
] |
||||
# Default primary key field type |
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field |
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" |
@ -0,0 +1,23 @@
|
||||
"""blog URL Configuration |
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see: |
||||
https://docs.djangoproject.com/en/4.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')) |
||||
""" |
||||
from django.contrib import admin |
||||
from django.urls import path, include |
||||
|
||||
urlpatterns = [ |
||||
path("", include("mainpage.urls")), |
||||
path("posts/", include("posts.urls")), |
||||
path("admin/", admin.site.urls), |
||||
] |
@ -0,0 +1,16 @@
|
||||
""" |
||||
WSGI config for blog project. |
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``. |
||||
|
||||
For more information on this file, see |
||||
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/ |
||||
""" |
||||
|
||||
import os |
||||
|
||||
from django.core.wsgi import get_wsgi_application |
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings') |
||||
|
||||
application = get_wsgi_application() |
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin |
||||
|
||||
# Register your models here. |
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig |
||||
|
||||
|
||||
class MainpageConfig(AppConfig): |
||||
default_auto_field = 'django.db.models.BigAutoField' |
||||
name = 'mainpage' |
@ -0,0 +1,3 @@
|
||||
from django.db import models |
||||
|
||||
# Create your models here. |
@ -0,0 +1,42 @@
|
||||
{% extends 'base.html' %} |
||||
{% block title %}Типулькины писульки{% endblock %} |
||||
{% block content %} |
||||
<section class="section"> |
||||
|
||||
|
||||
|
||||
<div class="tile is-ancestor"> |
||||
|
||||
<div class="tile is-parent is-6"> |
||||
<div class="tile is-child box"> |
||||
<h2 class="title is-4">Главное</h2> |
||||
<div class="content"> |
||||
<p>Информация о сайте.</p> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="tile is-vertical is-parent"> |
||||
|
||||
<div class="tile is-child box"> |
||||
<h2 class="title is-4">Какая-то классная инфа</h2> |
||||
</div> |
||||
|
||||
<div class="tile is-child box"> |
||||
<h2 class="title is-4">Последние статьи</h2> |
||||
<div class="content"> |
||||
<ul> |
||||
{% for post in posts %} |
||||
<li><a href={% url 'posts:detail' post.id %}>{{post.title}}</a></li> |
||||
{% endfor %} |
||||
</ul> |
||||
<br> |
||||
<p>Или можно посмотреть <a href={% url 'posts:index' %}>все посты</a>.</p> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
|
||||
</div> |
||||
<section> |
||||
{% endblock %} |
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase |
||||
|
||||
# Create your tests here. |
@ -0,0 +1,7 @@
|
||||
from django.urls import path |
||||
from . import views |
||||
|
||||
app_name = "mainpage" |
||||
urlpatterns = [ |
||||
path("", views.index, name="index"), |
||||
] |
@ -0,0 +1,8 @@
|
||||
from django.shortcuts import render |
||||
from django.http import HttpResponse |
||||
from posts.models import Post |
||||
|
||||
|
||||
def index(request): |
||||
post_list = Post.objects.order_by("-pub_date")[:10] |
||||
return render(request, "mainpage/index.html", {"posts": post_list}) |
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python |
||||
"""Django's command-line utility for administrative tasks.""" |
||||
import os |
||||
import sys |
||||
|
||||
|
||||
def main(): |
||||
"""Run administrative tasks.""" |
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.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?" |
||||
) from exc |
||||
execute_from_command_line(sys.argv) |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
main() |
@ -0,0 +1,8 @@
|
||||
from django.contrib import admin |
||||
|
||||
from .models import Post |
||||
|
||||
|
||||
@admin.register(Post) |
||||
class PostAdmin(admin.ModelAdmin): |
||||
fields = ("title", "text", "pub_date") |
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig |
||||
|
||||
|
||||
class PostConfig(AppConfig): |
||||
default_auto_field = "django.db.models.BigAutoField" |
||||
name = "posts" |
@ -0,0 +1,22 @@
|
||||
# Generated by Django 4.0.3 on 2022-03-30 14:07 |
||||
|
||||
from django.db import migrations, models |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
initial = True |
||||
|
||||
dependencies = [ |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.CreateModel( |
||||
name='Post', |
||||
fields=[ |
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
('title', models.CharField(max_length=250)), |
||||
('text', models.TextField()), |
||||
], |
||||
), |
||||
] |
@ -0,0 +1,20 @@
|
||||
# Generated by Django 4.0.3 on 2022-03-30 14:32 |
||||
|
||||
from django.db import migrations, models |
||||
import django.utils.timezone |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('posts', '0001_initial'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.AddField( |
||||
model_name='post', |
||||
name='pub_date', |
||||
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='date published'), |
||||
preserve_default=False, |
||||
), |
||||
] |
@ -0,0 +1,17 @@
|
||||
# Generated by Django 4.0.3 on 2022-04-01 14:57 |
||||
|
||||
from django.db import migrations |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('posts', '0002_post_pub_date'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.AlterModelOptions( |
||||
name='post', |
||||
options={'verbose_name': 'Статья', 'verbose_name_plural': 'Статьи'}, |
||||
), |
||||
] |
@ -0,0 +1,29 @@
|
||||
from django.db import models |
||||
import re |
||||
|
||||
|
||||
class Post(models.Model): |
||||
"""Класс записи в блоге.""" |
||||
|
||||
title = models.CharField(max_length=250) |
||||
text = models.TextField() |
||||
pub_date = models.DateTimeField("date published") |
||||
|
||||
@property |
||||
def org_text(self): |
||||
"""Вернет text заменив html на org.""" |
||||
text = self.text |
||||
text = re.sub(r"(<strong>(.+?)</strong>)", r"\*\2\*") |
||||
return text |
||||
|
||||
def __str__(self): |
||||
return self.title |
||||
|
||||
def save(self, *args, **kwargs): |
||||
self.text = re.sub(r"(\n.+?\n)", r"<p>\1</p> ", self.text) |
||||
self.text = re.sub(r"(\*(.+?)\*)", r"<strong>\2</strong>", self.text) |
||||
super(Post, self).save(*args, **kwargs) |
||||
|
||||
class Meta: |
||||
verbose_name = "Статья" |
||||
verbose_name_plural = "Статьи" |
@ -0,0 +1,25 @@
|
||||
{% extends 'base.html' %} |
||||
{% block title %}Список статей{% endblock %} |
||||
{% block content %} |
||||
{% autoescape off %} |
||||
|
||||
<nav class="breadcrumb has-bullet-separator is-centered" aria-label="breadcrumbs"> |
||||
<ul> |
||||
<li><a href="/">Главная</a></li> |
||||
<li class="is-active"><a href="#" aria-current="page">Все посты</a></li> |
||||
</ul> |
||||
</nav> |
||||
<section class="section"> |
||||
<div class="content"> |
||||
{% if posts %} |
||||
{% for post in posts %} |
||||
<div class="block"> |
||||
<a href={% url 'posts:detail' post.id %}>{{post.title}}</a> |
||||
<p>{{ post.text | truncatewords_html:20 }}</p> |
||||
</div> |
||||
{% endfor %} |
||||
{% endif %} |
||||
</div> |
||||
<section> |
||||
{% endautoescape %} |
||||
{% endblock %} |
@ -0,0 +1,23 @@
|
||||
{% extends 'base.html' %} |
||||
{% load tz %} |
||||
{% block title %}{{ post.title }}{% endblock %} |
||||
{% block content %} |
||||
{% autoescape off %} |
||||
<nav class="breadcrumb has-bullet-separator is-centered" aria-label="breadcrumbs"> |
||||
<ul> |
||||
<li><a href="/">Главная</a></li> |
||||
<li><a href="/posts">Все посты</a></li> |
||||
<li class="is-active"><a href="#" aria-current="page">{{ post.title | truncatechars:20}}</a></li> |
||||
</ul> |
||||
</nav> |
||||
<section class="section"> |
||||
<h1 class="title is-spaced">{{ post.title }}</h1> |
||||
|
||||
{% get_current_timezone as TIME_ZONE %} |
||||
<div class="subtitle is-6">Опубликован: {{ post.pub_date | date:'Y-m-d, H:i' }}</div> |
||||
<div class="content is-medium">{{ post.text }}</div> |
||||
|
||||
</section> |
||||
{% endautoescape %} |
||||
|
||||
{% endblock %} |
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase |
||||
|
||||
# Create your tests here. |
@ -0,0 +1,8 @@
|
||||
from django.urls import path |
||||
from . import views |
||||
|
||||
app_name = "posts" |
||||
urlpatterns = [ |
||||
path("", views.index, name="index"), |
||||
path("<int:post_id>/", views.detail, name="detail"), |
||||
] |
@ -0,0 +1,20 @@
|
||||
from django.shortcuts import render, get_object_or_404 |
||||
from django.http import HttpResponse |
||||
|
||||
from .models import Post |
||||
|
||||
import re |
||||
|
||||
|
||||
def index(request): |
||||
"""Список постов.""" |
||||
post_list = Post.objects.order_by("-pub_date")[:20] |
||||
return render(request, "posts/index.html", {"posts": post_list}) |
||||
|
||||
|
||||
def detail(request, post_id): |
||||
"""Страница с просмотром поста.""" |
||||
# вынести отсюда все. Также надо обработать текст поста тут. |
||||
post = get_object_or_404(Post, pk=post_id) |
||||
|
||||
return render(request, "posts/post.html", {"post": post}) |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,23 @@
|
||||
{% load static %} |
||||
<!DOCTYPE html> |
||||
<html lang="ru"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>{% block title%}Мой сайт{% endblock %}</title> |
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
<meta name="description" content="HTML5 Example Page"> |
||||
<link rel="stylesheet" href="{% static 'css/bulma.css' %}"> |
||||
</head> |
||||
<body> |
||||
{% block content %}{% endblock %} |
||||
|
||||
<!-- <script src="/assets/js/scripts.js"></script> --> |
||||
|
||||
<!-- footer goes here --> |
||||
<footer class="footer"> |
||||
<div class="content has-text-centered"> |
||||
Made with emacs and happy with that. |
||||
</footer> |
||||
</body> |
||||
</html> |
Loading…
Reference in new issue