3. Disclaimer
• I’m not a super pro pythonista, but I’m a
very lazy one.
Wednesday, June 19, 13
4. Disclaimer
• I’m not a super pro pythonista, but I’m a
very lazy one.
• Speed - means programmer’s programming
speed, unless specified otherwise.
Wednesday, June 19, 13
5. Disclaimer
• I’m not a super pro pythonista, but I’m a
very lazy one.
• Speed - means programmer’s programming
speed, unless specified otherwise.
• I like to do things as short and as easy as
possible.
Wednesday, June 19, 13
6. Disclaimer
• I’m not a super pro pythonista, but I’m a
very lazy one.
• Speed - means programmer’s programming
speed, unless specified otherwise.
• I like to do things as short and as easy as
possible.
• DRYKISS =
Don’t repeat yourself + Keep it super simple
Wednesday, June 19, 13
7. ACE EdVenture Pixel
Head of R&D and Lead Developer
SchoolHub
School Management System
What we use python for ?
SchoolHub is built on top of Django Web Framework
Wednesday, June 19, 13
8. ACE EdVenture Studio
Head of R&D
ChemQuest: Petticles in Peril
Chemistry based RPG game.
What we use python for ?
Most of the web components are built with
Django Web Framework
(Web login, Game Achievements, etc.)
Wednesday, June 19, 13
11. • use lists[] instead of tuples() in default_settings.py
• Use list methods - add(), remove(), +=
• Default naming convention to project name
• use project as default “theme” app for project
Wednesday, June 19, 13
25. • Automatically load all apps in a directory.
• Useful for plugins*
• For more complex usage, .autodiscover()
might be a better choice
Wednesday, June 19, 13
26. 1 # installed_plugins_list.py
2
3 def installed_plugins_list(plugin_path=None):
4 """Function to get a list of plugins from plugin_path
5 """
6 import os
7
8 path = os.path.dirname(__file__)
9 path = os.path.join(path, plugin_path)
10
11 installed_plugins = []
12 for module in os.listdir(path):
13 if os.path.isdir(path + '/' + module) == True:
14 installed_plugins.append(module)
15 return installed_plugins
Wednesday, June 19, 13
27. 1 ##########################
2 # LABS SETTINGS #
3 ##########################
4 # Developer's playground #
5 # Play at ur own risk #
6 ##########################
7
8 if LABS_ENABLED and not "sis.labs" in INSTALLED_APPS:
9 from .installed_plugins_list import installed_plugins_list
10
11 TEMPLATE_CONTEXT_PROCESSORS += [
12 "sis.context_processors.sis_labs"
13 ]
14
15 # Loads all modules from sis.plugins
16 for plugin in installed_plugins_list('plugins'):
17 INSTALLED_APPS.insert(0, "sis.plugins.%s" % plugin)
18
19 # Loads all modules from sis.labs.ui
20 for plugin in installed_plugins_list('labs/ui'):
21 INSTALLED_APPS.insert(0, "sis.labs.ui.%s" % plugin)
22
23 # Loads all modules from sis.labs.apps
24 INSTALLED_APPS.append('sis.labs')
25 for plugin in installed_plugins_list('labs/app'):
26 INSTALLED_APPS.append(0, "sis.labs.app.%s" % plugin)
Wednesday, June 19, 13
29. • Themes are just Django apps.
• Actually, themes are Django app with static
files and templates.
• Themes can be overridden, just like how
we override templates.
• For more information,
https://github.com/renyi/mezzanine-themes
Wednesday, June 19, 13
31. Where to put the themes ?
Wednesday, June 19, 13
32. 1. Use main app as theme
# directory structure
my_project/my_app/templates
my_project/my_app/static
# in settings.py
INSTALLED_APPS.insert(1, "my_app")
Wednesday, June 19, 13
33. 2. Have a dedicated theme
directory
# directory structure
my_project/my_app/themes/default/templates
my_project/my_app/themes/default/static
# in settings.py
INSTALLED_APPS.insert(1, "my_app.themes.default")
Wednesday, June 19, 13
35. • {% overextends %} is written by
@stephen_mcd for Mezzanine CMS.
• Also available as pluggable app.
https://github.com/stephenmcd/django-
overextends
• Allows circular template inheritance.
(base.html can “extend” base.html)
• This allows for simple way of managing
plugable apps (javascripts libraries, etc.) or
let’s call it “plugins”.
Wednesday, June 19, 13
70. 2. Custom User Model ?
Pros
-You don’t need a user profile model
- Faster, as you don’t have to refer to profiles as foreign
keys.
- More flexibility
Wednesday, June 19, 13
71. 2. Custom User Model ?
Cons
- might break contrib.admin
- might break old apps
- might break stuffs tied to user (like permission) if
custom model is not implemented correctly.
Wednesday, June 19, 13
72. 2. Custom User Model ?
Conclusion
-Yes, if you’re just extending the user model. If you
inherit from AbstractUser, you should be fine.
- No, if you want to override existing fields or
functions. Unless you know what you’re doing, you
might end up breaking compatibility with other apps.
Wednesday, June 19, 13
73. 2. Custom User Model ?
Implementation
- Add to settings.py, AUTH_USER_MODEL = 'myuser.MyModel'.
Wednesday, June 19, 13
74. Thank You !
by Renyi Khor
renyi.ace@gmail.com
@renyikhor
https://github.com/renyi/django-tips-and-tricks
Wednesday, June 19, 13