Requires virtualenv and virtualenvwrapper.
cdco # cd to buildout root cds voxin # (will autocomplete with tab and will cd into the project named voxin in the src dir) buildout # will run buildout, but from the buildout root.
| import json | |
| import logging | |
| import traceback | |
| from django.http import HttpResponseServerError | |
| from oscarapi.middleware import IsApiRequest | |
| logger = logging.getLogger(__name__) | |
| """ | |
| Ensure that only 1 process can be running a managment command at the same | |
| time, even across multiple application servers. | |
| Uses a database lock on a table row, in a separate database connection. | |
| """ | |
| import logging | |
| from django.conf import settings | |
| from django.db import models |
| from rest_framework import serializers | |
| from rest_framework.utils.serializer_helpers import BindingDict | |
| class PolymorphicModelSerializer(serializers.ModelSerializer): | |
| """ | |
| Serializer that serializes a polymorphic model | |
| Since the whole point of polymorphism is to have models | |
| with different properties in the same queryset, the ``fields`` meta | |
| specification in rest_framework becomes rather useless. That is |
| # this file is in a package named verboten | |
| from django.utils.translation import ugettext_lazy as _ | |
| from django.http import HttpResponseForbidden | |
| from django.template import RequestContext, loader | |
| from django.db import models | |
| from django.conf import settings | |
| class LanguagePermissions(models.Model): | |
| """Only used to define permissions""" |
| from django import template | |
| register = template.Library() | |
| @register.simple_tag | |
| def props(obj): | |
| result = [] | |
| for key in dir(obj): | |
| try: | |
| result.append("%s -> %s<br/>" % (key, getattr(obj, key))) | |
| except Exception as e: |
| from copy import deepcopy | |
| from google.appengine.ext import db | |
| import settings | |
| class I18nModelMetaClass(db.PropertiedClass): | |
| """ | |
| Metaclass for adding language specific attributes to a |
| AuthorizationRef authorizationRef; | |
| OSStatus status; | |
| status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, | |
| kAuthorizationFlagDefaults, &authorizationRef); | |
| // suppose we've got the new hosts file in an NSString called new_hosts_file | |
| NSString *overwrite_hosts = [NSString stringWithFormat:@"echo %s > /private/etc/hosts", new_hosts_file]; | |
| char *args[] = {[overwrite_hosts cstring]}; | |
| status = AuthorizationExecuteWithPrivileges(authorizationRef, "/bin/sh", | |
| kAuthorizationFlagDefaults, args, NULL); |
| > var one = 1; | |
| > var two = new one; | |
| > two; | |
| 1 | |
| > one = 2; | |
| > two; | |
| 1 | |
| > one; | |
| 2 |
| > var next = function(input) { | |
| > return input + 1; | |
| > } | |
| > var three = new next; | |
| > three; | |
| [Function] | |
| > three(2); | |
| 3 |