Commit 207ee9d5 authored by David Haynes's avatar David Haynes
Browse files

PY3 compat reached in views

- plus spacing fixes
parent 6881b662
...@@ -85,11 +85,11 @@ def index(request): ...@@ -85,11 +85,11 @@ def index(request):
# Determine what the expiration date is # Determine what the expiration date is
if expires == URLForm.DAY: if expires == URLForm.DAY:
url.expires = timezone.now() + timedelta(days=1) url.expires = timezone.now() + timedelta(days = 1)
elif expires == URLForm.WEEK: elif expires == URLForm.WEEK:
url.expires = timezone.now() + timedelta(weeks=1) url.expires = timezone.now() + timedelta(weeks = 1)
elif expires == URLForm.MONTH: elif expires == URLForm.MONTH:
url.expires = timezone.now() + timedelta(weeks=3) url.expires = timezone.now() + timedelta(weeks = 3)
elif expires == URLForm.CUSTOM: elif expires == URLForm.CUSTOM:
url.expires = url_form.cleaned_data.get('expires_custom') url.expires = url_form.cleaned_data.get('expires_custom')
else: else:
...@@ -118,7 +118,7 @@ def view(request, short): ...@@ -118,7 +118,7 @@ def view(request, short):
domain = "%s://%s" % (request.scheme, request.META.get('HTTP_HOST')) + "/" domain = "%s://%s" % (request.scheme, request.META.get('HTTP_HOST')) + "/"
# Get the URL that is being requested # Get the URL that is being requested
url = get_object_or_404(URL, short__iexact=short) url = get_object_or_404(URL, short__iexact = short)
# Render view.html passing the specified URL and Domain to the template # Render view.html passing the specified URL and Domain to the template
return render(request, 'view.html', { return render(request, 'view.html', {
...@@ -142,7 +142,7 @@ def my_links(request): ...@@ -142,7 +142,7 @@ def my_links(request):
domain = "%s://%s" % (request.scheme, request.META.get('HTTP_HOST')) + "/" domain = "%s://%s" % (request.scheme, request.META.get('HTTP_HOST')) + "/"
# Grab a list of all the URL's that are currently owned by the user # Grab a list of all the URL's that are currently owned by the user
urls = URL.objects.filter(owner=request.user.registereduser) urls = URL.objects.filter(owner = request.user.registereduser)
# Render my_links.html passing the list of URL's and Domain to the template # Render my_links.html passing the list of URL's and Domain to the template
return render(request, 'my_links.html', { return render(request, 'my_links.html', {
...@@ -164,7 +164,7 @@ def delete(request, short): ...@@ -164,7 +164,7 @@ def delete(request, short):
return render(request, 'not_registered.html') return render(request, 'not_registered.html')
# Get the URL that is going to be deleted # Get the URL that is going to be deleted
url = get_object_or_404(URL, short__iexact=short) url = get_object_or_404(URL, short__iexact = short)
# If the RegisteredUser is the owner of the URL # If the RegisteredUser is the owner of the URL
if url.owner == request.user.registereduser: if url.owner == request.user.registereduser:
...@@ -201,8 +201,8 @@ def signup(request): ...@@ -201,8 +201,8 @@ def signup(request):
if request.method == 'POST': if request.method == 'POST':
# Now we initialize the form again but this time we have the POST # Now we initialize the form again but this time we have the POST
# request # request
signup_form = SignupForm(request, request.POST, instance=request.user.registereduser, signup_form = SignupForm(request, request.POST, instance = request.user.registereduser,
initial={'full_name': request.user.first_name + " " + request.user.last_name}) initial = {'full_name': request.user.first_name + " " + request.user.last_name})
# set the readonly flag again for good measure # set the readonly flag again for good measure
signup_form.fields['full_name'].widget.attrs['readonly'] = 'readonly' signup_form.fields['full_name'].widget.attrs['readonly'] = 'readonly'
...@@ -235,7 +235,7 @@ def signup(request): ...@@ -235,7 +235,7 @@ def signup(request):
###################### ######################
settings.EMAIL_FROM, settings.EMAIL_FROM,
[settings.EMAIL_TO], [settings.EMAIL_TO],
reply_to=[user_mail] reply_to = [user_mail]
).send() ).send()
# Confirmation email sent to Users # Confirmation email sent to Users
send_mail( send_mail(
...@@ -275,7 +275,7 @@ def redirection(request, short): ...@@ -275,7 +275,7 @@ def redirection(request, short):
domain = "%s://%s" % (request.scheme, request.META.get('HTTP_HOST')) + "/" domain = "%s://%s" % (request.scheme, request.META.get('HTTP_HOST')) + "/"
# Get the URL object that relates to the requested Go link # Get the URL object that relates to the requested Go link
url = get_object_or_404(URL, short__iexact=short) url = get_object_or_404(URL, short__iexact = short)
# Increment our clicks by one # Increment our clicks by one
url.clicks += 1 url.clicks += 1
...@@ -299,11 +299,11 @@ def redirection(request, short): ...@@ -299,11 +299,11 @@ def redirection(request, short):
Decorator function for views that checks that the user is logged in and is Decorator function for views that checks that the user is logged in and is
a staff member, displaying the login page if necessary. a staff member, displaying the login page if necessary.
""" """
def staff_member_required(view_func, redirect_field_name=REDIRECT_FIELD_NAME, login_url='/'): def staff_member_required(view_func, redirect_field_name = REDIRECT_FIELD_NAME, login_url = '/'):
return user_passes_test( return user_passes_test(
lambda u: u.is_active and u.is_staff, lambda u: u.is_active and u.is_staff,
login_url=login_url, login_url = login_url,
redirect_field_name=redirect_field_name redirect_field_name = redirect_field_name
)(view_func) )(view_func)
""" """
...@@ -320,7 +320,7 @@ def useradmin(request): ...@@ -320,7 +320,7 @@ def useradmin(request):
# If we're approving users # If we're approving users
if '_approve' in request.POST: if '_approve' in request.POST:
for name in userlist: for name in userlist:
toApprove = RegisteredUser.objects.get(user__username__exact=name) toApprove = RegisteredUser.objects.get(user__username__exact = name)
toApprove.approved = True toApprove.approved = True
toApprove.save() toApprove.save()
...@@ -344,7 +344,7 @@ def useradmin(request): ...@@ -344,7 +344,7 @@ def useradmin(request):
# If we're denying users # If we're denying users
elif '_deny' in request.POST: elif '_deny' in request.POST:
for name in userlist: for name in userlist:
toDeny = RegisteredUser.objects.get(user__username__exact=name) toDeny = RegisteredUser.objects.get(user__username__exact = name)
if settings.EMAIL_HOST and settings.EMAIL_PORT: if settings.EMAIL_HOST and settings.EMAIL_PORT:
user_mail = toDeny.user.username + settings.EMAIL_DOMAIN user_mail = toDeny.user.username + settings.EMAIL_DOMAIN
# Send an email letting them know they are denied # Send an email letting them know they are denied
...@@ -369,7 +369,7 @@ def useradmin(request): ...@@ -369,7 +369,7 @@ def useradmin(request):
# If we're blocking users # If we're blocking users
elif '_block' in request.POST: elif '_block' in request.POST:
for name in userlist: for name in userlist:
toBlock = RegisteredUser.objects.get(user__username__exact=name) toBlock = RegisteredUser.objects.get(user__username__exact = name)
if settings.EMAIL_HOST and settings.EMAIL_PORT: if settings.EMAIL_HOST and settings.EMAIL_PORT:
user_mail = toBlock.user.username + settings.EMAIL_DOMAIN user_mail = toBlock.user.username + settings.EMAIL_DOMAIN
send_mail( send_mail(
...@@ -393,7 +393,7 @@ def useradmin(request): ...@@ -393,7 +393,7 @@ def useradmin(request):
# If we're un-blocking users # If we're un-blocking users
elif '_unblock' in request.POST: elif '_unblock' in request.POST:
for name in userlist: for name in userlist:
toUnBlock = RegisteredUser.objects.get(user__username__exact=name) toUnBlock = RegisteredUser.objects.get(user__username__exact = name)
if settings.EMAIL_HOST and settings.EMAIL_PORT: if settings.EMAIL_HOST and settings.EMAIL_PORT:
user_mail = toUnBlock.user.username + settings.EMAIL_DOMAIN user_mail = toUnBlock.user.username + settings.EMAIL_DOMAIN
send_mail( send_mail(
...@@ -418,7 +418,7 @@ def useradmin(request): ...@@ -418,7 +418,7 @@ def useradmin(request):
# If we're removing existing users # If we're removing existing users
elif '_remove' in request.POST: elif '_remove' in request.POST:
for name in userlist: for name in userlist:
toRemove = RegisteredUser.objects.get(user__username__exact=name) toRemove = RegisteredUser.objects.get(user__username__exact = name)
if settings.EMAIL_HOST and settings.EMAIL_PORT: if settings.EMAIL_HOST and settings.EMAIL_PORT:
user_mail = toRemove.user.username + settings.EMAIL_DOMAIN user_mail = toRemove.user.username + settings.EMAIL_DOMAIN
send_mail( send_mail(
...@@ -449,5 +449,4 @@ def useradmin(request): ...@@ -449,5 +449,4 @@ def useradmin(request):
'need_approval': need_approval, 'need_approval': need_approval,
'current_users': current_users, 'current_users': current_users,
'blocked_users': blocked_users 'blocked_users': blocked_users
}, })
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment