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

Clean up SteamID modal, upgrade django-boostrap library to v5 #112

Merged
merged 2 commits into from
Aug 17, 2024
Merged
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
7 changes: 2 additions & 5 deletions Spybot2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'django.forms',
'bootstrap4',
'django_bootstrap5',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -221,10 +221,7 @@
# }
# }

FORM_RENDERER = 'spybot.forms.CustomFormRenderer'

BOOTSTRAP4 = {
BOOTSTRAP5 = {
'include_jquery': False,
'javascript_in_head': False,
'label_class': 'form-label',
}
49 changes: 7 additions & 42 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ num2words = "^0.5.12"
requests = "^2.31.0"
fido2 = "^1.1.3"
user-agents = "^2.2.0"
django-bootstrap4 = "^24.3"
django-bootstrap5 = "^24.2"


[tool.poetry.group.test.dependencies]
Expand Down
35 changes: 4 additions & 31 deletions spybot/forms.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from django import forms
from django.core.exceptions import ValidationError
from django.forms.renderers import TemplatesSetting

from spybot.remote.steam_api import get_steam_user_playing_info, get_steam_account_info
from spybot.remote.steam_api import get_steam_account_info


class CustomFormRenderer(TemplatesSetting):
form_template_name = 'spybot/form_snippet.html'

class TimeRangeForm(forms.Form):
RANGES = (
('6', '6 hours'),
Expand Down Expand Up @@ -35,38 +31,15 @@ def clean(self):


class AddSteamIDForm(forms.Form):
steamid = forms.CharField(label="Account ID (what comes after https://steamcommunity.com/profiles/)", initial="123456", required=True)
steamid = forms.CharField(label="Account ID Number", required=True,
widget=forms.TextInput(attrs={'addon_before': "https://steamcommunity.com/profiles/"}))
name = forms.CharField(label="Account name")

def clean_steamid(self):
cleaned_data = super().clean()
steamid = cleaned_data.get("steamid")
steamid = self.cleaned_data.get("steamid")

steam_info = get_steam_account_info(steamid)
if steam_info is None:
raise ValidationError("Can't load steam information for this user")

return steamid


"""
<label class="form-label">Account URL</label>
<div class="input-group input-group-flat">
<span class="input-group-text">
https://steamcommunity.com/profiles/
</span>
<input type="text" class="form-control ps-0" name="steamid" placeholder="123456" required pattern="[0-9]*" autocomplete="off">
</div>
</div>
</div>
</div>
</div>
<div class="modal-body">
<div class="row">
<div class="col-lg-12">
<div class="mb-3">
<label class="form-label">Account name</label>
<input type="text" name="name" class="form-control">
</div>
</div>
"""
2 changes: 1 addition & 1 deletion spybot/templates/spybot/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{% include 'spybot/base/footer.html' %}
</div>
</div>
<div id="modal" class="modal fade">
<div id="modal" class="modal modal-blur fade">
<div id="dialog" class="modal-dialog" hx-target="this"></div>
</div>
{% block content_body_end %}
Expand Down
35 changes: 0 additions & 35 deletions spybot/templates/spybot/form_snippet.html

This file was deleted.

74 changes: 20 additions & 54 deletions spybot/templates/spybot/profile/add_steamid_modal.html
Original file line number Diff line number Diff line change
@@ -1,56 +1,22 @@
{% load tabler_icons %}
{% load bootstrap4 %}
{% load django_bootstrap5 %}

<form hx-post="{{ request.path }}" class="modal-content">
{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title">Add linked Steam account</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{# <div class="row">#}
{# <div class="col-lg-12">#}
{# <div class="mb-3">#}
{# <label class="form-label">Account URL</label>#}
{# <div class="input-group input-group-flat">#}
{# <span class="input-group-text">#}
{# https://steamcommunity.com/profiles/#}
{# </span>#}
{# <input type="text" class="form-control ps-0" name="steamid" placeholder="123456" required pattern="[0-9]*" autocomplete="off">#}
{# </div>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# <div class="row">#}
{# <div class="col-lg-12">#}
{# <div class="mb-3">#}
{# <label class="form-label">Account name</label>#}
{# <input type="text" name="name" class="form-control">#}
{# </div>#}
{# </div>#}
{# </div>#}
{% bootstrap_form_errors form type='non_fields' %}
<div class="row">
<div class="col-lg-12">
<div class="mb-3">
{% bootstrap_field form.steamid label_class='form-label' %}
</div>
</div>
<div class="col-lg-12">
<div class="mb-3">
{% bootstrap_field form.name label_class='form-label' %}
</div>
</div>
</div>
{# {% bootstrap_form form %}#}
</div>
<div class="modal-footer">
<a href="#" class="btn btn-link link-secondary" data-bs-dismiss="modal">
Cancel
</a>
<button href="#" class="btn btn-primary ms-auto" type="submit">
{% tabler_icon 'plus' class="icon" %}
Link account
</button>
</div>
</form>
<form hx-post="{{ request.path }}" class="modal-content">
{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title">Add linked Steam account</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{% bootstrap_form form %}
</div>
<div class="modal-footer">
<a href="#" class="btn" data-bs-dismiss="modal">
Cancel
</a>
<button href="#" class="btn btn-primary ms-auto" type="submit">
{% tabler_icon 'plus' class="icon" %}
Link account
</button>
</div>
</form>
4 changes: 2 additions & 2 deletions spybot/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
path('recent_events_fragment', views.recent_events_fragment, name='recent_events_fragment'),
path('profile', views.profile, name='profile'),
path('profile/passkey/<str:id>', views.profile_passkey, name='profile_passkey'),
path('profile/add_steamid', views.profile_add_steamid, name='profile_add_steamid'),
path('profile/steamid', views.profile_add_steamid, name='profile_add_steamid'),
path('profile/steamid/all', views.profile_steamids_fragment, name='profile_steamids_fragment'),
path('profile/steamid/<str:id>', views.profile_delete_steamid, name='profile_delete_steamid'),
path('profile/steamids', views.profile_steamids_fragment, name='profile_steamids_fragment'),
path('login', views.login, name='login'),
path('login_teamspeak', views.login_teamspeak, name='login_teamspeak'),
path('link_auth', auth.link_login, name='link_login'),
Expand Down
Loading