This commit is contained in:
emile 2019-11-25 12:18:15 +01:00
commit d306aad6e2
36 changed files with 457 additions and 0 deletions

BIN
db.sqlite3 Normal file

Binary file not shown.

21
manage.py Normal file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'przyrost2.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
przyrost/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

1
przyrost/admin.py Normal file
View File

@ -0,0 +1 @@
from django.contrib import admin

5
przyrost/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class PrzyrostConfig(AppConfig):
name = 'przyrost'

View File

@ -0,0 +1,70 @@
# Generated by Django 2.2.7 on 2019-11-25 08:54
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
],
),
migrations.CreateModel(
name='Menu',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.CreateModel(
name='Post',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.TextField()),
],
),
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=20)),
],
),
migrations.CreateModel(
name='StaticPage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('own_text', models.TextField()),
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='przyrost.Post')),
],
),
migrations.AddField(
model_name='post',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='przyrost.User'),
),
migrations.AddField(
model_name='post',
name='category',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='przyrost.Category'),
),
migrations.CreateModel(
name='Comment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('unregistered_author', models.CharField(max_length=20)),
('text', models.TextField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='przyrost.User')),
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='przyrost.Post')),
],
),
]

View File

@ -0,0 +1,43 @@
# Generated by Django 2.2.7 on 2019-11-25 09:29
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('przyrost', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='MenuEntry',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('link', models.TextField()),
('alt', models.TextField()),
],
),
migrations.RemoveField(
model_name='post',
name='author',
),
migrations.AddField(
model_name='post',
name='authors',
field=models.ManyToManyField(to='przyrost.User'),
),
migrations.CreateModel(
name='Config',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('topMenu', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='przyrost.Menu')),
],
),
migrations.AddField(
model_name='menu',
name='entry',
field=models.ManyToManyField(to='przyrost.MenuEntry'),
),
]

View File

@ -0,0 +1,24 @@
# Generated by Django 2.2.7 on 2019-11-25 09:43
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('przyrost', '0002_auto_20191125_1029'),
]
operations = [
migrations.RemoveField(
model_name='post',
name='authors',
),
migrations.AddField(
model_name='post',
name='authors',
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='przyrost.User'),
preserve_default=False,
),
]

View File

@ -0,0 +1,22 @@
# Generated by Django 2.2.7 on 2019-11-25 09:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('przyrost', '0003_auto_20191125_1043'),
]
operations = [
migrations.RemoveField(
model_name='post',
name='authors',
),
migrations.AddField(
model_name='post',
name='authors',
field=models.ManyToManyField(to='przyrost.User'),
),
]

View File

@ -0,0 +1,32 @@
# Generated by Django 2.2.7 on 2019-11-25 09:50
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('przyrost', '0004_auto_20191125_1045'),
]
operations = [
migrations.AddField(
model_name='category',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=None),
preserve_default=False,
),
migrations.AddField(
model_name='post',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=None),
preserve_default=False,
),
migrations.AddField(
model_name='user',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
]

View File

40
przyrost/models.py Normal file
View File

@ -0,0 +1,40 @@
from django.db import models
import datetime
from django.utils import timezone
from django.core.paginator import Paginator
class Category(models.Model):
name=models.CharField(max_length=50)
created_at = models.DateTimeField(auto_now_add=True)
class User(models.Model):
name = models.CharField(max_length=20)
created_at = models.DateTimeField(auto_now_add=True)
class Post(models.Model):
text = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
authors=models.ManyToManyField(User)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
@staticmethod
def getTodays():
return Post.objects.filter(created_at=timezone.datetime.today())
@staticmethod
def getPage(page:int):
a = Post.objects.all()
paginator = Paginator(a,5)
return paginator.get_page(page)
class StaticPage(models.Model):
own_text = models.TextField()
post = models.ForeignKey(Post,on_delete=models.CASCADE)
class MenuEntry(models.Model):
link = models.TextField()
alt = models.TextField()
class Menu(models.Model):
entry = models.ManyToManyField(MenuEntry)
class Comment(models.Model):
post = models.ForeignKey(Post,on_delete=models.CASCADE)
author=models.ForeignKey(User,on_delete=models.CASCADE)
unregistered_author = models.CharField(max_length=20)
text = models.TextField()
class Config(models.Model):
topMenu = models.ForeignKey(Menu, on_delete=models.CASCADE)

23
przyrost/tests.py Normal file
View File

@ -0,0 +1,23 @@
from django.test import TestCase
from przyrost.models import *
from django.utils import timezone
class testbasic(TestCase):
def setUp(self) -> None:
User.objects.all().delete()
Category.objects.all().delete()
Post.objects.all().delete()
u=User.objects.create(name="Admin")
c=Category.objects.create(name="test")
u.save()
c.save()
p=Post.objects.create(
created_at=timezone.datetime.now(),
category=c,
text="I nawet kiedy będę sam nie zmienię się to nie móóóój świattttt"
)
p.authors.set([u])
p.save()
def test_getPostByDate(self):
self.assertEqual(len(Post.objects.all()),1)
self.assertEqual(len(Post.getTodays()), 1)

7
przyrost/urls.py Normal file
View File

@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]

8
przyrost/views.py Normal file
View File

@ -0,0 +1,8 @@
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")

0
przyrost2/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

123
przyrost2/settings.py Normal file
View File

@ -0,0 +1,123 @@
"""
Django settings for przyrost2 project.
Generated by 'django-admin startproject' using Django 2.2.7.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
import os
# 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.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'fivf5z16i9%e81m3!h67g0)diw%d@y=#2s2kff8i_=ic#q6d!v'
# 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',
'przyrost.apps.PrzyrostConfig',
]
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 = 'przyrost2.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 = 'przyrost2.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.2/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/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'

0
przyrost2/tests.py Normal file
View File

22
przyrost2/urls.py Normal file
View File

@ -0,0 +1,22 @@
"""przyrost2 URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/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 include,path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include("przyrost.urls"))
]

16
przyrost2/wsgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
WSGI config for przyrost2 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/2.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'przyrost2.settings')
application = get_wsgi_application()