Skip to content

Instantly share code, notes, and snippets.

Avatar

Jari Pennanen Ciantic

  • Finland, Jyväskylä
View GitHub Profile
@Ciantic
Ciantic / djangosessionjson.py
Created Jun 16, 2010
Django JSON serialized database SessionStore
View djangosessionjson.py
"""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 Jun 17, 2010
PHP DjangoUser class
View django_session.php
<?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 Jun 27, 2010
Django object permission backend, that passesthrough
View objectperms.py
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 Jul 8, 2010
Django FCGI application
View django.fcgi.py
#!/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"
View keyboardlistener.cs
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 Jan 25, 2011
My Site object cache
View sitecache.py
"""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
View multisitedmiddleware.py
"""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 Jan 29, 2011
Django settings.py that can handle
View multisettings.py
"""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 Feb 2, 2011
ForbiddenMixin can't be Mixin for security's sake
View forbiddenmixintests.py
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"""
View forbiddenviewtests.py
# 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