diff --git a/.gitignore b/.gitignore index de240f5..e7216ea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ db.sqlite3 news/__pycache__ pokercc/__pycache__ - - +news/migrations/__pycache__/ +**/.DS_Store +rumble/ diff --git a/news/choices.py b/news/choices.py index 74ac3e2..92fc064 100644 --- a/news/choices.py +++ b/news/choices.py @@ -1,5 +1,6 @@ STYLE_CHOICES = ( - (0, "Standard"), - (1, "Quote"), - (2, "Image Only") + (0, "Standard [Title + URL + Image]"), + (1, "Quote [Title]"), + (2, "Image Only [Image]"), + (3, "Youtube [Put video id in URL]") ) diff --git a/news/forms.py b/news/forms.py index 652e213..386bdc7 100644 --- a/news/forms.py +++ b/news/forms.py @@ -10,18 +10,18 @@ from datetime import datetime, date, time, timedelta class PostForm(forms.Form): style = forms.ChoiceField(label='Style',choices=STYLE_CHOICES, required=True) - title = forms.CharField(label='Title', max_length=200, required=False) - body = forms.CharField(label='Optional text', max_length=10000, required=False) - + title = forms.CharField(label='Title (required for slug/SEO)', max_length=200, required=True) url = forms.CharField(label='URL', max_length=200, required=False) - # date = forms.DateTimeField('date published') - # state = forms.IntegerField(label='State', default=1) + + body = forms.CharField(label='Optional body', max_length=10000, required=False) today = datetime.today() # + datetime.timedelta(days=1) 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) - image = forms.FileField() class SigninForm(forms.Form): username = forms.CharField(label='Enter Username', min_length=4, max_length=150) 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/migrations/0008_auto_20191010_0909.py b/news/migrations/0008_auto_20191010_0909.py new file mode 100644 index 0000000..6fce27c --- /dev/null +++ b/news/migrations/0008_auto_20191010_0909.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.6 on 2019-10-10 09:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('news', '0007_auto_20191009_1009'), + ] + + operations = [ + migrations.AddField( + model_name='post', + name='slug', + field=models.SlugField(default='', unique=True), + ), + migrations.AlterField( + model_name='tag', + name='post', + field=models.ManyToManyField(blank=True, to='news.Post'), + ), + ] diff --git a/news/migrations/0009_auto_20191010_0910.py b/news/migrations/0009_auto_20191010_0910.py new file mode 100644 index 0000000..ad315f8 --- /dev/null +++ b/news/migrations/0009_auto_20191010_0910.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.6 on 2019-10-10 09:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('news', '0008_auto_20191010_0909'), + ] + + operations = [ + migrations.AlterField( + model_name='post', + name='slug', + field=models.SlugField(default=''), + ), + ] diff --git a/news/migrations/0010_auto_20191010_0945.py b/news/migrations/0010_auto_20191010_0945.py new file mode 100644 index 0000000..5cbb56e --- /dev/null +++ b/news/migrations/0010_auto_20191010_0945.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.6 on 2019-10-10 09:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('news', '0009_auto_20191010_0910'), + ] + + operations = [ + migrations.AlterField( + model_name='post', + name='slug', + field=models.SlugField(default='', max_length=200), + ), + ] diff --git a/news/migrations/__pycache__/0001_initial.cpython-37.pyc b/news/migrations/__pycache__/0001_initial.cpython-37.pyc deleted file mode 100644 index ba6cfaa..0000000 Binary files a/news/migrations/__pycache__/0001_initial.cpython-37.pyc and /dev/null differ diff --git a/news/migrations/__pycache__/0002_auto_20190917_1255.cpython-37.pyc b/news/migrations/__pycache__/0002_auto_20190917_1255.cpython-37.pyc deleted file mode 100644 index f179e43..0000000 Binary files a/news/migrations/__pycache__/0002_auto_20190917_1255.cpython-37.pyc and /dev/null differ diff --git a/news/migrations/__pycache__/0003_auto_20190917_1258.cpython-37.pyc b/news/migrations/__pycache__/0003_auto_20190917_1258.cpython-37.pyc deleted file mode 100644 index ef15007..0000000 Binary files a/news/migrations/__pycache__/0003_auto_20190917_1258.cpython-37.pyc and /dev/null differ diff --git a/news/migrations/__pycache__/0004_auto_20190917_1301.cpython-37.pyc b/news/migrations/__pycache__/0004_auto_20190917_1301.cpython-37.pyc deleted file mode 100644 index aa3204c..0000000 Binary files a/news/migrations/__pycache__/0004_auto_20190917_1301.cpython-37.pyc and /dev/null differ diff --git a/news/migrations/__pycache__/0005_auto_20190918_0918.cpython-37.pyc b/news/migrations/__pycache__/0005_auto_20190918_0918.cpython-37.pyc deleted file mode 100644 index d815e75..0000000 Binary files a/news/migrations/__pycache__/0005_auto_20190918_0918.cpython-37.pyc and /dev/null differ diff --git a/news/migrations/__pycache__/__init__.cpython-37.pyc b/news/migrations/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 6521513..0000000 Binary files a/news/migrations/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/news/models.py b/news/models.py index 2300b0b..e5288df 100644 --- a/news/models.py +++ b/news/models.py @@ -1,6 +1,8 @@ from django.db import models from django.contrib.auth.models import User from django.conf import settings +from django.db.models import Q +from django.utils.text import slugify from enum import Enum # Create your models here. @@ -11,7 +13,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) @@ -19,25 +21,45 @@ class Post(models.Model): state = models.IntegerField(default=0) style = models.IntegerField(default=0) image_url = models.CharField(max_length=100) + slug = models.SlugField(default='', max_length=200) + + def save(self, *args, **kwargs): + self.slug = slugify(self.title) + super(Post, self).save(*args, **kwargs) + def __str__(self): - return self.title + string = self.title + if self.style == 2: + string = "some image" + elif self.style == 3: + string = "Youtube: " + self.title + return string + + def get_absolute_url(self): + kwargs = { + 'pk': self.id, + 'slug': self.slug + } + return reverse('post_detail', kwargs=kwargs) def top_comments(self): - return self.comment_set.order_by('-voters').all()[:1] + return self.comment_set.filter(Q(parent_comment=None)).order_by('-voters').all()[:1] def flat_comments(self, user): flat = [] - for comment in self.comment_set.all(): - # flat.append(comment) - flat.extend(comment.flat_children(0, user)) + for comment in self.comment_set.filter(Q(parent_comment=None)).all(): + children = comment.flat_children(0, user) + flat.extend(children) return flat - def is_youtube_video(self): - return "youtube.com" in self.url - - # return self.comment_set.annotate(ratings_num=count('voters')).order_by('-ratings_num')[:5] - # return self.comment_set.order_by('voters_num').all()[:5] + def formatted_tags(self): + tag_names = map(lambda t: t.name, self.tag_set.all()) + return ", ".join(tag_names) + def html_title(self): + if self.title: + return self.title + return 'Poker Rumble - Amazing content' class Comment(models.Model): author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True) @@ -68,7 +90,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 +99,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, 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 e68f179..e8543b5 100644 --- a/news/static/news/css/app.css +++ b/news/static/news/css/app.css @@ -46,10 +46,6 @@ header { } } -/* header a { - text-decoration: none; -} */ - .title { background-color: var(--header-bg-color); } @@ -59,8 +55,7 @@ header h1 { margin-bottom: 0px; font-family: "HelveticaNeue-CondensedBlack", "HelveticaNeueBlackCondensed", "HelveticaNeue-Black-Condensed", "Helvetica Neue Black Condensed", "HelveticaNeueBlack", "HelveticaNeue-Black", "Helvetica Neue Black", "HelveticaNeue", "Helvetica Neue", 'TeXGyreHerosCnBold', "Helvetica", "Tahoma", "Geneva", "Arial Narrow", "Arial", sans-serif; font-weight:900; - font-stretch:condensed; /* font-family: 'LibreBaskervilleBold'; */ - /* letter-spacing: -1px; */ + font-stretch:condensed; text-transform: uppercase; font-size: 32px; } @@ -75,6 +70,9 @@ header h1 a { color: #fff; } +header h1 a:hover { + color: #BFA030; +} header h2 { margin-top: -10px; padding: 0; @@ -83,7 +81,6 @@ header h2 { nav { padding: 4px; - /* margin-top: 4px; */ font-size: 14px; background-color: #333; } @@ -152,18 +149,6 @@ a h1 { } } -.inside_image_top { - position: absolute; - top: 12px; - left: 12px; -} - -.inside_image_bottom { - position: absolute; - bottom: 12px; - left: 12px; -} - .details { font-size: 14px; color: #999; @@ -192,17 +177,39 @@ a h1 { .imgcontainer { position: relative; color: white; - border-bottom: 10px solid #111; - border-top: 10px solid #111; + /* border-bottom: 0px solid #111; */ + /* border-top: 20px solid #111; */ } @media print, screen and (min-width: 40em) { .imgcontainer { - width: 500px; - border-bottom: 10px solid #111; - border-top: 10px solid #111; + width: 600px; + /* border-bottom: 10px solid #111; */ + /* border-top: 20px solid #111; */ } } +.imgcontainer h1 { + padding: 0px 8px; + line-height: 120%; +} + +.imgcontainer h1 span { + background-color: #000; +} + +.inside_image_top { + position: absolute; + top: 0px; + left: 12px; + right: 12px; +} + +.inside_image_bottom { + position: absolute; + bottom: 12px; + left: 12px; +} + .post { padding: 10px 0px; margin-bottom: 10px; @@ -293,7 +300,7 @@ input[type=email] { input[type=file] { font-size: 14px; padding:10px 15px; - background:#e8e8e8; + background:#555; border:0 none; cursor:pointer; -webkit-border-radius: 8px; @@ -303,7 +310,7 @@ input[type=file] { input[type=file]:hover { font-size: 14px; padding:10px 15px; - background:#fcf; + background:#777; border:0 none; cursor:pointer; -webkit-border-radius: 8px; @@ -339,3 +346,26 @@ form .secondary_button { .reply_form { margin-top: 8px; } + +.youtube { + width: 95vw; + height: 60vw; +} +/* @media print, screen and (min-width: 40em) { + .youtube { + width: 90vw; + height: 60vw; + } +} */ +@media print, screen and (min-width: 50em) { + .youtube { + width: 60vw; + height: 35vw; + } +} +@media print, screen and (min-width: 70em) { + .youtube { + width: 45vw; + height: 25vw; + } +} diff --git a/news/templates/base.html b/news/templates/base.html index a761eb5..b94b408 100644 --- a/news/templates/base.html +++ b/news/templates/base.html @@ -8,6 +8,22 @@
+ {% endfor %} +
{{ post.title }}
+ + + + +- + {% else %}
- + Please login to comment the post
- - + {% endif %}