Skip to content
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

resolution of Django template for the example sp #89

Merged
merged 9 commits into from
Nov 14, 2023
2 changes: 1 addition & 1 deletion example_sp/djangosaml2_sp/custom_accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CustomUserAdmin(UserAdmin):
(_('Angrafica'), {'fields': (( 'first_name', 'last_name'),
( 'matricola', 'email'),
('codice_fiscale',),
('gender', 'location', 'birth_date'),
('gender', 'birth_date'),
)
}
),
Expand Down
1 change: 1 addition & 0 deletions example_sp/djangosaml2_sp/djangosaml2_sp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

DJANGO_BOOTSTRAP_ITALIA_USE_CDN = False

if 'saml2_sp' in INSTALLED_APPS or \
'djangosaml2_spid' in INSTALLED_APPS:
Expand Down
12 changes: 10 additions & 2 deletions example_sp/djangosaml2_sp/djangosaml2_sp/settingslocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@
# SAML2 SP
'djangosaml2',
'saml2_sp',
'djangosaml2_sp'
]
'djangosaml2_sp',

#bootstrap_italia_template
'bootstrap_italia_template',
'sass_processor'
]
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'sass_processor.finders.CssFinder'
]
AUTH_USER_MODEL = 'custom_accounts.User'

LOGGING = {
Expand Down
4 changes: 4 additions & 0 deletions example_sp/djangosaml2_sp/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ cffi
# django saml2 SP
djangosaml2>=1.0.0
importlib-resources<6.0.0

# design-django-theme
design-django-theme>=2.7.0
django-sass-processor>=1.2.2
40 changes: 40 additions & 0 deletions example_sp/djangosaml2_sp/saml2_sp/templates/amministrazione.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends "base.html" %}

{%block tab_active%} active{%endblock%}
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
{%block tab_active%} active{%endblock%}
{% block tab_active %} active{% endblock %}

{% block centered_container %}
<section id="head-section">
<div class="container">
<div class="row">
<div class="col-lg-6 offset-lg-1 order-lg-2">
<img src="https://picsum.photos/800/600" title="titolo immagine" alt="descrizione immagine" class="img-fluid">
Copy link
Member

Choose a reason for hiding this comment

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

please change the following value with a static image on the local storage, using {% static "..." %}

"https://picsum.photos/800/600"

</div>
<div class="col-lg-5 order-lg-1">
<div class="card">
<div class="card-body pb-5">
<div class="category-top">
<svg class="icon">
<use xlink:href="/bootstrap-italia/dist/svg/sprites.svg#it-calendar"></use>
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
<use xlink:href="/bootstrap-italia/dist/svg/sprites.svg#it-calendar"></use>
<use xlink:href="/bootstrap-italia/dist/svg/sprites.svg#it-calendar"></use>

please use {% static %}, don't use absolute webpaths

Copy link
Member

Choose a reason for hiding this comment

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

here and in all the occurences

</svg>
<a class="category" href="#">Notizie</a>
<span class="data">18 mag 2023</span>
</div>
<h1 class="h4 card-title">Parte l'estate con oltre 300 eventi in centro e nei quartieri, tutti gli eventi previsti</h1>
<p class="card-text">
Inaugurazione lunedì 2 luglio con il concerto gratuito in piazza XX Settembre degli Sweet Soul Revue. Sul palco 20 musicisti da tutto il mondo.
</p>
<div class="chip chip-simple chip-primary">
<a href="#" class="chip-label">Estate in città</a>
</div>
<a class="read-more pb-3" href="/bootstrap-italia/docs/esempi/comuni/template-novita/">
<span class="text">Tutte le novità</span>
<svg class="icon">
<use xlink:href="/bootstrap-italia/dist/svg/sprites.svg##it-arrow-right"></use>
</svg>
</a>
</div>
</div>
</div>
</div>
</div>
</section>
{%endblock%}
560 changes: 560 additions & 0 deletions example_sp/djangosaml2_sp/saml2_sp/templates/base.html

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions example_sp/djangosaml2_sp/saml2_sp/templates/echo_attributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends "base.html" %}
{% load i18n %}
{% load static %}

{% block centered_container %}
<section id="area-riservata">
<div class="nav-tabs-hidescroll mt-4 mt-md-5">
<div class="tab-content">
<div id="profile" class="tab-pane fade show active">
<h5 class="text-center mb-4">Profilo Utente</h5>
<ul class="list-group">
<li class="list-group-item"><strong>Username:</strong> {{ user.username }}</li>
<li class="list-group-item"><strong>Email:</strong> {{ user.email }}</li>
<li class="list-group-item"><strong>Nome:</strong> {{ user.first_name }}</li>
<li class="list-group-item"><strong>Cognome:</strong> {{ user.last_name }}</li>
<li class="list-group-item"><strong>Attivo:</strong> {% if user.is_active %}Sì{% else %}No{% endif %}</li>
<li class="list-group-item"><strong>Matricola:</strong> {% if user.matricola %}{{ user.matricola }}{% else %}N/A{% endif %}</li>
<li class="list-group-item"><strong>Codice Fiscale:</strong> {% if user.codice_fiscale %}{{ user.codice_fiscale }}{% else %}N/A{% endif %}</li>
<li class="list-group-item"><strong>Genere:</strong> {% if user.gender %}{{ user.gender }}{% else %}N/A{% endif %}</li>
<li class="list-group-item"><strong>Data di Nascita:</strong> {% if user.birth_date %}{{ user.birth_date }}{% else %}N/A{% endif %}</li>
<li class="list-group-item"><strong>Luogo di Nascita:</strong> {% if user.place_of_birth %}{{ user.place_of_birth }}{% else %}N/A{% endif %}</li>
</ul>
</div>
</div>
</div>
</section>
{% endblock %}


2 changes: 2 additions & 0 deletions example_sp/djangosaml2_sp/saml2_sp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

urlpatterns = [
path('', views.index),
path('amministrazione/',views.amministrazione),
path("echo_attributes/",views.echo_attributes),
]
25 changes: 15 additions & 10 deletions example_sp/djangosaml2_sp/saml2_sp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,25 @@


logger = logging.getLogger('djangosaml2')

context = {
"LOGOUT_URL" : settings.LOGOUT_URL,
"LOGIN_URL" : settings.LOGIN_URL,
"LOGIN_REDIRECT_URL" : settings.LOGIN_REDIRECT_URL
}

def index(request):
""" Barebone 'diagnostics' view, print user attributes if logged in + login/logout links.
"""
if request.user.is_authenticated:
out = "LOGGED IN: <a href={0}>LOGOUT</a><br>".format(settings.LOGOUT_URL)
out += "".join(['%s: %s</br>' % (field.name, getattr(request.user, field.name))
for field in request.user._meta.get_fields()
if field.concrete])
return HttpResponse(out)
else:
return HttpResponse("LOGGED OUT: <a href={0}>LOGIN</a>".format(settings.LOGIN_URL))

context["user"] = request.user
return render(request,"base.html",context)
Gartic99 marked this conversation as resolved.
Show resolved Hide resolved
def amministrazione(request):
context["user"] = request.user
return render(request,"amministrazione.html",context)
def echo_attributes(request):
Gartic99 marked this conversation as resolved.
Show resolved Hide resolved
context["out"] = "".join(['%s: %s</br>' % (field.name, getattr(request.user, field.name))
for field in request.user._meta.get_fields()
if field.concrete])
return render(request,"echo_attributes.html",context)

# TODO fix this in IdP side?
@receiver(pre_user_save, sender=User)
Expand Down
Loading