Repository: UTNkar/moore

Issue:
Create a block for the member check
The member check (https://utn.se/medlemskoll) goes to the old website (old.utn.se). Since we want to get rid of the old website, we need to rebuild it into moore. The current member check has the following documentation (https://docs.utn.se/other_applications/member_check/). We don’t have to make the rebuild exactly as the old member check was, but it can be nice to have this as a base. 

What needs to be constructed is a block with a form where you can enter your person nummer.


Discussion:

Resolving patch:
diff --git a/src/blocks/models.py b/src/blocks/models.py
--- a/src/blocks/models.py
+++ b/src/blocks/models.py
@@ -121,6 +121,15 @@ class Meta:
         group = _('Basic')
 
 
+class MemberCheckAPIBlock(blocks.StructBlock):
+
+    class Meta:
+        label = _('Member Check')
+        icon = 'tick'
+        template = 'blocks/member_check.html'
+        group = _('Basic')
+
+
 BASIC_BLOCKTYPES = [
     ('heading', HeadingBlock()),
     ('image', ResponsiveImageBlock()),
@@ -129,6 +138,7 @@ class Meta:
     ('divider', DividerBlock()),
     ('button_group', ButtonGroupBlock()),
     ('icons', IconGroupBlock()),
+    ('member_check', MemberCheckAPIBlock())
 ]
 
 # CONTENT BLOCKTYPES
diff --git a/src/members/fields.py b/src/members/fields.py
new file mode 100644
--- /dev/null
+++ b/src/members/fields.py
@@ -0,0 +1,38 @@
+from django import forms
+from phonenumbers import parse, is_valid_number
+from django.utils.translation import gettext_lazy as _
+from django.utils.encoding import force_text
+from utils.validators import SSNValidator
+
+
+class PhoneNumberField(forms.CharField):
+    def __init__(self, *args, **kwargs):
+        super(PhoneNumberField, self).__init__(*args, **kwargs)
+
+    def clean(self, phonenumber):
+        try:
+            parsed_phone = parse(phonenumber, "SE")
+            if not is_valid_number(parsed_phone):
+                raise Exception
+
+            return phonenumber
+        except Exception:
+            raise forms.ValidationError(_("Invalid phonenumber"))
+
+
+class PersonNumberField(forms.Field):
+    def __init__(self, *args, **kwargs):
+        super(PersonNumberField, self).__init__(*args, **kwargs)
+
+    def to_python(self, value):
+        if value in self.empty_values:
+            return None, ''
+        value = force_text(value).strip()
+        SSNValidator()(value)
+        return value
+
+    def widget_attrs(self, widget):
+        attrs = super(PersonNumberField, self).widget_attrs(widget)
+        attrs['class'] = attrs.get('class', '') + ' person_number'
+        attrs['placeholder'] = 'YYYYMMDD-XXXX'
+        return attrs
diff --git a/src/members/forms.py b/src/members/forms.py
--- a/src/members/forms.py
+++ b/src/members/forms.py
@@ -1,7 +1,6 @@
 from django import forms
 from django.conf import settings
 from django.contrib.auth import forms as auth
-from django.utils.encoding import force_str
 from django.utils.translation import gettext_lazy as _
 from wagtail.users import forms as wagtail
 from django.utils.html import mark_safe
@@ -18,46 +17,12 @@
 from django.utils.http import urlsafe_base64_encode
 
 from members.models import StudyProgram, Member, Section
-from utils.validators import SSNValidator
 from utils.melos_client import MelosClient
-from phonenumbers import parse, is_valid_number
+from members.fields import PhoneNumberField, PersonNumberField
 
 User = get_user_model()
 
 
-class PhoneNumberField(forms.CharField):
-    def __init__(self, *args, **kwargs):
-        super(PhoneNumberField, self).__init__(*args, **kwargs)
-
-    def clean(self, phonenumber):
-        try:
-            parsed_phone = parse(phonenumber, "SE")
-            if not is_valid_number(parsed_phone):
-                raise Exception
-
-            return phonenumber
-        except Exception:
-            raise forms.ValidationError(_("Invalid phonenumber"))
-
-
-class PersonNumberField(forms.Field):
-    def __init__(self, *args, **kwargs):
-        super(PersonNumberField, self).__init__(*args, **kwargs)
-
-    def to_python(self, value):
-        if value in self.empty_values:
-            return None, ''
-        value = force_str(value).strip()
-        SSNValidator()(value)
-        return value
-
-    def widget_attrs(self, widget):
-        attrs = super(PersonNumberField, self).widget_attrs(widget)
-        attrs['class'] = attrs.get('class', '') + ' person_number'
-        attrs['placeholder'] = 'YYYYMMDD-XXXX'
-        return attrs
-
-
 class MemberForm(forms.ModelForm):
     person_number = PersonNumberField(
         label=_('Person number'),


Test patch: