Beispiel #1
0
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,
    })
Beispiel #2
0
 def value_from_datadict(self, data, files, name):
     location_data = data.getlist(name)
     location_ids = []
     for data in location_data:
         if not data: continue
         location = Location.get_or_create(data)
         location_ids.append(location.id)
     return location_ids
Beispiel #3
0
def setup(request):
    sans_facebook = True if request.GET.has_key(
        'sans_facebook') and request.GET['sans_facebook'] else False
    redirect_to = request.GET.get('redirect_to', "/")

    form = CreateAccountForm(initial={
        'redirect_to': redirect_to,
    })
    if request.POST:
        sans_facebook = True if request.POST.has_key(
            'sans_facebook') and request.POST['sans_facebook'] else False
        form = CreateAccountForm(request.POST)
        if form.is_valid():
            u = User()
            u.bio = form.cleaned_data['bio']
            u.birth_year = form.cleaned_data['birth_year']
            u.email = u.long_email = form.cleaned_data['email']
            u.fb_access_token = form.cleaned_data['fb_access_token']
            u.gender = form.cleaned_data['gender']
            u.first_name = form.cleaned_data['first_name']
            u.last_name = form.cleaned_data['last_name']
            u.facebook_id = form.cleaned_data['fbid']
            u.bio = u.bio.encode('utf-8') if u.bio else ""
            u.first_name = u.first_name.encode('utf-8') if u.first_name else ""
            u.last_name = u.last_name.encode('utf-8') if u.last_name else ""
            if form.cleaned_data['location_data']:
                u.location = Location.get_or_create(
                    form.cleaned_data['location_data'])
            u.next_email_time = datetime.datetime.now() + timedelta(days=1)
            u.username = create_handle('%s%s' % (u.first_name, u.last_name))
            u.password = hash_password(form.cleaned_data['password'])
            u.save()

            Subscription.get_or_create(user=u, pub_id=NOTIFICATIONS_PUB)

            #Post to Facebook
            if form.cleaned_data['post_to_facebook']:
                fb_helpers.post_joined_to_wall(u)

            cache.put_on_handle(u, u.username)

            redirect_to = form.cleaned_data['redirect_to'] or '/'
            #perform for all that login magic that happens under the covers
            attempt_login(request, u.username, form.cleaned_data["password"])
            return set_auth_cookies(HttpResponseRedirect(redirect_to), u)

    return render(
        request, 'user/setup.html', {
            'title': 'Setup your account',
            'create_form': form,
            'sans_facebook': sans_facebook,
        })
Beispiel #4
0
def setup(request):
    sans_facebook = True if request.GET.has_key('sans_facebook') and request.GET['sans_facebook'] else False
    redirect_to = request.GET.get('redirect_to', "/")

    form = CreateAccountForm(initial={'redirect_to': redirect_to,})
    if request.POST:
        sans_facebook = True if request.POST.has_key('sans_facebook') and request.POST['sans_facebook'] else False
        form = CreateAccountForm(request.POST)
        if form.is_valid():
            u = User()
            u.bio = form.cleaned_data['bio']
            u.birth_year = form.cleaned_data['birth_year']
            u.email = u.long_email = form.cleaned_data['email']
            u.fb_access_token = form.cleaned_data['fb_access_token']
            u.gender = form.cleaned_data['gender']
            u.first_name = form.cleaned_data['first_name']
            u.last_name = form.cleaned_data['last_name']
            u.facebook_id = form.cleaned_data['fbid']
            u.bio = u.bio.encode('utf-8') if u.bio else ""
            u.first_name = u.first_name.encode('utf-8') if u.first_name else ""
            u.last_name = u.last_name.encode('utf-8') if u.last_name else ""
            if form.cleaned_data['location_data']:
                u.location = Location.get_or_create(form.cleaned_data['location_data'])
            u.next_email_time = datetime.datetime.now() + timedelta(days = 1)
            u.username = create_handle('%s%s' % (u.first_name, u.last_name))
            u.password = hash_password(form.cleaned_data['password'])
            u.save()

            Subscription.get_or_create(user = u, pub_id = NOTIFICATIONS_PUB)

            #Post to Facebook
            if form.cleaned_data['post_to_facebook']:
                fb_helpers.post_joined_to_wall(u)

            cache.put_on_handle(u, u.username)

            redirect_to = form.cleaned_data['redirect_to'] or '/'
            #perform for all that login magic that happens under the covers
            attempt_login(request, u.username, form.cleaned_data["password"])
            return set_auth_cookies(HttpResponseRedirect(redirect_to), u)

    return render(request, 'user/setup.html', {
        'title' : 'Setup your account',
        'create_form' : form,
        'sans_facebook': sans_facebook,
        })
Beispiel #5
0
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,
        })
Beispiel #6
0
 def value_from_datadict(self, data, files, name):
     location_data = data.get(name)
     location = Location.get_or_create(location_data)
     if location:
         return location.id
     return None