2018-08-09 09:15:40 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
2017-01-15 23:01:18 +00:00
|
|
|
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
|
|
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
|
|
# quelques clics.
|
|
|
|
#
|
|
|
|
# Copyright © 2017 Gabriel Détraz
|
2019-09-29 14:02:28 +00:00
|
|
|
# Copyright © 2017 Lara Kermarec
|
2017-01-15 23:01:18 +00:00
|
|
|
# Copyright © 2017 Augustin Lemesle
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2017-10-14 02:48:43 +00:00
|
|
|
"""
|
|
|
|
Fonctions de la page d'accueil et diverses fonctions utiles pour tous
|
|
|
|
les views
|
|
|
|
"""
|
2017-01-15 23:01:18 +00:00
|
|
|
|
2017-09-10 23:29:24 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2018-04-14 19:29:16 +00:00
|
|
|
import git
|
|
|
|
|
2018-07-19 10:30:15 +00:00
|
|
|
from django.shortcuts import render
|
2016-12-12 12:32:18 +00:00
|
|
|
from django.template.context_processors import csrf
|
2018-03-04 16:16:57 +00:00
|
|
|
from django.conf import settings
|
2018-04-10 22:07:26 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2018-04-11 11:40:55 +00:00
|
|
|
from django.views.decorators.cache import cache_page
|
|
|
|
|
2018-04-16 04:41:38 +00:00
|
|
|
from preferences.models import (
|
|
|
|
Service,
|
2018-07-01 08:49:47 +00:00
|
|
|
MailContact,
|
2018-04-16 04:41:38 +00:00
|
|
|
AssoOption,
|
2019-10-10 16:06:38 +00:00
|
|
|
HomeOption,
|
|
|
|
GeneralOption,
|
2019-11-04 16:55:03 +00:00
|
|
|
Mandate,
|
2018-04-16 04:41:38 +00:00
|
|
|
)
|
2018-04-11 11:40:55 +00:00
|
|
|
|
2018-04-10 22:07:26 +00:00
|
|
|
from .contributors import CONTRIBUTORS
|
2019-08-11 16:03:45 +00:00
|
|
|
from importlib import import_module
|
2019-08-11 19:51:31 +00:00
|
|
|
from re2o.settings_local import OPTIONNAL_APPS_RE2O
|
2017-10-14 02:48:43 +00:00
|
|
|
|
2018-04-13 23:42:22 +00:00
|
|
|
|
2016-07-19 01:12:48 +00:00
|
|
|
def form(ctx, template, request):
|
2017-10-14 02:48:43 +00:00
|
|
|
"""Form générique, raccourci importé par les fonctions views du site"""
|
2017-10-13 20:47:32 +00:00
|
|
|
context = ctx
|
|
|
|
context.update(csrf(request))
|
|
|
|
return render(request, template, context)
|
2016-07-19 01:12:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def index(request):
|
2017-10-14 02:48:43 +00:00
|
|
|
"""Affiche la liste des services sur la page d'accueil de re2o"""
|
2017-08-25 02:35:49 +00:00
|
|
|
services = [[], [], []]
|
|
|
|
for indice, serv in enumerate(Service.objects.all()):
|
|
|
|
services[indice % 3].append(serv)
|
2019-11-04 16:55:03 +00:00
|
|
|
twitter_url = HomeOption.get_cached_value("twitter_url")
|
|
|
|
facebook_url = HomeOption.get_cached_value("facebook_url")
|
|
|
|
twitter_account_name = HomeOption.get_cached_value("twitter_account_name")
|
|
|
|
asso_name = AssoOption.get_cached_value("pseudo")
|
|
|
|
return form(
|
|
|
|
{
|
|
|
|
"services_urls": services,
|
|
|
|
"twitter_url": twitter_url,
|
|
|
|
"twitter_account_name": twitter_account_name,
|
|
|
|
"facebook_url": facebook_url,
|
|
|
|
"asso_name": asso_name,
|
|
|
|
},
|
|
|
|
"re2o/index.html",
|
|
|
|
request,
|
|
|
|
)
|
2018-07-01 08:49:47 +00:00
|
|
|
|
|
|
|
|
2018-01-08 15:33:50 +00:00
|
|
|
def about_page(request):
|
2018-04-14 19:29:16 +00:00
|
|
|
""" The view for the about page.
|
|
|
|
Fetch some info about the configuration of the project. If it can't
|
|
|
|
get the info from the Git repository, fallback to default string """
|
2018-01-08 15:33:50 +00:00
|
|
|
option = AssoOption.objects.get()
|
2019-10-10 16:06:38 +00:00
|
|
|
general = GeneralOption.objects.get()
|
2018-04-10 22:07:26 +00:00
|
|
|
git_info_contributors = CONTRIBUTORS
|
|
|
|
try:
|
2018-04-14 19:29:16 +00:00
|
|
|
git_repo = git.Repo(settings.BASE_DIR)
|
2018-04-11 13:29:14 +00:00
|
|
|
git_info_remote = ", ".join(git_repo.remote().urls)
|
|
|
|
git_info_branch = git_repo.active_branch.name
|
|
|
|
last_commit = git_repo.commit()
|
|
|
|
git_info_commit = last_commit.hexsha
|
|
|
|
git_info_commit_date = last_commit.committed_datetime
|
|
|
|
except:
|
2019-01-08 23:40:08 +00:00
|
|
|
NO_GIT_MSG = _("Unable to get the information.")
|
2018-04-10 22:07:26 +00:00
|
|
|
git_info_remote = NO_GIT_MSG
|
|
|
|
git_info_branch = NO_GIT_MSG
|
|
|
|
git_info_commit = NO_GIT_MSG
|
|
|
|
git_info_commit_date = NO_GIT_MSG
|
|
|
|
|
2018-04-14 19:29:16 +00:00
|
|
|
dependencies = settings.INSTALLED_APPS + settings.MIDDLEWARE_CLASSES
|
2018-04-10 22:07:26 +00:00
|
|
|
|
2018-01-08 15:33:50 +00:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"re2o/about.html",
|
2018-04-10 22:07:26 +00:00
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"option": option,
|
|
|
|
"gtu": general.GTU,
|
|
|
|
"president": Mandate.get_mandate().president.get_full_name(),
|
|
|
|
"git_info_contributors": git_info_contributors,
|
|
|
|
"git_info_remote": git_info_remote,
|
|
|
|
"git_info_branch": git_info_branch,
|
|
|
|
"git_info_commit": git_info_commit,
|
|
|
|
"git_info_commit_date": git_info_commit_date,
|
|
|
|
"dependencies": dependencies,
|
|
|
|
},
|
2018-01-08 15:33:50 +00:00
|
|
|
)
|
2018-04-15 17:05:27 +00:00
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-01 08:49:47 +00:00
|
|
|
def contact_page(request):
|
|
|
|
"""The view for the contact page
|
|
|
|
Send all the objects MailContact
|
|
|
|
"""
|
|
|
|
address = MailContact.objects.all()
|
|
|
|
|
2019-08-11 19:51:31 +00:00
|
|
|
optionnal_apps = [import_module(app) for app in OPTIONNAL_APPS_RE2O]
|
2019-11-04 16:55:03 +00:00
|
|
|
optionnal_templates_contact_list = [
|
|
|
|
app.views.contact(request)
|
|
|
|
for app in optionnal_apps
|
|
|
|
if hasattr(app.views, "contact")
|
|
|
|
]
|
2019-08-11 16:03:45 +00:00
|
|
|
|
2018-07-01 08:49:47 +00:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"re2o/contact.html",
|
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"contacts": address,
|
|
|
|
"asso_name": AssoOption.objects.first().name,
|
|
|
|
"optionnal_templates_contact_list": optionnal_templates_contact_list,
|
|
|
|
},
|
2018-07-01 08:49:47 +00:00
|
|
|
)
|
|
|
|
|
2018-04-15 17:05:27 +00:00
|
|
|
|
|
|
|
def handler500(request):
|
|
|
|
"""The handler view for a 500 error"""
|
2019-11-04 16:55:03 +00:00
|
|
|
return render(request, "errors/500.html", status=500)
|
2018-07-20 18:12:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def handler404(request):
|
|
|
|
"""The handler view for a 404 error"""
|
2019-11-04 16:55:03 +00:00
|
|
|
return render(request, "errors/404.html", status=404)
|