email login, fixing bulk
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
from rules.permissions import ObjectPermissionBackend
|
||||
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):
|
||||
def user_can_authenticate(self, user):
|
||||
return getattr(user, "is_active", True)
|
||||
@@ -11,4 +15,31 @@ class MyObjectPermissionBackend(ObjectPermissionBackend):
|
||||
except User.DoesNotExist:
|
||||
return 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):
|
||||
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())
|
||||
|
||||
def __init__(self, *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):
|
||||
workouts = forms.ModelMultipleChoiceField(
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
{% block title %}Change Workout {% endblock %}
|
||||
|
||||
{% block main %}
|
||||
|
||||
<h1>Bulk Actions</h1>
|
||||
<ul class="main-content">
|
||||
<li class="grid_4">
|
||||
@@ -12,22 +13,18 @@
|
||||
<p>
|
||||
Edit and confirm the action you want to perform on the following workouts:
|
||||
</p>
|
||||
<p>
|
||||
<div id="workouts">
|
||||
{{ form.as_p }}
|
||||
</p>
|
||||
<p>
|
||||
</div>
|
||||
<div id="action">
|
||||
{{ actionform.as_p }}
|
||||
</p>
|
||||
{% if action == 'export' %}
|
||||
<p>
|
||||
</div>
|
||||
<div id="export">
|
||||
{{ exportchoice.as_p }}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if action == 'rower assign' %}
|
||||
<p>
|
||||
</div>
|
||||
<div id="assign">
|
||||
{{ assignchoices.as_p }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</li>
|
||||
<li class="grid_2">
|
||||
{% csrf_token %}
|
||||
@@ -35,7 +32,53 @@
|
||||
</li>
|
||||
</form>
|
||||
</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 %}
|
||||
|
||||
|
||||
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)
|
||||
if assignchoices.is_valid():
|
||||
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)
|
||||
messages.info(request, "Your action will be performed in the background. It may take a few minutes to complete")
|
||||
url = reverse('workouts_view')
|
||||
return HttpResponseRedirect(url)
|
||||
else: # pragma: no cover
|
||||
@@ -2049,10 +2050,10 @@ def workouts_bulk_actions(request):
|
||||
actionform.fields["action"].initial = action
|
||||
assignchoices = AssignChoices()
|
||||
teams = Team.objects.filter(manager=request.user)
|
||||
assignchoices.fields["destination"].queryset = Rower.objects.filter(
|
||||
assignchoices.fields["rowers"].queryset = Rower.objects.filter(
|
||||
team__in=teams
|
||||
).distinct().order_by("user__last_name", "user__first_name").exclude(rowerplan='freecoach')
|
||||
assignchoices.fields["destination"].initial = []
|
||||
assignchoices.fields["rowers"].initial = []
|
||||
form = WorkoutMultipleCompareForm()
|
||||
form.fields["workouts"].queryset = Workout.objects.filter(id__in=[w.id for w in workouts])
|
||||
form.fields["workouts"].initial = workouts
|
||||
|
||||
Reference in New Issue
Block a user