diff --git a/db.sqlite3 b/db.sqlite3 index 7acf0aa..f6f97dd 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/news/__pycache__/choices.cpython-37.pyc b/news/__pycache__/choices.cpython-37.pyc index d2e07d7..6271ed9 100644 Binary files a/news/__pycache__/choices.cpython-37.pyc and b/news/__pycache__/choices.cpython-37.pyc differ diff --git a/news/__pycache__/forms.cpython-37.pyc b/news/__pycache__/forms.cpython-37.pyc index a957475..9fc2b5e 100644 Binary files a/news/__pycache__/forms.cpython-37.pyc and b/news/__pycache__/forms.cpython-37.pyc differ diff --git a/news/__pycache__/models.cpython-37.pyc b/news/__pycache__/models.cpython-37.pyc index d7b7439..1307b32 100644 Binary files a/news/__pycache__/models.cpython-37.pyc 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 index e5ecb0f..5009421 100644 Binary files a/news/__pycache__/urls.cpython-37.pyc 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 index 2d16379..66cb150 100644 Binary files a/news/__pycache__/views.cpython-37.pyc and b/news/__pycache__/views.cpython-37.pyc differ diff --git a/news/forms.py b/news/forms.py index 17e73b8..f4af69c 100644 --- a/news/forms.py +++ b/news/forms.py @@ -3,14 +3,22 @@ from django.contrib.auth.models import User from django import forms from django.core.exceptions import ValidationError from .choices import * +import time +from datetime import datetime, date, time, timedelta +# from datetime import datetime class PostForm(forms.Form): - title = forms.CharField(label='Title', max_length=200) - body = forms.CharField(label='Optional text', max_length=10000) url = forms.CharField(label='URL', max_length=200) + title = forms.CharField(label='Title', max_length=200) + body = forms.CharField(label='Optional text', max_length=10000, required=False) # date = forms.DateTimeField('date published') # state = forms.IntegerField(label='State', default=1) style = forms.ChoiceField(label='Style',choices=STYLE_CHOICES, required=True) + + today = datetime.today() # + datetime.timedelta(days=1) + today_formatted = today.strftime("%Y-%m-%d %H:%M:%S") + + pub_date = forms.DateTimeField(label='Optional publication date, example: ' + today_formatted, required=False) image = forms.FileField() class SigninForm(forms.Form): diff --git a/news/migrations/0005_auto_20190918_0918.py b/news/migrations/0005_auto_20190918_0918.py new file mode 100644 index 0000000..b4fcec0 --- /dev/null +++ b/news/migrations/0005_auto_20190918_0918.py @@ -0,0 +1,30 @@ +# Generated by Django 2.2.5 on 2019-09-18 09:18 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('news', '0004_auto_20190917_1301'), + ] + + operations = [ + migrations.AddField( + model_name='comment', + name='deleted', + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name='comment', + name='parent_comment', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='news.Comment'), + ), + migrations.AlterField( + model_name='comment', + name='post', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='news.Post'), + preserve_default=False, + ), + ] diff --git a/news/migrations/__pycache__/0005_auto_20190918_0918.cpython-37.pyc b/news/migrations/__pycache__/0005_auto_20190918_0918.cpython-37.pyc new file mode 100644 index 0000000..d815e75 Binary files /dev/null and b/news/migrations/__pycache__/0005_auto_20190918_0918.cpython-37.pyc differ diff --git a/news/models.py b/news/models.py index aee717c..524e02d 100644 --- a/news/models.py +++ b/news/models.py @@ -23,7 +23,7 @@ class Post(models.Model): return self.title def top_comments(self): - return self.comment_set.all()[:5] + return self.comment_set.all()[:3] def flat_comments(self, user): flat = [] @@ -38,10 +38,11 @@ class Post(models.Model): 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) - parent_comment = models.ForeignKey("self", on_delete=models.CASCADE, null=True, blank=True) + parent_comment = models.ForeignKey("self", on_delete=models.SET_NULL, null=True, blank=True) body = models.CharField(max_length=100) voters = models.ManyToManyField(User, related_name='voted_comments', null=True, blank=True) date = models.DateTimeField('date published') + deleted = models.BooleanField(default=False) def __str__(self): return self.body @@ -52,6 +53,7 @@ class Comment(models.Model): self.level = range(level) self.upvoted = user in self.voters.all() self.score = len(self.voters.all()) + self.is_deletable = (self.deleted == False and user == self.author) flat = [self] for comment in self.comment_set.all(): flat.extend(comment.flat_children(level + 1, user)) diff --git a/news/static/media/7490e65c-5ca7-4734-882a-8b268b1662d2 b/news/static/media/7490e65c-5ca7-4734-882a-8b268b1662d2 new file mode 100644 index 0000000..c7f434f Binary files /dev/null and b/news/static/media/7490e65c-5ca7-4734-882a-8b268b1662d2 differ diff --git a/news/static/media/7c44bcb2-d09e-4a68-839e-3e1dfecd9c63 b/news/static/media/7c44bcb2-d09e-4a68-839e-3e1dfecd9c63 new file mode 100644 index 0000000..4c9b220 Binary files /dev/null and b/news/static/media/7c44bcb2-d09e-4a68-839e-3e1dfecd9c63 differ diff --git a/news/static/media/9ebca694-d49c-4f4d-81f5-5d953b5f449b b/news/static/media/9ebca694-d49c-4f4d-81f5-5d953b5f449b new file mode 100644 index 0000000..4c9b220 Binary files /dev/null and b/news/static/media/9ebca694-d49c-4f4d-81f5-5d953b5f449b differ diff --git a/news/static/news/css/app.css b/news/static/news/css/app.css index db2f889..7d8c360 100644 --- a/news/static/news/css/app.css +++ b/news/static/news/css/app.css @@ -143,3 +143,7 @@ header { li a { color: red; } + +.inline { + display: inline-block; +} diff --git a/news/templates/base.html b/news/templates/base.html index 4ed97a0..7d1d37c 100644 --- a/news/templates/base.html +++ b/news/templates/base.html @@ -20,8 +20,8 @@
diff --git a/news/templates/news/post.html b/news/templates/news/post.html
index 1d733bf..23e3503 100644
--- a/news/templates/news/post.html
+++ b/news/templates/news/post.html
@@ -19,31 +19,61 @@
----Comments----
{% for comment in comments %}{% for n in comment.level %}
+ {% if comment.upvoted == False %} +
+ {% endif %} + + {% if comment.is_deletable %} + + {% endif %} + + + + + + + {% for n in comment.level %}{% endfor %} diff --git a/news/templates/news/submission.html b/news/templates/news/submission.html index ff7a283..548cf35 100644 --- a/news/templates/news/submission.html +++ b/news/templates/news/submission.html @@ -1,9 +1,13 @@ {% extends "base.html" %} +{% load static %} + {% block title %}My amazing submission{% endblock %} {% block content %} +{{ form.media }} + {% if error_message %}{{ error_message }}
{% endif %} {% if user.is_authenticated %} diff --git a/news/urls.py b/news/urls.py index 644e8e6..9659c7f 100644 --- a/news/urls.py +++ b/news/urls.py @@ -6,10 +6,11 @@ app_name = 'news' urlpatterns = [ path('', views.index, name='index'), path('