Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ticket7: pep8, remove render in model

  • Loading branch information...
commit 79e15c8c6c689078baee202b3ebc07f56b155432 1 parent 79d764d
@andreysobol authored
View
15 testsobol/mainapp/models.py
@@ -1,9 +1,7 @@
from django.db import models
-from utils import Render
-
-class Bio(models.Model, Render):
+class Bio(models.Model):
name = models.CharField(max_length=250, verbose_name='Name')
surname = models.CharField(max_length=250, verbose_name='Last name')
birth = models.DateField(verbose_name='Date of birth')
@@ -14,17 +12,6 @@ class Bio(models.Model, Render):
bio = models.TextField(verbose_name='Bio')
img = models.ImageField(verbose_name='Photo', upload_to='img/')
- def render(self):
- field_types = dict([(field.name, field.verbose_name) \
- for field in self._meta.fields])
-
- get = lambda item: {'value':\
- unicode(getattr(self, item)) if item != 'img'\
- else '<img src="%s" />' % getattr(self, item).url,
- 'label': field_types[item]}
-
- return self.get_struct(get, False)
-
class Request(models.Model):
date = models.DateTimeField()
View
17 testsobol/mainapp/tests.py
@@ -103,17 +103,20 @@ def test(self):
class EditReverse(TestCase):
def test(self):
- fixtures = ['initial_data.json']
-
page = self.client.get('/')
- self.assertTrue(page.content.find('>Name:') < page.content.find('Last name:'))
- self.assertTrue(page.content.find('Bio:') > page.content.find('Other'))
+ self.assertTrue(page.content.find('>Name:')
+ < page.content.find('Last name:'))
+ self.assertTrue(page.content.find('Bio:')
+ > page.content.find('Other'))
- page = self.client.post('/accounts/login/', {'username': 'admin', 'password': 'admin'})
+ page = self.client.post('/accounts/login/',
+ {'username': 'admin', 'password': 'admin'})
page = self.client.get('/edit/')
- self.assertTrue(page.content.find('>Name:') > page.content.find('Last name:'))
- self.assertTrue(page.content.find('Bio:') < page.content.find('Other'))
+ self.assertTrue(page.content.find('>Name:')
+ > page.content.find('Last name:'))
+ self.assertTrue(page.content.find('Bio:')
+ < page.content.find('Other'))
class NameUrlTest(TestCase):
View
27 testsobol/mainapp/utils.py
@@ -7,18 +7,29 @@
class Render(object):
-<<<<<<< HEAD
-
+
def get_struct(self, get, reverse):
if reverse:
local_structs = [struct[::-1] for struct in structs]
else:
local_structs = structs
- return [[dict(get(item).items() + [('multiline',(item in multiline))]) for item in struct] for struct in local_structs]
-=======
-
- def get_struct(self, get):
return [[dict(get(item).items() + [('multiline', (item in multiline))])
for item in struct]
- for struct in structs]
->>>>>>> t6_ajax
+ for struct in local_structs]
+
+
+class DataRender(Render):
+
+ def __init__(self, model):
+ self.model = model
+
+ def render(self):
+ field_types = dict([(field.name, field.verbose_name) \
+ for field in self.model._meta.fields])
+
+ get = lambda item: {'value':\
+ unicode(getattr(self.model, item)) if item != 'img'\
+ else '<img src="%s" />' % getattr(self.model, item).url,
+ 'label': field_types[item]}
+
+ return self.get_struct(get, False)
View
4 testsobol/mainapp/views.py
@@ -8,6 +8,7 @@
from models import Bio, Request
from forms import BioForm
+from utils import DataRender
class Index(TemplateView):
@@ -16,7 +17,8 @@ class Index(TemplateView):
def get_context_data(self, **kwargs):
super(Index, self).get_context_data(**kwargs)
- return {'renders': Bio.objects.get(pk=1).render()}
+ d = DataRender(Bio.objects.get(pk=1))
+ return {'renders': d.render()}
class Edit(View):
Please sign in to comment.
Something went wrong with that request. Please try again.