Exemple #1
0
	# form processors. Input is the form slug and a function, which will
	# be called when a form receives a valid submission. The function called
	# is passed the form object.
	@staticmethod
	def add_action(form_slug, func):
		if form_slug in FormsAPI.actions:
			FormsAPI.actions[form_slug].append(func)
		else:
			FormsAPI.actions[form_slug] = (func,)

# Using the Shortcodes API (juice.front.shortcodes) add a new shortcode
# called form. The general usage is: 

# * [form id="1"]
# * [form slug="contact-form"]
# * [form name="My Form Name"]
shortcodes.add("form", FormsAPI.shortcode)

# Use this to accept non-static methods in the Forms API
# Reserved for the action pool which will be worked out at a later
# stage.
# Update: The action pool is a static attribute inside FormsAPI, so api
# is no longer needed. Will be removed.
#api = FormsAPI()

# The following is a sample of how do add custom form processors
def form_debug(form, **kwargs):
	debug("Form debug: %s" % form.slug)
	
FormsAPI.add_action('*', form_debug)
Exemple #2
0
from django.db import models
from juice.front.shortcodes import shortcodes

# Create your models here.
class Chunk(models.Model):
	name = models.CharField(max_length=255, unique=True)
	content = models.TextField(blank=True)
	
	published = models.DateTimeField('Date published', auto_now_add=True)
	updated = models.DateTimeField('Date updated', auto_now=True, auto_now_add=True)
	
	def __unicode__(self):
		return self.name

class ChunksAPI():
	@staticmethod
	def shortcode(kwargs):
		chunk_name = kwargs.get("name").__str__()
		chunk = Chunk.objects.get(name=chunk_name)
		return chunk.content

shortcodes.add("chunk", ChunksAPI.shortcode)