Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/generate pass #25

Open
wants to merge 9 commits into
base: 1.2.1
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def long_description():
#'django-debug-toolbar==1.3',
#'django-devserver',
#'django-extensions',
'django-autocomplete-light==2.0.0a15',
'django-autocomplete-light==1.4.14',

'xlrd',
'xlwt'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
(function($) {
$.fn.select2tree = function(options) {
var defaults = {
language: "en",
theme: "bootstrap"
};
var opts = $.extend(defaults, options);
opts.templateResult = function(data, container) {
if(data.element) {
//insert span element and add 'parent' property
var $wrapper = $("<span></span><span>" + data.text + "</span>");
var $element = $(data.element);
$(container).attr("val", $element.val());
if($element.attr("parent")) {
$(container).attr("parent", $element.attr("parent"));
$.fn.select2tree = function(options, field_id) {
return this.each(function() {
var defaults = {
language: "en",
theme: "bootstrap",
};
var opts = $.extend(defaults, options);
opts.templateResult = function (data, container) {
if (data.element) {
//insert span element and add 'parent' property
var $wrapper = $("<span></span><span>" + data.text + "</span>");
var $element = $(data.element);
$(container).attr("val", $element.val());
if ($element.attr("parent")) {
$(container).attr("parent", $element.attr("parent"));
}
return $wrapper;
} else {
return data.text;
}
return $wrapper;
} else {
return data.text;
}
};
$(this).select2(opts).on("select2:open", open);
};
$(this).select2(opts).on("select2:open", open);
});
};
function recursiveParentSelection(child, parentVals){
var parentVal = child.attr('parent');
var parent = $('li[val=' + parentVal + ']');
parentVals.push(parentVal);
if (parent.attr('parent') != undefined) { recursiveParentSelection(parent, parentVals); }
else { $('#id_{{ field.html_name }}').val(parentVals).trigger('select2:select'); }
else { $(field_id).val(parentVals).trigger('select2:select'); }
}
function getExistedValues(){
var vals = [];
$('#id_{{ field.html_name }} option').each(function(){
$(field_id + ' option').each(function(){
var optionText = $(this).text();
var optVal = $(this).val();
$('.select2-selection__choice').each(function(){
Expand Down Expand Up @@ -104,4 +106,6 @@
});
}, 0);
}
})(jQuery);
})(jQuery);


Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
</select>
<script type="text/javascript">
$(function() {
$("#id_{{ field.html_name }}").select2tree();
$("#id_{{ field.html_name }}").select2tree(field_id='#id_{{ field.html_name }}');
{% if field.value %}
$("#id_{{ field.html_name }}").val({{ field.value }}).trigger('change');
{% endif %}
Expand Down Expand Up @@ -382,6 +382,7 @@

</div>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.formset/1.2.2/jquery.formset.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<script>
$(document).ready(function(){
Expand All @@ -395,4 +396,4 @@
</script>
{% endif %}

{% endspaceless %}
{% endspaceless %}
9 changes: 5 additions & 4 deletions src/spicy/core/profile/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,11 @@ def profiles_list(request):
('group', None), ('search_text', ''), ('is_staff', None),
('last_login', None)])
search_args, search_kwargs = [], {}
form = forms.ProfileFiltersForm(request.GET)
status = 'ok'
message = ''

ExportProfileForm = utils.load_module(defaults.ADMIN_EXPORT_PROFILE_FORM)

if nav.search_text:
search_args.append(
Q(username__icontains=nav.search_text) |
Expand All @@ -245,7 +246,7 @@ def profiles_list(request):
if form.cleaned_data['file_kind'] == u'0':
queryset = Profile.objects.filter(pk__in=nav.get_queryset_ids(
Profile, search_query=(search_args, search_kwargs)))
columns_form = forms.DynamicProfileColumnForm(
columns_form = ExportProfileForm(
request.POST, prefix='columns')
columns_form.is_valid()
columns = [
Expand All @@ -263,7 +264,7 @@ def profiles_list(request):
form = forms.ProfileUploadForm(request.POST, request.FILES)
form.is_valid()
if form.cleaned_data['file_kind'] == u'0':
columns_form = forms.DynamicProfileColumnForm(
columns_form = ExportProfileForm(
request.POST, prefix='columns')
columns_form.is_valid()
columns = [
Expand All @@ -284,7 +285,7 @@ def profiles_list(request):
raise NotImplementedError
else:
form = forms.ProfileUploadForm()
columns_form = forms.DynamicProfileColumnForm(prefix='columns')
columns_form = ExportProfileForm(prefix='columns')

is_staff = request.GET.get('is_staff', False)
if nav.is_staff:
Expand Down
3 changes: 3 additions & 0 deletions src/spicy/core/profile/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
ADMIN_EDIT_PROFILE_FORM = getattr(
settings, 'ADMIN_EDIT_PROFILE_FORM',
'spicy.core.profile.forms.ProfileForm')
ADMIN_EXPORT_PROFILE_FORM = getattr(
settings, 'ADMIN_EXPORT_PROFILE_FORM',
'spicy.core.profile.forms.ExportProfileForm')

LOGIN_WARNING = getattr(settings, 'LOGIN_WARNING', False)

Expand Down
9 changes: 7 additions & 2 deletions src/spicy/core/profile/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,5 +634,10 @@ class ProfileUploadForm(forms.Form):
search_text = forms.CharField(label=_('Search'), required=False)




class ExportProfileForm(forms.Form):
username = forms.CharField(label=_('Username'), widget=forms.CheckboxInput, initial=1)
email = forms.CharField(label=_('Email'), widget=forms.CheckboxInput, initial=1)
first_name = forms.CharField(label=_('First Name'), widget=forms.CheckboxInput, initial=1)
last_name = forms.CharField(label=_('Last Name'), widget=forms.CheckboxInput, initial=1)
second_name = forms.CharField(label=_('Second Name'), widget=forms.CheckboxInput, initial=1)
phone = forms.CharField(label=_('Phone'), widget=forms.CheckboxInput, initial=1)
3 changes: 2 additions & 1 deletion src/spicy/core/profile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ class Meta:
)

def save(self, *args, **kwargs):
is_old = bool(self.id or False)
is_old = bool(self.pk or False)
dct = self.__dict__
if is_old:
old = self.__class__.objects.get(pk=self.pk)

Expand Down
32 changes: 19 additions & 13 deletions src/spicy/core/profile/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@
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 import utils
from spicy.core.service import api
from spicy.utils import load_module, generate_random_password
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 = utils.get_custom_model_class(defaults.CUSTOM_USER_MODEL)
Profile = get_custom_model_class(defaults.CUSTOM_USER_MODEL)

CUSTOM_USER_SIGNUP_FORM = getattr(
settings, 'CUSTOM_USER_SIGNUP_FORM', 'spicy.core.profile.forms.SignupForm')


class ProfileProvider(api.Provider):
model = defaults.CUSTOM_PERMISSION_PROVIDER_MODEL

Expand All @@ -44,6 +43,13 @@ def register(self, request):

return dict(status=status, message=message)

@ajax_request('/$', is_public=True, use_siteskin=True, use_cache=False)
def restore_pass(self, request):
result = self.service.restore(request)
status = 'ok' if not result['form'].errors else 'fail'
message = unicode(result['message'])
return dict(status=status, message=message)

@render_to('profile/social_associations.html', is_public=True,
url_pattern='/(?P<profile_id>[\d]+)/$', use_siteskin=True)
def social_associations(self, request, profile_id):
Expand Down Expand Up @@ -153,7 +159,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 = utils.load_module(defaults.DEFAULT_PROFILE_URL)(
user_redirect_uri = load_module(defaults.DEFAULT_PROFILE_URL)(
request.user)
else:
user_redirect_uri = defaults.DEFAULT_PROFILE_URL
Expand Down Expand Up @@ -262,7 +268,7 @@ def register(self, request):
REGISTRATION_ENABLED=defaults.REGISTRATION_ENABLED)

elif request.method == "POST":
form = utils.load_module(CUSTOM_USER_SIGNUP_FORM)(request.POST)
form = 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 @@ -273,7 +279,7 @@ def register(self, request):
request.session['profile_email'] = new_profile.email

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

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

action = 'register'
register_form = utils.load_module(CUSTOM_USER_SIGNUP_FORM)(request.POST)
register_form = 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 @@ -318,7 +324,7 @@ def login_or_register(self, request):

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

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

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

def restore(self, request):
message = ''
RestorePasswordForm = utils.load_module(defaults.RESTORE_PASSWORD_FORM)
RestorePasswordForm = 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 = utils.generate_random_password()
if 'send_pass' in request.POST:
newpass = generate_random_password()
profile.set_password(newpass)
profile.save()
profile.email_forgotten_passwd(newpass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
{% with perms.profile.view_profile as view_profile %}
{% with perms.profile.delete_profile as delete_profile %}

{% if objects_list.count > 0 %}

<div class="container-fluid padded">
<div class="row-fluid">
<div class="span12">
Expand Down Expand Up @@ -108,8 +106,7 @@ <h4 class="padded">{% trans "Profile export and import" %}</h4>
{% for profile in objects_list %}
<tr class="{% cycle 'odd' 'even' %}">
<td class="icon">
<input type="checkbox" name="select" class="groupSelectCheckbox"
id="groupSelect_profile_{{ profile.id }}" autocomplete="off"/>
{{ forloop.counter }}
</td>
<td>
{% if change_profile or view_profile %}
Expand All @@ -128,8 +125,8 @@ <h4 class="padded">{% trans "Profile export and import" %}</h4>
<td style="text-align: center;">
<i class='{{ profile.subscribe_me|yesno:"green icon-ok,icon-remove red" }}'></i>
</td>
<td>{{ profile.date_joined|date:"j M Y" }}</td>
<td>{{ profile.last_login|date:"j M Y" }}</td>
<td>{{ profile.date_joined|date:"j M Y" }}</td>
<td>{% if profile.groups.all.count %}
{% for group in profile.groups.all %}
<div class="state blocked">
Expand Down Expand Up @@ -169,7 +166,6 @@ <h4 class="padded">{% trans "Profile export and import" %}</h4>
</div>
</div>

{% endif %}
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/spicy/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
from .permissions import *
from .printing import *
from .templates import *
from .common import *

7 changes: 7 additions & 0 deletions src/spicy/utils/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import string
import random


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