Skip to content

WIP: Update to Python 3 and modern Django #22

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

Merged
merged 10 commits into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
*.swp
test.db*
*.log
sabot/settings.py
sabot/prodSettings.py
sabot/localSettings.py
sabot/privateSettings.py
sabot/local_settings.py
sabot/conferenceSettings.py
templates/sponsor/internalFaq.html
templates/sponsor/publicFaq.html
*.db
media/*
static/GitHub-Mark-32px.png
d10env
venv
.idea
*.bck
*.old
email_files
4 changes: 4 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
The complete software part and website templates is licensed under the MIT License (see below).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The complete software part and website templates is licensed under the MIT License (see below).
The software as well as the website templates are licensed under the MIT License (see below).

However, we use the python rt module that is licensed und GPLv3. As a consequence, this whole
project is distributed under the terms of the GPLv3 even though all SaBot code itself is lisenced
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
project is distributed under the terms of the GPLv3 even though all SaBot code itself is lisenced
project is distributed under the terms of the GPLv3, even though all SaBot code itself is licensed

under the terms of the MIT License. If you want to use it under these terms, either disable the RT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
under the terms of the MIT License. If you want to use it under these terms, either disable the RT
under the terms of the MIT License. If you want to use it under those terms, either disable the RT

support on the code or provide an alternative implementation in sabot/rt.py.

This license does not apply to
- Sample invoice and offer documents provided in invoice/
Expand Down
51 changes: 26 additions & 25 deletions account/backend.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import models
from django.contrib.auth.models import User


class TokenAuthenticationBackend(object):
supports_inactive_user = False
supports_inactive_user = False

def authenticate(self, token=None):
if token is None or len(token) == 0:
return None
try:
profile = models.UserProfile.objects.get(authToken__iexact=token)
return profile.user
except models.UserProfile.DoesNotExist:
return None
def authenticate(self, token=None):
if token is None or len(token) == 0:
return None
try:
profile = models.UserProfile.objects.get(authToken__iexact=token)
return profile.user
except models.UserProfile.DoesNotExist:
return None

def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None

def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None

class APITokenMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
try:
token = request.META.get("HTTP_TOKEN")
if token is not None:
profile = models.UserProfile.objects.get(authToken__iexact=token)
request.user = profile.user
except models.UserProfile.DoesNotExist:
pass
return self.get_response(request)
def __call__(self, request):
try:
token = request.META.get("HTTP_TOKEN")
if token is not None:
profile = models.UserProfile.objects.get(authToken__iexact=token)
request.user = profile.user
except models.UserProfile.DoesNotExist:
pass
return self.get_response(request)
67 changes: 34 additions & 33 deletions account/forms.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
from registration.forms import RegistrationFormUniqueEmail
from django import forms
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _


from django_registration.forms import RegistrationFormUniqueEmail
from captcha.fields import ReCaptchaField
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Field, Submit, Div, HTML
from crispy_forms.bootstrap import FormActions, StrictButton, TabHolder, Tab


class RegistrationFormNameAndUniqueEmail(RegistrationFormUniqueEmail):
class Meta(RegistrationFormUniqueEmail.Meta):
fields = [
'username',
'first_name',
'last_name',
'email',
'password1',
'password2'
]
required_css_class = 'required'
class Meta(RegistrationFormUniqueEmail.Meta):
fields = [
User.USERNAME_FIELD,
User.get_email_field_name(),
"first_name",
"last_name",
"password1",
"password2",
]
required_css_class = "required"

captcha = ReCaptchaField()
captcha = ReCaptchaField()


class UserProfileForm(forms.Form):
firstName = forms.CharField(max_length=64,label=_("First name"))
lastName = forms.CharField(max_length=64,label=_("Last name"))
email = forms.EmailField(max_length=75,label=_("E-mail"))
firstName = forms.CharField(max_length=64, label=_("First name"))
lastName = forms.CharField(max_length=64, label=_("Last name"))
email = forms.EmailField(max_length=75, label=_("E-mail"))

def __init__(self, *args, **kwargs):
super(UserProfileForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.add_input(Submit("Save","Save"))
def __init__(self, *args, **kwargs):
super(UserProfileForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.add_input(Submit("Save", "Save"))


class SetPasswordForm(forms.Form):
password1 = forms.CharField(widget=forms.PasswordInput, label=_("Password"))
password2 = forms.CharField(widget=forms.PasswordInput, label=_("Password (again)"))

def clean(self):
if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
if self.cleaned_data['password1'] != self.cleaned_data['password2']:
raise forms.ValidationError(_("The two password fields didn't match."))
return self.cleaned_data

def __init__(self, *args, **kwargs):
super(SetPasswordForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.add_input(Submit("submit","Set password"))
password1 = forms.CharField(widget=forms.PasswordInput, label=_("Password"))
password2 = forms.CharField(widget=forms.PasswordInput, label=_("Password (again)"))

def clean(self):
if "password1" in self.cleaned_data and "password2" in self.cleaned_data:
if self.cleaned_data["password1"] != self.cleaned_data["password2"]:
raise forms.ValidationError(_("The two password fields didn't match."))
return self.cleaned_data

def __init__(self, *args, **kwargs):
super(SetPasswordForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.add_input(Submit("submit", "Set password"))
23 changes: 19 additions & 4 deletions account/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,26 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name='UserProfile',
name="UserProfile",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('authToken', models.CharField(max_length=64, null=True)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='legacy_profile', to=settings.AUTH_USER_MODEL)),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("authToken", models.CharField(max_length=64, null=True)),
(
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="legacy_profile",
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
9 changes: 5 additions & 4 deletions account/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

class UserProfile(models.Model):
user = models.OneToOneField(User, related_name="legacy_profile")
authToken = models.CharField(max_length=64, null=True)

class UserProfile(models.Model):
user = models.OneToOneField(
User, related_name="legacy_profile", on_delete=models.CASCADE
)
authToken = models.CharField(max_length=64, null=True)
Loading