Skip to content

Commit

Permalink
Use "private" attribute names.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Kaskel committed Jun 9, 2011
1 parent d331f58 commit fcb83ae
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cbv_formpreview/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.contrib.formtools.utils import form_hmac
from django.views.generic import FormView

PREVIEW_STAGE = 'preview'
POST_STAGE = 'post'
AUTO_ID = 'formtools_%s' # Each form here uses this as its auto_id parameter.
STAGE_FIELD = 'stage'
HASH_FIELD = 'hash'
Expand All @@ -21,20 +23,19 @@ def __init__(self, form_class, *args, **kwargs):
super(FormPreview, self).__init__(*args, **kwargs)
# form should be a Form class, not an instance.
self.form_class = form_class
# A relic from the past; override get_context_data to pass extra context
self._preview_stage = PREVIEW_STAGE
self._post_stage = POST_STAGE
self._stages = {'1': self._preview_stage, '2': self._post_stage}
# A relic of the past; override get_context_data to pass extra context
# to the template. Left in for backwards compatibility.
self.state = {}

def __call__(self, request, *args, **kwargs):
return self.dispatch(request, *args, **kwargs)

def dispatch(self, request, *args, **kwargs):
self.preview_stage = 'preview'
self.post_stage = 'post'
stages = {'1': self.preview_stage, '2': self.post_stage}

posted_stage = request.POST.get(self.unused_name(STAGE_FIELD))
self.stage = stages.get(posted_stage, self.preview_stage)
self._stage = self._stages.get(posted_stage, self._preview_stage)

# For backwards compatiblity
self.parse_params(*args, **kwargs)
Expand Down Expand Up @@ -78,12 +79,12 @@ def _check_security_hash(self, token, form):
def preview_post(self, request):
""" For backwards compatibility. failed_hash calls this method by
default. """
self.stage = self.preview_stage
self._stage = self._preview_stage
return self.post(request)

def form_valid(self, form):
context = self._get_context_data(form)
if self.stage == self.preview_stage:
if self._stage == self._preview_stage:
self.process_preview(self.request, form, context)
context['hash_field'] = self.unused_name(HASH_FIELD)
context['hash_value'] = self.security_hash(self.request, form)
Expand Down

0 comments on commit fcb83ae

Please sign in to comment.