def get_execute_args(self, form, data): request_factory = RequestFactory() request = request_factory.post(build_url('/', **{'from': '/'}), data) form_obj = form.build_form_class()(request.POST) assert form_obj.is_valid() return request, form_obj
def get_diff_urls(self, before_node, after_node): if DIFF_ENABLED: for a, b in zip(self.get_preview_urls(before_node), self.get_preview_urls(after_node)): yield build_url(self.site.reverse(self.site.diff_view), before=a['url'], after=b['url'])
def get_preview_url(self): options = { 'size': '300x200', 'zoom': self.zoom, 'maptype': self.type, 'sensor': 'true', 'markers': '|%s' % self.address, } return build_url('https://maps.googleapis.com/maps/api/staticmap', **options)
def get_neighbor_rel_links(self): neighbor_pages = self.get_neighbor_pages() querystring = self.request.GET.copy() prev_link = None next_link = None if neighbor_pages['prev']: if neighbor_pages['prev'] == 1: # Link to the canonical url del querystring['page'] else: querystring['page'] = neighbor_pages['prev'] prev_link = build_url(self.request.path, querystring) if neighbor_pages['next']: querystring['page'] = neighbor_pages['next'] next_link = build_url(self.request.path, querystring) return {'prev_link': prev_link, 'next_link': next_link}
def execute(self, request, form): # TODO: does this redirect belong here or in the view? We populate # request.GET['form'] in the model, so we should probable handle it in # the model too. resp = redirect(build_url( request.GET['from'], success=self.success_key, )) for child in self.depth_first_order(): if isinstance(child, FormReponseHandler): resp = child.execute(request, form) elif isinstance(child, FormSuccessHandler): child.execute(request, form) return resp
def render(self, context): if self.context_var in context: # when the form fails validation, the submission view passes # the existing instance back to us in the context form = context[self.context_var] else: form = self.build_form_class()() request = context.get('request') action_url = build_url( self.action_url(context['widgy']), **{'from': request and (request.GET.get('from') or request.path)}) ctx = { 'form': form, 'action_url': action_url, 'success': request and request.GET.get('success') == self.success_key, } with update_context(context, ctx): return super(Form, self).render(context)
def render(self, context): if self.context_var in context: # when the form fails validation, the submission view passes # the existing instance back to us in the context form = context[self.context_var] else: form = self.build_form_class()() request = context.get('request') action_url = build_url( self.action_url(context['widgy']), **{'from': request and (request.GET.get('from') or request.path)} ) ctx = { 'form': form, 'action_url': action_url, 'success': request and request.GET.get('success') == self.success_key, } with update_context(context, ctx): return super(Form, self).render(context)
def get_absolute_url(self): options = self.get_map_options() options['source'] = 'embed' return build_url('https://maps.google.com/', **options)
def get_embed_url(self): options = self.get_map_options() options['output'] = 'embed' return build_url('https://maps.google.com/', **options)