Created
November 11, 2012 07:50
-
-
Save tmc/4054110 to your computer and use it in GitHub Desktop.
wat django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#views.py | |
def link_accounts(request): | |
if request.method == 'POST': # If the form has been submitted... | |
#De-listify the stupid freakin' post request11!!11 | |
form = LinkForm(initial=init) # A form bound to the POST data | |
print "HEREEEEEE" | |
if form.is_valid(): # All validation rules pass | |
# Process the data in form.cleaned_data | |
# ... | |
return HttpResponseRedirect('/thanks/') # Redirect after POST | |
else: | |
token = request.GET.get('token') | |
events, client = cal_events.getAllEvents(token) | |
calendars = cal_events.getAllCalendars(client) | |
calendar_choices = tuple((val, choice) for val, choice in enumerate(calendars)) | |
profiles = request.user.get_profile().profiles | |
profiles = eval(profiles) | |
profiles.pop("id") | |
profile_choices = tuple(((val, choice.capitalize()) for val, choice in enumerate(profiles.keys()))) | |
form = LinkForm(initial= {'calendar_choices': calendar_choices, | |
'share_choices': profile_choices, | |
'format_text': 'Hello World'}) | |
return render(request, 'link_form.html', { | |
'form': form, | |
}) | |
#forms.py | |
def link_accounts(request): | |
if request.method == 'POST': # If the form has been submitted... | |
#De-listify the stupid freakin' post request11!!11 | |
form = LinkForm(initial=init) # A form bound to the POST data | |
print "HEREEEEEE" | |
if form.is_valid(): # All validation rules pass | |
# Process the data in form.cleaned_data | |
# ... | |
return HttpResponseRedirect('/thanks/') # Redirect after POST | |
else: | |
token = request.GET.get('token') | |
events, client = cal_events.getAllEvents(token) | |
calendars = cal_events.getAllCalendars(client) | |
calendar_choices = tuple((val, choice) for val, choice in enumerate(calendars)) | |
profiles = request.user.get_profile().profiles | |
profiles = eval(profiles) | |
profiles.pop("id") | |
profile_choices = tuple(((val, choice.capitalize()) for val, choice in enumerate(profiles.keys()))) | |
form = LinkForm(initial= {'calendar_choices': calendar_choices, | |
'share_choices': profile_choices, | |
'format_text': 'Hello World'}) | |
return render(request, 'link_form.html', { | |
'form': form, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment