python - Django: Using Twitter credentials of users to fill in form data -
my application has simple form, , twitter login feature implemented using django-social-auth
forms.py
django import forms rango.models import evangelized class evangelizedform(forms.modelform): full_name = forms.charfield(help_text="full name") email = forms.charfield(help_text="email id") mobile_no = forms.charfield(help_text="mobile number") twitter_url = forms.charfield(help_text="twitter url") gender = forms.charfield(widget=forms.radioselect( choices=evangelized.gender_choices), help_text="gender", max_length = 128) area_of_interest = forms.charfield(max_length = 1230, widget=forms.checkboxselectmultiple( choices=evangelized.area_choices), help_text="areas of interest(upto 3)") """def clean_area_of_interest(self): if len(self.cleaned_data['area_of_interest']) > 3: raise forms.validationerror('select no more 3.') return self.cleaned_data['area_of_interest']""" other_area_of_interest = forms.field(help_text="other area of interest") city = forms.charfield(help_text="city") social_clout = forms.charfield(max_length = 1280, widget=forms.checkboxselectmultiple(choices=evangelized.social_clout_choices), help_text="i'd monetise social clout because ") other_social_accounts = forms.charfield(widget=forms.radioselect(choices=evangelized.bool_choices), help_text="do have other social accounts?", max_length=128) questions = forms.charfield(help_text="do have questions?", widget=forms.textarea) about_yourself = forms.charfield(help_text="tell yourself", widget=forms.textarea) referrer = forms.charfield(help_text="i heard platform via:") class meta: model = evangelized fields = ('full_name', 'email', 'mobile_no', 'twitter_url', 'gender', 'area_of_interest', 'other_area_of_interest', 'city', 'social_clout', 'other_social_accounts', 'questions', 'about_yourself', 'referrer')
models.py
from django.db import models class evangelized(models.model): full_name = models.charfield(max_length=128) email = models.emailfield() mobile_no = models.charfield(unique=true, max_length=128) twitter_url = models.charfield(unique=true, max_length=128) gender_choices = (('m', 'male'), ('f', 'female'), ('u', 'unisex/parody')) gender = models.charfield(choices=gender_choices, max_length = 128) area_choices = (('govt', 'govt'), ('entertainment', 'entertainment'), ('automobile', 'automobile'), ('careers', 'careers'), ('books', 'books'), ('family', 'family'), ('food', 'food'), ('gaming', 'gaming'), ('beauty', 'beauty'), ('sports', 'sports'), ('events', 'events'), ('business', 'business'), ('travel', 'travel'), ('health', 'health'), ('technology','technology')) area_of_interest = models.charfield(max_length = 1280) other_area_of_interest = models.charfield(blank=true, max_length=128) city = models.charfield(max_length=128) social_clout_choices = (('one', 'i think i\'ve built - earned - deserve it'), ('two', 'i\'d love raise funds favorite charity.'), ('three', 'i\'ve been doing it, more avenues won\'t hurt.')) social_clout = models.charfield(max_length = 1280) bool_choices = (('yes', 'yes'), ('no', 'no')) other_social_accounts = models.charfield(choices=bool_choices, max_length=128) questions = models.charfield(blank=true, max_length=1280) about_yourself = models.charfield(blank=false, max_length=1280) referrer = models.charfield(max_length=128)
views.py
from django.shortcuts import render django.http import httpresponse rango.models import evangelized rango.forms import evangelizedform django.http import httpresponseredirect, httpresponse def index(request): return httpresponse("<a href = '/rango/fillform'>microcelebrity form</a>") def fillform(request): if request.method == 'post': form = evangelizedform(request.post) if form.is_valid(): form.save(commit=true) return index(request) else: form.errors else: form = evangelizedform() return render(request, 'rango/fillform.html', {'form': form})
fillform.html
<body> <h1>microcelebrity form</h1><br> {% load twitter %} {% twitter_button %} <br> <form id="evangelized_form" method="post" action="/rango/fillform/"> {% csrf_token %} {% hidden in form.hidden_fields %} {{ hidden }} {% endfor %} {% field in form.visible_fields %} {{ field.errors }} <b>{{ field.help_text }}</b><br> {{ field }}<br><br> {% endfor %} <input type="submit" name="submit" value="submit" /> </form> </body>
now, want obtain email address, name , twitter account url user's twitter credentials. basically, after user has logged-in using twitter account details, want application redirect form, entries full name
, email id
, twitter url
pre-filled, user doesn't have enter details again, , has fill in details of other form fields.
how can make possible? leads appreciated. thanks.
Comments
Post a Comment