Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions configstore/.idea/configstore.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions configstore/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions configstore/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions configstore/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

777 changes: 777 additions & 0 deletions configstore/.idea/workspace.xml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions configstore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from configs import register, get_config, ConfigurationInstance
from forms import ConfigurationForm
import listeners
#from .configs import register, get_config, ConfigurationInstance
#from .forms import ConfigurationForm
#import configstore.listeners
11 changes: 6 additions & 5 deletions configstore/admin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from filecmp import cmp

from django.contrib import admin
from django.shortcuts import render_to_response
from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django import template

from models import Configuration
from configs import CONFIGS
from .models import Configuration
from .configs import CONFIGS

class ConfigurationAdmin(admin.ModelAdmin):
list_display = ('name', 'key', 'site')
Expand Down Expand Up @@ -38,7 +39,7 @@ def sort_by_label(a, b):
return cmp(a[1].name, b[1].name)
configs.sort(sort_by_label)
context = {
'title': _('Select %s') % force_unicode(opts.verbose_name),
'title': _('Select %s') % opts.verbose_name,
'configs': configs,
#'adminform': adminForm,
'is_popup': request.REQUEST.has_key('_popup'),
Expand Down Expand Up @@ -66,6 +67,6 @@ def sort_by_label(a, b):
return render_to_response(self.change_form_template or [
"admin/%s/%s/add_form.html" % (app_label, opts.object_name.lower()),
"admin/%s/add_form.html" % app_label,
], context, context_instance=template.RequestContext(request))
], context)

admin.site.register(Configuration, ConfigurationAdmin)
7 changes: 4 additions & 3 deletions configstore/configs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.sites.models import Site

from models import Configuration
from settings import SITE_ID
from .models import Configuration

import threading

Expand All @@ -24,8 +24,9 @@ def get_config(self):
"""
#CONSIDER should we plug in caching here?
try:
Site.objects.clear_cache()
configuration = Configuration.objects.get(key=self.key, site=Site.objects.get_current())
except Configuration.DoesNotExist:
except Configuration.DoesNotExist or Exception:
return {}
else:
return configuration.data
Expand Down
3 changes: 1 addition & 2 deletions configstore/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.core.files.storage import default_storage
from django.db.models.fields.files import FieldFile as _FieldFile
from django.utils.encoding import smart_str
from django.utils.translation import force_unicode
import datetime
import os

Expand All @@ -23,7 +22,7 @@ def _require_file(self):
raise ValueError("This instance has no file associated with it.")

def get_directory_name(self):
return os.path.normpath(force_unicode(datetime.datetime.now().strftime(smart_str(CONFIGSTORE_FILE_PATH))))
return os.path.normpath(datetime.datetime.now().strftime(smart_str(CONFIGSTORE_FILE_PATH)))

def get_filename(self, filename):
return os.path.normpath(self.storage.get_valid_name(os.path.basename(filename)))
Expand Down
6 changes: 3 additions & 3 deletions configstore/forms.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django import forms
from django.core.files.base import File
from django.utils import simplejson
import json
from django.contrib.sites.models import Site
from django.core.serializers.json import DjangoJSONEncoder

from fields import FieldFile
from models import Configuration
from .fields import FieldFile
from .models import Configuration

class ConfigurationForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion configstore/listeners.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from configs import CONFIG_CACHE, CONFIGS
from .configs import CONFIG_CACHE, CONFIGS
from django.core.signals import request_started

def nuke_cache(**kwargs):
Expand Down
9 changes: 5 additions & 4 deletions configstore/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.db import models
from django.contrib.sites.models import Site
from serializer import make_serializers
from .serializer import make_serializers

ENCODER, DECODER = make_serializers()

class Configuration(models.Model):
key = models.CharField(max_length=50)
site = models.ForeignKey(Site)
site = models.ForeignKey(Site, on_delete=models.CASCADE)
_data = models.TextField(db_column='data')

def get_data(self):
Expand All @@ -21,14 +21,15 @@ def set_data(self, data):

@property
def name(self):
from configs import CONFIGS
from .configs import CONFIGS
try:
return CONFIGS[self.key].name
except KeyError:
return self.key

def __unicode__(self):
def __str__(self):
return '%s: %s' % (self.key, self.site)

class Meta:
unique_together = [('key', 'site')]
app_label = 'configstore'
8 changes: 4 additions & 4 deletions configstore/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from django.core.exceptions import ObjectDoesNotExist
from django.db.models.query import QuerySet
from django.db import models
from django.utils import simplejson
import json

from decimal import Decimal

from fields import FieldFile
from .fields import FieldFile

class Handler(object):
def encode(self, obj):
Expand Down Expand Up @@ -43,7 +43,7 @@ def decode(self, dct):
ct = ContentType.objects.get(app_label=dct.pop('app'),
model=dct.pop('model'))
try:
kwargs = dict([(str(key), value) for key, value in dct.iteritems()])
kwargs = dict([(str(key), value) for key, value in dct.items()])
return ct.get_object_for_this_type(**kwargs)
except ObjectDoesNotExist:
if not self.nullify_notfound:
Expand Down Expand Up @@ -73,7 +73,7 @@ def encode(self, obj):
def decode(self, dct):
return FieldFile(dct['name'])

class JSONDecoder(simplejson.JSONDecoder):
class JSONDecoder(json.JSONDecoder):
def __init__(self, *args, **kwargs):
kwargs.setdefault('object_hook', self.decode_objects)
self.handlers = kwargs.pop('handlers')
Expand Down
122 changes: 122 additions & 0 deletions configstore/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
"""
Django settings for example20 project.

Generated by 'django-admin startproject' using Django 2.0.5.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'ar654!zeb(3@zgm#25)t!sn65$cd+otxx)-4+v@767be_by(lh'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

#ROOT_URLCONF = 'example20.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'example20.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'

TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)
12 changes: 12 additions & 0 deletions configstore/templates/admin/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "admin/base_site.html" %}
{% load i18n %}

{% block title %}{% trans 'Page not found' %}{% endblock %}

{% block content %}

<h2>{% trans 'Page not found' %}</h2>

<p>{% trans "We're sorry, but the requested page could not be found." %}</p>

{% endblock %}
17 changes: 17 additions & 0 deletions configstore/templates/admin/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "admin/base_site.html" %}
{% load i18n %}

{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
&rsaquo; {% trans 'Server error' %}
</div>
{% endblock %}

{% block title %}{% trans 'Server error (500)' %}{% endblock %}

{% block content %}
<h1>{% trans 'Server Error <em>(500)</em>' %}</h1>
<p>{% trans "There's been an error. It's been reported to the site administrators via email and should be fixed shortly. Thanks for your patience." %}</p>

{% endblock %}
15 changes: 15 additions & 0 deletions configstore/templates/admin/actions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% load i18n %}
<div class="actions">
{% for field in action_form %}{% if field.label %}<label>{{ field.label }} {% endif %}{{ field }}{% if field.label %}</label>{% endif %}{% endfor %}
<button type="submit" class="button" title="{% trans "Run the selected action" %}" name="index" value="{{ action_index|default:0 }}">{% trans "Go" %}</button>
{% if actions_selection_counter %}
<span class="action-counter" data-actions-icnt="{{ cl.result_list|length }}">{{ selection_note }}</span>
{% if cl.result_count != cl.result_list|length %}
<span class="all">{{ selection_note_all }}</span>
<span class="question">
<a href="#" title="{% trans "Click here to select the objects across all pages" %}">{% blocktrans with cl.result_count as total_count %}Select all {{ total_count }} {{ module_name }}{% endblocktrans %}</a>
</span>
<span class="clear"><a href="#">{% trans "Clear selection" %}</a></span>
{% endif %}
{% endif %}
</div>
Loading