Skip to content

Commit

Permalink
fix #1742; make start page configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
janno42 committed Jul 31, 2023
1 parent 5069ee1 commit 1fd18e4
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 2 deletions.
8 changes: 7 additions & 1 deletion evap/contributor/templates/contributor_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<a href="{% url 'contributor:export' %}" class="btn btn-sm btn-light">{% trans 'Export results' %}</a>
</div>
{% if user.is_delegate %}
<div class="btn-switch btn-switch-light mb-auto ms-2 d-print-none">
<div class="btn-switch btn-switch-light ms-2 d-print-none">
<div class="btn-switch-label"><span class="fas fa-people-arrows-left-right"></span> {% trans 'Delegated evaluations' %}</div>
<div class="btn-switch btn-group">
<a href="{% url 'contributor:index' %}?show_delegated=true" role="button" class="btn btn-sm btn-light{% if show_delegated %} active{% endif %}">
Expand All @@ -28,6 +28,12 @@
</div>
</div>
{% endif %}
{% if user.show_startpage_button %}
<div class="ms-2 d-print-none">
{% include 'startpage_button.html' with page='CO' %}
</div>
{% endif %}

</div>

{% for semester in semester_list %}
Expand Down
23 changes: 23 additions & 0 deletions evap/evaluation/migrations/0139_userprofile_startpage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.1 on 2022-11-21 19:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("evaluation", "0138_votetimestamp"),
]

operations = [
migrations.AddField(
model_name="userprofile",
name="startpage",
field=models.CharField(
choices=[("UN", "undefined"), ("ST", "student"), ("CO", "contributor")],
default="UN",
max_length=2,
verbose_name="start page of the user",
),
),
]
16 changes: 16 additions & 0 deletions evap/evaluation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,18 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):

is_active = models.BooleanField(default=True, verbose_name=_("active"))

class StartPage(models.TextChoices):
UNDEFINED = "UN", _("undefined")
STUDENT = "ST", _("student")
CONTRIBUTOR = "CO", _("contributor")

startpage = models.CharField(
max_length=2,
choices=StartPage.choices,
verbose_name=_("start page of the user"),
default=StartPage.UNDEFINED,
)

class Meta:
# keep in sync with ordering_key
ordering = [
Expand Down Expand Up @@ -1829,6 +1841,10 @@ def is_editor_or_delegate(self):
def is_responsible_or_contributor_or_delegate(self):
return self.is_responsible or self.is_contributor or self.is_delegate

@cached_property
def show_startpage_button(self):
return self.is_student and self.is_responsible_or_contributor_or_delegate

@property
def is_external(self):
if not self.email:
Expand Down
25 changes: 25 additions & 0 deletions evap/evaluation/templates/startpage_button.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% if user.startpage == page %}
<div data-bs-toggle="tooltip" data-bs-placement="left" title="{% trans 'This is your startpage' %}">
<button type="button" class="btn btn-sm btn-light" disabled><span class="fas fa-house"></span></button>
</div>
{% else %}
<button id="makeStartPageButton" type="button" class="btn btn-sm btn-light" onclick="makeStartPage();" data-bs-toggle="tooltip" data-bs-placement="left" title="{% trans 'Make this my startpage' %}"><span id="span-set-startpage" class="fas fa-house"></span></button>
{% endif %}


{% block additional_javascript %}
<script type="text/javascript">
function makeStartPage() {
var makeStartPageButton = $('#makeStartPageButton');
makeStartPageButton.prop('disabled', true);
setSpinnerIcon('span-set-startpage');
$.ajax({
type: "POST",
url: "{% url 'evaluation:set_startpage' %}",
data: {"page": "{{ page }}"},
success: function() { location.reload(); },
error: function() { window.alert("{% trans 'The server is not responding.' %}") },
});
}
</script>
{% endblock %}
1 change: 1 addition & 0 deletions evap/evaluation/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
path("contact", views.contact, name="contact"),
path("key/<int:key>", views.login_key_authentication, name="login_key_authentication"),
path("profile", views.profile_edit, name="profile_edit"),
path("set_startpage", views.set_startpage, name="set_startpage"),
]
19 changes: 18 additions & 1 deletion evap/evaluation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.views.i18n import set_language

from evap.evaluation.forms import LoginEmailForm, NewKeyForm, ProfileForm
from evap.evaluation.models import EmailTemplate, FaqSection, Semester
from evap.evaluation.models import EmailTemplate, FaqSection, Semester, UserProfile
from evap.middleware import no_login_required

logger = logging.getLogger(__name__)
Expand All @@ -36,6 +36,11 @@ def redirect_user_to_start_page(user):
return redirect("grades:semester_view", active_semester.id)
return redirect("grades:index")

if user.startpage == UserProfile.StartPage.STUDENT and user.is_student:
return redirect("student:index")
if user.startpage == UserProfile.StartPage.CONTRIBUTOR and user.is_responsible_or_contributor_or_delegate:
return redirect("contributor:index")

if user.is_student:
return redirect("student:index")
if user.is_responsible_or_contributor_or_delegate:
Expand Down Expand Up @@ -215,3 +220,15 @@ def profile_edit(request):
context = {"user": user, "profile_form": profile_form, **(editor_context if user.is_editor else {})}

return render(request, "profile.html", context)


@require_POST
def set_startpage(request):
user = request.user
startpage = request.POST.get("page")
if not startpage in UserProfile.StartPage.values:
return HttpResponseBadRequest()
user.startpage = startpage
user.save()

return HttpResponse()
7 changes: 7 additions & 0 deletions evap/student/templates/student_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
{{ block.super }}

{% show_infotext "student_index" %}
{% if user.show_startpage_button %}
<div class="d-flex mb-3">
<div class="ms-auto d-print-none">
{% include 'startpage_button.html' with page='ST' %}
</div>
</div>
{% endif %}

{% if unfinished_evaluations %}
<div class="card card-outline-primary mb-3">
Expand Down

0 comments on commit 1fd18e4

Please sign in to comment.