Skip to content

Instantly share code, notes, and snippets.

View Ciantic's full-sized avatar

Jari Pennanen Ciantic

View GitHub Profile
@Ciantic
Ciantic / djangosessionjson.py
Created June 16, 2010 19:18
Django JSON serialized database SessionStore
"""Session table that stores session data as JSON
Works similarily as :mod:`django.contrib.sessions.backends.db`
To use this add to your settings.py::
SESSION_ENGINE = 'djangosessionjson'
"""
@Ciantic
Ciantic / django_session.php
Created June 17, 2010 13:57
PHP DjangoUser class
<?PHP
/*
DjangoUser object to Joomla in PHP.
(Can be adapted easily to other PHP frameworks)
Usage::
$user =& DjangoUser::getUser();
if ($user && $user->hasPerm("polls.can_vote")) {
@Ciantic
Ciantic / objectperms.py
Created June 27, 2010 13:18
Django object permission backend, that passesthrough
from django.conf import settings
class ObjectPermBackend(object):
"""Simple object permission backend that passesthrough the has_perm calls
to the object.
"""
supports_object_permissions = True
supports_anonymous_user = True
@Ciantic
Ciantic / django.fcgi.py
Created July 8, 2010 21:45
Django FCGI application
#!/usr/bin/python
import sys, os
# Add a custom Python path.
THE_SITE = "mysite"
PYTHONPATH = "/var/www/mysite.example.com/django-fcgi/pythonpath/"
# Following is inferred from above
THE_DIR = PYTHONPATH + THE_SITE
DJANGO_PATH = PYTHONPATH + "django"
@Ciantic
Ciantic / keyboardlistener.cs
Created July 11, 2010 17:33
C# Keyboard listener
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using System.Windows.Threading;
using System.Collections.Generic;
namespace Ownskit.Utils
{
@Ciantic
Ciantic / sitecache.py
Created January 25, 2011 16:17
My Site object cache
"""Cache of Site related settings
Site IDs and urlconfs are such that are testd on *all* requests thus they need
to be cached.
"""
from django.conf import settings
from django.contrib.sites.models import Site
@Ciantic
Ciantic / multisitedmiddleware.py
Created January 25, 2011 16:19
MultiSitedMiddleware
"""Allows serving multiple sites per Django instance
"""
from django.utils.cache import patch_vary_headers
from sitecache import get_site_id, get_urlconf
class MultiSitedMiddleware:
@Ciantic
Ciantic / multisettings.py
Created January 29, 2011 17:31
Django settings.py that can handle
"""Multisite - individual site for request"""
from django.conf import settings
from threading import local
def make_tls_property(default=None):
"""Creates a class-wide instance property with a thread-specific value."""
class TLSProperty(object):
def __init__(self):
self.local = local()
@Ciantic
Ciantic / forbiddenmixintests.py
Created February 2, 2011 21:44
ForbiddenMixin can't be Mixin for security's sake
from django.conf.urls.defaults import * #@UnusedWildImport
from django.contrib.auth.models import Permission, User
from django.http import HttpResponse
from django.test import TestCase
from django.test.client import Client
from django.views.generic.base import View
class ForbiddenMixin(object):
"""ForbiddenMixin"""
@Ciantic
Ciantic / forbiddenviewtests.py
Created February 3, 2011 08:31
First working test.
# REPLACE urls parameter of the TestCase and create test.html in order to test
# this
from django.conf.urls.defaults import * #@UnusedWildImport
from django.contrib.auth.models import Permission, User
from django.http import HttpResponse
from django.test import TestCase
from django.test.client import Client
from django.views.generic.base import View, TemplateView