Skip to content

Commit

Permalink
TRAC#7497 Adds the page update view
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsmkn committed Mar 2, 2018
1 parent 2dc6af7 commit eb3f9d9
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 26 deletions.
9 changes: 4 additions & 5 deletions app/comicsite/templates/mainpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@
<br/>

{% get_obj_perms user for site as "site_perms" %}
{% if "change_comicsite" in site_perms or request.user.is_superuser %}
{% if "change_comicsite" in site_perms %}

<a class="editPageLink"
href="{% url 'admin:comicmodels_page_change' currentpage.pk %}">Edit
this page</a>
href="{% url 'pages:update' currentpage.comicsite.short_name currentpage.title %}">
Edit this page
</a>
{% endif %}


{% endblock %}


{% endblock %}
4 changes: 2 additions & 2 deletions app/comicsite/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
{% if not currentpage.is_error_page %}
{% block editlink %}
{% if currentpage.pk %}
{% if "change_comicsite" in site_perms or request.user.is_superuser %}
{% if "change_comicsite" in site_perms %}
<a class="editPageLink"
href="{% url 'admin:comicmodels_page_change' currentpage.pk %}">Edit
href="{% url 'pages:update' currentpage.comicsite.short_name currentpage.title %}">Edit
this
page</a>

Expand Down
23 changes: 13 additions & 10 deletions app/pages/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@


class PageCreateForm(forms.ModelForm):
move = forms.CharField(widget=forms.Select)
move.required = False
move.widget.choices = (
(BLANK_CHOICE_DASH[0]),
('FIRST', 'First'),
('UP', 'Up'),
('DOWN', 'Down'),
('LAST', 'Last'),
)

def __init__(self, *args, **kwargs):
challenge_name = kwargs.pop('challenge_short_name', None)

Expand All @@ -29,3 +19,16 @@ def __init__(self, *args, **kwargs):
class Meta:
model = Page
fields = ('title', 'permission_lvl', 'display_title', 'hidden', 'html')


class PageUpdateForm(PageCreateForm):
""" Like the page update form but you can also move the page """
move = forms.CharField(widget=forms.Select)
move.required = False
move.widget.choices = (
(BLANK_CHOICE_DASH[0]),
('FIRST', 'First'),
('UP', 'Up'),
('DOWN', 'Down'),
('LAST', 'Last'),
)
7 changes: 5 additions & 2 deletions app/pages/templates/comicmodels/page_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ <h2>Pages for {{ site.short_name }}</h2>
<a href="{{ page.get_absolute_url }}">View {{ page.title }}</a>
</td>
<td>
<i class="fa fa-edit" title="edit"></i>
<a href="{% url 'pages:update' site.short_name page.title %}">
<i class="fa fa-edit" title="edit"></i>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>

<p><a class="btn btn-primary" href="{% url 'pages:create' site.short_name %}">
<p><a class="btn btn-primary"
href="{% url 'pages:create' site.short_name %}">
<i class="fa fa-plus"></i> Add a new page
</a></p>

Expand Down
3 changes: 3 additions & 0 deletions app/pages/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
insertedpage,
PageList,
PageCreate,
PageUpdate,
)

urlpatterns = [
url(r'^pages/$', PageList.as_view(), name='list'),
url(r'^pages/create/$', PageCreate.as_view(), name='create'),
url(r'^(?P<page_title>[\w-]+)/$', page, name='detail'),
url(r'^(?P<page_title>[\w-]+)/update/$', PageUpdate.as_view(), name='update'),

url(r'^(?P<page_title>[\w-]+)/insert/(?P<dropboxpath>.+)/$', insertedpage,
name='insert-detail'),
]
14 changes: 9 additions & 5 deletions app/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db.models import Q
from django.http import Http404, HttpResponseForbidden
from django.shortcuts import render, get_object_or_404
from django.views.generic import ListView, CreateView
from django.views.generic import ListView, CreateView, UpdateView

from comicmodels.models import Page, ComicSite
from comicsite.core.urlresolvers import reverse
Expand All @@ -18,7 +18,7 @@
)
from filetransfers.api import serve_file
from filetransfers.views import can_access
from pages.forms import PageCreateForm
from pages.forms import PageCreateForm, PageUpdateForm


class PageCreate(UserIsChallengeAdminMixin, CreateView):
Expand All @@ -27,9 +27,7 @@ class PageCreate(UserIsChallengeAdminMixin, CreateView):

def get_form_kwargs(self):
kwargs = super(PageCreate, self).get_form_kwargs()

kwargs.update({'challenge_short_name': self.request.projectname})

return kwargs

def form_valid(self, form):
Expand All @@ -43,10 +41,16 @@ class PageList(UserIsChallengeAdminMixin, ListView):

def get_queryset(self):
queryset = super(PageList, self).get_queryset()

return queryset.filter(Q(comicsite__pk=self.request.project_pk))


class PageUpdate(UserIsChallengeAdminMixin, UpdateView):
model = Page
form_class = PageUpdateForm
slug_url_kwarg = 'page_title'
slug_field = 'title'


def page(request, challenge_short_name, page_title):
""" show a single page on a site """

Expand Down
16 changes: 14 additions & 2 deletions app/tests/pages_tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ def test_page_admin_permissions(view, client, TwoChallengeSets):
)


@pytest.mark.django_db
def test_page_update_permissions(client, TwoChallengeSets):
p1 = PageFactory(comicsite=TwoChallengeSets.ChallengeSet1.challenge,
title='challenge1page1permissiontest')

validate_admin_only_view(
viewname='pages:update',
two_challenge_set=TwoChallengeSets,
client=client,
reverse_kwargs={'page_title': p1.title},
)


@pytest.mark.django_db
def test_page_list_filter(client, TwoChallengeSets):
""" Check that only pages related to this challenge are listed """
Expand Down Expand Up @@ -52,6 +65,7 @@ def test_page_list_filter(client, TwoChallengeSets):
assert p1.title not in response.rendered_content
assert p2.title in response.rendered_content


@pytest.mark.django_db
def test_page_create(client, TwoChallengeSets):
page_html = '<h1>HELLO WORLD</h1>'
Expand Down Expand Up @@ -101,5 +115,3 @@ def test_page_create(client, TwoChallengeSets):
)

assert response.status_code == 404


0 comments on commit eb3f9d9

Please sign in to comment.