-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from Volontaria/new_feature-dynamical_informa…
…tion_page Add pages app to manage information page
- Loading branch information
Showing
15 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.contrib import admin | ||
from orderable.admin import OrderableAdmin | ||
from reversion.admin import VersionAdmin | ||
|
||
from .models import InfoSection | ||
|
||
|
||
@admin.register(InfoSection) | ||
class InfoSectionAdmin(OrderableAdmin, VersionAdmin): | ||
list_display = ('sort_order_display', 'is_active', 'is_accordion', 'title') | ||
list_display_links = ('title',) | ||
list_editable = ('is_active', 'is_accordion') | ||
|
||
fields = ('is_active', 'is_accordion', 'title', 'content', ) | ||
|
||
search_fields = ('content', 'title', ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 2.1.5 on 2019-05-03 13:45 | ||
|
||
import ckeditor.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='InfoSection', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('sort_order', models.IntegerField(blank=True, db_index=True)), | ||
('is_active', models.BooleanField(default=True, verbose_name='Actif')), | ||
('title', models.CharField(max_length=255, verbose_name='Titre')), | ||
('content', ckeditor.fields.RichTextField(verbose_name='Contenu')), | ||
], | ||
options={ | ||
'ordering': ['sort_order'], | ||
'abstract': False, | ||
}, | ||
), | ||
] |
22 changes: 22 additions & 0 deletions
22
source/apiVolontaria/pages/migrations/0002_auto_20190509_1544.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 2.1.5 on 2019-05-09 19:44 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('pages', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='infosection', | ||
options={'ordering': ['sort_order'], 'verbose_name': 'Section page informations', 'verbose_name_plural': 'Sections page informations'}, | ||
), | ||
migrations.AddField( | ||
model_name='infosection', | ||
name='is_accordion', | ||
field=models.BooleanField(default=True, verbose_name='Accordeon'), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.db import models | ||
from orderable.models import Orderable | ||
from ckeditor.fields import RichTextField | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class InfoSection(Orderable): | ||
|
||
is_active = models.BooleanField(_('Active'), default=True) | ||
title = models.CharField(_('title'), max_length=255) | ||
content = RichTextField(_('Content')) | ||
is_accordion = models.BooleanField(_('Accordion'), default=True) | ||
|
||
class Meta(Orderable.Meta): | ||
verbose_name = _('Information Page section') | ||
verbose_name_plural = _('Information Page sections') | ||
|
||
def __str__(self): | ||
return '{0} (ID-{1})'.format(self.title, self.pk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from rest_framework import serializers | ||
|
||
from .models import InfoSection | ||
|
||
|
||
class InfoPageSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = InfoSection | ||
fields = ( | ||
'id', | ||
'is_accordion', | ||
'title', | ||
'content', | ||
) | ||
read_only_fields = ( | ||
'id', | ||
'is_accordion', | ||
'title', | ||
'content', | ||
) |
Empty file.
22 changes: 22 additions & 0 deletions
22
source/apiVolontaria/pages/tests/tests_model_InfoSection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from rest_framework.test import APITransactionTestCase | ||
|
||
from ..models import InfoSection | ||
|
||
|
||
class InfoSectionTests(APITransactionTestCase): | ||
|
||
def setUp(self): | ||
pass | ||
|
||
def test_create_info_section(self): | ||
""" | ||
Ensure we can create a new InfoSection | ||
""" | ||
info_section = InfoSection.objects.create( | ||
is_active=True, | ||
title='My title', | ||
content='My Content', | ||
) | ||
|
||
self.assertEqual(info_section.title, 'My title') | ||
self.assertEqual(info_section.content, 'My Content') |
52 changes: 52 additions & 0 deletions
52
source/apiVolontaria/pages/tests/tests_view_InfoPageView.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import json | ||
|
||
from rest_framework import status | ||
from rest_framework.test import APIClient, APITestCase | ||
|
||
from django.urls import reverse | ||
|
||
from apiVolontaria.factories import UserFactory, AdminFactory | ||
from ..models import InfoSection | ||
|
||
|
||
class InfoPageViewTests(APITestCase): | ||
|
||
def setUp(self): | ||
self.client = APIClient() | ||
|
||
self.user = UserFactory() | ||
self.user.set_password('Test123!') | ||
self.user.save() | ||
|
||
self.admin = AdminFactory() | ||
self.admin.set_password('Test123!') | ||
self.admin.save() | ||
|
||
self.info_section = InfoSection.objects.create( | ||
title='my title', | ||
content='my content', | ||
) | ||
|
||
def test_list_info_sections(self): | ||
""" | ||
Ensure we can list info sections. | ||
""" | ||
|
||
data = [ | ||
{ | ||
'id': self.info_section.pk, | ||
'is_accordion': True, | ||
'title': self.info_section.title, | ||
'content': self.info_section.content | ||
} | ||
] | ||
|
||
self.client.force_authenticate(user=self.user) | ||
|
||
response = self.client.get('/pages/info') | ||
|
||
response_parsed = json.loads(response.content) | ||
|
||
self.assertEqual(response_parsed['results'], data) | ||
self.assertEqual(response_parsed['count'], 1) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.conf.urls import include, url | ||
from rest_framework.urlpatterns import format_suffix_patterns | ||
|
||
from . import views | ||
|
||
app_name = 'pages' | ||
|
||
urlpatterns = format_suffix_patterns( | ||
[ | ||
# Information page | ||
url( | ||
r'^info$', | ||
views.InfoPageView.as_view(), | ||
name='info', | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from rest_framework import generics | ||
|
||
from .models import InfoSection | ||
from .serializers import InfoPageSerializer | ||
|
||
|
||
class InfoPageView(generics.ListAPIView): | ||
permission_classes = () | ||
serializer_class = InfoPageSerializer | ||
queryset = InfoSection.objects.filter(is_active=True) |