Permalink
Browse files

0.0.1

  • Loading branch information...
1 parent bae1e63 commit 098e4ddf1b65d31da05df41e82d54a2cd34b170c @d1ffuz0r committed Dec 10, 2011
View
@@ -1,2 +1,3 @@
*.pyc
lulz.db
+public/media/backgrounds/*.*
View
@@ -1,6 +1,5 @@
# -*- 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
@@ -27,6 +26,7 @@ def wrapper(request, *args, **kwargs):
return wrapper
return renderer
+
def render_json(func):
"""Decorator for rendering data as json"""
def wrap(request, *args, **kwargs):
@@ -38,4 +38,3 @@ def wrap(request, *args, **kwargs):
pass
return HttpResponse(dumps(response), mimetype="application/json")
return wrap
-
View
@@ -1,24 +1,31 @@
from django.contrib import admin
from django.contrib.auth.models import Group
-from models import Category, Comments, Job, Likes
+from models import Category, Comments, Job, Likes, Image
+
+
+class AdminImages(admin.ModelAdmin):
+ list_display = ("name", "image",)
class AdminJobs(admin.ModelAdmin):
- list_display = ("name", "date", "published")
+ list_display = ("name", "category", "published", "date")
class AdminCategory(admin.ModelAdmin):
list_display = ("name",)
class AdminComments(admin.ModelAdmin):
- list_display = ("text", "job")
+ list_display = ("text", "job", "ip", "agent")
+
class AdminLikes(admin.ModelAdmin):
list_display = ("ip", "type")
+
+admin.site.register(Image, AdminImages)
admin.site.register(Category, AdminCategory)
admin.site.register(Comments, AdminComments)
admin.site.register(Job, AdminJobs)
admin.site.register(Likes, AdminLikes)
-admin.site.unregister(Group)
+admin.site.unregister(Group)
View
@@ -12,14 +12,20 @@ class Meta:
"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"}),
+ "cateogry": forms.CheckboxInput(
+ attrs={"class": "required digits"}
+ ),
}
class AddComment(forms.ModelForm):
class Meta:
model = Comments
- fields = ("text",)
+ fields = ("text", "job")
+ widgets = {
+ "text": forms.Textarea(attrs={"class": "required"}),
+ "job": forms.HiddenInput()
+ }
class SearchForm(forms.Form):
View
@@ -2,12 +2,27 @@
from django.db import models
+class Image(models.Model):
+ name = models.CharField(max_length=100,
+ 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 Category(models.Model):
name = models.CharField(max_length=100,
blank=False,
verbose_name=u"Название")
- image = models.ImageField(upload_to='backgrounds',
- verbose_name=u"Фон")
+ image = models.ManyToManyField(Image,
+ related_name="catimages",
+ verbose_name=u"Фон")
class Meta:
verbose_name = u"Категория"
@@ -28,7 +43,7 @@ class Job(models.Model):
link = models.URLField(max_length=100,
verbose_name=u"Ссылка на оригинал")
published = models.BooleanField(default=False,
- verbose_name=u"Оубликовано")
+ verbose_name=u"Опубликовано")
date = models.DateTimeField(auto_now=True,
verbose_name=u"Дата публикации")
category = models.ForeignKey(Category,
@@ -38,7 +53,6 @@ class Job(models.Model):
blank=True,
verbose_name=u"Комментарии")
-
class Meta:
verbose_name = u"Вакансия"
verbose_name_plural = u"Вакансии"
@@ -53,6 +67,8 @@ class Comments(models.Model):
job = models.ForeignKey(Job,
related_name='jobcomm',
verbose_name=u"Вакансия")
+ agent = models.CharField(max_length=200, verbose_name=u"User-Agent")
+ ip = models.CharField(max_length=100, verbose_name=u"IP")
class Meta:
verbose_name = u"Комментарий"
@@ -67,7 +83,9 @@ class Likes(models.Model):
('1', '+'),
('0', '-')
)
- job = models.ForeignKey(Job, related_name='joblikes', verbose_name=u"Вакансия")
+ 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"Тип")
@@ -78,4 +96,3 @@ class Meta:
def __unicode__(self):
return '%s/%s' % (self.job.name, self.type)
-
@@ -1,2 +0,0 @@
-__author__ = 'd1ffuz0r'
-
View
@@ -1,18 +0,0 @@
-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()
View
@@ -1,45 +1,127 @@
# -*- coding: utf-8 -*-
from django.test import TestCase
+from unittest import skip
from django.test.client import Client
+from lulz.models import Image
from models import Job, Category, Comments, Likes
class ViewsTests(TestCase):
def setUp(self):
+ self.category = Category.objects.create(name="php")
self.client = Client()
def test_home(self):
- request = self.client.get('/')
- self.assertContains(request, text='Нет работ')
+ request = self.client.get("/")
+ self.assertContains(request, text="ДЖОПЛУЛЗ")
def test_admin(self):
- request = self.client.get('/admin/')
- self.assertContains(request, text='Django')
+ request = self.client.get("/admin/")
+ self.assertContains(request, text="Django")
+
+ def test_full_vacancy_get_fail(self):
+ request = self.client.get("/ajax/full/")
+ self.assertEqual(request.content, '{"success": false}')
+
+ def test_full_vacancy_ajax_true(self):
+ self.image = Image.objects.create(name="phpp",
+ image="img/php.png")
+
+ category = Category.objects.create(name="php")
+ category.image.add(self.image)
+ self.job = Job.objects.create(name="test",
+ desc="description",
+ category=category,
+ published=True)
+ self.comment = Comments.objects.create(text="lol",
+ job=self.job)
+ request = self.client.post("/ajax/full/", data={
+ "id": self.job.id
+ })
+ self.assertContains(request, "vacancy")
+
+ def test_create_comment_get_false(self):
+ request = self.client.get("/ajax/addcomment/")
+ self.assertEqual(request.content, '{"success": false}')
+
+ @skip("working")
+ def test_create_comment_ajax_true(self):
+ self.image = Image.objects.create(name="phpp",
+ image="img/php.png")
+ category = Category.objects.create(name="php", image=[1])
+ Job.objects.create(name="test",
+ desc="description",
+ category=category)
+ print self.job.id
+ request = self.client.post("/ajax/addcomment/", data={
+ "text": "test",
+ "job": 1
+ })
+ self.assertEqual(request.content, '{"success": true}')
+
+ def test_create_comment_ajax_false(self):
+ request = self.client.post("/ajax/addcomment/", data={
+ "text": "test"
+ })
+ self.assertEqual(request.content, '{"success": false}')
+
+ def test_create_vacancy_get_false(self):
+ request = self.client.get("/ajax/addvacancy/")
+ self.assertEqual(request.content, '{"success": false}')
+
+ def test_create_vacancy_ajax_true(self):
+ request = self.client.post("/ajax/addvacancy/", data={
+ "name": "test",
+ "desc": "testdesc",
+ "tags": "test, test1, test2",
+ "category": 1,
+ "link": "http://google.com"
+ })
+ self.assertEqual(request.content, '{"success": true}')
+
+ def test_create_vacancy_ajax_false(self):
+ request = self.client.post("/ajax/addvacancy/", data={
+ "name": "test",
+ "desc": "testdesc",
+ "tags": "test, test1, test2",
+ "category": 1,
+ })
+ self.assertEqual(request.content, '{"success": false}')
+
class ModelsTest(TestCase):
def setUp(self):
- self.category = Category.objects.create(name="php",
- image="php.png")
+ self.image = Image.objects.create(name="phpp",
+ image="img/php.png")
+
+ self.category = Category.objects.create(name="php")
+
self.job = Job.objects.create(name="test",
desc="description",
category=self.category)
+
self.comment = Comments.objects.create(text="lol",
- job=self.job)
+ 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')
+ self.assertEqual(job.__unicode__(), "test")
def test_category(self):
cat = Category.objects.filter(name="php").get()
- self.assertEqual(cat.__unicode__(), 'php')
+ self.assertEqual(cat.__unicode__(), "php")
def test_comment(self):
comm = Comments.objects.filter(text="lol").get()
- self.assertEqual(comm.__unicode__(), 'lol/test')
+ self.assertEqual(comm.__unicode__(), "lol/test")
def test_like(self):
like = Likes.objects.filter(job=self.job).get()
- self.assertEqual(like.__unicode__(), 'test/True')
+ self.assertEqual(like.__unicode__(), "test/True")
+
+ def test_image(self):
+ image = Image.objects.filter(name="phpp").get()
+ self.assertEqual(image.__unicode__(), "phpp")
Oops, something went wrong.

0 comments on commit 098e4dd

Please sign in to comment.