Skip to content

Commit

Permalink
Added profilepage
Browse files Browse the repository at this point in the history
  • Loading branch information
danielengelhardt committed Jul 30, 2023
1 parent 84e0cd7 commit 19ae4db
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 651 deletions.
Binary file added .DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions DSTBundesliga/apps/dstffbl/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,23 @@ def clean_sleeper_username(self):
message=_('Dein Sleeper Benutzername scheint falsch zu sein - bitte gib deinen aktuellen Benutzernamen an!'))

return sleeper_id


class ProfileForm(forms.Form):
sleeper_username = forms.CharField(max_length=100)
region = forms.ChoiceField(choices=REGIONS)
email = forms.EmailField()
possible_commish = forms.BooleanField(required=False)

def clean_sleeper_username(self):
data = self.cleaned_data
sleeper_username = data.get('sleeper_username')

try:
sleeper_user = sleeper_wrapper.User(sleeper_username)
sleeper_id = sleeper_user.get_user_id()
except TypeError:
raise forms.ValidationError(
message=_('Dein Sleeper Benutzername scheint falsch zu sein - bitte gib deinen aktuellen Benutzernamen an!'))

return sleeper_id
2 changes: 1 addition & 1 deletion DSTBundesliga/apps/dstffbl/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def get_email_subject(self):
return self.EMAIL_SUBJECT.format(current_season=Season.get_active())

def get_confirm_link(self):
return "https://dstffbl.uber.space" + reverse('dstffbl:accept_invite', kwargs={"registration_id": self.id})
return "https://www.fantasybundesliga.de" + reverse('dstffbl:accept_invite', kwargs={"registration_id": self.id})

def get_email_text(self):
return self.EMAIL_TEXT.format(current_season=state_service.get_season(),
Expand Down
154 changes: 97 additions & 57 deletions DSTBundesliga/apps/dstffbl/templates/dstffbl/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,116 @@
<div class="ui container">
<div class="dst-spacer dst-spacer-100">
<div class="ui container home-container">
{{ season }}
{% if season_user %}
<div class="title-container">
<h2 class="title">Let's gooo!</h2>
</div>
<div class="ui segment">
<h3>Du bist für die {{ current_season }} angemeldet! </h3>
<p>Weitere Infos folgen bald.</p>
</div>
{% else %}
<div class="title-container">
<h2 class="title">Anmeldung zu {{current_season}}</h2>
</div>
<div class="ui container">
<div class="ui segment">
<h4>Wichtig</h4>
<p>Der Spielbetrieb wird über die App <a href="https://sleeper.app/">Sleeper</a> durchgeführt. Für die Anmeldung benötigt ihr daher schon einen entsprechenden Account. Falls ihr noch keinen Sleeper-Account besitzt, so könnt ihr euch <a href="https://sleeper.app/create">hier</a> kostenfrei einen erstellen.</p>
<form class="ui form" action="/anmeldung/" method="post">
{% csrf_token %}
<div class="fields">
<div class="six wide field">
<label for="sleeper_username">Wie lautet dein Sleeper Benutzername?</label>
<input type="text" id="sleeper_username" name="sleeper_username" maxlength="50"
placeholder="Benutzername oder ID" value="{{form.sleeper_username.value|default_if_none:'' }}">
</div>
<div class="ui segment">
{% if message %}
<h2 class="ui header">
<div class="content">
Deine Daten wurden erfolgreich gespeichert!
</div>
</h2>
{% endif %}
{% if registration_status == "not_registered" %}
{% if registration_open %}
Du bist noch nicht zur Saison {{ season }} angemeldet.
Jetzt anmelden
{% else %}
Die Anmeldung zur Saison {{ season }} ist noch nicht gestartet.
{% endif %}
{# {% else %}
{% if registration_status == "pending" %}
<h2 class="ui header">
<div class="content">
Du bist vorregistriert, hast aber deine Anmeldung noch nicht bestätigt!
</div>
<div class="fields">
<div class="ten wide field">
<label for="region">Für welche Region trittst du an? Mitspieler außerhalb Deutschlands dürfen sich eine Region aussuchen.</label>
<select class="ui fluid search dropdown" name="region" id="region">
{% for value, region in region_choices %}
<option value="{{value}}" {% if value == form.region.value %}selected{% endif %}>{{region}}</option>
{% endfor %}
</select>
</div>

</h2>
<div class="content">
Bitte nutze den Link in der Email, die wir dir zugesandt haben.

Du kannst hier deine Anmeldedaten prüfen, anpassen und dir erneut eine Email zusenden lassen.
Bitte beachte, dass es ein wenig dauern kann, bis die Email bei dir eingegangen ist. Sieh im Zweifel auch in deinem Spamordner nach.
Solltest du nach 24h noch nichts erhalten haben, so wende dich bitte direkt an uns!
</div>
{% else %}
<h2 class="ui header">
<div class="content">
Du bist erfolgreich für die Saison {{ season }} angemeldet!
</div>
</h2>
{% endif %}
<form class="ui form" action="/profile/" method="post">
{% csrf_token %}
<div class="fields">
<div class="six wide field">
<label for="sleeper_username">Sleeper Benutzername:</label>
<input type="text" id="sleeper_username" name="sleeper_username" maxlength="50"
placeholder="Benutzername oder ID" value="{{ form.sleeper_username.value|default_if_none:'' }}">
</div>
<div class="fields">
<div class="ten wide field">
<div class="ui checkbox {% if form.possible_commish.value == True %}checked{% endif %}">
<input type="checkbox" {% if form.possible_commish.value == True %}checked=""{% endif %} name="possible_commish">
<label>Ich kann mir vorstellen in meiner Liga die Rolle des Comissioners zu übernehmen</label>
</div>
</div>
<div class="fields">
<div class="six wide field">
<label for="email">Email für Kontaktaufnahme:</label>
<input type="email" id="email" name="email"
placeholder="[email protected]" value="{{ form.email.value|default_if_none:'' }}">
</div>
</div>
<div class="fields">
<div class="ten wide field">
<label for="region">Für welche Region trittst du an? Mitspieler außerhalb Deutschlands dürfen sich eine Region aussuchen.</label>
<select class="ui fluid search dropdown" name="region" id="region">
{% for value, region in region_choices %}
<option value="{{value}}" {% if value == form.region.value %}selected{% endif %}>{{region}}</option>
{% endfor %}
</select>
</div>
</div>
<div class="fields">
<div class="ten wide field">
<div class="ui checkbox {% if form.possible_commish.value %}checked{% endif %}">
<input type="checkbox" {% if form.possible_commish.value %}checked=""{% endif %} name="possible_commish">
<label>Ich kann mir vorstellen in meiner Liga die Rolle des Comissioners zu übernehmen</label>
</div>
</div>
<div class="fields">
<div class="ten wide field">
{% if form.errors %}
{% for field in form %}
{% for error in field.errors %}
<div class="ui negative message">
<strong>{{ error|escape }}</strong>
</div>
{% endfor %}
{% endfor %}
{% for error in form.non_field_errors %}
</div>
<div class="fields">
<div class="ten wide field">
{% if form.errors %}
{% for field in form %}
{% for error in field.errors %}
<div class="ui negative message">
<strong>{{ error|escape }}</strong>
</div>
{% endfor %}
{% endif %}
</div>
</div>
<div class="dst-spacer-25">
<button class="ui approve submit button">Absenden</button>
{% endfor %}
{% for error in form.non_field_errors %}
<div class="ui negative message">
<strong>{{ error|escape }}</strong>
</div>
{% endfor %}
{% endif %}
</div>
</form>
</div>
<div class="dst-spacer-25">
<button class="ui approve submit button">Anmeldung aktualisieren</button>
</div>

</form>
{% endif %}
</div>

{% if registration_status == "pending" %}
<div class="ui segment">
<div class="dst-spacer-50">
<a href="{{ resend_url }}" class="ui approve submit button">Bestätigungslink erneut zusenden</a>
</div>
<p>
<br>
Wenn du deine email Adresse ändern möchtest, speichere bitte zunächst deine Änderungen!
</p>

</div>
{% endif %}

</div>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion DSTBundesliga/apps/dstffbl/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
path('anmeldung/', views.register, name='anmeldung'),
path('early-bird/', views.early_bird, name='early-bird'),
path('accept_invite/<str:registration_id>/', views.confirm_registration, name='accept_invite'),
path('login/', views.login, name='login')
path('login/', views.login, name='login'),
path('profile/', views.profile, name='profile'),
path('resend_invite', views.resend_invite, name='resend_invite')
]
79 changes: 78 additions & 1 deletion DSTBundesliga/apps/dstffbl/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sleeper_wrapper
from django.urls import reverse

from DSTBundesliga.apps.dstffbl.forms import RegisterForm
from DSTBundesliga.apps.dstffbl.forms import RegisterForm, ProfileForm
from DSTBundesliga.apps.dstffbl.models import SeasonUser, News, SeasonRegistration, DSTEmail, REGIONS
from DSTBundesliga.apps.dstffbl.services import season_service
from DSTBundesliga.apps.leagues.models import Matchup, Season, DSTPlayer, League
Expand Down Expand Up @@ -173,3 +173,80 @@ def login(request):
return redirect(next)

return render(request, 'dstffbl/login.html', {'next': next})


def profile(request):
user = request.user
season = Season.get_active()

season_user = None
season_registration = None
message = ""
season_data = {}
registration_open = is_registration_open()

try:
season_user = SeasonUser.objects.get(user=user, season=season)
season_data = season_user
registration_status = "confirmed"
except SeasonUser.DoesNotExist:
try:
season_registration = SeasonRegistration.objects.get(user=user, season=Season.get_active())
season_data = season_registration
registration_status = "pending"
except SeasonRegistration.DoesNotExist:

registration_status = "not_registered"

if request.method == 'POST':
form = ProfileForm(request.POST)

if form.is_valid():
submitted_sleeper_id = form.cleaned_data.get('sleeper_username')
sleeper_user = sleeper_wrapper.User(submitted_sleeper_id)
sleeper_id = sleeper_user.get_user_id()
sleeper_username = sleeper_user.get_username()
dst_player, _ = DSTPlayer.objects.update_or_create(sleeper_id=sleeper_id, defaults={
"display_name": sleeper_username
})

season_data.sleeper_id = sleeper_id
season_data.dst_player.display_name = sleeper_username

season_data.user.email = form.cleaned_data.get('email')
season_data.region = form.cleaned_data.get('region')
season_data.possible_commish = form.cleaned_data.get('possible_commish')
season_data.save()
season_data.user.save()
season_data.dst_player.save()

message = "Deine Daten wurden erfolgreich gespeichert!"

else:
form = ProfileForm(data={
"sleeper_username": season_data.dst_player.display_name,
"email": season_data.user.email,
"possible_commish": season_data.possible_commish,
"region": season_data.region
})

return render(request, "dstffbl/profile.html", {
"season": season,
"season_data": season_data,
"registration_status": registration_status,
"registration_open": registration_open,
'region_choices': REGIONS,
"form": form,
"message": message,
"resend_url": reverse("dstffbl:resend_invite")
})


def resend_invite(request):
try:
season_registration = SeasonRegistration.objects.get(user=request.user, season=Season.get_active())
season_registration.create_mail()
except SeasonRegistration.DoesNotExist:
pass

return render(request, 'dstffbl/registration_success.html')
3 changes: 3 additions & 0 deletions DSTBundesliga/apps/leagues/cms_menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def get_nodes(self, request):
counter += 1
nodes.append(NavigationNode("DST - Hörerliga", reverse('dst-league'), counter))

counter += 1
nodes.append(NavigationNode("Deine Anmeldung", reverse('dstffbl:profile'), counter, attr={'visible_for_anonymous': False}))

return nodes


Expand Down
4 changes: 3 additions & 1 deletion DSTBundesliga/apps/leagues/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
path('stats/some_quali/', views.some_quali, name='some-quali'),
path('stats/facts_and_figures/', views.facts_and_figures, name='facts_and_figures'),
path('stats/waiver/', views.waiver_stats, name='waiver_stats'),
path('playoffs/<str:league_id>/', views.playoffs, name='playoffs')
path('playoffs/<str:league_id>/', views.playoffs, name='playoffs'),
]


6 changes: 3 additions & 3 deletions DSTBundesliga/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

REGISTRATION_STARTS = "2022-08-01"
REGISTRATION_STOPS = "2022-08-10"
REGISTRATION_STARTS = "2023-07-31"
REGISTRATION_STOPS = "2023-08-11"

if os.getenv('DEV', 0) == '1':
from local_settings import *
Expand Down Expand Up @@ -285,7 +285,7 @@ def md5(fname):
},
}

DEFAULT_FROM_EMAIL = 'DSTFanFooBL - Down Set Talk! Fantasy Football Bundesliga <[email protected]>'
DEFAULT_FROM_EMAIL = 'DSTFanFooBL - Down Set Talk! Fantasy Football Bundesliga <[email protected]>'
EMAIL_HOST = os.getenv('EMAIL_HOST', 'localhost')
EMAIL_PORT = int(os.getenv('EMAIL_PORT', 25))
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER', '')
Expand Down
Loading

0 comments on commit 19ae4db

Please sign in to comment.