Tumblelog by Soup.io
Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.

November 04 2017

Generic CBV Permissions Helper

A permission helper that can be included in any generic CBV, it uses the model attribute of the class to load all the permissions and tests a user can perform that action before dispatching the view.

October 19 2017

Soft hyphenation filters

Automatically hyphenate raw text or HTML code

October 15 2017

inline forms for deeply nested models

I had a problem trying to display my model would have a foreign key and that model would have one too etc.

Now there was a point I wanted to display the foreign keys of that field and display its fields and so on so forth.

This pretty much expands ...

October 09 2017

add encoding comment to project all python file

add comment "# coding:utf8# to all python file

October 07 2017

Do Not Escape Characters When Using dumpdata Command (Tested in Django 1.11)

Adds --pretty option to django ./manage.py dumpdata command, which produces pretty utf-8 strings instead of ugly unicode-escaped s**t:

$ ./manage.py dumpdata app.pricingplan --indent=1

[
 {
  "pk": 1, 
  "model": "app.pricingplan", 
  "fields": {
   "name": "\u0411\u0430\u0437\u043e\u0432\u044b\u0439", 
  }
 }, 
 {
  "pk": 2, 
  "model": "app.pricingplan", 
  "fields": {
   "name": "\u0425\u0443 ...

October 03 2017

CBV decorator from view function decorator

The Mixin approach for applying permissions to CBV views has 2 issues:

  1. you need to read the code to see what permissions are being applied to a View
  2. multiple bits of disparate code required to specify, e.g., a simple permission check

Here's an alternative -- takes any function decorator ...

September 21 2017

Convert tab indented string to dictionary

output:

{u'Ogrenci': [u'Tum okullar', u'Lisans', u'Onlisans', u'Yuksek Lisans / Doktora', u'Ingilizce Hazirlik'], u'Ogretim Elemani': [u'Tum okullar', u'Lisans', u'Onlisans', u'Yuksek Lisans / Doktora', u'Ingilizce Hazirlik']}

September 17 2017

Automigrate, autocreatesuperuser if not User.count() in runserver and use manage.py:main as entrypoint

With this awesome manage.py, it will try to migrate first when called with runserver.

Also, this manege.py has super power to be used in your entry point as such:

entry_points = {
    'console_scripts': [
        # u haz a setup.py -> u haz importable module :) 
        'yourcommand = yourproject.manage:main',
    ],
},

Example output:

$ yourcommand ...

September 12 2017

Show Logs on Django Admin

Place the code any admin.py file in your registered apps

August 22 2017

Compact primary keys

If the primary key on a table is an integer, it can be desirable after a lot of adding and removing either during testing (as was my case) or otherwise, to tidy up the key space a little and see the primary keys run up as unbroken sequences from 1 ...

August 21 2017

update primary key (cascade to child tables and inherited models) - Django 1.11

An upgrade to the excellent snippet by variant at https://djangosnippets.org/snippets/2915/

Upgraded to work with Django 1.11.

October 19 2017

Soft hyphenation filters

Automatically hyphenate raw text or HTML code

October 15 2017

inline forms for deeply nested models

I had a problem trying to display my model would have a foreign key and that model would have one too etc.

Now there was a point I wanted to display the foreign keys of that field and display its fields and so on so forth.

This pretty much expands ...

October 09 2017

add encoding comment to project all python file

add comment "# coding:utf8# to all python file

October 07 2017

Do Not Escape Characters When Using dumpdata Command (Tested in Django 1.11)

Adds --pretty option to django ./manage.py dumpdata command, which produces pretty utf-8 strings instead of ugly unicode-escaped s**t:

$ ./manage.py dumpdata app.pricingplan --indent=1

[
 {
  "pk": 1, 
  "model": "app.pricingplan", 
  "fields": {
   "name": "\u0411\u0430\u0437\u043e\u0432\u044b\u0439", 
  }
 }, 
 {
  "pk": 2, 
  "model": "app.pricingplan", 
  "fields": {
   "name": "\u0425\u0443 ...

October 03 2017

CBV decorator from view function decorator

The Mixin approach for applying permissions to CBV views has 2 issues:

  1. you need to read the code to see what permissions are being applied to a View
  2. multiple bits of disparate code required to specify, e.g., a simple permission check

Here's an alternative -- takes any function decorator ...

September 21 2017

Convert tab indented string to dictionary

output:

{u'Ogrenci': [u'Tum okullar', u'Lisans', u'Onlisans', u'Yuksek Lisans / Doktora', u'Ingilizce Hazirlik'], u'Ogretim Elemani': [u'Tum okullar', u'Lisans', u'Onlisans', u'Yuksek Lisans / Doktora', u'Ingilizce Hazirlik']}

September 17 2017

Automigrate, autocreatesuperuser if not User.count() in runserver and use manage.py:main as entrypoint

With this awesome manage.py, it will try to migrate first when called with runserver.

Also, this manege.py has super power to be used in your entry point as such:

entry_points = {
    'console_scripts': [
        # u haz a setup.py -> u haz importable module :) 
        'yourcommand = yourproject.manage:main',
    ],
},

Example output:

$ yourcommand ...

September 12 2017

Show Logs on Django Admin

Place the code any admin.py file in your registered apps

August 22 2017

Compact primary keys

If the primary key on a table is an integer, it can be desirable after a lot of adding and removing either during testing (as was my case) or otherwise, to tidy up the key space a little and see the primary keys run up as unbroken sequences from 1 ...

Older posts are this way If this message doesn't go away, click anywhere on the page to continue loading posts.
Could not load more posts
Maybe Soup is currently being updated? I'll try again automatically in a few seconds...
Just a second, loading more posts...
You've reached the end.

Don't be the product, buy the product!

Schweinderl