Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Burus committed Feb 10, 2017
1 parent 9d80ee9 commit ee8dfdd
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/spicy/core/admin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.sites.models import Site
from django.db import models
from django.utils.translation import ugettext_lazy as _
from . import conf, abs
from . import conf


class AdminApp(models.Model):
Expand Down
1 change: 1 addition & 0 deletions src/spicy/core/profile/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
admin.site.register(Profile)



class AdminApp(conf.AdminAppBase):
name = 'profile'
label = _('Profile')
Expand Down
3 changes: 2 additions & 1 deletion src/spicy/core/profile/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
USE_CAPTCHA = getattr(settings, 'USE_CAPTCHA', True)
# django.contrib.auth required settings

settings.LOGIN_URL = getattr(settings, 'LOGIN_URL_CMS', '/signin/')
# XXX
settings.LOGIN_URL = getattr(settings, 'LOGIN_URL', '/signin/')
settings.LOGIN_REDIRECT_URL = '/'
settings.LOGOUT_URL = '/signout/'

Expand Down
23 changes: 15 additions & 8 deletions src/spicy/core/profile/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from captcha.conf.settings import get_challenge, CAPTCHA_FLITE_PATH
from captcha.models import CaptchaStore
from captcha.fields import CaptchaField, CaptchaTextInput, ImproperlyConfigured

from django.conf import settings
from django import forms
from django.contrib.admin import widgets
Expand All @@ -16,6 +17,7 @@
from django.db import transaction
from django.forms.extras.widgets import SelectDateWidget
from django.utils.translation import ugettext_lazy as _

from spicy.core.siteskin.widgets import LabledRegexField, LabledEmailField
from spicy.utils.models import get_custom_model_class
from . import defaults
Expand Down Expand Up @@ -495,6 +497,16 @@ class Meta:
fields = ['accept_agreement']


# XXX rename
class DynamicProfileColumnForm(forms.Form):
class Meta:
model = Profile
fields = [
'username', 'email', 'password', 'first_name',
'second_name', 'last_name', 'phone', 'subscribe_me'
]


class HiddenCaptchaWidget(forms.MultiWidget):
def __init__(self, attrs=None):
widgets = forms.HiddenInput, forms.HiddenInput
Expand Down Expand Up @@ -621,11 +633,6 @@ class ProfileUploadForm(forms.Form):
)
search_text = forms.CharField(label=_('Search'), required=False)

DynamicProfileColumnForm = type(
'DynamicProfileColumnForm', (forms.Form,),
dict(
(field,
forms.BooleanField(
initial=True, label=Profile.get_field_label(field), required=False))
for field in Profile.get_exported_fields()
))



7 changes: 5 additions & 2 deletions src/spicy/core/profile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import smtplib
import socket
import datetime as dt
from StringIO import StringIO
from uuid import uuid4

from django.conf import settings
from django.contrib.auth.models import User, UserManager, Group, Permission
from django.contrib.auth.models import AnonymousUser as BasicAnonymousUser
Expand All @@ -22,10 +25,9 @@
from django.utils.html import escape
from django.utils.translation import ugettext, ugettext_lazy as _
from django.core.mail import EmailMultiAlternatives

from spicy.core.service.models import ProviderModel
from spicy.utils.printing import print_error
from StringIO import StringIO
from uuid import uuid4
from . import cache, defaults, signals


Expand Down Expand Up @@ -283,6 +285,7 @@ def get_field_label(cls, field):
raise
return unicode(label)

# XXX deprecated
@classmethod
def get_exported_fields(cls):
return [
Expand Down
25 changes: 12 additions & 13 deletions src/spicy/core/profile/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import login as auth_login
from django.contrib.auth import REDIRECT_FIELD_NAME
from spicy.core.profile.views import generate_random_password

from spicy import utils
from spicy.core.service import api
from spicy.utils import load_module
from spicy.utils.models import get_custom_model_class
from spicy.core.siteskin.decorators import ajax_request, render_to
from . import defaults, models
from .decorators import is_staff
from .forms import LoginForm

Profile = get_custom_model_class(defaults.CUSTOM_USER_MODEL)
Profile = utils.get_custom_model_class(defaults.CUSTOM_USER_MODEL)

CUSTOM_USER_SIGNUP_FORM = getattr(
settings, 'CUSTOM_USER_SIGNUP_FORM', 'spicy.core.profile.forms.SignupForm')
Expand Down Expand Up @@ -154,7 +153,7 @@ def _get_redirect(self, request):
if callable(defaults.DEFAULT_PROFILE_URL):
user_redirect_uri = defaults.DEFAULT_PROFILE_URL(request.user)
elif isinstance(defaults.DEFAULT_PROFILE_URL, basestring):
user_redirect_uri = load_module(defaults.DEFAULT_PROFILE_URL)(
user_redirect_uri = utils.load_module(defaults.DEFAULT_PROFILE_URL)(
request.user)
else:
user_redirect_uri = defaults.DEFAULT_PROFILE_URL
Expand Down Expand Up @@ -263,7 +262,7 @@ def register(self, request):
REGISTRATION_ENABLED=defaults.REGISTRATION_ENABLED)

elif request.method == "POST":
form = load_module(CUSTOM_USER_SIGNUP_FORM)(request.POST)
form = utils.load_module(CUSTOM_USER_SIGNUP_FORM)(request.POST)
redirect = reverse('profile:public:success-signup')
if not is_blacklisted and form.is_valid():
status = 'ok'
Expand All @@ -274,7 +273,7 @@ def register(self, request):
request.session['profile_email'] = new_profile.email

else:
form = load_module(CUSTOM_USER_SIGNUP_FORM)()
form = utils.load_module(CUSTOM_USER_SIGNUP_FORM)()
request.session.set_test_cookie()

# Display the login form and handle the login action.
Expand Down Expand Up @@ -307,7 +306,7 @@ def login_or_register(self, request):
elif 'register' in request.POST:

action = 'register'
register_form = load_module(CUSTOM_USER_SIGNUP_FORM)(request.POST)
register_form = utils.load_module(CUSTOM_USER_SIGNUP_FORM)(request.POST)
login_form = LoginForm(request)
if not is_blacklisted and register_form.is_valid():
status = 'ok'
Expand All @@ -319,7 +318,7 @@ def login_or_register(self, request):

elif 'login' in request.POST:
action = 'login'
register_form = load_module(CUSTOM_USER_SIGNUP_FORM)()
register_form = utils.load_module(CUSTOM_USER_SIGNUP_FORM)()
login_form = LoginForm(data=request.POST)

# Brute force check.
Expand Down Expand Up @@ -365,7 +364,7 @@ def login_or_register(self, request):

else:
login_form = LoginForm(request)
register_form = load_module(CUSTOM_USER_SIGNUP_FORM)()
register_form = utils.load_module(CUSTOM_USER_SIGNUP_FORM)()
request.session.set_test_cookie()
action = None
if not redirect:
Expand All @@ -380,14 +379,14 @@ def login_or_register(self, request):

def restore(self, request):
message = ''
RestorePasswordForm = load_module(defaults.RESTORE_PASSWORD_FORM)
RestorePasswordForm = utils.load_module(defaults.RESTORE_PASSWORD_FORM)
if request.method == 'POST':
form = RestorePasswordForm(request.POST)
if form.is_valid():
profile = Profile.objects.get(
email__iexact=form.cleaned_data['email'])
if 'send_pass' in request.POST:
newpass = generate_random_password()
if 'send_pass' in request.POST:
newpass = utils.generate_random_password()
profile.set_password(newpass)
profile.save()
profile.email_forgotten_passwd(newpass)
Expand Down
5 changes: 0 additions & 5 deletions src/spicy/core/profile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
Profile = get_custom_model_class(defaults.CUSTOM_USER_MODEL)


def generate_random_password(length=10):
chars = string.letters + string.digits
return ''.join([random.choice(chars) for i in range(length)])


@render_to('spicy.core.profile/profile.html')
def profile(request, username):
user = get_object_or_404(Profile, username=username)
Expand Down
13 changes: 9 additions & 4 deletions src/spicy/core/service/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,15 @@ def __new__(mcs, name, bases, attrs):

class Provider(object):
"""
Provide common views, api methods for defined web-application service.
Service choose provider instance using own schema.
Provide common views(reusable controllers),
api methods by pre-configured web-application service.
provider = api.register['service_name'][ConsumerDjangoModel]
Service provider choose correct provider for any DjangoAppModelConsumer
using own schemas if its necessary.
provider = api.register['service_name'][DjangoAppModelConsumer]
provider.view_method()
:param model: ManyToMany model for consumer 'app.ModelName'
:type str:
Expand Down Expand Up @@ -415,7 +420,7 @@ def add(self, path_to_srv_interface):

if service is None:
print_error(
'Cannt initialize %s, check module version and reinstall tested copy.'
'Cannt initialize %s, check module and reinstall worked copy.'
% path_to_srv_interface)
return

Expand Down
1 change: 1 addition & 0 deletions src/spicy/core/simplepages/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

USE_DEFAULT_SIMPLE_PAGE_MODEL = getattr(
settings, 'USE_DEFAULT_SIMPLE_PAGE_MODEL', True)

SIMPLE_PAGE_MODEL = (
'simplepages.DefaultSimplePage' if USE_DEFAULT_SIMPLE_PAGE_MODEL else
settings.SIMPLE_PAGE_MODEL)
23 changes: 12 additions & 11 deletions src/spicy/core/simplepages/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import connection


from django.conf import settings
from django.conf.urls import patterns, url, include
Expand All @@ -22,16 +22,17 @@

urlpatterns = patterns('')

if 'django_site' in connection.introspection.table_names():
# XXX
# load it only after syncdb and check database exist
for page in SimplePage.objects.filter(sites__id__exact=settings.SITE_ID):
urlpatterns += patterns(
'spicy.core.simplepages.views',
url(r'^%s$' % page.url.lstrip('/'), 'render_simplepage',
{'page': page},
name=page.template_name)
)
#from django.db import connection
#if 'django_site' in connection.introspection.table_names():
# XXX
# load it only after syncdb and check database exist
for page in SimplePage.objects.filter(sites__id__exact=settings.SITE_ID):
urlpatterns += patterns(
'spicy.core.simplepages.views',
url(r'^%s$' % page.url.lstrip('/'), 'render_simplepage',
{'page': page},
name=page.template_name)
)


urlpatterns += patterns(
Expand Down
23 changes: 12 additions & 11 deletions src/spicy/core/siteskin/defaults.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from django.conf import settings
from spicy.core.simplepages.defaults import SIMPLE_PAGE_MODEL
#from spicy.core.simplepages.defaults import SIMPLE_PAGE_MODEL

SITESKIN_SETTINGS_MODEL = getattr(
settings, 'SITESKIN_SETTINGS_MODEL', 'siteskin.Siteskin')
Expand Down Expand Up @@ -87,16 +87,17 @@
# 'has_media': True
# },
# },
{
'model': SIMPLE_PAGE_MODEL,
'filter': {'sites__id__exact': settings.SITE_ID},
'exclude': {'url__startswith': '/test/'},
'gen': {
'loc': lambda x: x.get_absolute_url(),
'changefreq': 'daily',
'priority': '0.7'
}
}]
# {
# 'model': SIMPLE_PAGE_MODEL,
# 'filter': {'sites__id__exact': settings.SITE_ID},
# 'exclude': {'url__startswith': '/test/'},
# 'gen': {
# 'loc': lambda x: x.get_absolute_url(),
# 'changefreq': 'daily',
# 'priority': '0.7'
# }
# }
]
)

DATETIME_FORMAT = getattr(settings, 'DATETIME_FORMAT', '%Y-%m-%dT%H:%M:%S+03:00')
Expand Down
14 changes: 8 additions & 6 deletions src/spicy/core/siteskin/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from django.db import connection

from django.conf import settings
from django.conf.urls import patterns, url, include
from django.contrib.staticfiles import urls as st_urls
Expand All @@ -17,11 +17,13 @@
{'template_name': 'index.html', 'page_slug': 'index'}, name='index'),
)

if settings.DEBUG and 'spicy_siteskin' in connection.introspection.table_names():
current_theme = os.path.basename(
utils.get_siteskin_settings().theme)
st_urls.urlpatterns = [st_urls.staticfiles_urlpatterns(
'{}{}/'.format(settings.STATIC_URL, current_theme))]
#from django.db import connection
#if settings.DEBUG and 'spicy_siteskin' in connection.introspection.table_names():
current_theme = os.path.basename(
utils.get_siteskin_settings().theme)

st_urls.urlpatterns = [st_urls.staticfiles_urlpatterns(
'{}{}/'.format(settings.STATIC_URL, current_theme))]

urlpatterns = patterns(
'',
Expand Down
7 changes: 3 additions & 4 deletions src/spicy/core/trash/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.sites.models import Site
from django.contrib.sites.managers import CurrentSiteManager
from django.db import models, connection
from django.db import models
from django.utils.translation import ugettext_lazy as _
from spicy.core.service import api
from spicy.core.service.models import ProviderModel
Expand All @@ -25,9 +25,8 @@ def get_query_set(self):
query_set = super(MultiSitesNonTrashManager, self).get_query_set()

# XXX for syncdb
if connection.introspection.table_names():
return query_set.filter(sites=Site.objects.get_current())
return query_set
#if connection.introspection.table_names():
return query_set.filter(sites=Site.objects.get_current())


class TrashManager(models.Manager):
Expand Down
4 changes: 4 additions & 0 deletions src/spicy/utils/permissions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from functools import partial

def generate_random_password(length=10):
chars = string.letters + string.digits
return ''.join([random.choice(chars) for i in range(length)])


def perm(custom_model, prefix):
app, model = custom_model.split('.', 1)
Expand Down
17 changes: 9 additions & 8 deletions src/spicy/utils/settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from django.conf import settings
from django.db import models
from spicy.utils import get_custom_model_class

# from spicy.utils import get_custom_model_class

class CustomSettings(models.Model):
class Meta:
abstract = True
# from django.db import models

# TODO
def get_settings_from_db(model_name, field):
return get_custom_model_class(model_name).objects.get(site__id=SITE_ID)
# class CustomSettings(models.Model):
# class Meta:
# abstract = True

# # TODO
# def get_settings_from_db(model_name, field):
# return get_custom_model_class(model_name).objects.get(site__id=SITE_ID)
Loading

0 comments on commit ee8dfdd

Please sign in to comment.