@ -11,7 +11,7 @@ from django.contrib.auth.decorators import login_required
from django . contrib . auth . forms import PasswordChangeForm
from django . contrib . auth . forms import PasswordChangeForm
from django . db . models import Q
from django . db . models import Q
from django . utils . html import strip_tags
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 . forms import PostForm , CustomUserCreationForm , SigninForm
from datetime import datetime
from datetime import datetime
import logging
import logging
@ -106,6 +106,9 @@ def submission(request):
post . url = form . cleaned_data [ ' url ' ]
post . url = form . cleaned_data [ ' url ' ]
post . style = form . cleaned_data [ ' style ' ]
post . style = form . cleaned_data [ ' style ' ]
tags = parsed_tags ( form . cleaned_data [ ' tags ' ] )
post . tag_set . add ( * tags )
file = request . FILES . get ( ' image ' , None )
file = request . FILES . get ( ' image ' , None )
if file is not None :
if file is not None :
filename = str ( uuid . uuid4 ( ) )
filename = str ( uuid . uuid4 ( ) )
@ -128,6 +131,15 @@ def submission(request):
return render ( request , ' news/submission.html ' , { ' form ' : form } )
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 ) :
def handle_uploaded_file ( filename , f ) :
with open ( settings . MEDIA_ROOT + filename , ' wb+ ' ) as destination :
with open ( settings . MEDIA_ROOT + filename , ' wb+ ' ) as destination :
for chunk in f . chunks ( ) :
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 )
comment . post = get_object_or_404 ( Post , pk = post_id )
if comment_id is not None :
if comment_id is not None :
comment . parent_comment = get_object_or_404 ( Comment , pk = comment_id )
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 . save ( )
comment . voters . add ( request . user )
comment . voters . add ( request . user )
comment . save ( )
comment . save ( )