diff --git a/news/forms.py b/news/forms.py index 3874a87..6de3f19 100644 --- a/news/forms.py +++ b/news/forms.py @@ -19,6 +19,8 @@ class PostForm(forms.Form): today_formatted = today.strftime("%Y-%m-%d %H:%M:%S") image = forms.FileField(required=False) + tags = forms.CharField(label='Tags (separated by a comma)', max_length=200, required=False) + pub_date = forms.DateTimeField(label='Optional publication date, example: ' + today_formatted, required=False) class SigninForm(forms.Form): diff --git a/news/migrations/0006_auto_20191009_1004.py b/news/migrations/0006_auto_20191009_1004.py new file mode 100644 index 0000000..d66c7ed --- /dev/null +++ b/news/migrations/0006_auto_20191009_1004.py @@ -0,0 +1,35 @@ +# Generated by Django 2.2.6 on 2019-10-09 10:04 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('news', '0005_auto_20190918_0918'), + ] + + operations = [ + migrations.AlterField( + model_name='comment', + name='voters', + field=models.ManyToManyField(blank=True, related_name='voted_comments', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='player', + name='post', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='news.Post'), + ), + migrations.AlterField( + model_name='post', + name='author', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='tag', + name='post', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='news.Post'), + ), + ] diff --git a/news/migrations/0007_auto_20191009_1009.py b/news/migrations/0007_auto_20191009_1009.py new file mode 100644 index 0000000..210df31 --- /dev/null +++ b/news/migrations/0007_auto_20191009_1009.py @@ -0,0 +1,22 @@ +# Generated by Django 2.2.6 on 2019-10-09 10:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('news', '0006_auto_20191009_1004'), + ] + + operations = [ + migrations.RemoveField( + model_name='tag', + name='post', + ), + migrations.AddField( + model_name='tag', + name='post', + field=models.ManyToManyField(blank=True, null=True, to='news.Post'), + ), + ] diff --git a/news/models.py b/news/models.py index 52e4525..9020bb0 100644 --- a/news/models.py +++ b/news/models.py @@ -12,7 +12,7 @@ class PostState(Enum): USER_SUBMITTED = 3 class Post(models.Model): - author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True) title = models.CharField(max_length=200) body = models.CharField(max_length=10000) url = models.CharField(max_length=200) @@ -39,6 +39,10 @@ class Post(models.Model): flat.extend(children) return flat + def formatted_tags(self): + tag_names = map(lambda t: t.name, self.tag_set.all()) + return ", ".join(tag_names) + class Comment(models.Model): author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True) post = models.ForeignKey(Post, on_delete=models.CASCADE) @@ -68,7 +72,7 @@ class Comment(models.Model): class Player(models.Model): name = models.CharField(max_length=100) - post = models.ForeignKey(Post, on_delete=models.CASCADE) + post = models.ForeignKey(Post, on_delete=models.SET_NULL, null=True) image_url = models.CharField(max_length=100) def __str__(self): @@ -77,6 +81,6 @@ class Player(models.Model): class Tag(models.Model): name = models.CharField(max_length=100) - post = models.ForeignKey(Post, on_delete=models.CASCADE) + post = models.ManyToManyField(Post, null=True, blank=True) def __str__(self): return self.name diff --git a/news/static/news/css/app.css b/news/static/news/css/app.css index b0655d2..af9faae 100644 --- a/news/static/news/css/app.css +++ b/news/static/news/css/app.css @@ -181,13 +181,13 @@ a h1 { position: relative; color: white; /* border-bottom: 0px solid #111; */ - border-top: 20px solid #111; + /* border-top: 20px solid #111; */ } @media print, screen and (min-width: 40em) { .imgcontainer { width: 600px; /* border-bottom: 10px solid #111; */ - border-top: 20px solid #111; + /* border-top: 20px solid #111; */ } } diff --git a/news/templates/base.html b/news/templates/base.html index 49a5f9f..b94b408 100644 --- a/news/templates/base.html +++ b/news/templates/base.html @@ -8,6 +8,22 @@ {% block title %}My amazing site{% endblock %} + + + + @@ -61,6 +77,8 @@ diff --git a/news/templates/news/index.html b/news/templates/news/index.html index caee1d8..4a88248 100644 --- a/news/templates/news/index.html +++ b/news/templates/news/index.html @@ -2,7 +2,7 @@ {% load static %} -{% block title %}My amazing blog{% endblock %} +{% block title %}Poker Rumble - {% endblock %} {% block content %} {% if latest_post_list %} @@ -95,6 +95,11 @@ {% endif %} + + + diff --git a/news/templates/news/static/about.html b/news/templates/news/static/about.html new file mode 100644 index 0000000..f75243b --- /dev/null +++ b/news/templates/news/static/about.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} + +{% block title %}About - Poker Rumble{% endblock %} + +{% block content %} + +

About

+ +

+ This site is owned by Stax River. + It is hosted by ALWAYSDATA, 91 rue du Faubourg Saint-Honoré, 75008 Paris (phone: +33 1 84 16 23 40). +

+ +{% endblock content %} diff --git a/news/templates/news/static/contact.html b/news/templates/news/static/contact.html index 5d5acce..5bf2e81 100644 --- a/news/templates/news/static/contact.html +++ b/news/templates/news/static/contact.html @@ -1,13 +1,13 @@ {% extends "base.html" %} -{% block title %}Contact{% endblock %} +{% block title %}Contact - Poker Rumble{% endblock %} {% block content %}

Contact

- Please contact us directly on social media! + Please contact us directly on social media, @pokerrumble on twitter and instagram!

{% endblock content %} diff --git a/news/templates/news/user/password_reset_html_email.html b/news/templates/news/user/password_reset_html_email.html index 234bfef..f6bcfad 100644 --- a/news/templates/news/user/password_reset_html_email.html +++ b/news/templates/news/user/password_reset_html_email.html @@ -1,3 +1,3 @@ -Someone asked for password reset for email {{ email }}. -Follow the link below: +Someone asked for a password reset for email {{ email }}. +Please follow the link below: {{ protocol}}://{{ domain }}{% url 'news:password_reset_confirm' uidb64=uid token=token %} diff --git a/news/urls.py b/news/urls.py index f8f4936..48f2a90 100644 --- a/news/urls.py +++ b/news/urls.py @@ -8,6 +8,7 @@ app_name = 'news' urlpatterns = [ # Static path('contact', TemplateView.as_view(template_name='news/static/contact.html'), name='contact'), + path('about', TemplateView.as_view(template_name='news/static/about.html'), name='about'), # Posts path('', views.index, name='index'), path('', views.post, name='post'), diff --git a/news/views.py b/news/views.py index 4b0f68e..1384a91 100644 --- a/news/views.py +++ b/news/views.py @@ -11,7 +11,7 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.forms import PasswordChangeForm from django.db.models import Q from django.utils.html import strip_tags -from .models import Post, Comment, PostState +from .models import Post, Comment, PostState, Tag from .forms import PostForm, CustomUserCreationForm, SigninForm from datetime import datetime import logging @@ -106,6 +106,9 @@ def submission(request): post.url = form.cleaned_data['url'] post.style = form.cleaned_data['style'] + tags = parsed_tags(form.cleaned_data['tags']) + post.tag_set.add(*tags) + file = request.FILES.get('image', None) if file is not None: filename = str(uuid.uuid4()) @@ -128,6 +131,15 @@ def submission(request): return render(request, 'news/submission.html', {'form': form}) +def parsed_tags(tag_strings): + tags = [] + separated_tags_strings = tag_strings.split(",") + for tag_string in separated_tags_strings: + tag, created = Tag.objects.get_or_create(name=tag_string.strip()) + tag.save() + tags.append(tag) + return tags + def handle_uploaded_file(filename, f): with open(settings.MEDIA_ROOT + filename, 'wb+') as destination: for chunk in f.chunks(): @@ -144,7 +156,7 @@ def comment_with_parent(request, post_id, comment_id): comment.post = get_object_or_404(Post, pk=post_id) if comment_id is not None: comment.parent_comment = get_object_or_404(Comment, pk=comment_id) - comment.body = strip_tags(request.POST['body']) + comment.body = strip_tags(request.POST['body']) # removes HTML tags comment.save() comment.voters.add(request.user) comment.save()