Skip to content

Commit

Permalink
Sync with development (#796)
Browse files Browse the repository at this point in the history
* Bug fix. Removed unnecessary text next to the title in webpage (#785)

* Fix/sorted section list 467 (#790)

* Sort section list by its abbreviation

* Changed RegistrationForm to CustomUserCreationForm
This is the same form that admin page uses when creating users.
RegistrationForm is not affected by change in forms.py in commit:
9be07d3
and thereby did not get a sorted section list from previous change.
I do not see the diffrence in accont creation between the two forms.

* Changed forms.py
Changed so that section sorting occurs on all ModelForm's.
This allows us to yet again use a custom ModelForm for admin page
and another for the registration page.

* Fixed number check. (#791)

Reusing the the check that is used when creating a member on
https://utn.se/accounts/register/

* Fix footer translation (#794)

* fixed the quickfix, added translation string to po

* Test changing req.

* Undo

* Test #2

---------

Co-authored-by: Robin Dymér <[email protected]>

* rename melos to unicore (#784)

* rename melos to unicore

* fix formatting

* Fix lint

* Fix migrations

* Fix build check bug

---------

Co-authored-by: Robin Dymér <[email protected]>

* Forced date to be handeld with swedish format (#793)

* Forced date to be handeld with swedish format

* Fix build issue

---------

Co-authored-by: Robin Dymér <[email protected]>

---------

Co-authored-by: GansaK <[email protected]>
Co-authored-by: Hampus Toft <[email protected]>
Co-authored-by: Ludvig Aldén <[email protected]>
  • Loading branch information
4 people authored Dec 6, 2023
1 parent a752200 commit f7ac4d3
Show file tree
Hide file tree
Showing 26 changed files with 190 additions and 147 deletions.
8 changes: 4 additions & 4 deletions .env-template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Make a copy of this file and rename it to .env if you are using docker. This file is only meant for development
# MELOS_URL=
# MELOS_ORG_ID=
# MELOS_ADMIN=
# UNICORE_URL=
# UNICORE_ORG_ID=
# UNICORE_ADMIN=

# GOOGLE_API_KEY=

Expand All @@ -14,4 +14,4 @@
# DJANGO_DB_USER=
# DJANGO_DB_PASS=
# DJANGO_DB_HOST=
# DJANGO_DB_PORT=
# DJANGO_DB_PORT=
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Extended createsuperuser so it gets a melos id
- Extended createsuperuser so it gets a unicore id
- Teams, roles and positions are now ordered alphabetically after their name
- Updated django-compressor to 2.4
- Updated django-libsass to 0.8
Expand Down Expand Up @@ -326,10 +326,10 @@ Exception to applications where a board member can see and modify applications f
| Applications | Full access | Board/Presidium (all teams) | Presidium (all teams) | Group Leader/Engaged | Engaged | |
| Contact Cards | Full access | Board/Presidium (all teams) | Presidium | Group Leader/Engaged | Engaged | |

- Melos is now used to fetch user-information such as name, ssn and member status.
- Registering an account requires the SSN to exist in Melos.
- Unicore is now used to fetch user-information such as name, ssn and member status.
- Registering an account requires the SSN to exist in Unicore.
- A user may now log in using both username or ssn.
- Firstname, Lastname, SSN, Registration Year and Study Program is no longer stored in Moores database and is instead fetched from Melos.
- Firstname, Lastname, SSN, Registration Year and Study Program is no longer stored in Moores database and is instead fetched from Unicore.
- Replaced Marvin to Bocken
- Upgrade dependencies

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ To get started with Project Moore, follow these instructions to set up a
- libpq-dev
4. Clone the repository.
5. Copy the file `.env-template` and name the copy `.env`
6. Fill in the necessary variables in `.env`. `MELOS_URL` and `MELOS_ADMIN` are required. You might have to fill in some database credidentils. Check `src/moore/settings/base.py` for which default values are used if you don't specify and credidentials.
6. Fill in the necessary variables in `.env`. `UNICORE_URL` and `UNICORE_ADMIN` are required. You might have to fill in some database credidentils. Check `src/moore/settings/base.py` for which default values are used if you don't specify and credidentials.
7. Run `source ./source_me.sh` to create a virtual environment.
8. Run `pip install --upgrade pip` to make sure that pip is running the latest version
9. Run `pip install -r dev-requirements.txt`
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

django_recaptcha==3.0.0
Django[argon2]==3.2.17
wagtail==2.16.2

Expand Down Expand Up @@ -40,4 +41,4 @@ django-jsonschema-form==1.0.3
python-decouple==3.7

# Search and select widget
django-select2==8.1.1
django-select2==8.1.1
2 changes: 1 addition & 1 deletion src/branding/locale/sv/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ msgstr "Branding"

#: branding/models.py:15
msgid "footer"
msgstr ""
msgstr "sidfot"

#: branding/models.py:33
msgid "social media accounts"
Expand Down
2 changes: 1 addition & 1 deletion src/branding/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@register_setting(icon='fa-window-minimize')
class FooterSettings(BaseSetting):
class Meta:
verbose_name = _('footer_en') # quickfix
verbose_name = _('footer') # quickfix

footer_en = StreamField(
[('column', blocks.StructBlock([
Expand Down
4 changes: 2 additions & 2 deletions src/events/models/participant.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from wagtail.admin.edit_handlers import MultiFieldPanel, FieldPanel
from utils.melos_client import MelosClient
from utils.unicore_client import UnicoreClient


class Participant(models.Model):
Expand Down Expand Up @@ -40,7 +40,7 @@ def __str__(self):
def calculate_order_cost(self):
cost = 0
price_list = self.ticket.event.price_list
is_member = self.person_nr and MelosClient.is_member(self.person_nr)
is_member = self.person_nr and UnicoreClient.is_member(self.person_nr)

if is_member:
cost += self.ticket.event.price_per_participant
Expand Down
4 changes: 2 additions & 2 deletions src/events/views/ticket_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from events.models import Event, Ticket, Participant
from events.forms import ParticipantForm
from django.contrib.auth.decorators import login_required
from utils.melos_client import MelosClient
from utils.unicore_client import UnicoreClient


@login_required
Expand Down Expand Up @@ -76,7 +76,7 @@ def my_ticket(request, event_pk):

# Set this as the first user has to be the owner.
formset[0].fields['person_nr'].disabled = True
owner_is_member = MelosClient.is_member(ticket.owner.person_nr)
owner_is_member = UnicoreClient.is_member(ticket.owner.person_nr)
base_price = event.base_price if owner_is_member \
else event.base_price_nonmember
cost = base_price + \
Expand Down
12 changes: 6 additions & 6 deletions src/involvement/forms/appointment_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.utils.translation import gettext_lazy as _
from involvement.models import Application
from utils.forms import AdvancedModelMultipleChoiceField
from utils.melos_client import MelosClient
from utils.unicore_client import UnicoreClient


class AppointmentForm(forms.Form):
Expand Down Expand Up @@ -39,17 +39,17 @@ def clean_overturn(self):
pnrs = string.split(',')
users = []
for pnr in pnrs:
melos_id = MelosClient.get_melos_id(pnr)
unicore_id = UnicoreClient.get_unicore_id(pnr)

if not get_user_model().objects.filter(
melos_id=melos_id
).exists() or melos_id is False:
unicore_id=unicore_id
).exists() or unicore_id is False:
raise forms.ValidationError(
_('No user with the person number %(pnr)s exists.'),
params={'pnr': pnr},
)
elif self.position.applications.filter(
applicant__melos_id=melos_id,
applicant__unicore_id=unicore_id,
).exclude(
status='draft'
).exists():
Expand All @@ -61,7 +61,7 @@ def clean_overturn(self):
)
else:
users.append(get_user_model().objects.filter(
melos_id=melos_id
unicore_id=unicore_id
).first())
return users

Expand Down
11 changes: 9 additions & 2 deletions src/involvement/templates/involvement/open_positions.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ <h1>{% trans 'open positions'|title %}</h1>
<h3>{{ pos }}</h3>
<div class="hide-on-med-and-up">
<b style="color: {{ pos.recruitment_end|date_color }};">
{% trans 'deadline'|capfirst %}: {{ pos.recruitment_end }}
{% trans 'deadline'|capfirst %}:
{% language 'sv' %}
{{ pos.recruitment_end|date:"SHORT_DATE_FORMAT" }}
{% endlanguage %}
</b>
</div>
<div class="team">
Expand All @@ -31,7 +34,11 @@ <h3>{{ pos }}</h3>
</div>
<div class="apply hide-on-small-and-down">
<a class="btn" href="{% routablepageurl page 'position' pos.id %}">{% trans 'apply' %}</a><br>
<div class="hide-on-small-only"><b style="color: {{ pos.recruitment_end|date_color }};">{% trans 'deadline'|capfirst %}: {{ pos.recruitment_end|date:"SHORT_DATE_FORMAT" }}</b></div>
<div class="hide-on-small-only"><b style="color: {{ pos.recruitment_end|date_color }};">
{% trans 'deadline'|capfirst %}:
{% language 'sv' %}
{{ pos.recruitment_end|date:"SHORT_DATE_FORMAT" }}
{% endlanguage %}</b></div>
</div>
</div>
<div class="collapsible-body">
Expand Down
2 changes: 1 addition & 1 deletion src/involvement/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create_test_user():
user_data['password'] = 'password'
user_data[user_model.EMAIL_FIELD] = "[email protected]"
user_data['phone_number'] = "0733221121"
user_data['melos_id'] = 8631280
user_data['unicore_id'] = 8631280

user_model.objects.create_superuser(**user_data)

Expand Down
2 changes: 1 addition & 1 deletion src/involvement/views/view_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def view_position(request, context, page, position=None):

# Load application form if user is logged in
if request.user.is_authenticated:
if request.user.melos_id:
if request.user.unicore_id:
context['membership_status'] = request.user.get_status
context['email'] = request.user.get_email
context['phone'] = request.user.get_phone_formatted
Expand Down
2 changes: 1 addition & 1 deletion src/members/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


# There is now good way for bulk updates and
# without bulk update we will need to make at least 2 requests against melos to
# without bulk update we'll need to make at least 2 requests against unicore to
# update one single member. To reduce the amounts of requests,
# we will only update status for active members e.g the ones that has
# status="member" as this value is updated when you log in to your account.
Expand Down
65 changes: 43 additions & 22 deletions src/members/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
from django.utils.http import urlsafe_base64_encode

from members.models import StudyProgram, Member, Section
from utils.melos_client import MelosClient
from utils.unicore_client import UnicoreClient
from members.fields import PhoneNumberField, PersonNumberField

User = get_user_model()


class MemberForm(forms.ModelForm):
section = forms.ModelChoiceField(
required=False,
queryset=Section.objects.order_by('abbreviation'),
label=_('Section'),
)
person_number = PersonNumberField(
label=_('Person number'),
help_text=_('Person number using the YYYYMMDD-XXXX format.'),
Expand Down Expand Up @@ -61,11 +66,11 @@ def clean_username(self):
def clean_person_number(self):
person_number = self.cleaned_data['person_number']
if self.instance.pk is None:
melos_id = MelosClient.get_melos_id(person_number)
if not melos_id or Member.find_by_melos_id(melos_id):
unicore_id = UnicoreClient.get_unicore_id(person_number)
if not unicore_id or Member.find_by_unicore_id(unicore_id):
raise forms.ValidationError(_("Incorrect SSN"))

self.instance.melos_id = melos_id
self.instance.unicore_id = unicore_id

return person_number

Expand All @@ -81,19 +86,28 @@ def save(self, commit=True):


class RegistrationForm(MemberForm, auth.UserCreationForm):
section = forms.ModelChoiceField(
required=False,
queryset=Section.objects.order_by('abbreviation'),
label=_('Section'),
)

class Meta:
model = Member
fields = ['username', 'email', 'phone_number', 'section']
field_classes = {'username': auth.UsernameField}

def save(self):
melos_id = MelosClient.get_melos_id(self.cleaned_data['person_number'])
unicore_id = UnicoreClient.get_unicore_id(
self.cleaned_data['person_number']
)

return Member.objects.create_user(
self.cleaned_data['username'],
self.cleaned_data['password1'],
self.cleaned_data['email'],
self.cleaned_data['phone_number'],
melos_id,
unicore_id,
section=self.cleaned_data['section']
)

Expand All @@ -105,8 +119,8 @@ class CustomPasswordResetForm(forms.Form):
help_text=_('Person number using the YYYYMMDD-XXXX format.'),
)

def get_email(self, melos_id):
member = Member.find_by_melos_id(melos_id)
def get_email(self, unicore_id):
member = Member.find_by_unicore_id(unicore_id)
if member:
return member.get_email
return ''
Expand Down Expand Up @@ -216,6 +230,12 @@ def password_enabled(self):
widget=forms.PasswordInput,
help_text=_("Enter the same password as above, for verification."))

section = forms.ModelChoiceField(
required=False,
queryset=Section.objects.order_by('abbreviation'),
label=_('Section'),
)

is_superuser = forms.BooleanField(
label=_("Administrator"), required=False,
help_text=_('Administrators have full access to manage any object '
Expand Down Expand Up @@ -304,6 +324,11 @@ def save(self, commit=True):

class UserEditForm(UserForm):
password_required = False
section = forms.ModelChoiceField(
required=False,
queryset=Section.objects.order_by('abbreviation'),
label=_('Section'),
)

def __init__(self, *args, **kwargs):
kwargs.pop('editing_self', False)
Expand All @@ -329,10 +354,9 @@ class CustomUserEditForm(UserEditForm):
help_text=_('Person number using the YYYYMMDD-XXXX format.'),
required=False
)
phone_number = forms.CharField(
required=True,
label=_('Phone number'),
)

phone_number = PhoneNumberField()

email = forms.EmailField(
required=True,
label=_('Email'),
Expand All @@ -348,7 +372,7 @@ class CustomUserEditForm(UserEditForm):
)
section = forms.ModelChoiceField(
required=False,
queryset=Section.objects,
queryset=Section.objects.order_by('abbreviation'),
label=_('Section'),
)
status = forms.ChoiceField(
Expand Down Expand Up @@ -397,10 +421,7 @@ class CustomUserCreationForm(UserCreationForm):
required=True,
label=_('Email'),
)
phone_number = forms.CharField(
required=True,
label=_('Phone number'),
)
phone_number = PhoneNumberField()
registration_year = forms.CharField(
required=False,
label=_('Registration year'),
Expand All @@ -412,7 +433,7 @@ class CustomUserCreationForm(UserCreationForm):
)
section = forms.ModelChoiceField(
required=False,
queryset=Section.objects,
queryset=Section.objects.order_by('abbreviation'),
label=_("Section"),
)

Expand All @@ -429,11 +450,11 @@ def __init__(self, *args, **kwargs):

def clean_person_number(self):
person_number = self.cleaned_data['person_number']
melos_id = MelosClient.get_melos_id(person_number)
if not melos_id or Member.find_by_melos_id(melos_id):
unicore_id = UnicoreClient.get_unicore_id(person_number)
if not unicore_id or Member.find_by_unicore_id(unicore_id):
raise forms.ValidationError(_("Incorrect SSN"))

self.instance.melos_id = melos_id
self.instance.unicore_id = unicore_id
return person_number

def save(self):
Expand All @@ -442,7 +463,7 @@ def save(self):
"password": self.cleaned_data["password1"],
"email": self.cleaned_data["email"],
"phone_number": self.cleaned_data["phone_number"],
"melos_id": self.instance.melos_id,
"unicore_id": self.instance.unicore_id,
'study': self.cleaned_data['study'],
"section": self.cleaned_data["section"],
"registration_year": self.cleaned_data["registration_year"]
Expand Down
Loading

0 comments on commit f7ac4d3

Please sign in to comment.