Пример #1
0
def profile_pic_upload(request):
    instance = get_object_or_404(Profile, id=request.user.profile.id)
    form = ProfilePhotoForm(request.POST, request.FILES, instance=instance)
    if form.is_valid():
        profile = form.save()
        data = {
            'is_valid': True,
            'name': profile.image.name,
            'url': profile.image.url
        }
    else:
        data = {'is_valid': False}
    return JsonResponse(data)
Пример #2
0
def profile_photo(request):
    if request.method == "POST":
        form = ProfilePhotoForm(request.FILES)

        if form.is_valid():
            if 'photo' in request.FILES:
                photo = request.FILES['photo']

                request.user.photo = settings.MEDIA_URL + save_photo_with_uuid(photo)

            request.user.save()

            return redirect(request.user)
    else:
        return HttpResponseNotFound()
Пример #3
0
 def dispatch(self, request, *args, **kwargs):
     meta = UserMetaData.objects.get( user = request.user )
     if not request.POST: address = AddressForm( instance = Address.objects.get( user = request.user ) )
     if not request.POST: pform = ProfilePhotoForm()
     try:
         photo = Photo.objects.get( user = request.user )
     except: 
         photo = None 
     if request.POST:
         if request.GET[ "f" ] == "a":
             address = AddressForm( request.POST )
             pform = ProfilePhotoForm()
             if address.is_valid():
                 obj = address.save( commit = False )
                 Address.objects.filter( user = request.user ).update( 
                                                                         city = obj.city,
                                                                         street = obj.street,
                                                                         postalCode = obj.postalCode,
                                                                         houseNo = obj.houseNo,
                                                                         flatNo = obj.flatNo,
                                                                         hide = obj.hide
                                                                      )
             else:
                 address = AddressForm( instance = Address.objects.get( user = request.user ) )
     
         elif request.GET[ "f" ]  == "p":
             address = AddressForm( instance = Address.objects.get( user = request.user ) )
             pform = ProfilePhotoForm( request.POST, request.FILES )
             print "ppp"
             if pform.is_valid():
                 print "valid"
                 obj = pform.save( commit = False )
                 Photo.objects.filter( user = request.user ).delete()
                 obj.user = request.user
                 obj.save()
                 photo = obj
             else:
                 pform = ProfilePhotoForm()
         else:
             address = AddressForm( instance = Address.objects.get( user = request.user ) )
             pform = ProfilePhotoForm()
     
     data = {
          "MEDIA_URL" : MEDIA_URL,
          "user" : request.user,
          "private" : True,
          "address" : address,
          "meta" : meta,
          "photo" : photo,
          "photo_form" :pform,
          "short": True
          }
     data.update( csrf( request ) )
     return render_to_response( "core/panel.html", data )