Skip to content

Commit

Permalink
Merge branch 'dev' into liste_chrono_par_défaut
Browse files Browse the repository at this point in the history
  • Loading branch information
philippemilink authored Oct 12, 2023
2 parents b6b7368 + 7329dd3 commit 479f11f
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 38 deletions.
2 changes: 1 addition & 1 deletion doc/source/front-end/arborescence-des-fichiers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Voici un extrait du dossier contenant les gabaris :
│ ...
├── pages/ # Dossier contenant les pages du site
│ ├── about.html
│ ├── technologies.html
│ ├── contact.html
│ ...
Expand Down
2 changes: 1 addition & 1 deletion templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<ul class="links">
<li><a href="{% url "api:docs" %}">{% trans "API" %}</a></li>
<li><a href="{% url "pages-eula" %}">{% trans "CGU" %}</a></li>
<li><a href="{% url "pages-about" %}">{% trans "À propos" %}</a></li>
<li><a href="{% url "pages-technologies" %}">{% trans "Crédits techniques" %}</a></li>
{% if app.site.association %}
<li><a href="{% url "pages-association" %}">{% trans "L’association" %}</a></li>
<li>
Expand Down
2 changes: 1 addition & 1 deletion templates/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1>{% trans "Pages" %}</h1>
{% block content %}
<ul>
<li><a href="{% url "pages-eula" %}"><abbr title="{% trans "Conditions générales d’utilisation" %}">{% trans "CGU" %}</abbr></a></li>
<li><a href="{% url "pages-about" %}">{% trans "À propos" %}</a></li>
<li><a href="{% url "pages-technologies" %}">{% trans "Crédits techniques" %}</a></li>
{% if app.site.association %}
<li><a href="{% url "pages-association" %}">{% trans "L’association" %}</a></li>
<li><a href="{{ app.site.association.subscribe_link }}">{% trans "Adhérer à l'association" %}</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@


{% block title %}
{% trans "À propos" %}
{% trans "Crédits techniques" %}
{% endblock %}



{% block breadcrumb %}
<li>{% trans "À propos" %}</li>
<li>{% trans "Crédits techniques" %}</li>
{% endblock %}



{% block headline %}
<h1>{% trans "À propos" %}</h1>
<h1>{% trans "Crédits techniques" %}</h1>
{% endblock %}


Expand Down Expand Up @@ -110,7 +110,7 @@ <h4>{% trans "Feuilles de style" %}</h4>

<h4>Javascript</h4>
<ul>
<li><a href="https://jquery.com/">jQuery 2.x</a></li>
<li><a href="https://jquery.com/">jQuery</a></li>
</ul>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions zds/forum/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.utils.translation import gettext as _
from zds.forum.models import Forum, Topic, Post
from zds.member.views import get_client_ip
from zds.utils.misc import contains_utf8mb4
from zds.utils.misc import contains_utf8mb4, is_ajax
from zds.utils.mixins import QuoteMixin
from zds.utils.models import CommentVote, get_hat_from_request

Expand Down Expand Up @@ -141,7 +141,7 @@ def get(self, request, *args, **kwargs):
if "cite" in request.GET:
text = self.build_quote(request.GET.get("cite"), request.user)

if request.is_ajax():
if is_ajax(request):
return HttpResponse(json.dumps({"text": text}), content_type="application/json")

form = self.create_forum(self.form_class, **{"text": text})
Expand Down Expand Up @@ -172,11 +172,11 @@ def get(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs):
form = self.get_form(self.form_class)
new_post = None
if not request.is_ajax():
if not is_ajax(request):
new_post = self.object.last_message.pk != int(request.POST.get("last_post"))

if "preview" in request.POST or new_post:
if request.is_ajax():
if is_ajax(request):
content = render(request, "misc/preview.part.html", {"text": request.POST.get("text")})
return StreamingHttpResponse(content)
else:
Expand Down
15 changes: 8 additions & 7 deletions zds/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from zds.utils import old_slugify
from zds.utils.context_processor import get_repository_url
from zds.forum.utils import create_topic, send_post, CreatePostView
from zds.utils.misc import is_ajax
from zds.utils.mixins import FilterMixin
from zds.utils.models import Alert, Tag, CommentVote
from zds.utils.paginator import ZdSPagingListView
Expand Down Expand Up @@ -108,7 +109,7 @@ def post(self, request, *args, **kwargs):
response["email"] = self.perform_follow_by_email(self.object, request.user)

self.object.save()
if request.is_ajax():
if is_ajax(request):
return HttpResponse(json.dumps(response), content_type="application/json")
return redirect(f"{self.object.get_absolute_url()}?page={self.page}")

Expand Down Expand Up @@ -265,7 +266,7 @@ def post(self, request, *args, **kwargs):
form = self.get_form(self.form_class)

if "preview" in request.POST:
if request.is_ajax():
if is_ajax(request):
content = render(request, "misc/preview.part.html", {"text": request.POST["text"]})
return StreamingHttpResponse(content)
else:
Expand Down Expand Up @@ -356,7 +357,7 @@ def post(self, request, *args, **kwargs):
form = self.get_form(self.form_class)

if "preview" in request.POST:
if request.is_ajax():
if is_ajax(request):
content = render(request, "misc/preview.part.html", {"text": request.POST["text"]})
return StreamingHttpResponse(content)
else:
Expand Down Expand Up @@ -391,7 +392,7 @@ def post(self, request, *args, **kwargs):
response["requesting"], response["newCount"] = self.toogle_featured_request(request.user)

self.object.save()
if request.is_ajax():
if is_ajax(request):
return HttpResponse(json.dumps(response), content_type="application/json")
return redirect(f"{self.object.get_absolute_url()}?page={self.page}")

Expand Down Expand Up @@ -511,7 +512,7 @@ def post(self, request, *args, **kwargs):
response["email"] = self.perform_follow_by_email(self.object, request.user)

self.object.save()
if request.is_ajax():
if is_ajax(request):
return HttpResponse(json.dumps(response), content_type="application/json")
return redirect(f"{self.object.get_absolute_url()}?page={self.page}")

Expand Down Expand Up @@ -635,7 +636,7 @@ def post(self, request, *args, **kwargs):
form = self.get_form(self.form_class)

if "preview" in request.POST:
if request.is_ajax():
if is_ajax(request):
content = render(request, "misc/preview.part.html", {"text": request.POST.get("text")})
return StreamingHttpResponse(content)
else:
Expand Down Expand Up @@ -717,7 +718,7 @@ def dispatch(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs):
self.perform_useful(self.object)

if request.is_ajax():
if is_ajax(request):
return HttpResponse(json.dumps(self.object.is_useful), content_type="application/json")

return redirect(self.object.get_absolute_url())
Expand Down
3 changes: 2 additions & 1 deletion zds/member/views/hats.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from zds.member.decorator import LoginRequiredMixin
from zds.member.forms import HatRequestForm
from zds.pages.models import GroupContact
from zds.utils.misc import is_ajax
from zds.utils.models import HatRequest, Hat, get_hat_to_add
from zds.utils.paginator import ZdSPagingListView

Expand Down Expand Up @@ -74,7 +75,7 @@ def get_initial(self):
return initial

def post(self, request, *args, **kwargs):
if "preview" in request.POST and request.is_ajax():
if "preview" in request.POST and is_ajax(request):
content = render(request, "misc/preview.part.html", {"text": request.POST.get("text")})
return StreamingHttpResponse(content)

Expand Down
3 changes: 2 additions & 1 deletion zds/member/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from zds.notification.models import TopicAnswerSubscription, NewPublicationSubscription
from zds.tutorialv2.models import CONTENT_TYPES
from zds.tutorialv2.models.database import PublishedContent, ContentContribution, ContentReaction
from zds.utils.misc import is_ajax
from zds.utils.templatetags.pluralize_fr import pluralize_fr


Expand Down Expand Up @@ -244,7 +245,7 @@ def get_form(self, form_class=ProfileForm):
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)

if "preview" in request.POST and request.is_ajax():
if "preview" in request.POST and is_ajax(request):
content = render(request, "misc/preview.part.html", {"text": request.POST.get("text")})
return StreamingHttpResponse(content)

Expand Down
3 changes: 2 additions & 1 deletion zds/middlewares/matomomiddleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.urls import reverse

from zds.member.views import get_client_ip
from zds.utils.misc import is_ajax

matomo_token_auth = settings.ZDS_APP["site"]["matomo_token_auth"]
matomo_api_url = "{}/matomo.php?token_auth={}".format(settings.ZDS_APP["site"]["matomo_url"], matomo_token_auth)
Expand Down Expand Up @@ -96,7 +97,7 @@ def matomo_track(self, request, search_data=None):
self.queue.put(tracking_params)

def process_response(self, request, response):
if response.status_code not in tracked_status_code or request.is_ajax():
if response.status_code not in tracked_status_code or is_ajax(request):
return response
# only on get
if request.method in tracked_methods:
Expand Down
5 changes: 3 additions & 2 deletions zds/mp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
PrivatePostVote,
is_reachable,
)
from zds.utils.misc import is_ajax


class PrivateTopicList(LoginRequiredMixin, ZdSPagingListView):
Expand Down Expand Up @@ -64,7 +65,7 @@ def post(self, request, *args, **kwargs):
form = self.get_form(self.form_class)

if "preview" in request.POST:
if request.is_ajax():
if is_ajax(request):
content = render(request, "misc/preview.part.html", {"text": request.POST["text"]})
return StreamingHttpResponse(content)
else:
Expand Down Expand Up @@ -307,7 +308,7 @@ def post(self, request, *args, **kwargs):
form = self.get_form(self.form_class)

if "preview" in request.POST:
if request.is_ajax():
if is_ajax(request):
content = render(request, "misc/preview.part.html", {"text": request.POST["text"]})
return StreamingHttpResponse(content)
elif form.is_valid():
Expand Down
6 changes: 3 additions & 3 deletions zds/pages/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_url_about(self):
"""Test: check that about page is alive."""

result = self.client.get(
reverse("pages-about"),
reverse("pages-technologies"),
)

self.assertEqual(result.status_code, 200)
Expand Down Expand Up @@ -98,7 +98,7 @@ def test_url_about(self):
"""Test: check that about page is alive."""

result = self.client.get(
reverse("pages-about"),
reverse("pages-technologies"),
)

self.assertEqual(result.status_code, 200)
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_url_about(self):
"""Test: check that about page is alive."""

result = self.client.get(
reverse("pages-about"),
reverse("pages-technologies"),
)

self.assertEqual(result.status_code, 200)
Expand Down
2 changes: 1 addition & 1 deletion zds/pages/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

urlpatterns = [
# single pages
path("apropos/", about, name="pages-about"),
path("technologies/", about, name="pages-technologies"),
path("association/", association, name="pages-association"),
path("contact/", ContactView.as_view(), name="pages-contact"),
path("cgu/", eula, name="pages-eula"),
Expand Down
2 changes: 1 addition & 1 deletion zds/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def about(request):
"""Display many informations about the website."""
return render(
request,
"pages/about.html",
"pages/technologies.html",
{
"default_repository_url": get_repository_url(
settings.ZDS_APP["github_projects"]["default_repository"], "base_url"
Expand Down
3 changes: 2 additions & 1 deletion zds/tutorialv2/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from zds.tutorialv2.models.database import PublishableContent, PublishedContent, ContentRead
from zds.tutorialv2.utils import mark_read
from zds.tutorialv2.models.help_requests import HelpWriting
from zds.utils.misc import is_ajax


class SingleContentViewMixin:
Expand Down Expand Up @@ -186,7 +187,7 @@ def post(self, request, *args, **kwargs):

if "preview" in request.POST:
self.form_invalid(form)
if request.is_ajax():
if is_ajax(self.request):
content = render_to_string("misc/preview.part.html", {"text": request.POST.get("text")})
return StreamingHttpResponse(content)

Expand Down
7 changes: 4 additions & 3 deletions zds/tutorialv2/views/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from zds.tutorialv2.forms import NoteForm, NoteEditForm
from zds.tutorialv2.mixins import SingleOnlineContentFormViewMixin, MustRedirect, SingleOnlineContentViewMixin
from zds.tutorialv2.models.database import ContentReaction
from zds.utils.misc import is_ajax
from zds.utils.models import CommentEdit, get_hat_from_request, Alert


Expand Down Expand Up @@ -97,7 +98,7 @@ def get(self, request, *args, **kwargs):
text = "\n".join("> " + line for line in reaction.text.split("\n"))
text += f"\nSource: [{reaction.author.username}]({reaction.get_absolute_url()})"

if self.request.is_ajax():
if is_ajax(self.request):
return StreamingHttpResponse(json_handler.dumps({"text": text}, ensure_ascii=False))
else:
self.quoted_reaction_text = text
Expand All @@ -110,7 +111,7 @@ def get(self, request, *args, **kwargs):
)

def post(self, request, *args, **kwargs):
if "preview" in request.POST and request.is_ajax():
if "preview" in request.POST and is_ajax(request):
content = render(request, "misc/preview.part.html", {"text": request.POST["text"]})
return StreamingHttpResponse(content)
else:
Expand Down Expand Up @@ -362,6 +363,6 @@ def post(self, request, *args, **kwargs):
response["follow"] = ContentReactionAnswerSubscription.objects.toggle_follow(
self.get_object(), self.request.user, True
).is_active
if self.request.is_ajax():
if is_ajax(self.request):
return HttpResponse(json_handler.dumps(response), content_type="application/json")
return redirect(self.get_object().get_absolute_url())
3 changes: 2 additions & 1 deletion zds/tutorialv2/views/containers_extracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
try_adopt_new_child,
TooDeepContainerError,
)
from zds.utils.misc import is_ajax

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -277,7 +278,7 @@ def form_valid(self, form):
self.object.update(sha_draft=sha, update_date=datetime.now())

self.success_url = extract.get_absolute_url()
if self.request.is_ajax():
if is_ajax(self.request):
return JsonResponse(
{"result": "ok", "last_hash": extract.compute_hash(), "new_url": extract.get_edit_url()}
)
Expand Down
5 changes: 3 additions & 2 deletions zds/tutorialv2/views/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from zds.tutorialv2.models.database import PublishableContent
from zds.tutorialv2.models.help_requests import HelpWriting
from zds.utils.misc import is_ajax
from zds.utils.paginator import ZdSPagingListView


Expand Down Expand Up @@ -84,12 +85,12 @@ def form_valid(self, form):
self.object.helps.remove(data["help_wanted"])
self.object.save()
signals.help_management.send(sender=self.__class__, performer=self.request.user, content=self.object)
if self.request.is_ajax():
if is_ajax(self.request):
return JsonResponse({"state": data["activated"]})
self.success_url = self.object.get_absolute_url()
return super().form_valid(form)

def form_invalid(self, form):
if self.request.is_ajax():
if is_ajax(self.request):
return JsonResponse({"errors": form.errors}, status=400)
return super().form_invalid(form)
Loading

0 comments on commit 479f11f

Please sign in to comment.