Skip to content

Commit

Permalink
Merge pull request #236 from Volontaria/new_feature-dynamical_informa…
Browse files Browse the repository at this point in the history
…tion_page

Add pages app to manage information page
  • Loading branch information
RignonNoel authored Aug 5, 2019
2 parents 85f79c2 + 0530c3c commit b10b758
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 2 deletions.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ factory-boy==2.10.0
django-import-export==1.2.0
django-anymail==6.1
coreapi==2.3.3
django-orderable==6.0.1
django-ckeditor==5.7.1
django-reversion==3.0.3
9 changes: 7 additions & 2 deletions source/apiVolontaria/apiVolontaria/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@
'rest_framework_docs',
'rest_framework.authtoken',
'corsheaders',
'import_export',
'anymail',
'orderable',
'ckeditor',
'reversion',

'apiVolontaria',
'volunteer',
'location',
'import_export',
'anymail'
'pages',
]

MIDDLEWARE = [
Expand Down
5 changes: 5 additions & 0 deletions source/apiVolontaria/apiVolontaria/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
r'^location/',
include('location.urls', namespace="location"),
),
# Pages
url(
r'^pages/',
include('pages.urls', namespace="pages"),
),
# DOCUMENTATION SWAGGER
path(
'docs/',
Expand Down
Empty file.
16 changes: 16 additions & 0 deletions source/apiVolontaria/pages/admin.py
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', )
29 changes: 29 additions & 0 deletions source/apiVolontaria/pages/migrations/0001_initial.py
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 source/apiVolontaria/pages/migrations/0002_auto_20190509_1544.py
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.
19 changes: 19 additions & 0 deletions source/apiVolontaria/pages/models.py
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)
21 changes: 21 additions & 0 deletions source/apiVolontaria/pages/serializers.py
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 source/apiVolontaria/pages/tests/tests_model_InfoSection.py
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 source/apiVolontaria/pages/tests/tests_view_InfoPageView.py
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)
17 changes: 17 additions & 0 deletions source/apiVolontaria/pages/urls.py
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',
),
]
)
10 changes: 10 additions & 0 deletions source/apiVolontaria/pages/views.py
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)

0 comments on commit b10b758

Please sign in to comment.