Skip to content

Commit 4317795

Browse files
author
Dairon Medina
committed
Adding Last Functionality
1 parent b1f6c85 commit 4317795

File tree

197 files changed

+1016
-416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+1016
-416
lines changed

CONTRIBUTORS

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
============
2+
CONTRIBUTORS
3+
============
4+
5+
Current primary developers:
6+
7+
* Dairon Medina (@codeadict) <dairon.medina@gmail.com>
8+
* Rhys Park (swparsley) <sales@openweight.co.uk>
9+
10+
Contributors:
11+
12+
Will be added here when more people contributes to this project.

Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Determine the command used to start Python. This will be the
2+
# shell's Python unless the variable ${PYTHON} is set.
3+
ifndef PYTHON
4+
PYTHON=python
5+
endif
6+
7+
# Command for running management tool.
8+
MANAGE=${PYTHON} manage.py
9+
10+
# List all installed applications
11+
APPS=$(notdir $(shell find apps -mindepth 1 -maxdepth 1 -type d -print))
12+
13+
# Clean up.
14+
clean : tidy
15+
16+
# Prepares existing .po for localizations and compiles them
17+
# Public domain
18+
# To make first time localization (for example for de_DE) run
19+
# $ python manage.py makemessages -e ".html,.txt" -l de_DE
20+
int :
21+
${MANAGE} makemessages -e ".html,.txt,.py" --all
22+
${MANAGE} compilemessages
23+
24+
# Handle schema migration for all applications.
25+
schemamigration :
26+
@for i in ${APPS}; do ${MANAGE} schemamigration $$i --auto; done
27+
28+
# Display the settings.
29+
settings :
30+
@echo "PYTHON:" ${PYTHON}
31+
@echo "APPS:" ${APPS}
32+
33+
# Synchronize the database.
34+
syncdb :
35+
@${PYTHON} manage.py syncdb --noinput --migrate
36+
37+
# Runs pep8 and pyflakes
38+
check_code :
39+
@-pep8 --exclude migrations .
40+
@pyflakes apps/ |grep -v migrations
41+
42+
# Tidy up by removing .pyc files.
43+
tidy :
44+
@rm -rf htmlcov `find . -name '*.pyc'` `find . -name '*~'`
File renamed without changes.
File renamed without changes.

apps/base/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (C) 2013 OpenWeigh.co.uk
3+
# Developer: Dairon Medina Caro <dairon.medina@gmail.com>
4+
# Co-Developer Rhys Park <sales@openweigh.co.uk>
5+
6+
from base import monkeypatch
File renamed without changes.

apps/base/auth.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (C) 2013 OpenWeigh.co.uk
3+
# Developer: Dairon Medina Caro <dairon.medina@gmail.com>
4+
# Co-Developer Rhys Park <sales@openweigh.co.uk>
5+
import logging
6+
7+
from django.contrib.auth.models import User
8+
9+
log = logging.getLogger(__name__)
10+
11+
class OWUserBackend(object):
12+
"""
13+
Backend to authenticate with Username or email
14+
"""
15+
supports_anonymous_user = False
16+
supports_object_permissions = True
17+
18+
def authenticate(self, username=None, password=None):
19+
log.debug("Attempting to authenticate user %s" % (username,))
20+
try:
21+
if '@' in username:
22+
user = User.objects.get(email=username)
23+
else:
24+
user = User.objects.get(username=username)
25+
if user.check_password(password):
26+
return user
27+
except User.DoesNotExist:
28+
log.debug("User does not exist: %s" % (username,))
29+
return None
30+
31+
def get_user(self, user_id):
32+
try:
33+
return User.objects.get(pk=user_id)
34+
except User.DoesNotExist:
35+
return None
File renamed without changes.

apps/base/forms.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (C) 2013 OpenWeigh.co.uk
3+
# Developer: Dairon Medina Caro <dairon.medina@gmail.com>
4+
# Co-Developer Rhys Park <sales@openweigh.co.uk>
5+
from django import forms
6+
from django.utils.translation import ugettext as _, ugettext_lazy as _lazy
7+
from django.conf import settings
8+
9+
from base.models import Setting
10+
11+
12+
class SettingsForm(forms.Form):
13+
"""
14+
Form to Edit Global Settings
15+
"""
16+
company_name = forms.CharField(
17+
required=False, initial='Your Company',
18+
label=_lazy(u'Company Name'))
19+
logo = forms.ImageField(
20+
required=False,
21+
label=_lazy(u'Company Logo'))
22+
street1 = forms.CharField(
23+
required=False,
24+
label=_lazy(u'Address 1'))
25+
street2 = forms.CharField(
26+
required=False,
27+
label=_lazy(u'Address 2'))
28+
city = forms.CharField(
29+
required=False,
30+
label=_lazy(u'City'))
31+
state = forms.CharField(
32+
required=False,
33+
label=_lazy(u'State/County'))
34+
postcode = forms.CharField(
35+
required=False,
36+
label=_lazy(u'Post/Zip-code'))
37+
38+
def save_settings(self):
39+
for field in self.fields.keys():
40+
value = str(self.cleaned_data[field])
41+
setting = Setting.objects.filter(name=field)
42+
update_count = setting.update(value=value)
43+
if update_count == 0:
44+
# This user didn't have this setting so create it.
45+
Setting.objects.create(name=field, value=value)
46+

base/models.py renamed to apps/base/models.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,33 +196,38 @@ def determine_image_upload_path(instance, filename):
196196
}
197197

198198
class ActivableMixin(models.Model):
199-
active = models.BooleanField(verbose_name=_('Active'))
199+
active = models.BooleanField(verbose_name=_('Active'), default=True)
200200

201201
class Meta:
202202
abstract = True
203203

204204

205-
class Configuration(models.Model):
205+
class Setting(models.Model):
206206
"""
207207
Global Company Settings
208208
"""
209-
company_name = models.CharField(_('Company Name'), max_length=200, blank=True, null=True)
210-
logo = models.ImageField(_('Company Logo'), upload_to=determine_image_upload_path, null=True,
211-
storage=filesystem.ImageStorage(), blank=True)
212-
street1 = models.CharField(_("Address 1"), max_length=255, blank=True, null=True)
213-
street2 = models.CharField(_("Address 2"), max_length=255, blank=True, null=True)
214-
city = models.CharField(_("City"), max_length=255, blank=True, null=True)
215-
state = models.CharField(_("State/County"), max_length=255, blank=True, null=True)
216-
postcode = models.CharField(_("Post/Zip-code"), max_length=64, blank=True, null=True)
217-
209+
name = models.CharField(max_length=100)
210+
value = models.CharField(blank=True, max_length=255,
211+
verbose_name=_(u'Value'))
212+
218213
class Meta:
219214
verbose_name = _('Configuration')
220215
verbose_name_plural = _('Configuration')
221216

222217
def __unicode__(self):
223-
return self.company_name
218+
return u'%s:%s' % (self.name, self.value or u'Not Set')
224219

225-
def get_image_url(self):
226-
missing = settings.STATIC_URL + 'images/missing-logo.png'
227-
image_path = self.logo.url if self.logo else missing
228-
return image_path
220+
@classmethod
221+
def get(cls, name):
222+
from base.forms import SettingsForm
223+
form = SettingsForm()
224+
if name not in form.fields.keys():
225+
raise KeyError(("'{name}' is not a field in "
226+
"base.forms.SettingsFrom()").format(name=name))
227+
try:
228+
setting = Setting.objects.get(name=name)
229+
except Setting.DoesNotExist:
230+
value = form.fields[name].initial or ''
231+
setting = Setting.objects.create(user=user, name=name, value=value)
232+
# Cast to the field's Python type.
233+
return form.fields[name].to_python(setting.value)

0 commit comments

Comments
 (0)