def update(request): if request.method == "POST": safe_form = SafeForm(data=request.POST) help_form = HelpForm(data=request.POST) update_form = UpdateForm(data=request.POST) if help_form.is_valid(): data = help_form.cleaned_data traveller = data['traveller'] update = TravellerUpdate(traveller=traveller, status=STATUS_IN_DANGER, current_country=data['country'], update=data['help_message']) do_help_actions(traveller) kwargs = {'traveller_id': str(traveller.id)} url_name = 'help' if data['country']: url_name = 'help-country' kwargs['country'] = data['country'] return HttpResponseRedirect(reverse(url_name, kwargs=kwargs)) if safe_form.is_valid(): traveller = safe_form.cleaned_data['traveller'] update = TravellerUpdate(traveller=traveller, status=STATUS_SAFE) update.save() do_safe_actions(traveller) return HttpResponseRedirect(reverse('safe')) if update_form.is_valid(): data = update_form.cleaned_data traveller = data['traveller'] update = TravellerUpdate(traveller=traveller, status=STATUS_IN_TRANSIT, update=data['message'], current_country=data['country']) do_update_actions(traveller) return HttpResponseRedirect(reverse('updated')) else: safe_form = SafeForm() help_form = HelpForm() update_form = UpdateForm() return render_to_response('update.html', {'safe_form': safe_form, 'help_form': help_form, 'update_form': update_form}, context_instance=RequestContext(request))
def register(request): if request.method == "POST": traveller_form = TravellerForm(request.POST, request.FILES) if traveller_form.is_valid(): # combine traveller's secret with site secret and hash before saving traveller = traveller_form.save(commit=False) display_secret = _get_unique_secret() store_secret = process_secret(display_secret.lower()) traveller.secret = store_secret traveller.save() initial_update = TravellerUpdate(traveller=traveller, status=STATUS_IN_TRANSIT, current_country=traveller.home_country) initial_update.save() return render_to_response('confirm.html', {'secret': display_secret}, context_instance=RequestContext(request)) else: traveller_form = TravellerForm() return render_to_response('register.html', {'traveller_form': traveller_form}, context_instance=RequestContext(request))