Permalink
Browse files

create project

  • Loading branch information...
0 parents commit 1777665985ac591c9d23d1094eacd96c42c0ddfe @d1ffuz0r committed Dec 8, 2011
@@ -0,0 +1,2 @@
+*.pyc
+lulz.db
No changes.
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+from functools import wraps
+import datetime
+from django.http import HttpResponse
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+from django.utils.simplejson import dumps
+#from django.views.decorators.cache import cache_control
+
+
+def render_to(template):
+ """Decorator for rendering views to template"""
+ def renderer(func):
+ @wraps(func)
+ #@cache_control(must_revalidate=True, max_age=3600)
+ def wrapper(request, *args, **kwargs):
+ output = func(request, *args, **kwargs)
+ if isinstance(output, (list, tuple)):
+ return render_to_response(output[1],
+ output[0],
+ context_instance=RequestContext(request))
+ elif isinstance(output, dict):
+ return render_to_response(template,
+ output,
+ context_instance=RequestContext(request))
+ return output
+ return wrapper
+ return renderer
+
+def render_json(func):
+ """Decorator for rendering data as json"""
+ def wrap(request, *args, **kwargs):
+ response = None
+ try:
+ response = func(request, *args, **kwargs)
+ assert isinstance(response, dict)
+ except ValueError:
+ pass
+ return HttpResponse(dumps(response), mimetype="application/json")
+ return wrap
+
No changes.
@@ -0,0 +1,24 @@
+from django.contrib import admin
+from django.contrib.auth.models import Group
+from models import Category, Comments, Job, Likes
+
+
+class AdminJobs(admin.ModelAdmin):
+ list_display = ("name", "date", "published")
+
+
+class AdminCategory(admin.ModelAdmin):
+ list_display = ("name",)
+
+
+class AdminComments(admin.ModelAdmin):
+ list_display = ("text", "job")
+
+class AdminLikes(admin.ModelAdmin):
+ list_display = ("ip", "type")
+
+admin.site.register(Category, AdminCategory)
+admin.site.register(Comments, AdminComments)
+admin.site.register(Job, AdminJobs)
+admin.site.register(Likes, AdminLikes)
+admin.site.unregister(Group)
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+from django import forms
+from lulz.models import Job, Comments, Category
+
+
+class AddJob(forms.ModelForm):
+ class Meta:
+ model = Job
+ fields = ("name", "desc", "tags", "link", "category")
+ widgets = {
+ "name": forms.TextInput(attrs={"class": "required"}),
+ "desc": forms.Textarea(attrs={"class": "required"}),
+ "tags": forms.TextInput(attrs={"class": "required"}),
+ "link": forms.TextInput(attrs={"class": "required url"}),
+ "cateogry": forms.CheckboxInput(attrs={"class": "required digits"}),
+ }
+
+
+class AddComment(forms.ModelForm):
+ class Meta:
+ model = Comments
+ fields = ("text",)
+
+
+class SearchForm(forms.Form):
+ query = forms.CharField(label=u'Ключевое слово')
+ cat = forms.IntegerField(
+ label=u'Категория',
+ widget=forms.Select(
+ choices=Category.objects.all().values_list('id', 'name')
+ )
+ )
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+from django.db import models
+
+
+class Category(models.Model):
+ name = models.CharField(max_length=100,
+ blank=False,
+ verbose_name=u"Название")
+ image = models.ImageField(upload_to='backgrounds',
+ verbose_name=u"Фон")
+
+ class Meta:
+ verbose_name = u"Категория"
+ verbose_name_plural = u"Категории"
+
+ def __unicode__(self):
+ return self.name
+
+
+class Job(models.Model):
+ name = models.CharField(max_length=100,
+ verbose_name=u"Заголовок")
+ desc = models.TextField(max_length=1000,
+ verbose_name=u"Описание")
+ tags = models.CharField(max_length=100,
+ verbose_name=u"Ключевые слова")
+ likes = models.IntegerField(verbose_name=u"Лайки", default=0)
+ link = models.URLField(max_length=100,
+ verbose_name=u"Ссылка на оригинал")
+ published = models.BooleanField(default=False,
+ verbose_name=u"Оубликовано")
+ date = models.DateTimeField(auto_now=True,
+ verbose_name=u"Дата публикации")
+ category = models.ForeignKey(Category,
+ verbose_name=u"Категория")
+ comments = models.ManyToManyField('Comments',
+ related_name='jobcomm',
+ blank=True,
+ verbose_name=u"Комментарии")
+
+
+ class Meta:
+ verbose_name = u"Вакансия"
+ verbose_name_plural = u"Вакансии"
+
+ def __unicode__(self):
+ return self.name
+
+
+class Comments(models.Model):
+ text = models.CharField(max_length=200,
+ verbose_name=u"Текст комментария")
+ job = models.ForeignKey(Job,
+ related_name='jobcomm',
+ verbose_name=u"Вакансия")
+
+ class Meta:
+ verbose_name = u"Комментарий"
+ verbose_name_plural = u"Комментарии"
+
+ def __unicode__(self):
+ return '%s/%s' % (self.text[:10], self.job.name)
+
+
+class Likes(models.Model):
+ CHOISES = (
+ ('1', '+'),
+ ('0', '-')
+ )
+ job = models.ForeignKey(Job, related_name='joblikes', verbose_name=u"Вакансия")
+ agent = models.CharField(max_length=200, verbose_name=u"User-Agent")
+ ip = models.CharField(max_length=100, verbose_name=u"IP")
+ type = models.BooleanField(choices=CHOISES, verbose_name=u"Тип")
+
+ class Meta:
+ verbose_name = u"Лайк"
+ verbose_name_plural = u"Лайки"
+
+ def __unicode__(self):
+ return '%s/%s' % (self.job.name, self.type)
+
@@ -0,0 +1,2 @@
+__author__ = 'd1ffuz0r'
+
@@ -0,0 +1,18 @@
+from django import template
+from lulz.forms import AddJob, AddComment, SearchForm
+register = template.Library()
+
+
+@register.simple_tag()
+def addjob():
+ return AddJob()
+
+
+@register.simple_tag()
+def addcomment():
+ return AddComment().as_p()
+
+
+@register.simple_tag()
+def search():
+ return SearchForm()
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+from django.test import TestCase
+from django.test.client import Client
+from models import Job, Category, Comments, Likes
+
+
+class ViewsTests(TestCase):
+ def setUp(self):
+ self.client = Client()
+
+ def test_home(self):
+ request = self.client.get('/')
+ self.assertContains(request, text='Нет работ')
+
+ def test_admin(self):
+ request = self.client.get('/admin/')
+ self.assertContains(request, text='Django')
+
+class ModelsTest(TestCase):
+ def setUp(self):
+ self.category = Category.objects.create(name="php",
+ image="php.png")
+ self.job = Job.objects.create(name="test",
+ desc="description",
+ category=self.category)
+ self.comment = Comments.objects.create(text="lol",
+ job=self.job)
+ self.like = Likes.objects.create(job=self.job,
+ type="1")
+
+ def test_job(self):
+ job = Job.objects.filter(name="test").get()
+ self.assertEqual(job.__unicode__(), 'test')
+
+ def test_category(self):
+ cat = Category.objects.filter(name="php").get()
+ self.assertEqual(cat.__unicode__(), 'php')
+
+ def test_comment(self):
+ comm = Comments.objects.filter(text="lol").get()
+ self.assertEqual(comm.__unicode__(), 'lol/test')
+
+ def test_like(self):
+ like = Likes.objects.filter(job=self.job).get()
+ self.assertEqual(like.__unicode__(), 'test/True')
@@ -0,0 +1,26 @@
+from decorators import render_json
+from forms import AddJob
+from models import Job
+
+@render_json
+def addvacancy(request):
+ form = AddJob(request.POST)
+ if form.is_valid():
+ form.save()
+ return {"success": True}
+ else:
+ return {"success": False}
+
+
+@render_json
+def full(request):
+ result = {}
+ if request.POST:
+ job = Job.objects.filter(published=True).get(pk=request.POST["id"])
+ result['name'] = job.name
+ result['desc'] = job.desc
+ result['cat_image'] = job.category.image.__str__()
+
+ return {"success": True, "vacancy": result}
+ else:
+ return {"success": False}
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+import imp
+try:
+ imp.find_module('settings') # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
+ sys.exit(1)
+
+import settings
+
+if __name__ == "__main__":
+ execute_manager(settings)
@@ -0,0 +1,4 @@
+AddHandler fcgid-script .fcgi
+RewriteEngine On
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]
@@ -0,0 +1,12 @@
+#!/usr/bin/python
+import os
+import sys
+
+_PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+sys.path.insert(0, _PROJECT_DIR)
+sys.path.insert(0, os.path.dirname(_PROJECT_DIR))
+
+_PROJECT_NAME = _PROJECT_DIR.split('/')[-1]
+os.environ['DJANGO_SETTINGS_MODULE'] = "%s.settings" % _PROJECT_NAME
+from django.core.servers.fastcgi import runfastcgi
+runfastcgi(method="threaded", daemonize="false")
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 1777665

Please sign in to comment.