예제 #1
0
파일: views.py 프로젝트: jcdean/mirosubs
def profile(request, user_id):
    try:
        user = User.objects.get(username=user_id)
    except User.DoesNotExist:
        try:
            user = User.objects.get(id=user_id)
        except User.DoesNotExist:
            raise Http404
    profile = user.get_profile()
    # TODO: get user's activity
    if request.user == user:
        if request.method == 'POST':
            edit_profile_form = EditProfileForm(request.POST,
                                                instance=profile,
                                                files=request.FILES)
            if edit_profile_form.is_valid():
                edit_profile_form.save()
                request.user.message_set.create(message='Your profile has been updated.')
        else:
            edit_profile_form = EditProfileForm(instance=profile)
        return render_to_response('profiles/edit_profile.html', locals(),
                                  context_instance=RequestContext(request))
    else:
        return render_to_response('profiles/view_profile.html', locals(),
                                  context_instance=RequestContext(request))
예제 #2
0
def profile_edit(request):
    profile = get_object_or_404(Profile, pk=request.user.pk)
    if request.method == 'POST':
        form = EditProfileForm(request.POST)
        if form.is_valid():
            profile.about = form.cleaned_data['about']
            with transaction.atomic():
                profile.save()
                profile.update_view_adult_content(
                    form.cleaned_data['view_adult'])
            return HttpResponseRedirect(
                reverse('profiles:profiles_view_profile', args=(profile.id, )))
        else:
            print(form.errors)
            return None
    else:
        form = EditProfileForm(initial={
            'about': profile.about,
            'view_adult': profile.view_adult_content,
        })
        context = {
            'profile': profile,
            'form': form,
        }
        return render(request, 'profiles/edit_profile.html', context)
예제 #3
0
def edit_profile(request):
	user = request.user
	email = user.email
	#after submission
	if request.method == 'POST':
		edit_profile_form = EditProfileForm(request.POST, request.FILES, instance=user.profile)
		edit_user_form = EditUserForm(request.POST, request.FILES, instance=user, request=request)
		#success
		if edit_profile_form.is_valid() and edit_user_form.is_valid():
			ms = MailSnake('f92abfa01e0a9cecc885186de4e37106-us7')
			print user.email
			ms.listUpdateMember(id='ed61191f4e', email_address=email, merge_vars={
				'FNAME':edit_user_form.cleaned_data.get('first_name'),
				'LNAME':edit_user_form.cleaned_data.get('last_name'),
				'EMAIL':edit_user_form.cleaned_data.get('email'),
				})
			edit_profile_form.save()
			edit_user_form.save()
			return redirect('/profiles/' + user.username)
	#before submission 
	else:
		edit_profile_form = EditProfileForm(instance=user.profile)
		edit_user_form = EditUserForm(instance=user, request=request)

	user_profile = user
	return render(request, 'edit_profile.html', {'edit_profile_form': edit_profile_form, 'edit_user_form': edit_user_form, 'user_profile' : user_profile })
예제 #4
0
def profile_edit(request):
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return redirect('profile')

    form = EditProfileForm(instance=request.user)
    return render(request, 'profiles/profile_edit.html', {'form': form})
예제 #5
0
def editProfile(request):
    userForm = EditUserForm(request.POST or None, instance=request.user)
    profileForm = EditProfileForm(request.POST or None, request.FILES or None, instance=request.user.profile)
    if userForm.is_valid() and profileForm.is_valid():
            userForm.save()
            profileForm.save()
            return HttpResponseRedirect('/Now/')
    return render_to_response('profiles/editProfile.html',{'userForm':userForm, 'profileForm':profileForm},
                                    context_instance=RequestContext(request))
예제 #6
0
def profile_edit(request, pk):
    user = get_object_or_404(User, id=pk)
    form = EditProfileForm(request.POST or None, instance=user)
    if form.is_valid():
        form.save()
        return redirect('/u')

    template_name = 'profiles/user_edit.html'
    context = {'form': form, 'id': pk}
    return render(request, template_name, context)
예제 #7
0
def profile(request):
    message = ''
    if request.method == 'POST':
        form = EditProfileForm(request.POST, request.FILES, instance = request.user.profile)
        if form.is_valid():
            form.save()
            message = """Los datos de su perfil han sido editados correctamente"""
    else:
        user = request.user
        profile = user.profile #Con esta linea me trae el lambda definido en el modelo
        form = EditProfileForm(instance = profile)
    return render(request, 'profiles/edit.html', {
        'form':form, 
        'message':message
    })
예제 #8
0
def edit_profile(request):
    my_profile_form = EditProfileForm(request.POST or None,
                                      instance=request.user)

    if my_profile_form.is_valid():
        my_profile_form.save()
        return redirect('manage_profile')

    context = {
        'user': request.user,
        'user_roles': [role for role in request.user.roles],
        'my_profile_form': my_profile_form
    }

    return render(request, 'user/edit_profile.html', context)
예제 #9
0
def account(request):
    """
    Return active subscriptions from a Stripe customer as well as the customer
    and id
    """
    """
    def return_subs():
        customer_id = Subscription.objects.filter(user_id=request.user).first()
        if customer_id:
            customer_id = customer_id.customer_id
            customer = stripe.Customer.retrieve(customer_id)
        
            subscriptions = []
            for sub in customer.subscriptions.data:
                subscriptions.append(sub)
            
            if customer:
                # Filters out subscriptions terminated before today
                active_subscriptions = [sub for sub in subscriptions if sub.created < time.time()]
                
                for sub in active_subscriptions:
                    sub.created = datetime.datetime.fromtimestamp(float(sub.created))
                    sub.current_period_end = datetime.datetime.fromtimestamp(float(sub.current_period_end))
            else:
                customer = {}
                active_subscriptions = {}
                customer_id = None
            
        else:
            customer = {}
            active_subscriptions = {}
            customer_id = None
        
        return active_subscriptions, customer, customer_id
    """
    # If user has submitted change account details form
    if request.method == "POST" and 'account-change-submit' in request.POST:
        password_form = PasswordChangeForm(request.user)
        user_form = EditProfileForm(request.POST,
                                    instance=request.user,
                                    user=request.user)
        if user_form.is_valid():
            #active_subscriptions, customer, customer_id = return_subs()
            user = User.objects.get(pk=request.user.id)
            user_form.save()
            user = User.objects.get(pk=request.user.id)
            # Update email in Stripe if customer exists
            if customer_id:
                stripe.Customer.modify(customer_id,
                                       email=user_form.cleaned_data['email'])
        else:
            # Ensure request.user does not change based on user_form
            user = User.objects.get(pk=request.user.id)
            request.user = user
            #active_subscriptions, customer, customer_id = return_subs()

    # If user has submitted change password form
    elif request.method == "POST" and 'password-change-submit' in request.POST:
        user_form = EditProfileForm(instance=request.user, user=request.user)
        password_form = PasswordChangeForm(request.user, request.POST)
        if password_form.is_valid():
            password_form.save()
            update_session_auth_hash(request, password_form.user)
            #active_subscriptions, customer, customer_id = return_subs()
        else:
            pass
        #active_subscriptions, customer, customer_id = return_subs()
    else:
        user_form = EditProfileForm(instance=request.user, user=request.user)
        password_form = PasswordChangeForm(request.user)
        #active_subscriptions, customer, customer_id = return_subs()

    context = {
        'password_form': password_form,
        'user_form': user_form,
        #'customer': customer,
        #'active_subscriptions': active_subscriptions
    }

    return render(request, 'account.html', context)
예제 #10
0
def profile_page(request):
    context = {}

    print request.user
    print request.user.pk
    try:
        context['user'] = CustomUser.objects.get(pk=request.user.pk)
    except Exception, e:
        raise Http404('404')
    return render(request, 'profile_page.html', context)


def edit_profile(request):
    context = {}
    try:
        user = CustomUser.objects.get(pk=request.user.pk)
    except Exception, e:
        raise Http404('404')

    form = EditProfileForm(request.POST or None, instance=user)

    context['form'] = form

    if form.is_valid():
        form.save()
        return redirect('/profile/')
    else:
        print form.errors
    return render(request, 'edit_profile.html', context)