From 2895a94ae7eea2ce558b3307cacc2b5c5c54926b Mon Sep 17 00:00:00 2001 From: Laurent Morvillier Date: Thu, 3 Oct 2019 15:29:35 +0200 Subject: [PATCH 1/9] removed pycache from git + updated config for prod --- .gitignore | 5 +++-- .../__pycache__/0001_initial.cpython-37.pyc | Bin 1578 -> 0 bytes .../0002_auto_20190917_1255.cpython-37.pyc | Bin 716 -> 0 bytes .../0003_auto_20190917_1258.cpython-37.pyc | Bin 920 -> 0 bytes .../0004_auto_20190917_1301.cpython-37.pyc | Bin 812 -> 0 bytes .../0005_auto_20190918_0918.cpython-37.pyc | Bin 890 -> 0 bytes .../__pycache__/__init__.cpython-37.pyc | Bin 141 -> 0 bytes pokercc/._settings.py | Bin 0 -> 4096 bytes pokercc/settings.py | 4 ++-- pokercc/urls.py | 2 +- 10 files changed, 6 insertions(+), 5 deletions(-) delete mode 100644 news/migrations/__pycache__/0001_initial.cpython-37.pyc delete mode 100644 news/migrations/__pycache__/0002_auto_20190917_1255.cpython-37.pyc delete mode 100644 news/migrations/__pycache__/0003_auto_20190917_1258.cpython-37.pyc delete mode 100644 news/migrations/__pycache__/0004_auto_20190917_1301.cpython-37.pyc delete mode 100644 news/migrations/__pycache__/0005_auto_20190918_0918.cpython-37.pyc delete mode 100644 news/migrations/__pycache__/__init__.cpython-37.pyc create mode 100644 pokercc/._settings.py 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/migrations/__pycache__/0001_initial.cpython-37.pyc b/news/migrations/__pycache__/0001_initial.cpython-37.pyc deleted file mode 100644 index ba6cfaa11d4abe5519b59e9a213748ac8242311e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1578 zcma)6OK;mo5ayB;B}$a6Bu-j8Y3jbAi{zrG21OCak2YwX2DN-4P!N=6L{nKlx}==S zJ+@c#A`cpZp z%O>M7J;fs$zyQXLg!zmq+vH|q`Bq~4w)QPv^PR5@u%Y&=0X4Ly^QOyWp{Wt^pjbdn5^7th8jZ*_IacuY_6H!}=0d8)vVdV6|Dv4Xc2=ERI#cza=LZac5#w!49Ie-j5DEK#gA z$~*r9Ws}>RFzq$w!`EU~I;|?)ROXHK!n>*hU^iO89=x}(NO#R+W9Gqf=6zbT4IgOL zKGdq!6}QOt@4`paHy=y)bk!t7X+O`3QkpTGNb~7Y&z4>|E3;rMFf0*dD;IGRih1w? z=h7`u#37HbPEY=?+mWP+OB z&C-B69ZQsEnNh&jtei=V913X-!${m$OYEGAy>e50S@dzT*!`k!)lrO6Fq@kNvIXl$G^V55Er1&yK$j zPQN=k{#JVHj2H{qI@FtZs!jo+P95nU(B7UXRit}(5sJ!e9}&-CoM7d8Pty`3TuwGm zGJ$cFenb23z%)#wOqwu~4J|mGGo;FnVxWhA z9u3Z^lZpWkXG-h=;N>9CUZ5C{2TJe3%^^0}-{1c{&Bx#nPxBO=Ac9I# z(~MFVd(x{}#%e$FyPU}&3ttl9i{Kj(0kA6i%CbnXIT?h%@qaR)Hg2G8OSNnUo=xg< zY4Wzzs!FsL6a?(-dDz5<{&IgwzNO3mUvoY`LoZEzR#H}S@+~@q`I+qUXG65@40#s2# zV;Ih7lc{XMoVZ(zliVgJ+CaHfui@H;qRQ1$TTfirxMPBf+309GKbjuTjOXxs)5ZBK zzL?M6@zb}*vo|);E4bD6J28(C)44yhbkTrmQkky}j++Yjl&NO#{KD|$4_79Y`#CQMz 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 ef15007084b50e9e3541f61dfff2bca46ccbfd55..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 920 zcmZWn&u`N(6n5eyP1APU4e>)9;FL?#4NWkF&`Q^V1RWCFE|HLx)m~}l*u_qV1`;4e_BjhVw_!l_woHR^gj{N-m^7%b~pWm}yFG4Ur{rK|s7e?r(-891kXBVb^42B}= za8x*{<5=J2Zh=!=c&S(IG56EpIieo*zai=~oVUK>v_tCcH7m=xnCaLx zQ8AyXtei`sO;AY6xIUO#Tr)c0?84Na!7!9M6s0b8W=@Kkm;2PEm<4$YDtau;+j)>j zd53lL9`!Fh8eBH0)^!vO|HHHavt~2VsLIf(Gt6+hPP@RMXWEnIx^Q<-un*eY7z_qm zBwLn}Yz;Pd20NP%$>!GfwrNdeQ7}=O0Diuc>L~V%f5J0y1}B%Co3<1L2(ywIx0Epk zF{}VYWCa6=wf^axacb5UnSxAYmGNWOR_>3Q{O7V{N}Dyi(gvhsPuWLRRzcHMjA!<* zO{;nkI*2z+NUA*{CL#oiFF6ChOUV0W#x2tBC|fW=nV8O*R?r;CL_-b*_wCh`?G6*| zOU33h@seGbfaaN)N#oKJ6IS%#aZPJ9JRA-8#>%z$_2Kc+3vzroenTd&_r|Zx`Xmz< zN7C9Vt%>A3oh7dr)w6B1ne zL-GcAF94tKv2?gGtPUufLobV5S!7oI1frF{ieH7{o>v~^I- zXELegqEy-|1czK5r6z7Y46j|B>Ma70*y1F%xizz53Qp#7n^W+z7I(nU+L@OHSqHjV zkGm_%z12FV)x`W8#eLphIVNUi$5(iO3_H4gxTb^LoDx1NePb{fY_Vin3AQ;H?hJN@ z_t|js-UHoAMNvRmX%9Ew33(h+JhIGl-4-Q7B~XF3D}nByR>sPt01Pqcp3WiX+F1xy zeQKMF`mfLo9qmr@q&$;Gx9k|`A{>Pq+GlkF#&p0KCS2x#c9*gD%Op2R&5FYUN)BZ@ z2PG+<)WImPKpvRuq-muN4upjHtb7jV+T&SL&V;u4RQok$?1XOZjV61e{jtQSK=j7w z;2HzorZcp73FC|w0+^>(^`3>_SRo# lzjfgc5cS8#v0Wz(7Z6fUaPlQipomsNsA*|AP%5Oh7fWd6W~NbG+iTWNQF}vh z;F2H0U)n1t{s0F~%-Tr{Ywh#w?9S|av$Nmp`38;R_m_{~ZNvDf7wf^u*rQnu3BUj| zGjcOFb1Sw?y|ywtW^WC!fqgT8p_z8R+HnW0QzPvBq8KBzl%LOMGO6dHsFafnz^po% z>b>>Q_wUiHY63K36O7mbb7saivXrucjZWGH2A!n|&Qg0_@^;DVfeSAB=|<|LLD~Zk z{3ZM6%tmu2xI58@9`u*Q7dDq{X2+Wl5Z8h7-mgg#V^-kjNp6JGf)pTp>!_*YSuEOg}}!0V_KS16~`NEafy@2!ZQ>&1W1wZrMn zc82AR)P3BgS#1%xw!@fd(bu=y|JLgN&}>eIj`CXKL%3+vx0)Z{Ifrc<57&~U&fCP^ Xb8oGuw4vNrZJl51(p8$wz;x}u*AMd{ diff --git a/news/migrations/__pycache__/__init__.cpython-37.pyc b/news/migrations/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 652151316cf383d8689c47ddb963f3c35354ffd0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 141 zcmZ?b<>g`k0`3LXu^{>}h=2h`Aj1KOi&=m~3PUi1CZpd$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xD64 z=wMg?WDB5aVFdD_;!?@^xq68O1v#mDIf=z3rNyZ!DTyVi$^pS3J*A(f#)4>Pm6w_z zdK8R?z-S1JhQMeDjE2By2#kinXb6mkz-S1JhQMeDjD`TN5CC;HK^P3=LNYRo6^c@e z^Gl18Qx($ki?S6m^GZ_lN;32F5_57Y6>?J3N)(cE67#ZwePO7sAx)wBAMO Date: Thu, 3 Oct 2019 16:43:09 +0200 Subject: [PATCH 2/9] UI / submission improvements --- news/choices.py | 6 ++--- news/forms.py | 8 +++---- news/static/news/css/app.css | 40 +++++++++++++++++++++------------- news/templates/news/index.html | 2 +- news/views.py | 8 ++++--- 5 files changed, 37 insertions(+), 27 deletions(-) diff --git a/news/choices.py b/news/choices.py index 74ac3e2..939064d 100644 --- a/news/choices.py +++ b/news/choices.py @@ -1,5 +1,5 @@ STYLE_CHOICES = ( - (0, "Standard"), - (1, "Quote"), - (2, "Image Only") + (0, "Standard [Title + URL + Image]"), + (1, "Quote [Title]"), + (2, "Image Only [Image]") ) diff --git a/news/forms.py b/news/forms.py index 652e213..3874a87 100644 --- a/news/forms.py +++ b/news/forms.py @@ -11,17 +11,15 @@ 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) - 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) 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/static/news/css/app.css b/news/static/news/css/app.css index e68f179..f7f6ad6 100644 --- a/news/static/news/css/app.css +++ b/news/static/news/css/app.css @@ -152,18 +152,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; @@ -197,12 +185,34 @@ a h1 { } @media print, screen and (min-width: 40em) { .imgcontainer { - width: 500px; + width: 600px; border-bottom: 10px solid #111; border-top: 10px solid #111; } } +.imgcontainer h1 { + padding: 0px 8px; + line-height: 120%; +} + +.imgcontainer h1 span { + background-color: #111111; +} + +.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 +303,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 +313,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; diff --git a/news/templates/news/index.html b/news/templates/news/index.html index 747f42f..7e2dbbe 100644 --- a/news/templates/news/index.html +++ b/news/templates/news/index.html @@ -30,7 +30,7 @@
{% if post.url %}{% endif %} -

{{ post.title }}

+

{{ post.title }}

{% if post.url %}
{% endif %} {% if post.body %} diff --git a/news/views.py b/news/views.py index 809cd41..4b0f68e 100644 --- a/news/views.py +++ b/news/views.py @@ -106,10 +106,12 @@ def submission(request): post.url = form.cleaned_data['url'] post.style = form.cleaned_data['style'] - filename = str(uuid.uuid4()) - handle_uploaded_file(filename, request.FILES['image']) + file = request.FILES.get('image', None) + if file is not None: + filename = str(uuid.uuid4()) + handle_uploaded_file(filename, file) + post.image_url = filename - post.image_url = filename if request.user.is_staff: post.state = PostState.PUBLISHED.value pub_date = form.cleaned_data['pub_date'] From 4a196fadd380ff82197dc69870cba8b4c7e98c88 Mon Sep 17 00:00:00 2001 From: Laurent Morvillier Date: Thu, 3 Oct 2019 17:49:45 +0200 Subject: [PATCH 3/9] bug fix on comments + UI improvements --- news/choices.py | 3 ++- news/models.py | 22 +++++++++++----------- news/static/news/css/app.css | 23 +++++++++++++++++++++++ news/templates/news/index.html | 19 ++++++++----------- 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/news/choices.py b/news/choices.py index 939064d..92fc064 100644 --- a/news/choices.py +++ b/news/choices.py @@ -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]") ) diff --git a/news/models.py b/news/models.py index 2300b0b..df6ab82 100644 --- a/news/models.py +++ b/news/models.py @@ -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) diff --git a/news/static/news/css/app.css b/news/static/news/css/app.css index f7f6ad6..78986aa 100644 --- a/news/static/news/css/app.css +++ b/news/static/news/css/app.css @@ -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; + } +} diff --git a/news/templates/news/index.html b/news/templates/news/index.html index 7e2dbbe..caee1d8 100644 --- a/news/templates/news/index.html +++ b/news/templates/news/index.html @@ -20,12 +20,6 @@ {% if post.style == 0 %} - {% if post.is_youtube_video %} - -

{{ post.title }}

-
- - {% else %}
@@ -40,7 +34,6 @@ {% endif %}
- {% endif %}
{% if post.comment_set.count > 0 %}{{ post.comment_set.count }} comment{% if post.comment_set.count > 1 %}s{% endif %}{% else %}write comment{% endif %} @@ -77,13 +70,9 @@ {% elif post.style == 2 %} - {% if post.is_youtube_video %} - - {% else %}
- {% endif %}
@@ -97,6 +86,14 @@
+ {% elif post.style == 3 %} + + +

{{ post.title }}

+
+ + + {% endif %} From f60444c231488bdc7cc8228b829272b8795399c0 Mon Sep 17 00:00:00 2001 From: Laurent Morvillier Date: Tue, 8 Oct 2019 16:26:31 +0200 Subject: [PATCH 4/9] various fixes and improvements --- news/models.py | 2 +- news/static/news/css/app.css | 8 ++-- news/templates/base.html | 2 +- news/templates/news/post.html | 27 ++++++++--- .../news/user/password_reset_confirm.html | 45 +++++++++++++------ .../news/user/password_reset_html_email.html | 3 +- .../news/user/password_reset_subject.txt | 1 + news/urls.py | 7 +-- pokercc/settings.py | 9 +++- 9 files changed, 72 insertions(+), 32 deletions(-) create mode 100644 news/templates/news/user/password_reset_subject.txt diff --git a/news/models.py b/news/models.py index df6ab82..52e4525 100644 --- a/news/models.py +++ b/news/models.py @@ -30,7 +30,7 @@ class Post(models.Model): return string 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 = [] diff --git a/news/static/news/css/app.css b/news/static/news/css/app.css index 78986aa..b0655d2 100644 --- a/news/static/news/css/app.css +++ b/news/static/news/css/app.css @@ -180,14 +180,14 @@ 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: 600px; - border-bottom: 10px solid #111; - border-top: 10px solid #111; + /* border-bottom: 10px solid #111; */ + border-top: 20px solid #111; } } diff --git a/news/templates/base.html b/news/templates/base.html index a761eb5..49a5f9f 100644 --- a/news/templates/base.html +++ b/news/templates/base.html @@ -61,7 +61,7 @@
Contact -

Copyright © 2019 Stax River

+

Copyright © 2019 Poker Rumble

diff --git a/news/templates/news/post.html b/news/templates/news/post.html index ea06802..4739df5 100644 --- a/news/templates/news/post.html +++ b/news/templates/news/post.html @@ -36,14 +36,20 @@ {% endif %}
-
- {% csrf_token %} -

Add comment

+ {% if user.is_authenticated %} + + {% csrf_token %} +

Add comment

+

+ +

+ +
+ {% else %}

- + Please login to comment the post

- - + {% endif %} + @@ -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() From 55252e5575c891624975f075193b16511ad54cca Mon Sep 17 00:00:00 2001 From: Laurent Morvillier Date: Wed, 9 Oct 2019 15:51:08 +0200 Subject: [PATCH 6/9] Adds comments to youtube videos --- news/models.py | 5 +++++ news/templates/news/index.html | 20 +++++++++++++++----- news/templates/news/post.html | 6 ++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/news/models.py b/news/models.py index 9020bb0..d939ba1 100644 --- a/news/models.py +++ b/news/models.py @@ -43,6 +43,11 @@ class Post(models.Model): tag_names = map(lambda t: t.name, self.tag_set.all()) return ", ".join(tag_names) + def html_title(self): + if self.title: + return title + return 'Poker Rumble - Amazing content' + 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) diff --git a/news/templates/news/index.html b/news/templates/news/index.html index 4a88248..c2dd151 100644 --- a/news/templates/news/index.html +++ b/news/templates/news/index.html @@ -2,22 +2,20 @@ {% load static %} -{% block title %}Poker Rumble - {% endblock %} +{% block title %}Poker Rumble - Your source of great poker content{% endblock %} {% block content %} {% if latest_post_list %} - {% for post in latest_post_list %} - - + {% for post in latest_post_list %} +
{{ post.date }} - {{ post.author.username }}
- {% if post.style == 0 %}
@@ -94,6 +92,18 @@ +
+ + +
+ {% for comment in post.top_comments %} + {{ comment.body }} - {{ comment.author.username }}
+ {% endfor %} +
+
+ {% endif %} {% extends 'base.html' %} -{% block title %}Email Sent{% endblock %} +{% block title %}Email Sent - Poker Rumble{% endblock %} {% block content %}

Check your inbox.

diff --git a/news/templates/news/user/password_reset_form.html b/news/templates/news/user/password_reset_form.html index 03a9232..e14388a 100644 --- a/news/templates/news/user/password_reset_form.html +++ b/news/templates/news/user/password_reset_form.html @@ -1,7 +1,7 @@ {% extends 'base.html' %} -{% block title %}Forgot Your Password?{% endblock %} +{% block title %}Forgot Your Password? - Poker Rumble{% endblock %} {% block content %}

Forgot your password?

diff --git a/news/templates/news/user/signin.html b/news/templates/news/user/signin.html index 0136853..dee8f83 100644 --- a/news/templates/news/user/signin.html +++ b/news/templates/news/user/signin.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% block title %} - Sign-in + Sign-in - Poker Rumble {% endblock %} {% block content %} From 9643962883f6273e11eafbdf3c1d56d7188d56a8 Mon Sep 17 00:00:00 2001 From: Laurent Morvillier Date: Wed, 9 Oct 2019 17:11:26 +0200 Subject: [PATCH 8/9] Fixes titles --- news/templates/news/user/register.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/templates/news/user/register.html b/news/templates/news/user/register.html index 8e4f185..e96ec0e 100644 --- a/news/templates/news/user/register.html +++ b/news/templates/news/user/register.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% block title %} - Create User + Create User - Poker Rumble {% endblock %} {% block content %} From d576fd969388f7593eed71ebd6c4055ddee8ebde Mon Sep 17 00:00:00 2001 From: Laurent Morvillier Date: Thu, 10 Oct 2019 11:47:38 +0200 Subject: [PATCH 9/9] Added slug to post urls --- news/forms.py | 2 +- news/migrations/0008_auto_20191010_0909.py | 23 ++++++++++++++++++++++ news/migrations/0009_auto_20191010_0910.py | 18 +++++++++++++++++ news/migrations/0010_auto_20191010_0945.py | 18 +++++++++++++++++ news/models.py | 17 ++++++++++++++-- news/static/news/css/app.css | 11 ++++------- news/templates/news/index.html | 8 ++++---- news/urls.py | 3 ++- news/views.py | 5 ++++- 9 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 news/migrations/0008_auto_20191010_0909.py create mode 100644 news/migrations/0009_auto_20191010_0910.py create mode 100644 news/migrations/0010_auto_20191010_0945.py diff --git a/news/forms.py b/news/forms.py index 6de3f19..386bdc7 100644 --- a/news/forms.py +++ b/news/forms.py @@ -10,7 +10,7 @@ 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) + title = forms.CharField(label='Title (required for slug/SEO)', max_length=200, required=True) url = forms.CharField(label='URL', max_length=200, required=False) body = forms.CharField(label='Optional body', max_length=10000, required=False) 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/models.py b/news/models.py index 80b7ef8..e5288df 100644 --- a/news/models.py +++ b/news/models.py @@ -1,8 +1,9 @@ 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 +from django.utils.text import slugify +from enum import Enum # Create your models here. class PostState(Enum): @@ -20,6 +21,11 @@ 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): string = self.title @@ -29,6 +35,13 @@ class Post(models.Model): 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.filter(Q(parent_comment=None)).order_by('-voters').all()[:1] @@ -45,7 +58,7 @@ class Post(models.Model): def html_title(self): if self.title: - return title + return self.title return 'Poker Rumble - Amazing content' class Comment(models.Model): diff --git a/news/static/news/css/app.css b/news/static/news/css/app.css index a574c88..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; } diff --git a/news/templates/news/index.html b/news/templates/news/index.html index c2dd151..0cb554f 100644 --- a/news/templates/news/index.html +++ b/news/templates/news/index.html @@ -34,7 +34,7 @@
@@ -54,7 +54,7 @@
@@ -74,7 +74,7 @@
@@ -94,7 +94,7 @@
diff --git a/news/urls.py b/news/urls.py index 48f2a90..1cd3c2a 100644 --- a/news/urls.py +++ b/news/urls.py @@ -11,7 +11,8 @@ urlpatterns = [ path('about', TemplateView.as_view(template_name='news/static/about.html'), name='about'), # Posts path('', views.index, name='index'), - path('', views.post, name='post'), + path("/", views.post, name="post"), + # path('', views.post, name='post'), path('/comment/', views.comment_with_parent, name='comment_with_parent'), path('/comment', views.comment, name='comment'), path('comment//delete', views.delete_comment, name='delete_comment'), diff --git a/news/views.py b/news/views.py index 1384a91..477dda5 100644 --- a/news/views.py +++ b/news/views.py @@ -11,6 +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 django.utils.text import slugify from .models import Post, Comment, PostState, Tag from .forms import PostForm, CustomUserCreationForm, SigninForm from datetime import datetime @@ -89,7 +90,7 @@ def index(request): context = { 'latest_post_list' : posts } return render(request, 'news/index.html', context) -def post(request, post_id): +def post(request, post_id, post_slug): post = get_object_or_404(Post, pk=post_id) return render(request, 'news/post.html', {'post': post, 'comments': post.flat_comments(request.user) }) @@ -109,6 +110,8 @@ def submission(request): tags = parsed_tags(form.cleaned_data['tags']) post.tag_set.add(*tags) + post.slug = slugify(post.title) + file = request.FILES.get('image', None) if file is not None: filename = str(uuid.uuid4())