Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:fromedwin/monitor into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbarbier committed Oct 14, 2024
2 parents 8651506 + 90bec70 commit 61b5407
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
18 changes: 18 additions & 0 deletions src/settings/migrations/0003_profile_disable_auto_redirect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.2 on 2024-10-14 07:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('settings', '0002_alter_profile_timezone'),
]

operations = [
migrations.AddField(
model_name='profile',
name='disable_auto_redirect',
field=models.BooleanField(default=False, help_text='Disable auto-redirect from homepage to dashboard'),
),
]
1 change: 1 addition & 0 deletions src/settings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Profile(models.Model):
on_delete=models.CASCADE,
related_name='profile'
)
disable_auto_redirect = models.BooleanField(default=False, help_text="Disable auto-redirect from homepage to dashboard")
timezone = TimeZoneField(null=True, choices_display="STANDARD")

def directory_path(self):
Expand Down
21 changes: 21 additions & 0 deletions src/settings/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@
</div>
</div>
</div>
<div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5">
<label for="{{ form.title.id_for_label }}" class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">
Redirect to dashboard
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<div class="mt-2 max-w-xl text-sm text-gray-500">
<p class="flex">
<form action="{% url 'settings' %}" method="POST">
<input type="hidden" name="disable_auto_redirect" value="{{ profile.disable_auto_redirect }}" />
<button type="submit" class="relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent {% if not profile.disable_auto_redirect %}bg-emerald-600{% else %}bg-gray-200{% endif %} transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2" role="switch" aria-checked="{{ profile.disable_auto_redirect }}">
<span class="sr-only">Use setting</span>
<!-- Enabled: "translate-x-5", Not Enabled: "translate-x-0" -->
<span aria-hidden="true" class="pointer-events-none inline-block h-5 w-5 {% if not profile.disable_auto_redirect %}translate-x-5{% else %}translate-x-0{% endif %} transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"></span>
</button>
{% csrf_token %}
</form>
</p>
<p class="text-xs pt-1.5">Auto-redirect from homepage to dashboard</p>
</div>
</div>
</div>
<div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5">
<label for="{{ form.title.id_for_label }}" class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">
Delete your account
Expand Down
8 changes: 5 additions & 3 deletions src/settings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ def settings(request):
"""
Set user settings
"""

profile = request.user.profile

if request.POST and 'disable_auto_redirect' in request.POST:
profile.disable_auto_redirect = not profile.disable_auto_redirect
profile.save()
return redirect(reverse('settings'))

return render(request, 'settings.html', {
'settings': django_settings,
'profile': profile,
Expand All @@ -34,7 +38,6 @@ def user_timezone_form(request):

if request.POST:
form = TimeZoneForm(request.POST, instance=request.user.profile)
form.fields['timezone'].choices.sort(key=lambda x: x[1])

if form.is_valid():
form.save()
Expand All @@ -43,7 +46,6 @@ def user_timezone_form(request):
return render(request, 'user/timezone.html', {'form': form})

form = TimeZoneForm(instance=profile)
form.fields['timezone'].choices.sort(key=lambda x: x[1])

return render(request, 'user/timezone.html', {
'form': form,
Expand Down
9 changes: 5 additions & 4 deletions src/website/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from django.shortcuts import render, redirect
from django.shortcuts import get_object_or_404
from django.http import HttpResponse
from django.conf import settings
from django.urls import reverse
from django.utils import timezone
from django.contrib.auth.decorators import login_required

from allauth.socialaccount.models import SocialApp
from rest_framework.authtoken.models import Token
Expand All @@ -15,6 +11,11 @@ def homepage(request):
"""
Home Welcome page
"""

if request.user and request.user.is_authenticated:
if not request.user.profile.disable_auto_redirect:
return redirect(reverse('dashboard'))

socialapps = SocialApp.objects.all()

return render(request, 'homepage.html', {
Expand Down

0 comments on commit 61b5407

Please sign in to comment.