Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django (web-mode) and (python-mode) snippets #40

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
233 changes: 233 additions & 0 deletions python-mode/django/README.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
#+TITLE: Django (python-mode) Snippets
#+DATE: March 29, 2020
#+SINCE: {replace with next tagged release version}
#+STARTUP: inlineimages nofold

* Table of Contents :TOC_3:noexport:
- [[#description][Description]]
- [[#maintainers][Maintainers]]
- [[#snippets][Snippets]]
- [[#imports-trigger-dji][Imports (:trigger dji)]]
- [[#views-trigger-djv][Views (:trigger djv)]]
- [[#settings-trigger-djs-or-settings][Settings (:trigger djs or settings.)]]
- [[#meta-trigger-djmeta][Meta (:trigger djmeta)]]
- [[#middleware-trigger-djmid][Middleware (:trigger djmid)]]
- [[#backends-trigger-djb][Backends (:trigger djb)]]
- [[#model-form-meta-trigger-djmeta][Model Form Meta (:trigger djmeta)]]
- [[#models-trigger-djmod][Models (:trigger djmod)]]
- [[#django-template-tags][Django Template Tags]]
- [[#common][Common]]
- [[#faq][FAQ]]
- [[#q-holy-settings-snippets-batman][Q: Holy settings snippets batman!?!]]
- [[#what-version-of-django-are-these-snippets-for][What version of Django are these snippets for?]]
- [[#contributing][Contributing]]

* Description
A bunch of Django specific python-mode snippets, including ~settings~, ~imports~
and ~views~. Here are some of them:

+ Complete global Django settings as dot references, i.e. ~settings.<tab>~ and
settings usage, i.e. ~djs<tab>~. The latter will insert to setting as it
would be in a settings module.
+ Meta class attributes
+ Common imports
+ Common function and class-based views
+ etc

These snippets are meant to act as more of a auto-completion / quick look-up instead of auto
expanding, therefore snippets are grouped as much as possible.

** Maintainers
+ @jsoa (Author)

* Snippets
** Imports (:trigger dji)
Common imports

+ ~:group django-imports~
+ ~:trigger dji~
+ ~http-response~
+ ~mark-safe~
+ ~models~
+ ~receiver~
+ ~reverse-url~
+ ~safe-string~
+ ~settings~
+ ~site-settings~
+ ~timezone~
+ ~ugettext~
+ ~url-path~
+ ~url-repath~

** Views (:trigger djv)
Common views

+ ~:group django-views~
+ ~:trigger djv~
+ ~basic-func-get-view~ - Basic function based GET view
+ ~basic-view~ - Basic function based view
+ ~redirect-cbv~ - Redirect class based view
+ ~template-cbv~ - Template class based view
+ ~basic-cbv~ - Basic class based view
+ ~detail-view-cbv~ - DetailView (class based view)
+ ~list-view-cbv~ - ListView (class based view)

** Settings (:trigger djs or settings.)
Global settings

These are the Django global settings, which can be expanded via dot reference or
expanded as if putting into a settings module. There are too many to list out
here so pressing ~djs<tab>~ or ~settings.<tab>~ will give you the full list.

Note: the names of these snippets include a brief explanation. The ~setting~
usage, i.e. when using it in a settings module, comments will be included where
possible.

+ ~:group django-settings~
+ ~:trigger djs~
+ [[file:settings/][list of snippets]]

+ ~:group django-settings-dot~
+ ~:trigger settings.~
+ [[file:settings/][list of snippets]]

** Meta (:trigger djmeta)
Django model ~Meta~ attributes

+ ~:group django-meta~
+ ~:trigger djmeta~
+ ~abstract~
+ ~app-label~
+ ~base-manager-name~
+ ~constraints~
+ ~db-table~
+ ~db-tablespace~
+ ~default-manager-name~
+ ~default-permissions~
+ ~default-related-name~
+ ~get-latest-by~
+ ~indexes~
+ ~index-together~
+ ~label~
+ ~label-lower~
+ ~managed~
+ ~ordering~
+ ~order-with-repect-to~
+ ~premissions~
+ ~proxy~
+ ~required-db-features~
+ ~required-db-vendor~
+ ~select-on-save~
+ ~unique-together~
+ ~verbose-name~
+ ~verbose-name-plural~

** Middleware (:trigger djmid)
All the built-in middleware in the form of the value used in the ~MIDDLEWARE~ setting

+ ~:group django-middleware~
+ ~:trigger djmid~
+ ~authentication~
+ ~broken-link-email~
+ ~cache-fetch~
+ ~cache-update~
+ ~common~
+ ~conditional-get~
+ ~csrf-view~
+ ~current-site~
+ ~gzip~
+ ~locale~
+ ~message~
+ ~persistent-remove-user~
+ ~remote-user~
+ ~security~
+ ~session~
+ ~x-frame-options~

** Backends (:trigger djb)
These snippets are possible options for other settings, such as ~ENGINE~ for
~DATABASES~ setting or ~BACKEND~ for ~CACHES~ setting.

+ ~:group django-backends~
+ ~:trigger djb~
+ ~authentication~
+ ~cache-database~
+ ~cache-file~
+ ~cache-locmem~
+ ~cache-memcached~
+ ~cache-pylibmc~
+ ~db-mysql~
+ ~db-oracle~
+ ~db-postgresql~
+ ~db-sqlite3~
+ ~email~
+ ~message-cookie~
+ ~message-fallback~
+ ~message-session~
+ ~session-cache~
+ ~session-cached-db~
+ ~session-db~
+ ~session-file~
+ ~session-signed-cookie~
+ ~signing~
+ ~staticfiles~
+ ~templates-django~
+ ~templates_jinja2~

** Model Form Meta (:trigger djmeta)
Django model form meta attributes, these reside in the same group as
~django-meta~ and contain a name prefix of ~form~

+ ~:group django-meta~
+ ~:trigger djmeta~
+ ~forms-error-messages~
+ ~forms-exclude~
+ ~forms-field-classes~
+ ~forms-fields~
+ ~forms-help-texts~
+ ~forms-labels~
+ ~forms-localized-fields~
+ ~forms-model~
+ ~forms-widgets~

** Models (:trigger djmod)
Common django models

+ ~:group django-models~
+ ~:trigger djmod~
+ ~common~
+ ~generic~

** Django Template Tags
Common template tag creation

+ ~:group django-custom~
+ ~:trigger djtt~
+ ~filter~ - python code to create a filter
+ ~filter-with_arg~ - same as above, but with an argument
+ ~inclusion-tag~ - python code to create an inclusion tag
+ ~inclusion-tag-with-context~ - same as above, but with context
+ ~simpletag~ - python code to create a simple template tag
+ ~simpletag-with-context~ - same as above, but with context

** Common
Other common snippets

+ ~:group django-common~
+ ~ugettextify~ - Wraps selection in the common ugettext
function, i.e. ~'test'~ becomes ~_('test')_~. You will need
to insert snippet after selecting text (i.e. via doom ~~SPC s i~)
+ ~modeladmin~ - A common model admin class with commented out extra
attributes

* FAQ
** Q: Holy settings snippets batman!?!
yea there is a lot, and since ~django~ collects and caches all these
settings in a class at run-time, they are not usually available for
auto-completing
** What version of Django are these snippets for?
Version ~3.0~

* Contributing
There is an included ~snippet-templates~ file the includes the templates used to
create the various groups of snippets
7 changes: 7 additions & 0 deletions python-mode/django/backends/authentication
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: auth.backends.ModelBackend
# key: djb
# uuid: django-backends-authentication
# group: django-backends
# --
django.contrib.auth.backends.ModelBackend
7 changes: 7 additions & 0 deletions python-mode/django/backends/cache-database
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: cache.backends.DatabaseCache
# key: djb
# uuid: django-backends-cache-database
# group: django-backends
# --
django.core.cache.backends.db.DatabaseCache
7 changes: 7 additions & 0 deletions python-mode/django/backends/cache-dummy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: cache.backends.DummyCache
# key: djb
# uuid: django-backends-cache-dummy
# group: django-backends
# --
django.core.cache.backends.dummy.DummyCache
7 changes: 7 additions & 0 deletions python-mode/django/backends/cache-file
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: cache.backends.FileBasedCache
# key: djb
# uuid: django-backends-cache-file
# group: django-backends
# --
django.core.cache.backends.filebased.FileBasedCache
7 changes: 7 additions & 0 deletions python-mode/django/backends/cache-locmem
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: cache.backends.LocMemCache
# key: djb
# uuid: django-backends-cache-locmem
# group: django-backends
# --
django.core.cache.backends.locmem.LocMemCache
7 changes: 7 additions & 0 deletions python-mode/django/backends/cache-memcached
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: cache.backends.MemcachedCache
# key: djb
# uuid: django-backends-cache-memcached
# group: django-backends
# --
django.core.cache.backends.memcached.MemcachedCache
7 changes: 7 additions & 0 deletions python-mode/django/backends/cache-pylibmc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: cache.backends.PyLibMCCache
# key: djb
# uuid: django-backends-cache-pylibmc
# group: django-backends
# --
django.core.cache.backends.memcached.PyLibMCCache
7 changes: 7 additions & 0 deletions python-mode/django/backends/db-mysql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: db.backends.mysql
# key: djb
# uuid: django-backends-db-mysql
# group: django-backends
# --
django.db.backends.mysql
7 changes: 7 additions & 0 deletions python-mode/django/backends/db-oracle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: db.backends.oracle
# key: djb
# uuid: django-backends-db-oracle
# group: django-backends
# --
django.db.backends.oracle
7 changes: 7 additions & 0 deletions python-mode/django/backends/db-postgresql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: db.backends.postgresql
# key: djb
# uuid: django-backends-db-postgresql
# group: django-backends
# --
django.db.backends.postgresql
7 changes: 7 additions & 0 deletions python-mode/django/backends/db-sqlite3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: db.backends.sqlite3
# key: djb
# uuid: django-backends-db-sqlite3
# group: django-backends
# --
django.db.backends.sqlite3
7 changes: 7 additions & 0 deletions python-mode/django/backends/email
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: core.mail.backends.smtp.EmailBackend
# key: djb
# uuid: django-backends-email
# group: django-backends
# --
django.core.mail.backends.smtp.EmailBackend
7 changes: 7 additions & 0 deletions python-mode/django/backends/message-cookie
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: messages.storage.CookieStorage
# key: djb
# uuid: django-backends-message-cookie
# group: django-backends
# --
django.contrib.messages.storage.cookie.CookieStorage
7 changes: 7 additions & 0 deletions python-mode/django/backends/message-fallback
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: messages.storage.FallbackStorage
# key: djb
# uuid: django-backends-message-fallback
# group: django-backends
# --
django.contrib.messages.storage.fallback.FallbackStorage
7 changes: 7 additions & 0 deletions python-mode/django/backends/message-session
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: messages.storage.SessionStorage
# key: djb
# uuid: django-backends-message-session
# group: django-backends
# --
django.contrib.messages.storage.session.SessionStorage
7 changes: 7 additions & 0 deletions python-mode/django/backends/session-cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: contrib.sessions.backends.cache
# key: djb
# uuid: django-backends-session-cache
# group: django-backends
# --
django.contrib.sessions.backends.cache
7 changes: 7 additions & 0 deletions python-mode/django/backends/session-cached-db
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: contrib.sessions.backends.cache_db
# key: djb
# uuid: django-backends-session-cache-db
# group: django-backends
# --
django.contrib.sessions.backends.cache_db
7 changes: 7 additions & 0 deletions python-mode/django/backends/session-db
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# name: contrib.sessions.backends.db
# key: djb
# uuid: django-backends-session-db
# group: django-backends
# --
django.contrib.sessions.backends.db
Loading