mirror of
https://github.com/ae-utbm/sith.git
synced 2025-11-22 20:56:59 +00:00
reuse last PageRev if same author and short time diff
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
{% from 'core/macros_pages.jinja' import page_history %}
|
||||
{% from 'core/page/macros.jinja' import page_history %}
|
||||
|
||||
{% block content %}
|
||||
{% if club.page %}
|
||||
{{ page_history(club.page) }}
|
||||
{% else %}
|
||||
{% trans %}No page existing for this club{% endtrans %}
|
||||
{% endif %}
|
||||
{{ page_history(club.page) }}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
{% from 'core/macros_pages.jinja' import page_edit_form %}
|
||||
|
||||
{% block content %}
|
||||
{{ page_edit_form(form, url('club:club_edit_page', club_id=page.club.id)) }}
|
||||
<h2>{% trans %}Edit page{% endtrans %}</h2>
|
||||
<form action="{{ url('club:club_edit_page', club_id=page.club.id) }}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p() }}
|
||||
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
@@ -3,9 +3,10 @@ from bs4 import BeautifulSoup
|
||||
from django.test import Client
|
||||
from django.urls import reverse
|
||||
from model_bakery import baker
|
||||
from pytest_django.asserts import assertHTMLEqual
|
||||
from pytest_django.asserts import assertHTMLEqual, assertRedirects
|
||||
|
||||
from club.models import Club
|
||||
from club.models import Club, Membership
|
||||
from core.baker_recipes import subscriber_user
|
||||
from core.markdown import markdown
|
||||
from core.models import PageRev, User
|
||||
|
||||
@@ -16,7 +17,6 @@ def test_page_display_on_club_main_page(client: Client):
|
||||
club = baker.make(Club)
|
||||
content = "# foo\nLorem ipsum dolor sit amet"
|
||||
baker.make(PageRev, page=club.page, revision=1, content=content)
|
||||
client.force_login(baker.make(User))
|
||||
res = client.get(reverse("club:club_view", kwargs={"club_id": club.id}))
|
||||
|
||||
assert res.status_code == 200
|
||||
@@ -30,10 +30,42 @@ def test_club_main_page_without_content(client: Client):
|
||||
"""Test the club view works, even if the club page is empty"""
|
||||
club = baker.make(Club)
|
||||
club.page.revisions.all().delete()
|
||||
client.force_login(baker.make(User))
|
||||
res = client.get(reverse("club:club_view", kwargs={"club_id": club.id}))
|
||||
|
||||
assert res.status_code == 200
|
||||
soup = BeautifulSoup(res.text, "lxml")
|
||||
detail_html = soup.find(id="club_detail")
|
||||
assert detail_html.find_all("markdown") == []
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_page_revision(client: Client):
|
||||
club = baker.make(Club)
|
||||
revisions = baker.make(
|
||||
PageRev, page=club.page, _quantity=3, content=iter(["foo", "bar", "baz"])
|
||||
)
|
||||
client.force_login(baker.make(User))
|
||||
url = reverse(
|
||||
"club:club_view_rev", kwargs={"club_id": club.id, "rev_id": revisions[1].id}
|
||||
)
|
||||
res = client.get(url)
|
||||
assert res.status_code == 200
|
||||
soup = BeautifulSoup(res.text, "lxml")
|
||||
detail_html = soup.find(class_="markdown")
|
||||
assertHTMLEqual(detail_html.decode_contents(), markdown(revisions[1].content))
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_edit_page(client: Client):
|
||||
club = baker.make(Club)
|
||||
user = subscriber_user.make()
|
||||
baker.make(Membership, user=user, club=club, role=3)
|
||||
client.force_login(user)
|
||||
url = reverse("club:club_edit_page", kwargs={"club_id": club.id})
|
||||
content = "# foo\nLorem ipsum dolor sit amet"
|
||||
|
||||
res = client.get(url)
|
||||
assert res.status_code == 200
|
||||
res = client.post(url, data={"content": content})
|
||||
assertRedirects(res, reverse("club:club_view", kwargs={"club_id": club.id}))
|
||||
assert club.page.revisions.last().content == content
|
||||
|
||||
@@ -22,12 +22,14 @@
|
||||
#
|
||||
#
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import csv
|
||||
import itertools
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.core.exceptions import NON_FIELD_ERRORS, PermissionDenied, ValidationError
|
||||
from django.core.paginator import InvalidPage, Paginator
|
||||
@@ -36,7 +38,7 @@ from django.http import Http404, HttpResponseRedirect, StreamingHttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import timezone
|
||||
from django.utils.safestring import SafeString
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import gettext
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@@ -61,11 +63,14 @@ from com.views import (
|
||||
PosterListBaseView,
|
||||
)
|
||||
from core.auth.mixins import CanEditMixin, PermissionOrClubBoardRequiredMixin
|
||||
from core.models import PageRev
|
||||
from core.views import DetailFormView, PageEditViewBase, UseFragmentsMixin
|
||||
from core.models import Page, PageRev
|
||||
from core.views import BasePageEditView, DetailFormView, UseFragmentsMixin
|
||||
from core.views.mixins import FragmentMixin, FragmentRenderer, TabedViewMixin
|
||||
from counter.models import Selling
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.utils.safestring import SafeString
|
||||
|
||||
|
||||
class ClubTabsMixin(TabedViewMixin):
|
||||
def get_tabs_title(self):
|
||||
@@ -75,6 +80,8 @@ class ClubTabsMixin(TabedViewMixin):
|
||||
self.object = self.object.page.club
|
||||
elif isinstance(self.object, Poster):
|
||||
self.object = self.object.club
|
||||
elif hasattr(self, "club"):
|
||||
self.object = self.club
|
||||
return self.object.get_display_name()
|
||||
|
||||
def get_list_of_tabs(self):
|
||||
@@ -202,7 +209,7 @@ class ClubView(ClubTabsMixin, DetailView):
|
||||
return kwargs
|
||||
|
||||
|
||||
class ClubRevView(ClubView):
|
||||
class ClubRevView(LoginRequiredMixin, ClubView):
|
||||
"""Display a specific page revision."""
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
@@ -216,27 +223,26 @@ class ClubRevView(ClubView):
|
||||
return kwargs
|
||||
|
||||
|
||||
class ClubPageEditView(ClubTabsMixin, PageEditViewBase):
|
||||
class ClubPageEditView(ClubTabsMixin, BasePageEditView):
|
||||
template_name = "club/pagerev_edit.jinja"
|
||||
current_tab = "page_edit"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.club = get_object_or_404(Club, pk=kwargs["club_id"])
|
||||
if not self.club.page:
|
||||
raise Http404
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
@cached_property
|
||||
def club(self):
|
||||
return get_object_or_404(Club, pk=self.kwargs["club_id"])
|
||||
|
||||
def get_object(self):
|
||||
self.page = self.club.page
|
||||
self.page.set_lock(self.request.user)
|
||||
return self.page.revisions.last()
|
||||
@cached_property
|
||||
def page(self) -> Page:
|
||||
page = self.club.page
|
||||
page.set_lock(self.request.user)
|
||||
return page
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return reverse_lazy("club:club_view", kwargs={"club_id": self.club.id})
|
||||
|
||||
|
||||
class ClubPageHistView(ClubTabsMixin, PermissionRequiredMixin, DetailView):
|
||||
"""Modification hostory of the page."""
|
||||
"""Modification history of the page."""
|
||||
|
||||
model = Club
|
||||
pk_url_kwarg = "club_id"
|
||||
|
||||
Reference in New Issue
Block a user