Commits

Svyatoslav Bulbakha committed 9109dd4

Add confs

Comments (0)

Files changed (12)

conf/nginx/djangoschool.conf

+upstream djangoschool_server{
+    server unix:/tmp/djangoschool.sock fail_timeout=0;
+}
+
+server {
+    listen 80;
+    server_name djangoschool.lc;
+    
+    location / {
+        client_max_body_size 20m;
+        
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        proxy_set_header Host $http_host;
+        proxy_redirect off;
+        proxy_pass http://djangoschool_server;
+    }
+    
+    location /media {
+        alias /home/ad3w/Workspace/djangoschool/media;
+    }
+
+    location /static {
+        alias /home/ad3w/Workspace/djangoschool/static;
+    }
+    
+    access_log /var/log/nginx/djangoschool.access.log;
+    error_log /var/log/nginx/djangoschool.error.log;
+}

conf/supervisor/djangoschool.conf

+[program:djangoschool]
+command=/home/ad3w/Workspace/djangoschool/run/run.sh
+directory=/home/ad3w/Workspace/djangoschool
+user=ad3w
+autostart=true
+autorestart=true
+redirect_stderr=True
+stderr_logfile=/home/ad3w/logs/djangoschool/errors.log
+stdout_logfile=/home/ad3w/logs/djangoschool/access.log

djangoschool/apps/core/migrations/0006_auto__add_field_blog_desc_short.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding field 'Blog.desc_short'
+        db.add_column('core_blog', 'desc_short',
+                      self.gf('django.db.models.fields.TextField')(null=True, blank=True),
+                      keep_default=False)
+
+    def backwards(self, orm):
+        # Deleting field 'Blog.desc_short'
+        db.delete_column('core_blog', 'desc_short')
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'core.blog': {
+            'Meta': {'object_name': 'Blog'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'desc': ('django.db.models.fields.TextField', [], {}),
+            'desc_short': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
+        },
+        'core.comment': {
+            'Meta': {'ordering': "['created']", 'object_name': 'Comment'},
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'entry': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['core.Entry']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
+        },
+        'core.entry': {
+            'Meta': {'object_name': 'Entry'},
+            '_content_rendered': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'blog': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['core.Blog']"}),
+            'content': ('markitup.fields.MarkupField', [], {'no_rendered_field': 'True'}),
+            'content_short': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['core.Tag']", 'symmetrical': 'False'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
+        },
+        'core.tag': {
+            'Meta': {'object_name': 'Tag'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        }
+    }
+
+    complete_apps = ['core']

djangoschool/apps/core/models.py

 class Blog(models.Model):
     title = models.CharField(_('title'), max_length=200)
     desc = models.TextField(_('description'))
+    desc_short = models.TextField(_('short description'), null=True,
+                                  blank=True)
     user = models.ForeignKey(User, verbose_name=_('user'))
     
     created = models.DateTimeField(auto_now_add=True)

djangoschool/apps/core/urls.py

 from django.conf.urls import patterns, include, url
 
 from .feeds import LatestEntriesFeed
+from .views import (EntryCreateView, EntryUpdateView, EntryDetailView,
+                    EntryListView)
 
 
 urlpatterns = patterns('core.views',
     # Entry
-    url(r'^$', 'entry_list', name='core_entry_list'),
+    url(r'^$', EntryListView.as_view(), name='core_entry_list'),
     url(r'^tag/(?P<tag_name>\w+)/$', 'entry_tag', name='core_entry_tag'),
-    url(r'^(?P<entry_id>\d+)/$', 'entry_detail',
+    url(r'^(?P<pk>\d+)/$', EntryDetailView.as_view(),
         name='core_entry_detail'),
     url(r'^(?P<entry_id>\d+)/text/$', 'entry_detail_text',
         name='core_entry_detail_text'),
-    url(r'^add/$', 'entry_add', name='core_entry_add'),
-    url(r'^(?P<entry_id>\d+)/edit/$', 'entry_edit', name='core_entry_edit'),
+    url(r'^add/$', EntryCreateView.as_view(), name='core_entry_add'),
+    url(r'^(?P<pk>\d+)/edit/$', EntryUpdateView.as_view(),
+        name='core_entry_edit'),
     
     # Blog
     url(r'^blogs/$', 'blog_list', name='core_blog_list'),

djangoschool/apps/core/views.py

 from django.contrib import messages
 from django.utils.translation import ugettext_lazy as _
 from django.http import HttpResponse
+from django.views.generic.edit import CreateView, UpdateView, ModelFormMixin
+from django.views.generic.detail import DetailView
+from django.views.generic.list import ListView
 
 from django_xhtml2pdf.utils import render_to_pdf_response
 from pytils.translit import slugify
 from . import signals
 
 
+class EntryListView(ListView):
+    model = Entry
+    paginate_by = settings.ENTRY_PER_PAGE
+
+
+class EntryDetailView(ModelFormMixin, DetailView):
+    model = Entry
+    form_class = CommentForm
+
+    def get_context_data(self, **kwargs):
+        context = super(EntryDetailView, self).get_context_data(**kwargs)
+        context['form'] = CommentForm
+        return context
+
+
+class EntryCreateView(CreateView):
+    model = Entry
+    form_class = EntryForm
+
+    def form_valid(self, form):
+        entry = form.save(self.request)
+        return redirect(entry)
+
+
+class EntryUpdateView(UpdateView):
+    model = Entry
+    form_class = EntryForm
+    template_name = 'core/entry_edit.html'
+
+    def form_valid(self, form):
+        entry = form.save(self.request)
+        return redirect(entry)
+
+
 def entry_list(request):
     entry_list = Entry.objects.all()
     paginator = Paginator(entry_list, settings.ENTRY_PER_PAGE)
     }, content_type='text/plain')
 
 
-@login_required
-def entry_add(request):
-    form = EntryForm(request.POST or None)
-
-    if form.is_valid():
-        entry = form.save(request)
-        return redirect(entry)
-
-    return render(request, 'core/entry_add.html', {
-        'form': form,
-    })
-
-
-@login_required
-def entry_edit(request, entry_id):
-    entry = get_object_or_404(Entry, pk=entry_id, user=request.user)
-    form = EntryForm(request.POST or None, instance=entry)
-
-    if form.is_valid():
-        form.save(request)
-        return redirect(entry)
-
-
-    return render(request, 'core/entry_edit.html', {
-        'form': form,
-    })
-    
     
 def blog_detail(request, blog_id):
     blog = get_object_or_404(Blog, pk=blog_id)

djangoschool/settings.py

     # Uncomment the next line for simple clickjacking protection:
     # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
     'debug_toolbar.middleware.DebugToolbarMiddleware',
-    'core.middleware.SQLMiddleware',
+    #'core.middleware.SQLMiddleware',
     #'core.middleware.AlwaysAuthenticatedMiddleware',
 )
 
     'guardian',
     'easy_thumbnails',
     'debug_toolbar',
+    'gunicorn',
 
     'core',
     'account',

djangoschool/templates/core/entry_edit.html

-{% extends "base.html" %}
+{% extends "core/entry_form.html" %}
 
 {% load i18n %}
-{% load markitup_tags %}
 
-{% block extra_head %}{% markitup_media %}{% endblock %}
+{% block title %}
+    {% block content_title %}{% trans 'Edit entry' %}{% endblock %}
+{% endblock %}
 
-{% block title %}{% trans 'Edit entry' %}{% endblock %}
-
-{% block content %}
-<form class="uniForm" action="" method="post">{% csrf_token %}
-    {% include 'core/includes/entry_form.html' %}
-    <div class="buttonHolder">
-        <input type="submit" value="{% trans 'Save' %}" class="primaryAction" />
-    </div>
-</form>
-
-{% markitup_editor form.content.auto_id %}
-{% endblock %}
+{% block btn_text %}{% trans 'Save' %}{% endblock %}

djangoschool/templates/core/entry_form.html

+{% extends "base.html" %}
+
+{% load i18n %}
+{% load markitup_tags %}
+
+{% block extra_head %}{% markitup_media %}{% endblock %}
+
+{% block title %}{% trans 'Add entry' %}{% endblock %}
+
+{% block content %}
+<form class="uniForm" action="" method="post">{% csrf_token %}
+    {% include 'core/includes/entry_form.html' %}
+    <div class="buttonHolder">
+        <input type="submit" value="{% block btn_text %}{% trans 'Add' %}{% endblock %}" class="primaryAction" />
+    </div>
+</form>
+
+{% markitup_editor form.content.auto_id %}
+{% endblock %}

djangoschool/templates/core/entry_list.html

 {% block title %}{% trans 'Entry list' %}{% endblock %}
 
 {% block content %}
-{% for entry in entries %}
+{% for entry in object_list %}
     <div class="entry">
         <h3>
             <a href="{{ entry.blog.get_absolute_url }}">{{ entry.blog.title }}</a> | 
     <p>{% trans 'Empty list' %}</p>
 {% endfor %}
 
-{% include "core/includes/paginator.html" with objects=entries %}
+{% include "core/includes/paginator.html" with objects=page_obj %}
 {% endblock %}
 -e git+https://github.com/chrisglass/xhtml2pdf.git#egg=xhtml2pdf
 -e git+https://github.com/chrisglass/django-xhtml2pdf.git#egg=django-xhtml2pdf
 -e git+https://github.com/j2a/pytils.git#egg=pytils
+gunicorn
+#!/bin/sh
+
+NAME=djangoschool
+SRCDIR=djangoschool
+
+GUNICORN=/usr/bin/gunicorn_django
+HOMEDIR=/home/ad3w
+
+VIRTUALENV=${HOMEDIR}/.virtualenvs/${NAME}
+PROJECTDIR=${HOMEDIR}/Workspace/${NAME}
+SOCKFILE=/tmp/${NAME}.sock
+MANAGE=${PROJECTDIR}/manage.py
+
+. ${VIRTUALENV}/bin/activate
+exec ${MANAGE} run_gunicorn --bind unix:${SOCKFILE}