Merge branch 'smart_staging' into master_merge_test

Conflicts:
	apps/common/__init__.py
	requirements/development.txt
	requirements/production.txt
This commit is contained in:
Roberto Rosario
2011-07-21 03:55:21 -04:00
66 changed files with 2596 additions and 998 deletions

View File

@@ -8,9 +8,7 @@ from django.db.models import signals
from navigation.api import register_links
from common.conf import settings as common_settings
TEMPORARY_DIRECTORY = common_settings.TEMPORARY_DIRECTORY \
if common_settings.TEMPORARY_DIRECTORY else tempfile.mkdtemp()
from common.utils import validate_path
def has_usable_password(context):
@@ -22,7 +20,6 @@ current_user_edit = {'text': _(u'edit details'), 'view': 'current_user_edit', 'f
register_links(['current_user_details', 'current_user_edit', 'password_change_view'], [current_user_details, current_user_edit, password_change_view], menu_name='secondary_menu')
if common_settings.AUTO_CREATE_ADMIN:
# From https://github.com/lambdalisue/django-qwert/blob/master/qwert/autoscript/__init__.py
# From http://stackoverflow.com/questions/1466827/ --
@@ -50,3 +47,6 @@ if common_settings.AUTO_CREATE_ADMIN:
dispatch_uid='django.contrib.auth.management.create_superuser')
signals.post_syncdb.connect(create_testuser,
sender=auth_models, dispatch_uid='common.models.create_testuser')
if (validate_path(common_settings.TEMPORARY_DIRECTORY) == False) or (not common_settings.TEMPORARY_DIRECTORY):
setattr(common_settings, 'TEMPORARY_DIRECTORY', tempfile.mkdtemp())

View File

@@ -3,6 +3,7 @@
{% load pagination_tags %}
{% load navigation_tags %}
{% load non_breakable %}
{% load variable_tags %}
{% if side_bar %}
<div class="block">
@@ -122,13 +123,17 @@
{% endif %}
{% endfor %}
{% if not hide_links %}
{% if list_object_variable_name %}
{% copy_variable object as list_object_variable_name %}
{% copy_variable list_object_variable_name as "navigation_object_name" %}
{% endif %}
<td class="last">
{% if navigation_object_links %}
{% with navigation_object_links as overrided_object_links %}
{% object_navigation_template %}
{% endwith %}
{% else %}
{% object_navigation_template %}
{% object_navigation_template %}
{% endif %}
</td>
{% endif %}

View File

@@ -0,0 +1,42 @@
import re
from django.template import Node, TemplateSyntaxError, Library, Variable
register = Library()
class CopyNode(Node):
def __init__(self, source_variable, var_name, delete_old=False):
self.source_variable = source_variable
self.var_name = var_name
self.delete_old = delete_old
def render(self, context):
context[Variable(self.var_name).resolve(context)] = Variable(self.source_variable).resolve(context)
if self.delete_old:
context[Variable(self.source_variable).resolve(context)] = u''
return ''
@register.tag
def copy_variable(parser, token):
return parse_tag(parser, token)
@register.tag
def rename_variable(parser, token):
return parse_tag(parser, token, {'delete_old': True})
def parse_tag(parser, token, *args, **kwargs):
# This version uses a regular expression to parse tag contents.
try:
# Splitting by None == splitting by spaces.
tag_name, arg = token.contents.split(None, 1)
except ValueError:
raise TemplateSyntaxError('%r tag requires arguments' % token.contents.split()[0])
m = re.search(r'(.*?) as ([\'"]*\w+[\'"]*)', arg)
if not m:
raise TemplateSyntaxError('%r tag had invalid arguments' % tag_name)
source_variable, var_name = m.groups()
return CopyNode(source_variable, var_name, *args, **kwargs)

View File

@@ -2,6 +2,7 @@
import os
import re
import types
import tempfile
from django.utils.http import urlquote as django_urlquote
from django.utils.http import urlencode as django_urlencode
@@ -12,6 +13,15 @@ from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
try:
from python_magic import magic
USE_PYTHON_MAGIC = True
except:
import mimetypes
mimetypes.init()
USE_PYTHON_MAGIC = False
def urlquote(link=None, get=None):
u'''
This method does both: urlquote() and urlencode()
@@ -337,3 +347,50 @@ def return_diff(old_obj, new_obj, attrib_list=None):
}
return diff_dict
def get_mimetype(filepath):
"""
Determine a file's mimetype by calling the system's libmagic
library via python-magic or fallback to use python's mimetypes
library
"""
file_mimetype = u''
file_mime_encoding = u''
if USE_PYTHON_MAGIC:
if os.path.exists(filepath):
try:
source = open(filepath, 'r')
mime = magic.Magic(mime=True)
file_mimetype = mime.from_buffer(source.read())
source.seek(0)
mime_encoding = magic.Magic(mime_encoding=True)
file_mime_encoding = mime_encoding.from_buffer(source.read())
finally:
if source:
source.close()
else:
path, filename = os.path.split(filepath)
file_mimetype, file_mime_encoding = mimetypes.guess_type(filename)
return file_mimetype, file_mime_encoding
def validate_path(path):
if os.path.exists(path) != True:
# If doesn't exist try to create it
try:
os.mkdir(path)
except:
return False
# Check if it is writable
try:
fd, test_filepath = tempfile.mkstemp(dir=path)
os.close(fd)
os.unlink(test_filepath)
except:
return False
return True