barttc / django-generic-flatblocks Goto Github PK
View Code? Open in Web Editor NEWA flatpages/flatblock application using generic relations to content models.
Home Page: https://django-generic-flatblocks.readthedocs.io/
License: Other
A flatpages/flatblock application using generic relations to content models.
Home Page: https://django-generic-flatblocks.readthedocs.io/
License: Other
When i add a generic flatblock how do i know the "object id" of the content (image, text, title, etc ...) in order to properly add the flatblock?
i use pinax and i create a cms_company project.
If the "object id" of the content is not displayed it would be nice to have it displayed in the administration interface. (I modified in contrib/gblock/models.py the unicode(self) function but maybe is a better solution (i am novice in django)).
Thanks.
Cristian Spiridon
updated to v0.9 this morning
$ python manage.py test django_generic_flatblocks
Creating test database...
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table notification_noticetype
Creating table notification_noticesetting
Creating table notification_notice
Creating table notification_noticequeuebatch
Creating table notification_observeditem
Creating table emailconfirmation_emailaddress
Creating table emailconfirmation_emailconfirmation
Creating table mailer_message
Creating table mailer_dontsendentry
Creating table mailer_messagelog
Creating table django_template
Creating table pages_page
Creating table basic_profiles_profile
Creating table account_account
Creating table account_otherserviceinfo
Creating table account_passwordreset
Creating table django_admin_log
Creating table django_generic_flatblocks_genericflatblock
Creating table gblocks_title
Creating table gblocks_text
Creating table gblocks_image
Creating table gblocks_titleandtext
Creating table gblocks_titletextandimage
Creating table django_openid_nonce
Creating table django_openid_association
Creating table django_openid_useropenidassociation
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for notification.NoticeSetting model
Installing index for notification.Notice model
Installing index for notification.ObservedItem model
Installing index for emailconfirmation.EmailAddress model
Installing index for emailconfirmation.EmailConfirmation model
Installing index for pages.Page model
Installing index for account.OtherServiceInfo model
Installing index for account.PasswordReset model
Installing index for admin.LogEntry model
Installing index for django_generic_flatblocks.GenericFlatblock model
Installing index for django_openid.UserOpenidAssociation model
.EEE...EF
======================================================================
ERROR: testContributedModels (django_generic_flatblocks.tests.GenericFlatblocksTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/tests/__init__.py", line 226, in testContributedModels
self.parseTemplate(template_string)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/tests/__init__.py", line 30, in parseTemplate
return t.render(c)
File "/Library/Python/2.5/site-packages/django/test/utils.py", line 29, in instrumented_test_render
return self.nodelist.render(context)
File "/Library/Python/2.5/site-packages/django/template/__init__.py", line 779, in render
bits.append(self.render_node(node, context))
File "/Library/Python/2.5/site-packages/django/template/debug.py", line 71, in render_node
result = node.render(context)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/templatetags/generic_flatblocks.py", line 124, in render
content = t.render(context)
File "/Library/Python/2.5/site-packages/django/test/utils.py", line 29, in instrumented_test_render
return self.nodelist.render(context)
File "/Library/Python/2.5/site-packages/django/template/__init__.py", line 779, in render
bits.append(self.render_node(node, context))
File "/Library/Python/2.5/site-packages/django/template/debug.py", line 81, in render_node
raise wrapped
TemplateSyntaxError: Caught an exception while rendering: 'request'
Original Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/django/template/debug.py", line 71, in render_node
result = node.render(context)
File "/Library/Python/2.5/site-packages/django/template/__init__.py", line 936, in render
dict = func(*args)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/frontendadmin/templatetags/frontendadmin_tags.py", line 52, in frontendadmin_change
'next_link': context['request'].META['PATH_INFO'],
File "/Library/Python/2.5/site-packages/django/template/context.py", line 44, in __getitem__
raise KeyError(key)
KeyError: 'request'
======================================================================
ERROR: testForArgument (django_generic_flatblocks.tests.GenericFlatblocksTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/tests/__init__.py", line 97, in testForArgument
self.assertRaises(AttributeError, self.parseTemplate, template_string)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/unittest.py", line 320, in failUnlessRaises
callableObj(*args, **kwargs)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/tests/__init__.py", line 30, in parseTemplate
return t.render(c)
File "/Library/Python/2.5/site-packages/django/test/utils.py", line 29, in instrumented_test_render
return self.nodelist.render(context)
File "/Library/Python/2.5/site-packages/django/template/__init__.py", line 779, in render
bits.append(self.render_node(node, context))
File "/Library/Python/2.5/site-packages/django/template/debug.py", line 81, in render_node
raise wrapped
TemplateSyntaxError: Caught an exception while rendering: 'NoneType' object has no attribute '_default_manager'
Original Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/django/template/debug.py", line 71, in render_node
result = node.render(context)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/templatetags/generic_flatblocks.py", line 95, in render
generic_object, related_object = self.get_content_object(related_model, slug)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/templatetags/generic_flatblocks.py", line 72, in get_content_object
related_object = related_model._default_manager.create()
AttributeError: 'NoneType' object has no attribute '_default_manager'
======================================================================
ERROR: testIntoArgument (django_generic_flatblocks.tests.GenericFlatblocksTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/tests/__init__.py", line 180, in testIntoArgument
t = self.parseTemplate(template_string)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/tests/__init__.py", line 30, in parseTemplate
return t.render(c)
File "/Library/Python/2.5/site-packages/django/test/utils.py", line 29, in instrumented_test_render
return self.nodelist.render(context)
File "/Library/Python/2.5/site-packages/django/template/__init__.py", line 779, in render
bits.append(self.render_node(node, context))
File "/Library/Python/2.5/site-packages/django/template/debug.py", line 81, in render_node
raise wrapped
TemplateSyntaxError: Caught an exception while rendering: User matching query does not exist.
Original Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/django/template/debug.py", line 71, in render_node
result = node.render(context)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/templatetags/generic_flatblocks.py", line 95, in render
generic_object, related_object = self.get_content_object(related_model, slug)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/templatetags/generic_flatblocks.py", line 55, in get_content_object
related_object = related_model._default_manager.get(pk=slug)
File "/Library/Python/2.5/site-packages/django/db/models/manager.py", line 120, in get
return self.get_query_set().get(*args, **kwargs)
File "/Library/Python/2.5/site-packages/django/db/models/query.py", line 305, in get
% self.model._meta.object_name)
DoesNotExist: User matching query does not exist.
======================================================================
ERROR: testSlugArgumentWithInteger (django_generic_flatblocks.tests.GenericFlatblocksTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/tests/__init__.py", line 73, in testSlugArgumentWithInteger
t = self.parseTemplate(template_string)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/tests/__init__.py", line 30, in parseTemplate
return t.render(c)
File "/Library/Python/2.5/site-packages/django/test/utils.py", line 29, in instrumented_test_render
return self.nodelist.render(context)
File "/Library/Python/2.5/site-packages/django/template/__init__.py", line 779, in render
bits.append(self.render_node(node, context))
File "/Library/Python/2.5/site-packages/django/template/debug.py", line 81, in render_node
raise wrapped
TemplateSyntaxError: Caught an exception while rendering: auth/user/flatblock.html
Original Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/django/template/debug.py", line 71, in render_node
result = node.render(context)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/templatetags/generic_flatblocks.py", line 119, in render
t = select_template(template_paths)
File "/Library/Python/2.5/site-packages/django/template/loader.py", line 118, in select_template
raise TemplateDoesNotExist, ', '.join(template_name_list)
TemplateDoesNotExist: auth/user/flatblock.html
======================================================================
FAIL: testWithArgument (django_generic_flatblocks.tests.GenericFlatblocksTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.9-py2.5.egg/django_generic_flatblocks/tests/__init__.py", line 113, in testWithArgument
self.assertTrue(u'<hello></hello>' in t)
AssertionError
----------------------------------------------------------------------
Ran 9 tests in 0.837s
FAILED (failures=1, errors=4)
Destroying test database...
----------------------------------------------------------------------
Unit Test Code Coverage Results
----------------------------------------------------------------------
Name Stmts Exec Cover Missing
-----------------------------------------------------------------------------------------
django_generic_flatblocks.__init__ 1 0 0% 1
django_generic_flatblocks.admin 20 13 65% 16, 25, 37-46
django_generic_flatblocks.contrib.__init__ 1 0 0% 1
django_generic_flatblocks.contrib.gblocks.__init__ 1 0 0% 1
django_generic_flatblocks.contrib.gblocks.admin 7 7 100%
django_generic_flatblocks.contrib.gblocks.models 25 20 80% 8, 14, 20, 27, 35
django_generic_flatblocks.models 11 11 100%
django_generic_flatblocks.templatetags.__init__ 1 1 100%
django_generic_flatblocks.templatetags.generic_flatblocks 93 88 94% 44-45, 60-61, 123
django_generic_flatblocks.tests.__init__ 116 85 73% 74-90, 100-104, 116-137, 181-192, 228-234
django_generic_flatblocks.tests.settings 12 0 0% 1-41
-----------------------------------------------------------------------------------------
TOTAL 288 225 78%
/django_generic_flatblocks/templatetags/generic_flatblocks.py in generate_admin_link, line 42
Hey,
I am trying to get this application runing but in admin I keep getting exceptions like:
AttributeError at /admin/django_generic_flatblocks/genericflatblock/2/
'NoneType' object has no attribute '_meta'
This happens if I click on any flatblock in the list.
And also tests are failing so I guess this app is not supported for Django 1.4 right?
http://docs.mahner.org/django-generic-flatblocks/ returns a 404 error.
When you call a tag like:
{% gblock 1 for "gblocks.TitleTextAndImage" into "advert" %}
And that TitleTextAndImage doesn't exist, we get a DoesNotExist exception because templatetags/generic_flatblocks.py:get_content_object calls get() without catching the exception. I'm not sure what the best thing to do is in this case, since we can't rely on the related_model being a GenericFlatblock at all. That means we can't just create and save one with that PK, because it could have other required arguments.
In general, it seems like throwing exceptions in templatetags is something that django avoids. I've got a fix put together that just creates the object and doesn't save it to the db that seems to work ok.
For reference, this came up for me when running unit tests for another app which tests views. I have the pk hardcoded because I'm using that flatblock to be an advertisement that's always present on every page. My users can edit that ad and I make sure it's always there to start with that pk (not the perfect solution, I know), so it's always there when anyone actually loads the page. When the unit tests are run, though, that data isn't there (and I obviously don't want to go mucking with another app's test). initial_data could work, except that would overwrite the advertisement every time I run a syncdb, which would lose any changes they'd potentially made in the interim.
The assumed behaviour is that "page",page.id,"main_content" would become "page_1_main_content".
Instead throws TemplateSyntaxError:
Caught an exception while rendering: sequence item 1: expected string or Unicode, int found
Original Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/django/template/debug.py", line 71, in render_node
result = node.render(context)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.5dev-py2.5.egg/django_generic_flatblocks/templatetags/generic_flatblocks.py", line 91, in render
slug = self.generate_slug(self.slug, context)
File "/Users/tanner/virtualenvs/pinax-env/lib/python2.5/site-packages/django_generic_flatblocks-0.5dev-py2.5.egg/django_generic_flatblocks/templatetags/generic_flatblocks.py", line 32, in generate_slug
return slugify('_'.join([self.resolve(i, context) for i in slug.split(',')]))
TypeError: sequence item 1: expected string or Unicode, int found
I've created a django.po file for Danish. Please add it to the project! It can be found at:
http://www.daimi.au.dk/~illio/pinax/django-generic-flatblocks/django.po
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.