add makorepost in apps

This commit is contained in:
Thomas NOËL 2013-06-05 13:32:04 +02:00
parent 8a31e010d4
commit 8c6bfa00a8
5 changed files with 78 additions and 0 deletions

View File

View File

@ -0,0 +1,9 @@
from django.contrib import admin
from models import MakoPrototypeRepost
class MakoPrototypeRepostAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('title',)}
admin.site.register(MakoPrototypeRepost, MakoPrototypeRepostAdmin)

View File

@ -0,0 +1,67 @@
import os
import json
from mako.template import Template
from django.conf import settings
from django.db import models
from passerelle.repost.models import BaseRepost
class BaseMakoRepost(BaseRepost):
def get_input_template(self):
return None
def get_output_template(self):
return None
def repost(self, data, **kwargs):
input_template = self.get_input_template()
if input_template:
data = json.loads(input_template.render(data=data, args=kwargs))
out_data = BaseRepost.repost(self, data, **kwargs)
output_template = self.get_output_template()
if output_template:
out_data = json.loads(output_template.render(data=out_data, args=kwargs))
return out_data
class Meta:
abstract = True
class MakoPrototypeRepost(BaseMakoRepost):
input_template = models.TextField(blank=True)
output_template = models.TextField(blank=True)
parameters = '*'
def get_input_template(self):
if self.input_template:
return Template(self.input_template)
return None
def get_output_template(self):
if self.output_template:
return Template(self.output_template)
return None
#from mako.lookup import TemplateLookup
#template_lookup = TemplateLookup(directories=settings.MAKO_TEMPLATES_DIRS,
# module_directory=settings.MAKO_TEMPLATES_MODULES)
#
#class MakoRepost(BaseMakoRepost):
#
# template_name = None
#
# def get_input_template(self):
# return template_lookup.get_template(template_name + '-input.mako')
#
# def get_output_template(self):
# return template_lookup.get_template(template_name + '-output.mako')
#
# class Meta:
# abstract = True

View File

@ -132,6 +132,7 @@ INSTALLED_APPS = (
'clicrdv',
'gdc',
'solis',
'makorepost',
)
# A sample logging configuration. The only tangible logging

View File

@ -3,3 +3,4 @@ http://pypi.python.org/packages/source/d/django-jsonresponse/django-jsonresponse
django-model-utils
SOAPpy
phpserialize
mako