Skip to content

Instantly share code, notes, and snippets.

View sehmaschine's full-sized avatar

Patrick Kranzlmueller sehmaschine

View GitHub Profile
@sehmaschine
sehmaschine / now.json
Created July 4, 2019 19:33
Custom 404 with Gatsby and Now
{
"version": 2,
"name": "xxx",
"builds": [
{
"src": "package.json",
"use": "@now/static-build",
"config": { "distDir": "public" }
}
],
@sehmaschine
sehmaschine / related.py
Created September 7, 2017 08:05
ModelAdmin.get_queryset with django-grappelli
@sehmaschine
sehmaschine / models.py
Created November 23, 2015 12:27
Signals for FileBrowseUploadField
from apps.images.signals import image_callback
def entry_upload_path(instance, filename):
return os.path.join("uploads", "blog", str(instance.id), filename)
class Entry(models.Model):
image = FileBrowseUploadField(max_length=250, upload_to=entry_upload_path)
post_save.connect(image_callback, sender=Entry)
@sehmaschine
sehmaschine / filters.py
Created September 14, 2015 18:47
OrderingFilter for Django Rest Framework
# coding: utf-8
# PYTHON IMPORTS
from django.utils import six
from django.core.exceptions import ImproperlyConfigured
# REST IMPORTS
from rest_framework.settings import api_settings
from rest_framework.filters import BaseFilterBackend
@sehmaschine
sehmaschine / navigation.jsx
Created June 23, 2015 13:24
react router context
var NavigationView = React.createClass({
childContextTypes: {
router: React.PropTypes.func.isRequired
},
showGroups: function(event) {
React.render(<NavigationGroup />, document.getElementById('menu'));
},
render: function() {
return (
<div id="parent">
@sehmaschine
sehmaschine / test_base64.html
Last active August 29, 2015 14:02
wkhtmltopdf with custom font (font-face)
<!DOCTYPE html>
<html>
<head>
<style>
@font-face {
font-family: "CustomFont";
src: url(data:font/opentype;charset=utf-8;base64,d09GRgABAAAAAJ2bABAAAAABU8wAAQAAAACanAAAAv8AAAYEAAAAAAAAAABPUy8yAAABbAAAAFgAAABgZpABsVZETVgAAAHEAAADfgAABeBvK3avY21hcAAABUQAAACpAAAA5LmCs2VjdnQgAAAF8AAAACAAAAAgBLgBVWZwZ20AAAYQAAABAgAAAXMGWZw3Z2FzcAAABxQAAAAIAAAACP//AARnbHlmAAAHHAAAcCsAAPo4D+TPemhlYWQAAHdIAAAANgAAADbxqmcSaGhlYQAAd4AAAAAgAAAAJAb8BA1obXR4AAB3oAAAAiEAAAO0yak2cGtlcm4AAHnEAAAWlQAANFya657HbG9jYQAAkFwAAAKHAAADuACGVGBtYXhwAACS5AAAACAAAAAgAwYEuG5hbWUAAJMEAAAG9QAAEp6VPrU+cG9zdAAAmfwAAAATAAAAIP+4ADJwcmVwAACaEAAAAIoAAADBPju7qXicY2Bm/MI4gYGVgYNpD1MXAwNDD4RmvMtgxPCLgYGJn5WZiYmZlYm5gYFhPVCeiwEKfDz9/IEUr6IS08v/jAwnmKcxXAHyGUFyjE+Y1jIoACEDAAaCD5t4nB3NU3AeChCG4bdXJ7Vt27Zt27Zt27Zt2z1F7MZO2qRu0zZN0+75zr8788w7sxdLKrT/D+lIcjKc+Mf+khonmYbUMi1p7I+uadXpSafOQHqZkQwyExllZjJZClnIrM4qU8hGFpmdrPabHGRT5yS7Ohc5ZG5yyjzksmTyklvmI4/MT15ZgHz2i4IymULkVxemgCxCQVmUQrIYhS2J4hSRJSgqS1JMlqK4/aQ0JdRlKKku67AcpWR5SssKlLEfVKSsu
@sehmaschine
sehmaschine / tests.py
Created May 19, 2013 14:26
simplified TestClient with rest framework
import time
from urlparse import urlparse
from django.conf import settings
from django.test import TestCase
from django.test.client import FakePayload, Client
class TestApiClient(object):
def __init__(self):
"""
@sehmaschine
sehmaschine / export.py
Created March 2, 2013 13:54
celery update_state issue
from tasks import full_export_task
def export_year_zip(user):
full_export_task.update_state(state="PROGRESS", meta={})
@sehmaschine
sehmaschine / base.py
Created January 22, 2013 14:13
FileBrowser ... updated walk for FileSubmit with SEARCH_TRAVERSE
def _walk(self, path, filelisting):
"""
Recursively walks the path and collects all files and
directories.
Danger: Symbolic links can create cycles and this function
ends up in a regression.
"""
dirs, files = self.site.storage.listdir(path)
@sehmaschine
sehmaschine / gist:2491298
Created April 25, 2012 16:58
Multiple FileBrowser Sites
from filebrowser.sites import site
from django.core.files.storage import DefaultStorage, default_storage, FileSystemStorage
site_1 = site(name="First FB Site", app_name="filebrowser", storage=default_storage) # default filebrowser site
site_2 = site(name="Second FB Site", app_name="filebrowser", storage=FileSystemStorage)