def post(self, request): form = UserSettingsForm(request.POST, request.FILES, instance=request.user) if form.is_valid(): form.save() return redirect('profile:settings') context = {'form': form} return render(request, self.template_name, context)
def settings(request): success = False if request.method == 'POST': form = UserSettingsForm(request.POST, request.FILES, instance=request.user) old_pw_hash = request.user.password if form.is_valid(): u = form.save(commit=False) if u.password: u.password = hash_password(u.password) else: u.password = old_pw_hash if form.cleaned_data['profile_pic']: u.upload_profile_pic(form.cleaned_data['profile_pic']) if form.cleaned_data['location_data']: u.location = Location.get_or_create(form.cleaned_data['location_data']) u.save() success = True else: if request.user.location: location_input = str(request.user.location) location_data = request.user.location.to_json() else: location_input = location_data = '' form = UserSettingsForm(instance=request.user, initial={'location_input':location_input, 'location_data':location_data,}) return render(request, 'user/settings.html', { 'success': success, #to drop a little notice like "CONGRATS #WINNING" 'entity':request.user, 'form': form, })
def settings(request): """displays the settings for an account""" user = request.user profile = user.get_profile() accounts = SocialAccount.objects.filter(user=user) accountlist = [] for account in accounts: accountlist.append(account.provider) apps = SocialApp.objects.all() context = {} if request.method == "POST": # If the form has been submitted... if request.POST["type"] == "location": lform = LocationForm(request.POST) mform = UserSettingsForm() if lform.is_valid(): # All validation rules pass if profile.location == None: location = Location() location.save() profile.location = location profile.save() else: location = profile.location location.city = lform.cleaned_data["city"] location.street = lform.cleaned_data["street"] location.postcode = lform.cleaned_data["postcode"] profile.displayLocation = lform.cleaned_data["displayLocation"] g = geocoders.Google() if location.city != "" or location.street != "" or location.street != "": try: places = g.geocode( location.street + ", " + location.postcode + " " + location.city, exactly_one=False ) location.latitude = places[0][1][0] location.longitude = places[0][1][1] location.save() except geocoders.google.GQueryError, e: messages.add_message( request, messages.ERROR, u"Es konnte kein Ort gefunden werden, der deiner Eingabe entspricht. Hast du dich vielleicht vertippt?", ) else: location.latitude = None location.longitude = None location.save() profile.save() else: lform = LocationForm() mform = UserSettingsForm(request.POST) mform.user = request.user if mform.is_valid(): if mform.cleaned_data["email"] != user.email: set_mail(user, mform.cleaned_data["email"]) if mform.cleaned_data["displayname"] != profile.displayname: profile.displayname = mform.cleaned_data["displayname"] profile.save() user.save()
def settings(request): """displays the settings for an account""" user = request.user profile = user.get_profile() accounts = SocialAccount.objects.filter(user=user) accountlist = [] for account in accounts: accountlist.append(account.provider) apps = SocialApp.objects.all() context = {} if request.method == 'POST': # If the form has been submitted... if request.POST["type"] == "location": lform = LocationForm(request.POST) mform = UserSettingsForm() if lform.is_valid(): # All validation rules pass if profile.location == None: location = Location() location.save() profile.location = location profile.save() else: location = profile.location location.city = lform.cleaned_data['city'] location.street = lform.cleaned_data['street'] location.postcode = lform.cleaned_data['postcode'] profile.displayLocation = lform.cleaned_data['displayLocation'] g = geocoders.Google() if location.city != "" or location.street != "" or location.street != "": try: places = g.geocode(location.street + ", " + location.postcode + " " + location.city, exactly_one=False) location.latitude = places[0][1][0] location.longitude = places[0][1][1] location.save() except geocoders.google.GQueryError, e: messages.add_message( request, messages.ERROR, u"Es konnte kein Ort gefunden werden, der deiner Eingabe entspricht. Hast du dich vielleicht vertippt?" ) else: location.latitude = None location.longitude = None location.save() profile.save() else: lform = LocationForm() mform = UserSettingsForm(request.POST) mform.user = request.user if mform.is_valid(): if mform.cleaned_data['email'] != user.email: set_mail(user, mform.cleaned_data['email']) if mform.cleaned_data['displayname'] != profile.displayname: profile.displayname = mform.cleaned_data['displayname'] profile.save() user.save()
def settings(request): success = False if request.method == 'POST': form = UserSettingsForm(request.POST, request.FILES, instance=request.user) old_pw_hash = request.user.password if form.is_valid(): u = form.save(commit=False) if u.password: u.password = hash_password(u.password) else: u.password = old_pw_hash if form.cleaned_data['profile_pic']: u.upload_profile_pic(form.cleaned_data['profile_pic']) if form.cleaned_data['location_data']: u.location = Location.get_or_create( form.cleaned_data['location_data']) u.save() success = True else: if request.user.location: location_input = str(request.user.location) location_data = request.user.location.to_json() else: location_input = location_data = '' form = UserSettingsForm(instance=request.user, initial={ 'location_input': location_input, 'location_data': location_data, }) return render( request, 'user/settings.html', { 'success': success, #to drop a little notice like "CONGRATS #WINNING" 'entity': request.user, 'form': form, })
location.save() profile.save() else: lform = LocationForm() mform = UserSettingsForm(request.POST) mform.user = request.user if mform.is_valid(): if mform.cleaned_data['email'] != user.email: set_mail(user, mform.cleaned_data['email']) if mform.cleaned_data['displayname'] != profile.displayname: profile.displayname = mform.cleaned_data['displayname'] profile.save() user.save() else: lform = LocationForm() mform = UserSettingsForm() if user.password != "": passform = ChangePasswordForm() else: passform = SetPasswordForm() context.update({ "apps": apps, "accountlist": accountlist, 'profile': profile, 'lform': lform, 'mform': mform, 'passform': passform }) map, showmap = create_map(profile.location) context["map"] = map context["showmap"] = showmap
def get(self, request): context = {'form': UserSettingsForm(instance=request.user)} return render(request, self.template_name, context)
def settings(request): """displays the settings for an account""" user = request.user profile = user.get_profile() accounts = SocialAccount.objects.filter(user=user) accountlist = [] for account in accounts: accountlist.append(account.provider) apps = SocialApp.objects.all() context = {} if request.method == 'POST': # If the form has been submitted... if request.POST["type"] == "location": lform = LocationForm(request.POST) mform = UserSettingsForm() if lform.is_valid(): # All validation rules pass if profile.location==None: location = Location() location.save() profile.location = location profile.save() else: location = profile.location location.city = lform.cleaned_data['city'] location.street = lform.cleaned_data['street'] location.postcode = lform.cleaned_data['postcode'] profile.displayLocation = lform.cleaned_data['displayLocation'] g = geocoders.Google() if location.city!= "" or location.street!="" or location.street!="": places = g.geocode(location.street + ", " + location.postcode + " " + location.city, exactly_one=False) location.latitude = places[0][1][0] location.longitude = places[0][1][1] else: location.latitude = None location.longitude = None location.save() profile.save() print profile.location.city else: lform = LocationForm() mform = UserSettingsForm(request.POST, request.FILES) if mform.is_valid(): print "valid" if 'avatar' in request.FILES: profile.avatar = request.FILES["avatar"] profile.save() print "file saved" if mform.cleaned_data['email'] != user.email: set_mail(user, mform.cleaned_data['email']) if mform.cleaned_data['displayname'] != profile.displayname: profile.displayname = mform.cleaned_data['displayname'] profile.save() user.save() else: lform = LocationForm() mform = UserSettingsForm() if not profile.mail_confirmed: context["mailconfirm"] = "We sent you a confirmation link. Please check your mail." context.update({"apps":apps, "accountlist":accountlist, 'profile':profile, 'lform':lform, 'mform':mform}) map, showmap = create_map(profile.location) context["map"] = map context["showmap"] = showmap return render_to_response('users/usersettings.html', context, RequestContext(request))