from .base import BaseView
from data.forms import PostCreationForm
from data.models import Post
from django.db.models import Q
from django.http import HttpResponseRedirect


class PostEdit(BaseView):

    # TODO Need to create an edit view, lots similiar in 401 proj
    #template_name = '.html'

    def preprocess(self, request, *args, **kwargs):
        super(PostEdit, self).preprocess(request, *args, **kwargs)

    def post(self, request, *args, **kwargs):
        pass


class PostDelete(BaseView):

    def preprocess(self, request, *args, **kwargs):
        super(PostDelete, self).preprocess(request, *args, **kwargs)

    def post(self, request, post_id=None, *args, **kwargs):
        pass


class PostCreate(BaseView):
    def post(self, request, *args, **kwags):
        print ("hi")
        title = request.POST.get("title")
        content_type = request.POST.get("content-type")
        image_url = request.POST.get("image_url")
        content = request.POST.get("content")
        categories = request.POST.get("categories")
        visibility = request.POST.get("visibility")
        print ("hi1")

@@ -164,17 +164,31 @@
 Redirect
+, HttpResponse
 %0A
-
 %0A%0Aclass 
@@ -788,29 +788,8 @@
 s):%0A
-        print (%22hi%22)%0A
     
@@ -1094,18 +1094,501 @@
     
-print (%22hi1%22
+try:%0A            new_post = Post(title=title, source=%22%22, origin=%22%22, description=%22%22, content_type=content_type, content=content, author=request.user, visibility = visibility)%0A            new_post.save()%0A        except Exception,e:%0A            print(e)%0A        self.context%5B'test'%5D = 'test'%0A%0A        try:%0A            response = HttpResponse(status=201)%0A            response%5B'Location'%5D = '/post/' + str(new_post.id) + '/'%0A            return response%0A        except Exception,e:%0A            print(e
 )%0A

create post