bug fix on comments + UI improvements

master
Laurent Morvillier 6 years ago
parent 1a6d822a08
commit 4a196fadd3
  1. 3
      news/choices.py
  2. 22
      news/models.py
  3. 23
      news/static/news/css/app.css
  4. 19
      news/templates/news/index.html

@ -1,5 +1,6 @@
STYLE_CHOICES = (
(0, "Standard [Title + URL + Image]"),
(1, "Quote [Title]"),
(2, "Image Only [Image]")
(2, "Image Only [Image]"),
(3, "Youtube [Put video id in URL]")
)

@ -2,6 +2,7 @@ from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
from enum import Enum
from django.db.models import Q
# Create your models here.
class PostState(Enum):
@ -19,26 +20,25 @@ class Post(models.Model):
state = models.IntegerField(default=0)
style = models.IntegerField(default=0)
image_url = models.CharField(max_length=100)
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 top_comments(self):
return self.comment_set.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]
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)

@ -349,3 +349,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;
}
}

@ -20,12 +20,6 @@
<!-- A post -->
{% if post.style == 0 %}
{% if post.is_youtube_video %}
<a href="{{ post.url }}">
<h1>{{ post.title }}</h1>
</a>
<iframe src="{{ post.url }}" width="600" height="400"></iframe>
{% else %}
<div class="imgcontainer">
<img src="{% static 'media/' %}{{ post.image_url }}"/>
<div class="inside_image_top">
@ -40,7 +34,6 @@
{% endif %}
</div>
</div>
{% endif %}
<div class="details">
<a href="{% url 'news:post' post.id %}">{% if post.comment_set.count > 0 %}{{ post.comment_set.count }} comment{% if post.comment_set.count > 1 %}s{% endif %}{% else %}write comment{% endif %}</a>
@ -77,13 +70,9 @@
<!-- Media no title no link -->
{% elif post.style == 2 %}
{% if post.is_youtube_video %}
<iframe src="{{ post.url }}" width="600" height="400"></iframe>
{% else %}
<div class="imgcontainer">
<img class="crop" src="{% static 'media/' %}{{ post.image_url }}"/>
</div>
{% endif %}
<div class="post_padding">
<div class="details info">
@ -97,6 +86,14 @@
</div>
</div>
{% elif post.style == 3 %}
<a href="{{ post.url }}">
<h1>{{ post.title }}</h1>
</a>
<iframe class="youtube" src="https://www.youtube.com/embed/{{ post.url }}"></iframe>
{% endif %}
</article>

Loading…
Cancel
Save