Skip to content

Commit

Permalink
Merge pull request #206 from Teknologforeningen/feature/user-editable…
Browse files Browse the repository at this point in the history
…-info

User-editable information
  • Loading branch information
filiptypjeu authored Oct 22, 2024
2 parents 35d8877 + 6ec111d commit 5fd212d
Show file tree
Hide file tree
Showing 32 changed files with 726 additions and 278 deletions.
2 changes: 1 addition & 1 deletion teknologr/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Meta:
def to_representation(self, instance):
data = super().to_representation(instance)

hide = not self.is_staff and not instance.showContactInformation()
hide = not self.is_staff and not instance.show_contact_info()
if hide:
for field in Member.HIDABLE_FIELDS:
data.pop(field)
Expand Down
6 changes: 3 additions & 3 deletions teknologr/api/tests_dumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from registration.models import *
from rest_framework import status
from rest_framework.test import APITestCase
from datetime import datetime
from django.utils import timezone

today = datetime.today().strftime('%Y-%m-%d')
today = timezone.now().date().strftime('%Y-%m-%d')

class BaseClass(APITestCase):
def setUp(self):
Expand Down Expand Up @@ -121,7 +121,7 @@ class Arsk(BaseClass, DumpsTestCases):
'country': 'Finland',
'associations': 'Hedersmedlem,Funkkis',
}]
today = datetime.today().strftime('%Y-%m-%d')

class RegEmails(BaseClass, DumpsTestCases):
path = f'/api/dump-regemails/'
response = [{
Expand Down
22 changes: 11 additions & 11 deletions teknologr/api/tests_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ def setUp(self):

# Should be found by all
Member.objects.create(
# In preferred name, even if hidden and dead
# In preferred name, even if hidden and alive
given_names='Sverker Svakar',
preferred_name='Svakar',
surname='von Teknolog',
allow_publish_info=False,
dead=True,
dead=False,
)
Member.objects.create(
# In surname, even if hidden and dead
# In surname, even if hidden and alive
given_names='Sverker',
surname='von Svakar',
allow_publish_info=False,
dead=True,
dead=False,
)
Member.objects.create(
# In given names for public Member
Expand All @@ -94,21 +94,21 @@ def setUp(self):
allow_publish_info=True,
dead=False,
)

# Should only be found by staff
Member.objects.create(
# No preferred name on hidden Member
# In given names but dead
given_names='Sverker Svakar',
surname='von Teknolog',
allow_publish_info=False,
dead=False,
dead=True,
)

# Should only be found by staff
Member.objects.create(
# In given names but dead
# No preferred name on hidden Member
given_names='Sverker Svakar',
surname='von Teknolog',
allow_publish_info=True,
dead=True,
allow_publish_info=False,
dead=False,
)


Expand Down
4 changes: 2 additions & 2 deletions teknologr/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def dump_modulen(request):
if connection.vendor == 'postgresql':
recipients = recipients.distinct('street_address', 'city')

recipients = [x for x in recipients if x.isValidMember()]
recipients = [x for x in recipients if x.is_valid_member()]

content = [{
'given_names': recipient.given_names,
Expand Down Expand Up @@ -815,7 +815,7 @@ def dump_reg_emails(request):
@api_view(['GET'])
def dump_studentbladet(request):
recipients = Member.objects.exclude(dead=True).filter(allow_studentbladet=True)
recipients = [m for m in recipients if m.isValidMember()]
recipients = [m for m in recipients if m.is_valid_member()]

content = [{
'name': recipient.full_name,
Expand Down
14 changes: 14 additions & 0 deletions teknologr/katalogen/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

from members.models import Member
from members.forms import BSModelForm
from members.validators import CommonValidators
from ldap import LDAPError

class EditProfileForm(BSModelForm, CommonValidators):
class Meta:
model = Member
fields = ['preferred_name', 'phone', 'email', 'street_address', 'postal_code', 'city', 'country', 'graduated', 'graduated_year', 'subscribed_to_modulen', 'allow_studentbladet', 'allow_publish_info']

def clean(self):
BSModelForm.clean(self)
CommonValidators.clean(self)
37 changes: 29 additions & 8 deletions teknologr/katalogen/static/css/katalogen.css
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
.navbar {
margin-bottom: 20px;
margin-bottom: 20px;
}

.searchbar {
padding: 20px;
padding-top: 0px;
padding: 20px;
padding-top: 0px;
}

.alphabet {
padding: 20px;
padding-top: 0px;
font-size: 130%;
padding: 20px;
padding-top: 0px;
font-size: 130%;
}

.errorlist {
padding: 10px;
list-style-type: none;
font-weight: bold;
}

#member-information button {
margin-bottom: 20px;
}

.monospace {
font-family: monospace;
}

.admin-link {
color: black;
color: black;
}

.order-by {
cursor: pointer;
cursor: pointer;
}

/* .text-right comes from Bootstrap, and is used (at least) on the member profile pages. This addition makes sure that the text in a table cell can be replaced with an input field (not checkbox) without the row changing size. */
.text-right:has(input):has(.form-control) {
vertical-align: middle !important;
padding-top: 0 !important;
padding-bottom: 0 !important;
}
2 changes: 1 addition & 1 deletion teknologr/katalogen/static/js/katalogen.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ $(document).ready(() => {
/**
* Make the searchbox into a filter too, filtering all table rows on the page.
*/
$("#searchbox").on("input", event => {
$("#searchboxfilter").on("input", event => {
const queries = event.target.value.toLowerCase().split(" ").filter(s => s);
$("tbody tr").each((_, e) => {
const str = e.children[0].textContent.toLowerCase();
Expand Down
18 changes: 9 additions & 9 deletions teknologr/katalogen/templates/browse.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

{% block content %}
{% if home %}
{% include "searchbar.html" with search=1 placeholder="Sök personer" %}
{% include "searchbar.html" with search=1 alphabet=1 placeholder="Sök personer" %}
{% else %}
{% include "searchbar.html" with search=1 placeholder="Filtrera eller sök personer" %}
{% include "searchbar.html" with search=1 filter=1 alphabet=1 placeholder="Filtrera eller sök personer" %}
{% endif %}
<div class="row">
{% if home %}
Expand All @@ -14,15 +14,15 @@ <h1>Katalogen på nätet</h1>
Bläddra i Teknologföreningens medlemsregister.
</p>
<p class="lead">
Du kan söka efter personer med sökfältet ovan, eller se din egen profil via menyn. Personuppgifter (utöver namn) kan endast ses för personer som tillåtit utgivning av dessa, men man kan alltid se sina egena personuppgifter. Namn, medlemskapstyp, betygelser, poster och grupper kan däremot ses för alla personer i registret.
Du kan söka efter personer med sökfältet ovan, eller se din egen profil via menyn. Kontaktuppgifter kan endast ses för personer som tillåtit utgivning av dessa, men man kan alltid se alla sina egna uppgifter. Du kan även uppdatera dina egna uppgifter via din profil.
</p>
<p class="lead">
Via menyn kan du även se alla betygelser, poster och grupper. Årsspecifika sammanfattningar hittas också via menyn.
</p>
</div>
{% else %}
<div class="col-12 col-md-10 offset-md-1 col-lg-8 offset-lg-2">
{% if persons %}
{% if members %}
<table class="table table-sm table-striped">
<thead>
<tr>
Expand All @@ -32,12 +32,12 @@ <h1>Katalogen på nätet</h1>
</tr>
</thead>
<tbody>
{% for person in persons %}
{% for member in members %}
<tr>
<td><a href="{% url 'katalogen:profile' person.id %}">{{ person.public_full_name }}</a></td>
{% if person.showContactInformation %}
<td><a href="tel:{{ person.phone }}">{{ person.phone }}</a></td>
<td><a href="mailto:{{ person.email }}">{{ person.email }}</a></td>
<td><a href="{% url 'katalogen:profile' member.id %}">{{ member.public_full_name }}</a></td>
{% if member.show_contact_info %}
<td><a href="tel:{{ member.phone }}">{{ member.phone }}</a></td>
<td><a href="mailto:{{ member.email }}">{{ member.email }}</a></td>
{% else %}
<td></td>
<td></td>
Expand Down
2 changes: 1 addition & 1 deletion teknologr/katalogen/templates/decorations.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "home.html" %}

{% block content %}
{% include "searchbar.html" with placeholder="Filtrera betygelser" %}
{% include "searchbar.html" with filter=1 placeholder="Filtrera betygelser" %}
<div class="row">
<div class="col-12 col-md-10 offset-md-1 col-lg-8 offset-lg-2">
{% if decorations %}
Expand Down
2 changes: 1 addition & 1 deletion teknologr/katalogen/templates/functionary_types.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "home.html" %}

{% block content %}
{% include "searchbar.html" with placeholder="Filtrera poster" %}
{% include "searchbar.html" with filter=1 placeholder="Filtrera poster" %}
<div class="row">
<div class="col-12 col-md-10 offset-md-1 col-lg-8 offset-lg-2">
{% if functionary_types %}
Expand Down
2 changes: 1 addition & 1 deletion teknologr/katalogen/templates/group_types.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "home.html" %}

{% block content %}
{% include "searchbar.html" with placeholder="Filtrera grupper" %}
{% include "searchbar.html" with filter=1 placeholder="Filtrera grupper" %}
<div class="row">
<div class="col-12 col-md-10 offset-md-1 col-lg-8 offset-lg-2">
{% if group_types %}
Expand Down
5 changes: 4 additions & 1 deletion teknologr/katalogen/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<link rel="stylesheet" href="{% static 'css/katalogen.css' %}">
</head>

<body>
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
<nav class="navbar navbar-expand-md navbar-dark bg-dark sticky-top">
<a class="navbar-brand" href="{% url 'katalogen:home' %}">Katalogen</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
Expand Down Expand Up @@ -70,6 +70,9 @@
<script src="{% static 'assets/js/jquery-3.3.1.min.js' %}"></script>
<script src="{% static 'assets/js/bootstrap.min.js' %}"></script>

<!-- HTMX -->
<script src="{% static 'assets/js/htmx-2.0.2.min.js' %}"></script>

<!-- Our own JS files -->
<script src="{% static 'js/katalogen.js' %}"></script>

Expand Down
69 changes: 22 additions & 47 deletions teknologr/katalogen/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,81 +5,56 @@
<div class="container-fluid">
<h1 class="page-header">
{% if is_staff %}
<a class="admin-link" href="{% url 'admin:member' person.id %}">{{ person.public_full_name }}</a>
<a class="admin-link" href="{% url 'admin:member' member.id %}">{{ member.public_full_name }}</a>
{% else %}
{{ person.public_full_name }}
{{ member.public_full_name }}
{% endif %}
</h1>
<div class="row">
<div class="col-12 col-lg-7">
{% include 'profile_information.html' %}
<div class="col-12 col-lg-5">
{% if own_profile %}
<h5>Övrig privat information</h5>
<table class="table table-striped table-borderless">
<tbody>
{% if show_all %}
<tr>
<th>Tilltalsnamn</th>
<td class="text-right">{{person.preferred_name}}</td>
<th>Födelsedatum</th>
<td class="text-right">{{ member.birth_date|default:'' }}</td>
</tr>
<tr>
<th>Telefonnummer</th>
<td class="text-right">
{% if person.mobile_phone %}
{{person.mobile_phone}}
{% else %}
{{person.phone}}
{% endif %}
</td>
<th>Studienummer</th>
<td class="text-right">{{ member.student_id|default:'' }}</td>
</tr>
<tr>
<th>E-postadress</th>
<td class="text-right">{{person.email}}</td>
</tr>
<tr>
<th>Hemadress</th>
<th>LDAP-användarnamn</th>
<td class="text-right">
{{person.street_address}}<br/>
{{person.postal_code}} {{person.city}}<br/>
{{person.country.name}}
<span class="monospace">{{ member.username|default:'' }}</span>
</td>
</tr>
<tr>
<th>Studieprogram</th>
<td class="text-right">{{person.degree_programme}}</td>
</tr>
<tr>
<th>Phuxår</th>
<th>LDAP-grupper</th>
<td class="text-right">
{{ person.phux_year|default_if_none:'' }}
<span class="monospace">{{ member.get_ldap_groups|join:', ' }}</span>
</td>
</tr>
<tr>
<th>Färdigbliven</th>
<th>BILL-konto</th>
<td class="text-right">
{% if person.graduated %}
{% if person.graduated_year %}
{{person.graduated_year}}
{% else %}
Ja
{% endif %}
{% else %}
Nej
{% endif %}
<span class="monospace">{{ member.bill_code|default:'' }}</span>
</td>
</tr>
{% endif %}
<tr>
<th>Medlemskapstyp</th>
<th>BILL-saldo</th>
<td class="text-right">
{% if person.current_member_type %}
{{ person.current_member_type }}
{% else %}
Ej medlem
{% endif %}
{% if bill_balance %}
{{ bill_balance }} €
{% endif %}
</td>
</tr>
</tbody>
</table>
</div>
<div class="col-12 col-lg-5">
{% endif %}

{% if decoration_ownerships %}
<h3>Betygelser</h3>
<table class="table table-striped table-borderless table-sm">
Expand Down
Loading

0 comments on commit 5fd212d

Please sign in to comment.