<file_sep>apturl==0.5.2

beautifulsoup4==4.4.1

blinker==1.3

Brlapi==0.6.4

chardet==2.3.0

checkbox-support==0.22

command-not-found==0.3

cryptography==1.2.3

defer==1.0.6

Django==1.11.5

django-bootstrap-form==3.3

django-bootstrap-toolkit==2.15.0

django-bootstrap3==9.1.0

django-widget-tweaks==1.4.1

feedparser==5.1.3

guacamole==0.9.2

html5lib==0.999

httplib2==0.9.1
idna==2.0

Jinja2==2.8

language-selector==0.1

louis==2.6.4

lxml==3.5.0

Mako==1.0.3

MarkupSafe==0.23

mysqlclient==1.3.12

oauthlib==1.0.3

onboard==1.2.0

padme==1.1.1

pexpect==4.0.1

Pillow==3.1.2

plainbox==0.25

ptyprocess==0.5

pyasn1==0.1.9

pycups==1.9.73

pycurl==7.43.0

pygobject==3.20.0

PyJWT==1.3.0

PyMySQL==0.7.11

pyparsing==2.0.3

python-apt==1.1.0b1

python-debian==0.1.27

python-systemd==231

pytz==2017.2

pyxdg==0.25

reportlab==3.3.0

requests==2.9.1

sessioninstaller==0.0.0

six==1.10.0

system-service==0.3

ubuntu-drivers-common==0.0.0

ufw==0.35

unattended-upgrades==0.1

unity-scope-calculator==0.1

unity-scope-chromiumbookmarks==0.1

unity-scope-colourlovers==0.1

unity-scope-devhelp==0.1

unity-scope-firefoxbookmarks==0.1

unity-scope-gdrive==0.7

unity-scope-manpages==0.1

unity-scope-openclipart==0.1

unity-scope-texdoc==0.1

unity-scope-tomboy==0.1

unity-scope-virtualbox==0.1

unity-scope-yelp==0.1

unity-scope-zotero==0.1

unity-tweak-tool==0.0.7

urllib3==1.13.1

usb-creator==0.3.0

virtualenv==15.1.0

xdiagnose==3.8.4.1

xkit==0.0.0

XlsxWriter==0.7.3
<file_sep>from __future__ import unicode_literals
from django.views.generic import ListView, CreateView, UpdateView, View, DetailView
from django.shortcuts import render, get_object_or_404, reverse, HttpResponseRedirect, HttpResponse
from .models import Blog, Post, Category, Like
from django.template import RequestContext, loader, Context
from django import forms
from comment.models import Comment


class BlogForm(forms.ModelForm):
    search = forms.CharField(required=False)
    order_by = forms.ChoiceField(choices=(
        ('name', 'A->Z'),
        ('-name', 'Z->A'),
        ('-createdata', 'Last created'),
        ('createdata', 'First created'),
    ), required=False)

    class Meta:
        model = Blog
        fields = 'name',


class BlogList(ListView):
    template_name = "blog/blogpage.html"
    context_object_name = 'blog'
    model = Blog

    def get_queryset(self):
        q = super(BlogList, self).get_queryset()
        self.form = BlogForm(self.request.GET)
        if self.form.is_valid():
            if self.form.cleaned_data['order_by']:
                q = q.order_by(self.form.cleaned_data['order_by'])
            if self.form.cleaned_data['search']:
                q = q.filter(name=self.form.cleaned_data['search'])
        return q

    def get_context_data(self, **kwargs):
        context = super(BlogList, self).get_context_data(**kwargs)
        context['customform1'] = self.form
        context['category'] = Blog.category
        bdict = dict(self.request.GET)
        bdict.pop('page', None)
        #from urllib.parse import urlencode
       # from urlparse import urlparse
        try:
            from urllib.parse import urlencode
        except ImportError:
            from urllib import urlencode

        context['querypart'] = urlencode(bdict)
        for blogs in context['blog']:
            blogs.form = BlogForm(instance=blogs)

        return context


class NewBlogForm(forms.ModelForm):
    class Meta:
        model = Blog
        fields = 'name', 'category',


class NewBlog(CreateView):
    form_class = NewBlogForm
    template_name = 'blog/new_blog.html'

    def get_success_url(self):
        return reverse('blog:listOfBlogs')

    def get_context_data(self, **kwargs):
        context = super(NewBlog, self).get_context_data(**kwargs)
        context['category_list'] = Category.objects.all()
        return context

    def form_valid(self, form):
        form.instance.author = self.request.user
        return super(NewBlog, self).form_valid(form)


class BlogUpdate(UpdateView):
    template_name = 'blog/edit_blog.html'
    model = Blog
    fields = 'name', 'category'

    def form_valid(self, form):
        if self.object.author == self.request.user:
            super(BlogUpdate, self).form_valid(form)
            template=loader.get_template('blog/blogpage.html')
            return HttpResponseRedirect('http://127.0.0.1:8080/blog/')
        else:
            return HttpResponseRedirect(404)

    def get_queryset(self):
        return super(BlogUpdate, self).get_queryset().filter(author=self.request.user)

    def get_success_url(self):
        return reverse('blog:listOfBlogs')

#------------------------------------------------------------------------#
#------------------------------------------------------------------------#
#------------------------------------------------------------------------#
#------------------------------------------------------------------------#


class PostList(ListView):
    template_name = "blog/posts_list.html"
    context_object_name = 'posts'
    model = Post
    paginate_by = 10

    def dispatch(self, request, *args, **kwargs):
        self.blog = get_object_or_404(Blog, id=self.kwargs['ident'])
        return super(PostList, self).dispatch(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(PostList, self).get_context_data(**kwargs)
        context['blog'] = self.blog
        return context


class NewPostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = 'postname', 'text'


class NewPost(CreateView):
    form_class = NewPostForm
    template_name = 'blog/new_post.html'

    def dispatch(self, request, *args, **kwargs):
        self.blog = get_object_or_404(Blog, id=self.kwargs['ident'], author=request.user)
        return super(NewPost, self).dispatch(request, *args, **kwargs)

    def get_success_url(self):
        return reverse('blog:concretePost', kwargs={'ident': self.object.id})

    def form_valid(self, form):
        form.instance.blog_id = self.kwargs['ident']
        form.instance.author = self.request.user
        return super(NewPost, self).form_valid(form)

    def get_context_data(self, **kwargs):
        context = super(NewPost, self).get_context_data(**kwargs)
        context['blog'] = self.blog
        return context


class PostUpdate(UpdateView):
    template_name = 'blog/edit_post.html'
    model = Post
    fields = 'postname', 'text'

    def form_valid(self, form):
        if self.object.author == self.request.user:
            return super(PostUpdate, self).form_valid(form)
        else:
            return HttpResponseRedirect(404)

    def get_queryset(self):
        return super(PostUpdate, self).get_queryset().filter(author=self.request.user)

    def get_success_url(self):
        return reverse('blog:concretePost', kwargs={'ident': self.object.id})


class PostPage(CreateView):
    template_name = "blog/post_page.html"
    context_object_name = 'post'
    model = Comment
    fields = ('text', )

    def dispatch(self, request, *args, **kwargs):
        self.postobject = get_object_or_404(Post, id=self.kwargs['ident'])
        return super(PostPage, self).dispatch(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(PostPage, self).get_context_data(**kwargs)
        context['post'] = self.postobject
        context['blog'] = self.postobject.blog
        context['likes'] = Like.objects.filter(post=self.postobject).count()
        context['comment_list'] = Comment.objects.filter(post=self.postobject)
        return context

    def get_success_url(self):
        return reverse('blog:concretePost', kwargs={'ident': self.object.post.id})

    def form_valid(self, form):
        if self.request.user.is_authenticated():
            form.instance.post_id = self.kwargs['ident']
            form.instance.author = self.request.user
            return super(PostPage, self).form_valid(form)
        else:
            return HttpResponseRedirect(reverse('core:login'))


class PostComments(CreateView):
    template_name = "blog/comments.html"
    context_object_name = 'post'
    model = Comment
    fields = ('text',)

    def get_context_data(self, **kwargs):
        self.postobject = get_object_or_404(Post, id=self.kwargs['ident'])
        context = super(PostComments, self).get_context_data(**kwargs)
        context['post'] = self.postobject
        return context


class PostLikeAjaxView(View):

    def dispatch(self, request, *args, **kwargs):
        self.post_object = get_object_or_404(Post, id=self.kwargs['ident'])
        return super(PostLikeAjaxView, self).dispatch(request, *args, **kwargs)

    def post(self, request, *args, **kwargs):
        if not self.request.user.is_authenticated() or not self.post_object.likes.filter(author=self.request.user).exists():
            b2 = Like(author=self.request.user, post=self.post_object)
            b2.save()
            return HttpResponse(Like.objects.filter(post=self.post_object).count())<file_sep>from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin

from .models import User


class UserAdmin(BaseUserAdmin):
    admin.site.register(User)







<file_sep>{% extends "core/base.html" %}
{% load bootstrap3 %}
{% load static %}

{% block content %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="{% static "edit_blog.js" %}"> </script>

<form data-formtype="ajaxForm" action="{% url "blog:edit_blog" pk=blog.id %}" method="post">
    {% bootstrap_form form show_label=False %}
    {%  csrf_token %}
    <input type="button" class="btn btn-default" onclick="history.back();" value="Back">
    <input type="submit"  class="btn btn-primary" onclick="winOpen();" value="Edit blog">
    <script type="text/javascript">
        function winOpen(){
            alert('Success!');
            };
    </script>
</form>

{% endblock %}