Skip to content

Instantly share code, notes, and snippets.

View dizpers's full-sized avatar
🐻

Dmitry Belaventsev dizpers

🐻
View GitHub Profile
@joshcartme
joshcartme / gist:5130702
Last active December 14, 2015 18:39
Mezzanine Form ajax processing
# template tag
from mezzanine import template
from mezzanine.forms.forms import FormForForm
from mezzanine.pages.models import Page
register = template.Library()
@register.as_tag
def form_from_page(slug):
@caruccio
caruccio / bash-path-vars
Last active December 28, 2023 22:47
Path manipulation with bash vars
$ FILE=/some/path/to/file.txt
###################################
### Remove matching suffix pattern
###################################
$ echo ${FILE%.*} # remove ext
/some/path/to/file
$ FILE=/some/path/to/file.txt.jpg.gpg # note various file exts
@epicserve
epicserve / factories.py
Created October 3, 2012 19:37
Example Factory-boy (https://github.com/dnerdy/factory_boy) factory that uses a file field.
from django.template.defaultfilters import slugify
from django.contrib.sites.models import Site
from django.core.files import File
from taggit.models import Tag
from .models import Photo
import factory
import os
TEST_MEDIA_PATH = os.path.join(os.path.dirname(__file__), 'tests', 'test_media')
TEST_PHOTO_PATH = os.path.join(TEST_MEDIA_PATH, 'test_photo.png')
@jantoniomartin
jantoniomartin / listappend.py
Created June 18, 2012 17:42
A Django class based "list and form" view
"""
This generic view displays a list of objects and a simple ModelForm to add a new
object to the list.
Just subclass this view and override the attributes and methods that you need. You
will probably need to override at least 'model', 'form_class' and 'success_url'.
See the documentation of the used mixins and ProcessFormView in
https://docs.djangoproject.com/en/1.4/ref/class-based-views/
"""
from django.views.generic.list import MultipleObjectMixin, MultipleObjectTemplateResponseMixin
from django.views.generic.edit import ModelFormMixin, ProcessFormView
@hrldcpr
hrldcpr / tree.md
Last active April 26, 2024 08:53
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!