email login, fixing bulk
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
from rules.permissions import ObjectPermissionBackend
|
from rules.permissions import ObjectPermissionBackend
|
||||||
from rowers.models import User
|
from rowers.models import User
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model # gets the user_model django default or your own custom
|
||||||
|
from django.contrib.auth.backends import ModelBackend
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
class MyObjectPermissionBackend(ObjectPermissionBackend):
|
class MyObjectPermissionBackend(ObjectPermissionBackend):
|
||||||
def user_can_authenticate(self, user):
|
def user_can_authenticate(self, user):
|
||||||
return getattr(user, "is_active", True)
|
return getattr(user, "is_active", True)
|
||||||
@@ -11,4 +15,31 @@ class MyObjectPermissionBackend(ObjectPermissionBackend):
|
|||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
return None
|
return None
|
||||||
return user if self.user_can_authenticate(user) else None
|
return user if self.user_can_authenticate(user) else None
|
||||||
|
|
||||||
|
class EmailLoginBackend(ModelBackend):
|
||||||
|
def user_can_authenticate(self, user):
|
||||||
|
return getattr(user, "is_active", True)
|
||||||
|
|
||||||
|
def authenticate(self, request, username=None, password=None, **kwargs):
|
||||||
|
try:
|
||||||
|
user = User.objects.filter(
|
||||||
|
Q(username__iexact=username) |
|
||||||
|
Q(email__iexact=username)
|
||||||
|
).distinct()
|
||||||
|
except User.DoesNotExist:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if user.exists():
|
||||||
|
user_obj = user.first()
|
||||||
|
if user_obj.check_password(password) and user_obj.is_active:
|
||||||
|
return user_obj
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_user(self, user_id):
|
||||||
|
try:
|
||||||
|
return User.objects.get(pk=user_id)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -1233,12 +1233,12 @@ class ExportChoices(forms.Form):
|
|||||||
|
|
||||||
class AssignChoices(forms.Form):
|
class AssignChoices(forms.Form):
|
||||||
remove_workout = forms.BooleanField(initial=False, required=False)
|
remove_workout = forms.BooleanField(initial=False, required=False)
|
||||||
destination = forms.ModelMultipleChoiceField(label='Rowers', required=False,
|
rowers = forms.ModelMultipleChoiceField(label='Rowers', required=False,
|
||||||
queryset=Rower.objects.filter(), widget=forms.CheckboxSelectMultiple())
|
queryset=Rower.objects.filter(), widget=forms.CheckboxSelectMultiple())
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(AssignChoices, self).__init__(*args, **kwargs)
|
super(AssignChoices, self).__init__(*args, **kwargs)
|
||||||
self.fields['destination'].queryset = Rower.objects.filter()
|
self.fields['rowers'].queryset = Rower.objects.filter()
|
||||||
|
|
||||||
class WorkoutMultipleCompareForm(forms.Form):
|
class WorkoutMultipleCompareForm(forms.Form):
|
||||||
workouts = forms.ModelMultipleChoiceField(
|
workouts = forms.ModelMultipleChoiceField(
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
{% block title %}Change Workout {% endblock %}
|
{% block title %}Change Workout {% endblock %}
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
|
|
||||||
<h1>Bulk Actions</h1>
|
<h1>Bulk Actions</h1>
|
||||||
<ul class="main-content">
|
<ul class="main-content">
|
||||||
<li class="grid_4">
|
<li class="grid_4">
|
||||||
@@ -12,22 +13,18 @@
|
|||||||
<p>
|
<p>
|
||||||
Edit and confirm the action you want to perform on the following workouts:
|
Edit and confirm the action you want to perform on the following workouts:
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<div id="workouts">
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
</p>
|
</div>
|
||||||
<p>
|
<div id="action">
|
||||||
{{ actionform.as_p }}
|
{{ actionform.as_p }}
|
||||||
</p>
|
</div>
|
||||||
{% if action == 'export' %}
|
<div id="export">
|
||||||
<p>
|
|
||||||
{{ exportchoice.as_p }}
|
{{ exportchoice.as_p }}
|
||||||
</p>
|
</div>
|
||||||
{% endif %}
|
<div id="assign">
|
||||||
{% if action == 'rower assign' %}
|
|
||||||
<p>
|
|
||||||
{{ assignchoices.as_p }}
|
{{ assignchoices.as_p }}
|
||||||
</p>
|
</div>
|
||||||
{% endif %}
|
|
||||||
</li>
|
</li>
|
||||||
<li class="grid_2">
|
<li class="grid_2">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
@@ -35,7 +32,53 @@
|
|||||||
</li>
|
</li>
|
||||||
</form>
|
</form>
|
||||||
</ul>
|
</ul>
|
||||||
|
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
|
||||||
|
<script>
|
||||||
|
var workoutsfield = $("#workouts")
|
||||||
|
var actionsfield = $("#action")
|
||||||
|
var exportfield = $("#export")
|
||||||
|
var assignfield = $("#assign")
|
||||||
|
var actionselect = $("#id_action")
|
||||||
|
|
||||||
|
exportfield.css('visibility', 'hidden')
|
||||||
|
assignfield.css('visibility', 'hidden')
|
||||||
|
|
||||||
|
if (actionselect.val() == 'remove') {
|
||||||
|
exportfield.css('visibility', 'hidden')
|
||||||
|
assignfield.css('visibility', 'hidden')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actionselect.val() == 'rower assign') {
|
||||||
|
assignfield.css('visibility','visible')
|
||||||
|
exportfield.css('visibility', 'hidden')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actionselect.val() == 'export') {
|
||||||
|
exportfield.css('visibility','visible')
|
||||||
|
assignfield.css('visibility', 'hidden')
|
||||||
|
}
|
||||||
|
|
||||||
|
actionselect.change(function() {
|
||||||
|
console.log("click", Value)
|
||||||
|
var Value = actionselect.val()
|
||||||
|
console.log("click", Value)
|
||||||
|
|
||||||
|
if (Value == 'remove') {
|
||||||
|
exportfield.css('visibility', 'hidden')
|
||||||
|
assignfield.css('visibility', 'hidden')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Value == 'rower assign') {
|
||||||
|
assignfield.css('visibility','visible')
|
||||||
|
exportfield.css('visibility', 'hidden')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Value == 'export') {
|
||||||
|
exportfield.css('visibility','visible')
|
||||||
|
assignfield.css('visibility', 'hidden')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
@@ -2035,8 +2035,9 @@ def workouts_bulk_actions(request):
|
|||||||
assignchoices = AssignChoices(request.POST)
|
assignchoices = AssignChoices(request.POST)
|
||||||
if assignchoices.is_valid():
|
if assignchoices.is_valid():
|
||||||
remove_workout = assignchoices.cleaned_data['remove_workout']
|
remove_workout = assignchoices.cleaned_data['remove_workout']
|
||||||
rowers = assignchoices.cleaned_data['destination']
|
rowers = assignchoices.cleaned_data['rowers']
|
||||||
_ = myqueue(queuehigh, handle_assignworkouts, workouts, rowers, remove_workout)
|
_ = myqueue(queuehigh, handle_assignworkouts, workouts, rowers, remove_workout)
|
||||||
|
messages.info(request, "Your action will be performed in the background. It may take a few minutes to complete")
|
||||||
url = reverse('workouts_view')
|
url = reverse('workouts_view')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
@@ -2049,10 +2050,10 @@ def workouts_bulk_actions(request):
|
|||||||
actionform.fields["action"].initial = action
|
actionform.fields["action"].initial = action
|
||||||
assignchoices = AssignChoices()
|
assignchoices = AssignChoices()
|
||||||
teams = Team.objects.filter(manager=request.user)
|
teams = Team.objects.filter(manager=request.user)
|
||||||
assignchoices.fields["destination"].queryset = Rower.objects.filter(
|
assignchoices.fields["rowers"].queryset = Rower.objects.filter(
|
||||||
team__in=teams
|
team__in=teams
|
||||||
).distinct().order_by("user__last_name", "user__first_name").exclude(rowerplan='freecoach')
|
).distinct().order_by("user__last_name", "user__first_name").exclude(rowerplan='freecoach')
|
||||||
assignchoices.fields["destination"].initial = []
|
assignchoices.fields["rowers"].initial = []
|
||||||
form = WorkoutMultipleCompareForm()
|
form = WorkoutMultipleCompareForm()
|
||||||
form.fields["workouts"].queryset = Workout.objects.filter(id__in=[w.id for w in workouts])
|
form.fields["workouts"].queryset = Workout.objects.filter(id__in=[w.id for w in workouts])
|
||||||
form.fields["workouts"].initial = workouts
|
form.fields["workouts"].initial = workouts
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ INSTALLED_APPS = [
|
|||||||
AUTHENTICATION_BACKENDS = (
|
AUTHENTICATION_BACKENDS = (
|
||||||
#'oauth2_provider.backends.OAuth2Backend',
|
#'oauth2_provider.backends.OAuth2Backend',
|
||||||
# Uncomment following if you want to access the admin
|
# Uncomment following if you want to access the admin
|
||||||
|
'rowers.backends.EmailLoginBackend',
|
||||||
'django.contrib.auth.backends.ModelBackend',
|
'django.contrib.auth.backends.ModelBackend',
|
||||||
'django.contrib.auth.backends.RemoteUserBackend',
|
'django.contrib.auth.backends.RemoteUserBackend',
|
||||||
'rowers.backends.MyObjectPermissionBackend',
|
'rowers.backends.MyObjectPermissionBackend',
|
||||||
|
|||||||
Reference in New Issue
Block a user