First steps with the api

This commit is contained in:
Antoine Bartuccio 2016-08-05 00:50:48 +02:00
parent ad36c1c6f6
commit feb7b4689b
15 changed files with 44 additions and 10 deletions

0
api/__init__.py Normal file
View File

3
api/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

3
api/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
api/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

16
api/urls.py Normal file
View File

@ -0,0 +1,16 @@
from django.conf.urls import url, include
from api.views import *
from rest_framework import routers
# Router config
router = routers.DefaultRouter()
urlpatterns = [
# API
url(r'^', include(router.urls)),
url(r'^login/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^markdown$', RenderMarkdown, name='api_markdown'),
]

2
api/views/__init__.py Normal file
View File

@ -0,0 +1,2 @@
from .api import *
from .serializers import *

13
api/views/api.py Normal file
View File

@ -0,0 +1,13 @@
from rest_framework.response import Response
from rest_framework.decorators import api_view
from core.templatetags.renderer import markdown
@api_view(['GET'])
def RenderMarkdown(request):
"""
Render Markdown
"""
if request.method == 'GET':
return Response(markdown(request.GET['text']))

1
api/views/serializers.py Normal file
View File

@ -0,0 +1 @@
from rest_framework import serializers

View File

@ -39,7 +39,4 @@ urlpatterns = [
url(r'^page/(?P<page_name>[a-z0-9/-_]*)/rev/(?P<rev>[0-9]+)/', PageRevView.as_view(), name='page_rev'), url(r'^page/(?P<page_name>[a-z0-9/-_]*)/rev/(?P<rev>[0-9]+)/', PageRevView.as_view(), name='page_rev'),
url(r'^page/(?P<page_name>[a-z0-9/-_]*)/$', PageView.as_view(), name='page'), url(r'^page/(?P<page_name>[a-z0-9/-_]*)/$', PageView.as_view(), name='page'),
# API
url(r'^api/markdown$', render_markdown, name='api_markdown'),
] ]

View File

@ -100,5 +100,3 @@ from .user import *
from .page import * from .page import *
from .site import * from .site import *
from .group import * from .group import *
from .api import *

View File

@ -1,5 +0,0 @@
from core.templatetags.renderer import markdown
from django.http import HttpResponse
def render_markdown(request):
return HttpResponse(markdown(request.GET['text']))

View File

@ -5,3 +5,4 @@ mistune
django-jinja django-jinja
pyopenssl pyopenssl
pytz pytz
djangorestframework

View File

@ -51,6 +51,7 @@ INSTALLED_APPS = (
'counter', 'counter',
'eboutic', 'eboutic',
'launderette', 'launderette',
'rest_framework',
'api', 'api',
) )

View File

@ -29,5 +29,6 @@ urlpatterns = [
url(r'^accounting/', include('accounting.urls', namespace="accounting", app_name="accounting")), url(r'^accounting/', include('accounting.urls', namespace="accounting", app_name="accounting")),
url(r'^eboutic/', include('eboutic.urls', namespace="eboutic", app_name="eboutic")), url(r'^eboutic/', include('eboutic.urls', namespace="eboutic", app_name="eboutic")),
url(r'^launderette/', include('launderette.urls', namespace="launderette", app_name="launderette")), url(r'^launderette/', include('launderette.urls', namespace="launderette", app_name="launderette")),
url(r'^api/', include('api.urls', namespace="api", app_name="api")),
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # TODO: remove me for production!!! ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # TODO: remove me for production!!!