This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AuditStatsModelMixin(models.Model): | |
"audit metadata" | |
created_on = models.DateTimeField(auto_now_add=True) | |
created_ip = models.IPAddressField(null=True) | |
created_by = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_created_by") | |
updated_on = models.DateTimeField(auto_now=True) | |
updated_ip = models.IPAddressField(null=True) | |
updated_by = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_updated_by", null=True) | |
class Meta: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AccessLevel(models.Model): | |
user = models.ForeignKey(User, related_name='access_levels') | |
access_level = models.CharField( | |
max_length=12, | |
choices=(("open", "open"), ("closed", "closed")), | |
default="open" | |
) | |
starts = models.DateTimeField(auto_now=True) | |
expires = models.DateTimeField(blank=True, null=True) | |
content_type = models.ForeignKey(ContentType, related_name='access_levels') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Group(models.Model): | |
""" | |
A generic grouping, other models m2m this. | |
""" | |
parent = models.ForeignKey('self', null=True, blank=True, related_name="children") | |
slug = models.SlugField(max_length=100, help_text="The slug field.", default="") | |
name = models.CharField(max_length=100) | |
def __unicode__(self): | |
return u"%s/%s" % ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Copyright (c) 2009 Blackgate Research. | |
This work is made available under the terms of the Creative Commons Attribution-ShareAlike 3.0 license, | |
http://creativecommons.org/licenses/by-sa/3.0/." | |
""" | |
import time | |
import os | |
import sys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This fabric file makes setting up and deploying a django application much | |
easier, but it does make a few assumptions. Namely that you're using Git, | |
Apache and mod_wsgi and your using Debian or Ubuntu. Also you should have | |
Django installed on your local machine and SSH installed on both the local | |
machine and any servers you want to deploy to. | |
_note that I've used the name project_name throughout this example. Replace | |
this with whatever your project is called._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask.ext.restful import Resource, Api | |
app = Flask(__name__) | |
api = Api(app) | |
class SimpleRest(Resource): | |
def get(self): | |
return { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import HttpResponse | |
class Stub(object): | |
""" | |
Mixin. Use: | |
class MyResource(Stub, ...) # (Stub must be the first parent class) | |
Now MyResource will do no processing, auth or model-checking. | |
It will simply respond with the contents of the json file in the local directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import sha1 | |
import uuid | |
import hmac | |
def generate_key(self): | |
""" | |
Lifted from: | |
https://github.com/toastdriven/django-tastypie/blob/master/tastypie/models.py#L46 | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import datetime | |
from collections import Counter | |
import json | |
import argparse | |
parser = argparse.ArgumentParser( | |
description='Count Tomcat errors and group by date.' | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git pull || (cd ../ && rmdir workspace && git checkout repo.git workspace && cd workspace) |