Commit 74fa71fc authored by Bruno Martin's avatar Bruno Martin
Browse files

django flatpages api and more

parent 88056517
Pipeline #7334 failed with stage
from django.contrib.flatpages.admin import FlatpageForm, FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
from ckeditor.widgets import CKEditorWidget
from django.contrib import admin
class PageForm(FlatpageForm):
class Meta:
model = FlatPage
fields = '__all__'
widgets = {
'content': CKEditorWidget()
}
class PageAdmin(FlatPageAdmin):
"""
Page Admin
"""
form = PageForm
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, PageAdmin)
from django.apps import AppConfig
class PagesConfig(AppConfig):
name = 'base_django_project.pages'
verbose_name = "Pages"
from django.db import models
# Create your models here.
from django.contrib.flatpages.models import FlatPage
from rest_framework import serializers
class FlatpageSerializer(serializers.ModelSerializer):
class Meta:
model = FlatPage
fields = ['id', 'url', 'title', 'content',]
from django.test import TestCase
# Create your tests here.
from rest_framework.routers import SimpleRouter
from . import views
router = SimpleRouter()
router.register(r'', views.FlatpageViewSet, base_name='flatpage')
app_name = 'pages'
urlpatterns = []
urlpatterns.extend(router.urls)
from django.contrib.flatpages.models import FlatPage
from rest_framework import viewsets
from .serializers import FlatpageSerializer
class FlatpageViewSet(viewsets.ReadOnlyModelViewSet):
model = FlatPage
queryset = FlatPage.objects.all()
serializer_class = FlatpageSerializer
filter_fields = ('url',)
def get_queryset(self):
queryset = super(FlatpageViewSet, self).get_queryset()
url_prefix = self.request.query_params.get('url_prefix')
if url_prefix:
queryset = queryset.filter(url__startswith=url_prefix)
return queryset
......@@ -65,6 +65,12 @@ THIRD_PARTY_APPS = [
'compressor',
'pinax.webanalytics',
# pages admin editor related
'ckeditor',
'easy_thumbnails',
'filer',
'mptt',
'courier',
'courier.emails',
# 'courier.emails.providers.onesignal',
......@@ -77,6 +83,7 @@ THIRD_PARTY_APPS = [
LOCAL_APPS = [
# custom users app
'users.apps.UsersConfig',
'pages.apps.PagesConfig',
'courses.apps.CoursesConfig',
'courses_learning_objects.apps.CoursesLearningObjectsConfig',
'courses_certification.apps.CoursesCertificationConfig',
......@@ -84,6 +91,7 @@ LOCAL_APPS = [
'courses_reports.apps.CoursesReportsConfig',
'courses_legacy.apps.CoursesLegacyConfig',
'courses_legacy.administration',
# 'courses_notes.apps.CoursesNotesConfig',
]
......
......@@ -21,6 +21,9 @@ urlpatterns = [
# Address utilities
url(r'^api/address/', include('base_django_project.cities_api.urls', namespace='cities')),
# User management
url(r'^api/pages/', include('base_django_project.pages.urls', namespace='pages')),
# User management
url(r'^api/profile/', include('base_django_project.users.urls', namespace='users')),
url(r'^rest-auth/facebook/$', FacebookLogin.as_view(), name='fb_login'),
......@@ -34,6 +37,7 @@ urlpatterns = [
url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
url(r'^accounts/', include('allauth.urls')),
url(r'^', include('django.contrib.auth.urls')),
## Dummy urls only to create reverse
url(r'^recuperar-senha/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', TemplateView.as_view(), name='password_reset_confirm'),
......
......@@ -68,3 +68,11 @@ django-compressor==2.2
django-libsass==0.7
pinax-webanalytics==4.0.2
# Page editor
django-ckeditor==5.6.1
# libs for django-filer
django-mptt==0.9.1
django-polymorphic==2.0.3
easy-thumbnails==2.5
django-filer==1.4.4
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment