commit 1514224b66dd66ec40f3cd093eb0a69b4708cc18 Author: Laurent Date: Tue Sep 10 15:47:15 2019 +0200 Initial commit diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..1d9712b Binary files /dev/null and b/db.sqlite3 differ diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..7b20271 --- /dev/null +++ b/manage.py @@ -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', 'pokercc.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() diff --git a/news/__init__.py b/news/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/news/__pycache__/__init__.cpython-37.pyc b/news/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..e20527d Binary files /dev/null and b/news/__pycache__/__init__.cpython-37.pyc differ diff --git a/news/__pycache__/admin.cpython-37.pyc b/news/__pycache__/admin.cpython-37.pyc new file mode 100644 index 0000000..b62c831 Binary files /dev/null and b/news/__pycache__/admin.cpython-37.pyc differ diff --git a/news/__pycache__/apps.cpython-37.pyc b/news/__pycache__/apps.cpython-37.pyc new file mode 100644 index 0000000..0004023 Binary files /dev/null and b/news/__pycache__/apps.cpython-37.pyc differ diff --git a/news/__pycache__/models.cpython-37.pyc b/news/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000..19840d3 Binary files /dev/null and b/news/__pycache__/models.cpython-37.pyc differ diff --git a/news/__pycache__/urls.cpython-37.pyc b/news/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..5adae1e Binary files /dev/null and b/news/__pycache__/urls.cpython-37.pyc differ diff --git a/news/__pycache__/views.cpython-37.pyc b/news/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000..5092237 Binary files /dev/null and b/news/__pycache__/views.cpython-37.pyc differ diff --git a/news/admin.py b/news/admin.py new file mode 100644 index 0000000..81af5f3 --- /dev/null +++ b/news/admin.py @@ -0,0 +1,7 @@ +from django.contrib import admin +from .models import Post, Comment, Tag, Player + +admin.site.register(Post) +admin.site.register(Comment) +admin.site.register(Tag) +admin.site.register(Player) diff --git a/news/apps.py b/news/apps.py new file mode 100644 index 0000000..5a7b92d --- /dev/null +++ b/news/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class NewsConfig(AppConfig): + name = 'news' diff --git a/news/migrations/0001_initial.py b/news/migrations/0001_initial.py new file mode 100644 index 0000000..f6cd385 --- /dev/null +++ b/news/migrations/0001_initial.py @@ -0,0 +1,59 @@ +# Generated by Django 2.2.5 on 2019-09-10 10:05 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Post', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('body', models.CharField(max_length=10000)), + ('url', models.CharField(max_length=200)), + ('date', models.DateTimeField(verbose_name='date published')), + ('state', models.IntegerField(default=0)), + ('image_url', models.CharField(max_length=100)), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.CreateModel( + name='Tag', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='news.Post')), + ], + ), + migrations.CreateModel( + name='Player', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ('image_url', models.CharField(max_length=100)), + ('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='news.Post')), + ], + ), + migrations.CreateModel( + name='Comment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('body', models.CharField(max_length=100)), + ('votes', models.IntegerField(default=0)), + ('date', models.DateTimeField(verbose_name='date published')), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('parent_comment', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='news.Comment')), + ('post', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='news.Post')), + ], + ), + ] diff --git a/news/migrations/__init__.py b/news/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/news/migrations/__pycache__/0001_initial.cpython-37.pyc b/news/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 0000000..b26093f Binary files /dev/null and b/news/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/news/migrations/__pycache__/__init__.cpython-37.pyc b/news/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..d16688b Binary files /dev/null and b/news/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/news/models.py b/news/models.py new file mode 100644 index 0000000..3729584 --- /dev/null +++ b/news/models.py @@ -0,0 +1,47 @@ +from django.db import models +from django.conf import settings +from enum import Enum + +# Create your models here. +class PostState(Enum): + PUBLISHED = 1 + DRAFT = 2 + PROGRAMMED = 3 + +class Post(models.Model): + author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + title = models.CharField(max_length=200) + body = models.CharField(max_length=10000) + url = models.CharField(max_length=200) + date = models.DateTimeField('date published') + state = models.IntegerField(default=0) + image_url = models.CharField(max_length=100) + # state: posted, draft, waiting for submission + # image + def __str__(self): + return self.title + +class Comment(models.Model): + author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True) + parent_comment = models.ForeignKey("self", on_delete=models.CASCADE, null=True) + body = models.CharField(max_length=100) + votes = models.IntegerField(default=0) + date = models.DateTimeField('date published') + def __str__(self): + return self.content + +class Player(models.Model): + name = models.CharField(max_length=100) + post = models.ForeignKey(Post, on_delete=models.CASCADE) + image_url = models.CharField(max_length=100) + + def __str__(self): + return self.name + # photo + +class Tag(models.Model): + name = models.CharField(max_length=100) + post = models.ForeignKey(Post, on_delete=models.CASCADE) + def __str__(self): + return self.name diff --git a/news/templates/news/index.html b/news/templates/news/index.html new file mode 100644 index 0000000..b2257a7 --- /dev/null +++ b/news/templates/news/index.html @@ -0,0 +1,13 @@ +

Poker CC

+ +{% if latest_post_list %} + +{% else %} +

No posts are available.

+{% endif %} + +Submit diff --git a/news/templates/news/post.html b/news/templates/news/post.html new file mode 100644 index 0000000..6c83520 --- /dev/null +++ b/news/templates/news/post.html @@ -0,0 +1,10 @@ +

{{ post.title }}

+

written by {{ post.author.username }}

+

----Body----

+

{{ post.content }}

+

----Comments----

+ diff --git a/news/templates/news/submission.html b/news/templates/news/submission.html new file mode 100644 index 0000000..7ae033c --- /dev/null +++ b/news/templates/news/submission.html @@ -0,0 +1,41 @@ +{% if error_message %}

{{ error_message }}

{% endif %} + +{% if user.is_authenticated %} + +
+ {% csrf_token %} + +

+ Title> + +

+

+ Image URL> + +

+

+ Content> + +

+

+ URL> + +

+ +

+ + + + + + +

+ +
+ + +
+ +{% else %} +Please log in +{% endif %} diff --git a/news/templates/news/submitted.html b/news/templates/news/submitted.html new file mode 100644 index 0000000..bf385ca --- /dev/null +++ b/news/templates/news/submitted.html @@ -0,0 +1,3 @@ +

Thanks :)

+ +

Home

diff --git a/news/tests.py b/news/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/news/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/news/urls.py b/news/urls.py new file mode 100644 index 0000000..35660d7 --- /dev/null +++ b/news/urls.py @@ -0,0 +1,13 @@ +from django.urls import path + +from . import views + +app_name = 'news' +urlpatterns = [ + path('', views.index, name='index'), + path('', views.post, name='post'), + path('submission', views.submission, name='submission'), + path('submit', views.submit, name='submit'), + path('submitted', views.submitted, name='submitted'), + +] diff --git a/news/views.py b/news/views.py new file mode 100644 index 0000000..b46ea5b --- /dev/null +++ b/news/views.py @@ -0,0 +1,39 @@ +from django.shortcuts import render, get_object_or_404 +from django.http import HttpResponse, Http404, HttpResponseRedirect +from django.template import loader +from django.urls import reverse +from .models import Post +from datetime import datetime +import logging + +# Create your views here. + +def index(request): + latest_post_list = Post.objects.filter(state=1).order_by('-date')[:10] + context = { 'latest_post_list' : latest_post_list } + return render(request, 'news/index.html', context) + +def post(request, post_id): + post = get_object_or_404(Post, pk=post_id) + return render(request, 'news/post.html', {'post': post}) + +def submission(request): + return render(request, 'news/submission.html', {}) + +def submit(request): + + if 'state' in request.POST: + post = Post.objects.create(author=request.user,date=datetime.today()) + post.title = request.POST['title'] + post.content = request.POST['content'] + post.url = request.POST['url'] + post.image_url = request.POST['image_url'] + post.state = request.POST['state'] + post.save() + else: + raise Http404("You must select a publication type") + + return HttpResponseRedirect(reverse('news:submitted')) + +def submitted(request): + return render(request, 'news/submitted.html', {}) diff --git a/pokercc/__init__.py b/pokercc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pokercc/__pycache__/__init__.cpython-37.pyc b/pokercc/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..57c96ff Binary files /dev/null and b/pokercc/__pycache__/__init__.cpython-37.pyc differ diff --git a/pokercc/__pycache__/settings.cpython-37.pyc b/pokercc/__pycache__/settings.cpython-37.pyc new file mode 100644 index 0000000..349a33d Binary files /dev/null and b/pokercc/__pycache__/settings.cpython-37.pyc differ diff --git a/pokercc/__pycache__/urls.cpython-37.pyc b/pokercc/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..a60926c Binary files /dev/null and b/pokercc/__pycache__/urls.cpython-37.pyc differ diff --git a/pokercc/__pycache__/wsgi.cpython-37.pyc b/pokercc/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 0000000..24fa38e Binary files /dev/null and b/pokercc/__pycache__/wsgi.cpython-37.pyc differ diff --git a/pokercc/settings.py b/pokercc/settings.py new file mode 100644 index 0000000..b8f5740 --- /dev/null +++ b/pokercc/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for pokercc project. + +Generated by 'django-admin startproject' using Django 2.2.5. + +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 = 'erk4wh93pi(m(odwg74lsy60tb$rz4=ndyiv3#2lcx^!$^kq@4' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'news.apps.NewsConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +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 = 'pokercc.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + '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 = 'pokercc.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 = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.2/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/pokercc/urls.py b/pokercc/urls.py new file mode 100644 index 0000000..acaed36 --- /dev/null +++ b/pokercc/urls.py @@ -0,0 +1,22 @@ +"""pokercc 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('news/', include('news.urls')), + path('admin/', admin.site.urls) +] diff --git a/pokercc/wsgi.py b/pokercc/wsgi.py new file mode 100644 index 0000000..1ed2e13 --- /dev/null +++ b/pokercc/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for pokercc 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', 'pokercc.settings') + +application = get_wsgi_application()