commit
1514224b66
Binary file not shown.
@ -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() |
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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) |
||||
@ -0,0 +1,5 @@ |
||||
from django.apps import AppConfig |
||||
|
||||
|
||||
class NewsConfig(AppConfig): |
||||
name = 'news' |
||||
@ -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')), |
||||
], |
||||
), |
||||
] |
||||
Binary file not shown.
Binary file not shown.
@ -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 |
||||
@ -0,0 +1,13 @@ |
||||
<h1>Poker CC</h1> |
||||
|
||||
{% if latest_post_list %} |
||||
<ul> |
||||
{% for post in latest_post_list %} |
||||
<li><a href="{% url 'news:post' post.id %}">{{ post.title }}</a></li> |
||||
{% endfor %} |
||||
</ul> |
||||
{% else %} |
||||
<p>No posts are available.</p> |
||||
{% endif %} |
||||
|
||||
<a href="{% url 'news:submission' %}">Submit</a></li> |
||||
@ -0,0 +1,10 @@ |
||||
<a href="{{ post.url }}"><h1>{{ post.title }}</h1></a> |
||||
<h3>written by {{ post.author.username }}</h3> |
||||
<p>----Body----</p> |
||||
<p>{{ post.content }}</p> |
||||
<p>----Comments----</p> |
||||
<ul> |
||||
{% for comment in post.comment_set.all %} |
||||
<li>{{ comment.content }}</li> |
||||
{% endfor %} |
||||
</ul> |
||||
@ -0,0 +1,41 @@ |
||||
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} |
||||
|
||||
{% if user.is_authenticated %} |
||||
|
||||
<form action="{% url 'news:submit' %}" method="post"> |
||||
{% csrf_token %} |
||||
|
||||
<p> |
||||
<span>Title</span>> |
||||
<input type="text" name="title" maxlength="200" required id="id_title"> |
||||
</p> |
||||
<p> |
||||
<span>Image URL</span>> |
||||
<input type="text" name="image_url" maxlength="200" required id="id_image_url"> |
||||
</p> |
||||
<p> |
||||
<span>Content</span>> |
||||
<input type="text" name="content" maxlength="10000" required id="id_content"> |
||||
</p> |
||||
<p> |
||||
<span>URL</span>> |
||||
<input type="text" name="url" maxlength="200" required id="id_url"> |
||||
</p> |
||||
|
||||
<p> |
||||
<input type="radio" name="state" id="1" value="1"> |
||||
<label for="choice1">Publish</label> |
||||
<input type="radio" name="state" id="2" value="2"> |
||||
<label for="choice2">Draft</label> |
||||
<input type="radio" name="state" id="3" value="3"> |
||||
<label for="choice3">Program</label> |
||||
</p> |
||||
|
||||
<br/> |
||||
|
||||
<input type="submit" value="Submit"> |
||||
</form> |
||||
|
||||
{% else %} |
||||
<a href="../admin/login">Please log in</a> |
||||
{% endif %} |
||||
@ -0,0 +1,3 @@ |
||||
<p>Thanks :)</p> |
||||
|
||||
<p><a href="{% url 'news:index' %}">Home</a></p> |
||||
@ -0,0 +1,3 @@ |
||||
from django.test import TestCase |
||||
|
||||
# Create your tests here. |
||||
@ -0,0 +1,13 @@ |
||||
from django.urls import path |
||||
|
||||
from . import views |
||||
|
||||
app_name = 'news' |
||||
urlpatterns = [ |
||||
path('', views.index, name='index'), |
||||
path('<int:post_id>', views.post, name='post'), |
||||
path('submission', views.submission, name='submission'), |
||||
path('submit', views.submit, name='submit'), |
||||
path('submitted', views.submitted, name='submitted'), |
||||
|
||||
] |
||||
@ -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', {}) |
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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/' |
||||
@ -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) |
||||
] |
||||
@ -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() |
||||
Loading…
Reference in new issue