image handling

2015-03-24 Thread akash . patni
hi..
Can anyone please tell me how to handle old image after uploading new image.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/83341a1f-5684-4aad-8f87-268f25f15adb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread akash . patni
Hi ,
I want to delete the old image.

On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, akash...@ranosys.com 
wrote:
>
> hi..
> Can anyone please tell me how to handle old image after uploading new 
> image.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4aa4ac92-e622-4130-8ea0-dfbe46862c08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread akash . patni
This is my model
class User(models.Model):
first_name=models.CharField(verbose_name = "First Name 
*",max_length=20,blank=False)
last_name=models.CharField(verbose_name = "Last Name 
*",max_length=20,blank=False)
username=models.EmailField(verbose_name = "Email 
*",max_length=30,blank=False)
password=models.CharField(verbose_name = "Password 
*",max_length=15,blank=False)
dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
mobileno=models.CharField(verbose_name = "Mobile No 
*",max_length=20,blank=False)
houseno=models.CharField(verbose_name = "House 
No",max_length=10,blank=True)
address1=models.CharField(verbose_name = 
"Adress1",max_length=30,blank=True)
city=models.CharField(verbose_name = "City",max_length=20,blank=True)
state=models.CharField(verbose_name = "State",max_length=30,blank=True)
pincode=models.CharField(verbose_name = 
"Pincode",max_length=20,blank=True)
country=models.CharField(verbose_name = 
"Country",max_length=30,blank=True)
comment=models.CharField(verbose_name = 
"Comment",max_length=200,blank=True)
sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
image=models.FileField(verbose_name = "Image(limit 1Mb) 
*",blank=True,upload_to='media/')

def __unicode__(self):
return self.first_name


this is my form
class Registration(forms.ModelForm):
  password = forms.CharField(label='Password 
*',widget=forms.PasswordInput())
  image = forms.ImageField(label='Select a file *',help_text='max. 1 
megabytes')
  class Meta:

view.py
def registration(request):
#request.session.set_test_cookie()
if request.method == "POST":
regform=Registration(request.POST,request.FILES)
if regform.is_valid():
   #item=resize_and_crop(img_path, modified_path, size, 
crop_type='top')
   regform.save();
   return HttpResponseRedirect('/login/')

else:
return 
render_to_response('registration.html',{"form":regform})
else:
regform=Registration()
return render_to_response('registration.html',{"form":regform})


can anyone please tell how to handle this means how to delete the old image

Please...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b8cf2d1a-ce01-431e-9e86-cac5d8103cd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Image resizing

2015-03-24 Thread akash . patni
Hi..
can anyone please tell me how to resize the uploaded image
This is my model
class User(models.Model):
first_name=models.CharField(
verbose_name = "First Name *",max_length=20,blank=False)
last_name=models.CharField(verbose_name = "Last Name 
*",max_length=20,blank=False)
username=models.EmailField(verbose_name = "Email 
*",max_length=30,blank=False)
password=models.CharField(verbose_name = "Password 
*",max_length=15,blank=False)
dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
mobileno=models.CharField(verbose_name = "Mobile No 
*",max_length=20,blank=False)
houseno=models.CharField(verbose_name = "House 
No",max_length=10,blank=True)
address1=models.CharField(verbose_name = 
"Adress1",max_length=30,blank=True)
city=models.CharField(verbose_name = "City",max_length=20,blank=True)
state=models.CharField(verbose_name = "State",max_length=30,blank=True)
pincode=models.CharField(verbose_name = 
"Pincode",max_length=20,blank=True)
country=models.CharField(verbose_name = 
"Country",max_length=30,blank=True)
comment=models.CharField(verbose_name = 
"Comment",max_length=200,blank=True)
sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
image=models.FileField(verbose_name = "Image(limit 1Mb) 
*",blank=True,upload_to='media/')

def __unicode__(self):
return self.first_name


this is my form
class Registration(forms.ModelForm):
  password = forms.CharField(label='Password 
*',widget=forms.PasswordInput())
  image = forms.ImageField(label='Select a file *',help_text='max. 1 
megabytes')
  class Meta:

view.py
def registration(request):
#request.session.set_test_cookie()
if request.method == "POST":
regform=Registration(request.POST,request.FILES)
if regform.is_valid():
   #item=resize_and_crop(img_path, modified_path, size, 
crop_type='top')
   regform.save();
   return HttpResponseRedirect('/login/')

else:
return 
render_to_response('registration.html',{"form":regform})
else:
regform=Registration()
return render_to_response('registration.html',{"form":regform})


def show_profile(request):
if 'username' in request.session:
 obj_user=User.objects.all().order_by('-id')
 return 
render_to_response("index.html",{"obj_user":obj_user,"message":"Hello 
World"})
else:
return HttpResponseRedirect('/login/')

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5938a0d0-af8a-44aa-96c4-5d234f3e2cc4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread akash . patni
This is my edit profile function in view

def edit_profile(request):  
if 'username' in request.session:
user_id=request.POST.get('id')
user_id=request.GET.get('id')
usr_obj=User.objects.get(id=int(user_id))
if request.method=="POST":
regform=Registration(instance=usr_obj,data = request.POST)
if regform.is_valid():
regform.save();
return HttpResponseRedirect('/index/')
else:
return 
render_to_response("edit_profile.html",{"form":regform,})
else:   
user_id=request.GET.get('id')
usr_obj=User.objects.get(id=int(user_id))
 
#temp_data={'first_name':user_id.first_name,'last_name':user_id.last_name,'email':user_id.email,'password':user_id.password,'dob':user_id.dob,'mobileno':user_id.mobileno,'houseno':user_id.houseno,'address1':user_id.address1,'city':user_id.city,'state':user_id.state,'pincode':user_id.pincode,'country':user_id.country,'comment':user_id.comment,'sex':user_id.sex}
regform=Registration(instance=usr_obj)
return 
render_to_response("edit_profile.html",{"form":regform,"user_id":user_id})


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dc65c1d1-62dd-4cfe-b957-ec4b5b1278e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread akash . patni
hi
any answer

On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, akash...@ranosys.com 
wrote:
>
> hi..
> Can anyone please tell me how to handle old image after uploading new 
> image.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e3dbbee2-ebcb-4900-b833-d146ecebdbd8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread akash . patni
When i edit image that is when i upload new image,the old image should get 
deleted

On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, akash...@ranosys.com 
wrote:
>
> hi..
> Can anyone please tell me how to handle old image after uploading new 
> image.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ca9fa002-cbd5-4bbf-b42c-2a6ce88e8e0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Image resizing

2015-03-24 Thread Akash Patni
can you please suggest me another answer...

On Tue, Mar 24, 2015 at 6:13 PM, Andreas Kuhne 
wrote:

> Hi,
>
> Check out the easy_thumbnails plugin.
> http://easy-thumbnails.readthedocs.org/en/2.1/
>
> It automatically resizes all images to the size you want if you use it
> correctly.
>
> Regards,
>
> Andréas
>
> 2015-03-24 11:07 GMT+01:00 :
>
>> Hi..
>> can anyone please tell me how to resize the uploaded image
>> This is my model
>> class User(models.Model):
>> first_name=models.CharField(
>> verbose_name = "First Name *",max_length=20,blank=False)
>> last_name=models.CharField(verbose_name = "Last Name
>> *",max_length=20,blank=False)
>> username=models.EmailField(verbose_name = "Email
>> *",max_length=30,blank=False)
>> password=models.CharField(verbose_name = "Password
>> *",max_length=15,blank=False)
>> dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
>> mobileno=models.CharField(verbose_name = "Mobile No
>> *",max_length=20,blank=False)
>> houseno=models.CharField(verbose_name = "House
>> No",max_length=10,blank=True)
>> address1=models.CharField(verbose_name =
>> "Adress1",max_length=30,blank=True)
>> city=models.CharField(verbose_name = "City",max_length=20,blank=True)
>> state=models.CharField(verbose_name = "State",max_length=30,blank=
>> True)
>> pincode=models.CharField(verbose_name =
>> "Pincode",max_length=20,blank=True)
>> country=models.CharField(verbose_name =
>> "Country",max_length=30,blank=True)
>> comment=models.CharField(verbose_name = "Comment",max_length=200,
>> blank=True)
>> sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
>> image=models.FileField(verbose_name = "Image(limit 1Mb)
>> *",blank=True,upload_to='media/')
>>
>> def __unicode__(self):
>> return self.first_name
>>
>>
>> this is my form
>> class Registration(forms.ModelForm):
>>   password = forms.CharField(label='Password
>> *',widget=forms.PasswordInput())
>>   image = forms.ImageField(label='Select a file *',help_text='max. 1
>> megabytes')
>>   class Meta:
>>
>> view.py
>> def registration(request):
>> #request.session.set_test_cookie()
>> if request.method == "POST":
>> regform=Registration(request.POST,request.FILES)
>> if regform.is_valid():
>>#item=resize_and_crop(img_path, modified_path, size,
>> crop_type='top')
>>regform.save();
>>return HttpResponseRedirect('/login/')
>>
>> else:
>> return render_to_response('registration.html',{"form":
>> regform})
>> else:
>> regform=Registration()
>> return render_to_response('registration.html',{"form":regform})
>>
>>
>> def show_profile(request):
>> if 'username' in request.session:
>>  obj_user=User.objects.all().order_by('-id')
>>  return
>> render_to_response("index.html",{"obj_user":obj_user,"message":"Hello
>> World"})
>> else:
>> return HttpResponseRedirect('/login/')
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/5938a0d0-af8a-44aa-96c4-5d234f3e2cc4%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/5938a0d0-af8a-44aa-96c4-5d234f3e2cc4%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/XjuyFyKNnEI/unsubscribe.
> To unsubscribe from this group and all it

Re: image handling

2015-03-24 Thread Akash Patni
Hey,
I am new to django. I have other feilds also other than image field in my
form, so will you please tell me how to use above mentioned function in
edit_profile function in view, Can i call another function from another
function in views.py, if yes please tell me

On Tue, Mar 24, 2015 at 6:11 PM, Andreas Kuhne 
wrote:

> Hi,
>
> Ok, so what you should do is add a signal to pre save and then delete the
> old image if the new image is attached.
>
> Something like this should work:
>
> from django.core.files.storage import default_storage as storage
> from django.db.models.signals import pre_save
>
>
> def image_delete(sender, instance, *args, **kwargs):
>   if instance.pk:
> old_instance = User.objects.get(pk=instance.pk)
>
> if old_instance.image != instance.image and instance.image:
>   storage.delete(old_instance.image.name)
>
> pre_save.connect(image_delete, sender=User)
>
> You can see more information about signals here:
> https://docs.djangoproject.com/en/1.7/topics/signals/
>
> Regards,
>
> Andréas
>
> 2015-03-24 11:40 GMT+01:00 :
>
>> When i edit image that is when i upload new image,the old image should
>> get deleted
>>
>> On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, akash...@ranosys.com
>> wrote:
>>>
>>> hi..
>>> Can anyone please tell me how to handle old image after uploading new
>>> image.
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/ca9fa002-cbd5-4bbf-b42c-2a6ce88e8e0c%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/ca9fa002-cbd5-4bbf-b42c-2a6ce88e8e0c%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/oZrAdWgzwo0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALXYUbkpM6op303LMxA2iGNuzqgzB%3DjBPWw2KXkpjwdaho2Z%2BQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CALXYUbkpM6op303LMxA2iGNuzqgzB%3DjBPWw2KXkpjwdaho2Z%2BQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Best Regards,*
Akash Patni
Software Engineer




*[image: ranosys] <http://ranosys.com/>  [image: facebook]
<https://www.facebook.com/ranosys>[image: twitter]
<https://twitter.com/ranosys>[image: linkedin]
<https://www.linkedin.com/company/741079?trk=prof-exp-company-name>[image:
googleplus] <https://plus.google.com/+Ranosys> Head Office: Oxley Bizhub,
#06-48 | 73 Ubi Road 1 | Singapore - 408733Tel: +65 66331556  |  HP: +65
98573420Global Offices:San Francisco, USA | Jaipur, India | Bikaner, India*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANSMZiTGE4rue_LtY3YrsERGqBuy%3DoFX0eJb_9o81R_us-OibQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread Akash Patni
is there any other changes that i have to made in model like how this above
mentioned function will be call.

Please suggest

On Tue, Mar 24, 2015 at 6:43 PM, Andreas Kuhne 
wrote:

> Hi,
>
> You shouldn't do it in the view, do it in the database model instead. It
> won't do anything to any other fields than the image field the way I wrote
> the function (all other fields are untouched).
>
> The reason you shouldn't do it in the view, is because if you were to
> update the image any other place than via the view, the code wouldn't run.
> It's more sensible and more DRY to do it in the model.
>
> Regards,
>
> Andréas
>
> 2015-03-24 14:10 GMT+01:00 Akash Patni :
>
>> Hey,
>> I am new to django. I have other feilds also other than image field in my
>> form, so will you please tell me how to use above mentioned function in
>> edit_profile function in view, Can i call another function from another
>> function in views.py, if yes please tell me
>>
>> On Tue, Mar 24, 2015 at 6:11 PM, Andreas Kuhne <
>> andreas.ku...@suitopia.com> wrote:
>>
>>> Hi,
>>>
>>> Ok, so what you should do is add a signal to pre save and then delete
>>> the old image if the new image is attached.
>>>
>>> Something like this should work:
>>>
>>> from django.core.files.storage import default_storage as storage
>>> from django.db.models.signals import pre_save
>>>
>>>
>>> def image_delete(sender, instance, *args, **kwargs):
>>>   if instance.pk:
>>> old_instance = User.objects.get(pk=instance.pk)
>>>
>>> if old_instance.image != instance.image and instance.image:
>>>   storage.delete(old_instance.image.name)
>>>
>>> pre_save.connect(image_delete, sender=User)
>>>
>>> You can see more information about signals here:
>>> https://docs.djangoproject.com/en/1.7/topics/signals/
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>> 2015-03-24 11:40 GMT+01:00 :
>>>
>>>> When i edit image that is when i upload new image,the old image should
>>>> get deleted
>>>>
>>>> On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, akash...@ranosys.com
>>>> wrote:
>>>>>
>>>>> hi..
>>>>> Can anyone please tell me how to handle old image after uploading new
>>>>> image.
>>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to django-users@googlegroups.com.
>>>> Visit this group at http://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/ca9fa002-cbd5-4bbf-b42c-2a6ce88e8e0c%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/ca9fa002-cbd5-4bbf-b42c-2a6ce88e8e0c%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/django-users/oZrAdWgzwo0/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CALXYUbkpM6op303LMxA2iGNuzqgzB%3DjBPWw2KXkpjwdaho2Z%2BQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CALXYUbkpM6op303LMxA2iGNuzqgzB%3DjBPWw2KXkpjwdaho2Z%2BQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> *Best Regards,*
>> Akash Patni
>> Software Engineer
>>
>>
>>
>>
>> *[image: ranosys] <http://ranosys.com/>  [image: facebook]
>> <https://www.facebook.com/ranos

Re: image handling

2015-03-24 Thread Akash Patni
i had made the changes in model .py but its not working

here is model.py


from django.db import models
import django.forms as forms
from virtualenv import REQUIRED_FILES
from _mysql import NULL
from datetime import datetime, date, time, timedelta
import time
import calendar
from django.contrib.auth.models import User
import os
from uuid import uuid4
from django.core.files.storage import default_storage as storage
from django.db.models.signals import pre_save


def path_and_rename(path):
def wrapper(instance, filename):
ext = filename.split('.')[-1]
# get filename
if instance.pk:
filename = '{}.{}'.format(instance.pk, ext)
else:
# set filename as random string
filename = '{}.{}'.format(uuid4().hex, ext)
# return the whole path to the file
return os.path.join(path, filename)
return wrapper

def image_delete(sender, instance, *args, **kwargs):
  if instance.pk:
old_instance = User.objects.get(pk=instance.pk)

if old_instance.image != instance.image and instance.image:
  storage.delete(old_instance.image.name)

pre_save.connect(image_delete, sender=User)

class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()

def __unicode__(self):
return self.name

class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()

def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)

class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()

def __unicode__(self):
return self.title

class User(models.Model):
first_name=models.CharField(verbose_name = "First Name
*",max_length=20,blank=False)
last_name=models.CharField(verbose_name = "Last Name
*",max_length=20,blank=False)
username=models.EmailField(verbose_name = "Email
*",max_length=30,blank=False)
password=models.CharField(verbose_name = "Password
*",max_length=15,blank=False)
dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
mobileno=models.CharField(verbose_name = "Mobile No
*",max_length=20,blank=False)
houseno=models.CharField(verbose_name = "House
No",max_length=10,blank=True)
address1=models.CharField(verbose_name =
"Adress1",max_length=30,blank=True)
city=models.CharField(verbose_name = "City",max_length=20,blank=True)
state=models.CharField(verbose_name = "State",max_length=30,blank=True)
pincode=models.CharField(verbose_name =
"Pincode",max_length=20,blank=True)
country=models.CharField(verbose_name =
"Country",max_length=30,blank=True)
comment=models.CharField(verbose_name =
"Comment",max_length=200,blank=True)
sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
image=models.FileField(verbose_name = "Image(limit 1Mb)
*",blank=True,upload_to=path_and_rename(''))

def __unicode__(self):
return self.first_name




On Tue, Mar 24, 2015 at 6:47 PM, Akash Patni 
wrote:

> is there any other changes that i have to made in model like how this
> above mentioned function will be call.
>
> Please suggest
>
> On Tue, Mar 24, 2015 at 6:43 PM, Andreas Kuhne  > wrote:
>
>> Hi,
>>
>> You shouldn't do it in the view, do it in the database model instead. It
>> won't do anything to any other fields than the image field the way I wrote
>> the function (all other fields are untouched).
>>
>> The reason you shouldn't do it in the view, is because if you were to
>> update the image any other place than via the view, the code wouldn't run.
>> It's more sensible and more DRY to do it in the model.
>>
>> Regards,
>>
>> Andréas
>>
>> 2015-03-24 14:10 GMT+01:00 Akash Patni :
>>
>>> Hey,
>>> I am new to django. I have other feilds also other than image field in
>>> my form, so will you please tell me how to use above mentioned function in
>>> edit_profile function in view, Can i call another function from another
>>> function in views.py, if yes please tell me
>>>
>>> On Tue, Mar 24, 2015 at 6:11 PM, Andreas Kuhne <
>>> andreas.ku...@suitopia.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> Ok, so what you shoul

Re: image handling

2015-03-24 Thread Akash Patni
Hi,
I have added the code to my  __init__.py file but still its not working.

__init__.py
from django.core.files.storage import default_storage as storage
from django.db.models.signals import pre_save
from django.db import models
import django.forms as forms
from django.contrib.auth.models import User

def image_delete(sender, instance, *args, **kwargs):
  if instance.pk:
old_instance = User.objects.get(pk=instance.pk)

if old_instance.image != instance.image and instance.image:
  storage.delete(old_instance.image.name)
  pre_save.connect(image_delete, sender=User)

model.py

class User(models.Model):
first_name=models.CharField(verbose_name = "First Name
*",max_length=20,blank=False)
last_name=models.CharField(verbose_name = "Last Name
*",max_length=20,blank=False)
username=models.EmailField(verbose_name = "Email
*",max_length=30,blank=False)
password=models.CharField(verbose_name = "Password
*",max_length=15,blank=False)
dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
mobileno=models.CharField(verbose_name = "Mobile No
*",max_length=20,blank=False)
houseno=models.CharField(verbose_name = "House
No",max_length=10,blank=True)
address1=models.CharField(verbose_name =
"Adress1",max_length=30,blank=True)
city=models.CharField(verbose_name = "City",max_length=20,blank=True)
state=models.CharField(verbose_name = "State",max_length=30,blank=True)
pincode=models.CharField(verbose_name =
"Pincode",max_length=20,blank=True)
country=models.CharField(verbose_name =
"Country",max_length=30,blank=True)
comment=models.CharField(verbose_name =
"Comment",max_length=200,blank=True)
sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
image=models.FileField(verbose_name = "Image(limit 1Mb)
*",blank=True,upload_to=path_and_rename(''))

def __unicode__(self):
return self.first_name


On Tue, Mar 24, 2015 at 7:44 PM, Andreas Kuhne 
wrote:

> First, make sure that the whitespace is the same in all of your methods
> (in python whitespace is significant, which means that you should indent
> all files the same amount, I wrote my example in my email, so I only
> indented twice, you seem to have 4 blankspaces in your file, so make sure
> the indentation is the same).
>
> Secondly, I think that you should add the code I sent to the __init__.py
> file in the project itself (in the same directory that you have you
> models.py). That way it will be run during startup (which needs to be done).
>
> Regards,
>
> Andréas
>
> 2015-03-24 14:20 GMT+01:00 Akash Patni :
>
>> i had made the changes in model .py but its not working
>>
>> here is model.py
>>
>>
>> from django.db import models
>> import django.forms as forms
>> from virtualenv import REQUIRED_FILES
>> from _mysql import NULL
>> from datetime import datetime, date, time, timedelta
>> import time
>> import calendar
>> from django.contrib.auth.models import User
>> import os
>> from uuid import uuid4
>> from django.core.files.storage import default_storage as storage
>> from django.db.models.signals import pre_save
>>
>>
>> def path_and_rename(path):
>> def wrapper(instance, filename):
>> ext = filename.split('.')[-1]
>> # get filename
>> if instance.pk:
>> filename = '{}.{}'.format(instance.pk, ext)
>> else:
>> # set filename as random string
>> filename = '{}.{}'.format(uuid4().hex, ext)
>> # return the whole path to the file
>> return os.path.join(path, filename)
>> return wrapper
>>
>> def image_delete(sender, instance, *args, **kwargs):
>>   if instance.pk:
>> old_instance = User.objects.get(pk=instance.pk)
>>
>> if old_instance.image != instance.image and instance.image:
>>   storage.delete(old_instance.image.name)
>>
>> pre_save.connect(image_delete, sender=User)
>>
>> class Publisher(models.Model):
>> name = models.CharField(max_length=30)
>> address = models.CharField(max_length=50)
>> city = models.CharField(max_length=60)
>> state_province = models.CharField(max_length=30)
>> country = models.CharField(max_length=50)
>> website = models.URLField()
>>
>> def __unicode__(self):
>> return self.name
>>
>> class Author(models.Model):
>> first_name = models.CharField(max_length=30)
>> last_name = models.CharField(max_length=40)
>> email = models

Re: image handling

2015-03-24 Thread Akash Patni
Hi,
Can i use this method in my model.py

def save(self, *args, **kwargs):
try:
this = MyModelName.objects.get(id=self.id)
if this.MyImageFieldName != self.MyImageFieldName:
this.MyImageFieldName.delete()
except: pass
super(MyModelName, self).save(*args, **kwargs)


class User(models.Model):

  image=models.FileField(verbose_name = "Image(limit 1Mb)
*",blank=True,upload_to=path_and_rename('')*,storage=save('self')*)

  def __unicode__(self):
return self.first_name
i have doubt about storage in my file field which i have
highlighted. Is it right, Please sugges.



On Wed, Mar 25, 2015 at 9:28 AM, Akash Patni 
wrote:

> Hi,
> I have added the code to my  __init__.py file but still its not working.
>
> __init__.py
> from django.core.files.storage import default_storage as storage
> from django.db.models.signals import pre_save
> from django.db import models
> import django.forms as forms
> from django.contrib.auth.models import User
>
> def image_delete(sender, instance, *args, **kwargs):
>   if instance.pk:
> old_instance = User.objects.get(pk=instance.pk)
>
> if old_instance.image != instance.image and instance.image:
>   storage.delete(old_instance.image.name)
>   pre_save.connect(image_delete, sender=User)
>
> model.py
>
> class User(models.Model):
> first_name=models.CharField(verbose_name = "First Name
> *",max_length=20,blank=False)
> last_name=models.CharField(verbose_name = "Last Name
> *",max_length=20,blank=False)
> username=models.EmailField(verbose_name = "Email
> *",max_length=30,blank=False)
> password=models.CharField(verbose_name = "Password
> *",max_length=15,blank=False)
> dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
> mobileno=models.CharField(verbose_name = "Mobile No
> *",max_length=20,blank=False)
> houseno=models.CharField(verbose_name = "House
> No",max_length=10,blank=True)
> address1=models.CharField(verbose_name =
> "Adress1",max_length=30,blank=True)
> city=models.CharField(verbose_name = "City",max_length=20,blank=True)
> state=models.CharField(verbose_name = "State",max_length=30,blank=True)
> pincode=models.CharField(verbose_name =
> "Pincode",max_length=20,blank=True)
> country=models.CharField(verbose_name =
> "Country",max_length=30,blank=True)
> comment=models.CharField(verbose_name =
> "Comment",max_length=200,blank=True)
> sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
> image=models.FileField(verbose_name = "Image(limit 1Mb)
> *",blank=True,upload_to=path_and_rename(''))
>
> def __unicode__(self):
> return self.first_name
>
>
> On Tue, Mar 24, 2015 at 7:44 PM, Andreas Kuhne  > wrote:
>
>> First, make sure that the whitespace is the same in all of your methods
>> (in python whitespace is significant, which means that you should indent
>> all files the same amount, I wrote my example in my email, so I only
>> indented twice, you seem to have 4 blankspaces in your file, so make sure
>> the indentation is the same).
>>
>> Secondly, I think that you should add the code I sent to the __init__.py
>> file in the project itself (in the same directory that you have you
>> models.py). That way it will be run during startup (which needs to be done).
>>
>> Regards,
>>
>> Andréas
>>
>> 2015-03-24 14:20 GMT+01:00 Akash Patni :
>>
>>> i had made the changes in model .py but its not working
>>>
>>> here is model.py
>>>
>>>
>>> from django.db import models
>>> import django.forms as forms
>>> from virtualenv import REQUIRED_FILES
>>> from _mysql import NULL
>>> from datetime import datetime, date, time, timedelta
>>> import time
>>> import calendar
>>> from django.contrib.auth.models import User
>>> import os
>>> from uuid import uuid4
>>> from django.core.files.storage import default_storage as storage
>>> from django.db.models.signals import pre_save
>>>
>>>
>>> def path_and_rename(path):
>>> def wrapper(instance, filename):
>>> ext = filename.split('.')[-1]
>>> # get filename
>>> if instance.pk:
>>> filename = '{}.{}'.format(instance.pk, ext)
>>> else:
>>> # set filename as random string
>>> filename

Re: Image resizing

2015-03-25 Thread Akash Patni
For image resizing i have used the following function*(in bold).*Is it
right??

def edit_profile(request):

if 'username' in request.session:
#user_id=request.POST.get('id')
user_id=request.GET.get('id')
usr_obj=User.objects.get(id=int(user_id))
if request.method=="POST":
if(request.POST['houseno']!=''):
  houseno=request.POST['houseno']
else:
  houseno=None
if(request.POST['address1']!=''):
  address1=request.POST['address1']
else:
  address1=None
if(request.POST['city']!=''):
  city=request.POST['city']
else:
  city=None
if(request.POST['state']!=''):
  state=request.POST['state']
else:
  state=None
if(request.POST['pincode']!=''):
  pincode=request.POST['pincode']
else:
  pincode=None
if(request.POST['country']!=''):
  country=request.POST['country']
else:
  country=None
if(request.POST['comment']!=''):
  comment=request.POST['comment']
else:
  comment=None

regform=Edit_Registration(instance=usr_obj,data=request.POST)

if regform.is_valid():
  *  try:*
*from PIL import Image, ImageOps*
*except ImportError:*
*import Image*
*import ImageOps*
*imagecontent=request.FILES['image']---At this point it
is giving MultiValueDicitionayKeyError(though the field name is same that
is image)*
*if imagecontent.mode not in ("L", "RGB"):*
*image = imagecontent.convert("RGB")*
*imageresize = image.resize((100,100),
Image.ANTIALIAS) *
*imageresize.save( 'JPEG', quality=75)*
*regform.save();*
return HttpResponseRedirect('/index/')
else:
return
render_to_response("edit_profile.html",{"form":regform,})
else:


regform=Edit_Registration(instance=usr_obj)
return
render_to_response("edit_profile.html",{"form":regform,"user_id":user_id})
else:
    return HttpResponseRedirect('/login/')

Please Suggest..

On Tue, Mar 24, 2015 at 6:41 PM, Andreas Kuhne 
wrote:

> You can use Pillow to change the size of the images yourself. That is
> however pretty complicated and IMO not really worth the effort. I would go
> with easy_thumbnails.
>
> Regards,
>
> Andréas
>
> 2015-03-24 14:04 GMT+01:00 Akash Patni :
>
>> can you please suggest me another answer...
>>
>> On Tue, Mar 24, 2015 at 6:13 PM, Andreas Kuhne <
>> andreas.ku...@suitopia.com> wrote:
>>
>>> Hi,
>>>
>>> Check out the easy_thumbnails plugin.
>>> http://easy-thumbnails.readthedocs.org/en/2.1/
>>>
>>> It automatically resizes all images to the size you want if you use it
>>> correctly.
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>> 2015-03-24 11:07 GMT+01:00 :
>>>
>>>> Hi..
>>>> can anyone please tell me how to resize the uploaded image
>>>> This is my model
>>>> class User(models.Model):
>>>> first_name=models.CharField(
>>>> verbose_name = "First Name *",max_length=20,blank=False)
>>>> last_name=models.CharField(verbose_name = "Last Name
>>>> *",max_length=20,blank=False)
>>>> username=models.EmailField(verbose_name = "Email
>>>> *",max_length=30,blank=False)
>>>> password=models.CharField(verbose_name = "Password
>>>> *",max_length=15,blank=False)
>>>> dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
>>>> mobileno=models.CharField(verbose_name = "Mobile No
>>>> *",max_length=20,blank=False)
>>>> houseno=models.CharField(verbose_name = "House
>>>> No",max_length=10,bl

Re: image handling

2015-03-25 Thread Akash Patni
Hi..
ok will not give storage parameter, but how the function save will
called.Will it be called automatically when i edit image.

I have used upload function to call a function which change the name of the
image and save it to the database.

On Wed, Mar 25, 2015 at 1:44 PM, Andreas Kuhne 
wrote:

> Hi,
>
> No, that is not correct. The storage parameter has nothing to do with
> this. Also, why are you not using an ImageField instead of the FileField?
> Also you have to put all methods with "self" as a parameter with the class
> itself. Self is a pointer to the instance of the class, so it needs to be
> within the class.
>
> You should do it this way:
>
> class User:
> image = models.ImageField(verbose_name="Image (limit 1Mb) *",
> blank=True, upload_to='var/user/images')
>
> def save(self, *args, **kwargs):
> try:
> original_image = User.objects.get(id=self.id)
> if original_image.image != self.image:
> original_image.image.delete()
> except:
> pass
> super(User, self).save(*args, **kwargs)
>
> Of course the other parts of the user object needs to be added as well. As
> you can see, I have also set a path for upload_to instead of a function,
> because using a function is only necessary when you want to set a unique
> path for each image (for example using the id for it).
>
> Regards,
>
> Andréas
>
> 2015-03-25 5:26 GMT+01:00 Akash Patni :
>
>> Hi,
>> Can i use this method in my model.py
>>
>> def save(self, *args, **kwargs):
>> try:
>> this = MyModelName.objects.get(id=self.id)
>> if this.MyImageFieldName != self.MyImageFieldName:
>> this.MyImageFieldName.delete()
>> except: pass
>> super(MyModelName, self).save(*args, **kwargs)
>>
>>
>> class User(models.Model):
>>
>>   image=models.FileField(verbose_name = "Image(limit 1Mb) 
>> *",blank=True,upload_to=path_and_rename('')*,storage=save('self')*)
>>
>>   def __unicode__(self):
>> return self.first_name
>> i have doubt about storage in my file field which i have highlighted. Is 
>> it right, Please sugges.
>>
>>
>>
>> On Wed, Mar 25, 2015 at 9:28 AM, Akash Patni 
>> wrote:
>>
>>> Hi,
>>> I have added the code to my  __init__.py file but still its not working.
>>>
>>> __init__.py
>>> from django.core.files.storage import default_storage as storage
>>> from django.db.models.signals import pre_save
>>> from django.db import models
>>> import django.forms as forms
>>> from django.contrib.auth.models import User
>>>
>>> def image_delete(sender, instance, *args, **kwargs):
>>>   if instance.pk:
>>> old_instance = User.objects.get(pk=instance.pk)
>>>
>>> if old_instance.image != instance.image and instance.image:
>>>   storage.delete(old_instance.image.name)
>>>   pre_save.connect(image_delete, sender=User)
>>>
>>> model.py
>>>
>>> class User(models.Model):
>>> first_name=models.CharField(verbose_name = "First Name
>>> *",max_length=20,blank=False)
>>> last_name=models.CharField(verbose_name = "Last Name
>>> *",max_length=20,blank=False)
>>> username=models.EmailField(verbose_name = "Email
>>> *",max_length=30,blank=False)
>>> password=models.CharField(verbose_name = "Password
>>> *",max_length=15,blank=False)
>>> dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
>>> mobileno=models.CharField(verbose_name = "Mobile No
>>> *",max_length=20,blank=False)
>>> houseno=models.CharField(verbose_name = "House
>>> No",max_length=10,blank=True)
>>> address1=models.CharField(verbose_name =
>>> "Adress1",max_length=30,blank=True)
>>> city=models.CharField(verbose_name = "City",max_length=20,blank=True)
>>> state=models.CharField(verbose_name =
>>> "State",max_length=30,blank=True)
>>> pincode=models.CharField(verbose_name =
>>> "Pincode",max_length=20,blank=True)
>>> country=models.CharField(verbose_name =
>>> "Country",max_length=30,blank=True)
>>> comment=models.CharField(verbose_name =
>>> "Comment",max_length=200,blank=True)
>>> sex=models.CharField(verbose_name = "Sex *",max_leng

Re: Image resizing

2015-03-25 Thread Akash Patni
if regform.is_valid():

image_file =
StringIO.StringIO(request.FILES['image'].read())
image = Image.open(image_file)

imageresize = image.resize((100,100), Image.ANTIALIAS)
*imageresize.save( 'abc.JPEG', quality=75)*
regform.save();
return HttpResponseRedirect('/index/')
else:
regform=Edit_Registration(instance=usr_obj)
return
render_to_response("edit_profile.html",{"form":regform,})
else:
#user_id=request.GET.get('id')
#usr_obj=User.objects.get(id=int(user_id))

 
#temp_data={'first_name':user_id.first_name,'last_name':user_id.last_name,'email':user_id.email,'password':user_id.password,'dob':user_id.dob,'mobileno':user_id.mobileno,'houseno':user_id.houseno,'address1':user_id.address1,'city':user_id.city,'state':user_id.state,'pincode':user_id.pincode,'country':user_id.country,'comment':user_id.comment,'sex':user_id.sex}
regform=Edit_Registration(instance=usr_obj)
return
render_to_response("edit_profile.html",{"form":regform,"user_id":user_id})
else:
return HttpResponseRedirect('/login/')

Hey ,
I am using the above method and able to resize the image but it is only
taking JPEG format and i want other format also. Can u please suggest
*imageresize.save( 'abc.JPEG', quality=75) it can take three
parameters..name, format and quality*

On Wed, Mar 25, 2015 at 1:29 PM, Andreas Kuhne 
wrote:

> Hi,
>
> Again, you should really put this in your database model instead of in the
> view. If you use your overriden save function, you would be able to add
> this there. Also, you check if the image is not an L or RGB image (don't
> know what L is) and resize it ONLY if it is on of them.
>
> Regards,
>
> Andréas
>
> 2015-03-25 8:26 GMT+01:00 Akash Patni :
>
>> For image resizing i have used the following function*(in bold).*Is it
>> right??
>>
>> def edit_profile(request):
>>
>> if 'username' in request.session:
>> #user_id=request.POST.get('id')
>> user_id=request.GET.get('id')
>> usr_obj=User.objects.get(id=int(user_id))
>> if request.method=="POST":
>> if(request.POST['houseno']!=''):
>>   houseno=request.POST['houseno']
>> else:
>>   houseno=None
>> if(request.POST['address1']!=''):
>>   address1=request.POST['address1']
>> else:
>>   address1=None
>> if(request.POST['city']!=''):
>>   city=request.POST['city']
>> else:
>>   city=None
>> if(request.POST['state']!=''):
>>   state=request.POST['state']
>> else:
>>   state=None
>> if(request.POST['pincode']!=''):
>>   pincode=request.POST['pincode']
>> else:
>>   pincode=None
>> if(request.POST['country']!=''):
>>   country=request.POST['country']
>> else:
>>   country=None
>> if(request.POST['comment']!=''):
>>   comment=request.POST['comment']
>> else:
>>   comment=None
>>
>> regform=Edit_Registration(instance=usr_obj,data=request.POST)
>>
>> if regform.is_valid():
>>   *  try:*
>> *from PIL import Image, ImageOps*
>> *except ImportError:*
>> *import Image*
>> *import ImageOps*
>> *imagecontent=request.FILES['image']---At this point
>> it is giving MultiValueDicitionayKeyError(though the field name is same
>> that is image)*
>> *if imagecontent.mode not in ("L", "RGB"):*
>> *image = image

Re: Image resizing

2015-03-26 Thread Akash Patni
*Hi,*
*Resizing is now working properly but the issue is that it is giving key
error.*
*it is taking all files for eg(images.bmp,xx.jpeg) but is giving error when
i am tryint to upload the file  (luzern-bridge-8q4_small.jpg) In short it
is giving error for jpg format. Please suggest*


def edit_profile(request):
# data = Thumbnail.objects.get(pk=id)
if 'username' in request.session:
#user_id=request.POST.get('id')
user_id=request.GET.get('id')
usr_obj=User.objects.get(id=int(user_id))
if request.method=="POST":


regform=Edit_Registration(instance=usr_obj,data=request.POST)

if regform.is_valid():
 image_file =
StringIO.StringIO(request.FILES['image'].read())

 imagename=request.FILES['image'].name

 ext = imagename.split('.')[-1]

 image = Image.open(image_file)

 imageresize = image.resize((100,100), Image.ANTIALIAS)

 filename =
hashlib.md5(image_file.getvalue()).hexdigest()+'.'+ext

*
imageresize.save("/home/ranosys-akash/workspace/mysite/src/media/"+filename,
ext, quality=75)*
* error at above line(key error...*u'JPG'*)*

 usr_obj.image=filename

 regform.save();
 return HttpResponseRedirect('/index/')
else:
 regform=Edit_Registration(instance=usr_obj)
 return
render_to_response("edit_profile.html",{"form":regform,})
else:
#user_id=request.GET.get('id')
#usr_obj=User.objects.get(id=int(user_id))

 
#temp_data={'first_name':user_id.first_name,'last_name':user_id.last_name,'email':user_id.email,'password':user_id.password,'dob':user_id.dob,'mobileno':user_id.mobileno,'houseno':user_id.houseno,'address1':user_id.address1,'city':user_id.city,'state':user_id.state,'pincode':user_id.pincode,'country':user_id.country,'comment':user_id.comment,'sex':user_id.sex}
regform=Edit_Registration(instance=usr_obj)
return
render_to_response("edit_profile.html",{"form":regform,"user_id":user_id})
else:
return HttpResponseRedirect('/login/')



On Thu, Mar 26, 2015 at 9:37 AM, Akash Patni 
wrote:

> if regform.is_valid():
>
> image_file =
> StringIO.StringIO(request.FILES['image'].read())
> image = Image.open(image_file)
>
> imageresize = image.resize((100,100), Image.ANTIALIAS)
> *imageresize.save( 'abc.JPEG', quality=75)*
> regform.save();
> return HttpResponseRedirect('/index/')
> else:
> regform=Edit_Registration(instance=usr_obj)
> return
> render_to_response("edit_profile.html",{"form":regform,})
> else:
> #user_id=request.GET.get('id')
> #usr_obj=User.objects.get(id=int(user_id))
>
>  
> #temp_data={'first_name':user_id.first_name,'last_name':user_id.last_name,'email':user_id.email,'password':user_id.password,'dob':user_id.dob,'mobileno':user_id.mobileno,'houseno':user_id.houseno,'address1':user_id.address1,'city':user_id.city,'state':user_id.state,'pincode':user_id.pincode,'country':user_id.country,'comment':user_id.comment,'sex':user_id.sex}
> regform=Edit_Registration(instance=usr_obj)
> return
> render_to_response("edit_profile.html",{"form":regform,"user_id":user_id})
> else:
> return HttpResponseRedirect('/login/')
>
> Hey ,
> I am using the above method and able to resize the image but it is only
> taking JPEG format and i want other format also. Can u please suggest
> *imageresize.save( 'abc.JPEG', quality=75) it can take three
> parameters..name, format and quality*
>
> On Wed, Mar 25, 2015 at 1:29 PM, Andreas Kuhne  > wrote:
>
>> Hi,
>>
>> Again, you should really put this in your database model instead of in
>> the view. If you use your overriden save function, you would be able to add
>> this there. Also, you check if the image is not an L or RGB image (don't
>> know what L is) and resize it ONLY if it is on of them.
>>
>> Regards,
>>

Textarea taking htnml tags

2015-03-26 Thread akash . patni
Hie to all,
In one of my template i am using text area. The issue is that when i write 
html tags with some image link using img tag, when i am saving this i am 
getting image on the desription field.

Actual-Image is comming

Expected-I want HTML code to be displayed in the discription.

Please suggest

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/32bb3e0a-1eb1-46d1-94fe-4135c7c916df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


textarea showing image instead of code

2015-03-27 Thread akash . patni
Hie to all,
In one of my template i am using text area. The issue is that when i write 
html tags with some image link using img tag, when i am saving this i am 
getting image on the desription field.

Actual-Image is comming

Expected-I want HTML code to be displayed in the discription.

Please suggest

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/597ca45f-a1d9-43a4-a77b-a4ffc29d1b69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: textarea showing image instead of code

2015-03-27 Thread Akash Patni
Hi This is my html

{% block content %}



  

View Notes
See your notes details.
  
  

{% for i in result %}

Note Title
{{i.note_title}}



Note
*{{i.note}*





Beneficiaries

{% if all_nominees %}
{% for nominee in all_nominees %}
{% if nominee.1 %}
{{nominee.0.first_name}} {% if nominee.last_name
%}{{nominee.last_name}}{% endif %} {% if nominee.0.is_charity %}(charity){%
else %}(individual){% endif %}

{% endif %}
{% endfor %}
{% else %}
No beneficiaries at the moment.
{% endif %}





Action

Edit
Delete



  {% endfor %}

{% endblock %}

This is my model

class AssetNotes(db.Model):
user_id = db.ReferenceProperty(User)
written_on = db.DateProperty(verbose_name="Note Date")
note_title = db.StringProperty(verbose_name = "Note Title *")
note = db.TextProperty(verbose_name = "Note")
add_date = db.DateTimeProperty(verbose_name=None, auto_now_add=True)
update_date = db.DateTimeProperty(verbose_name=None, auto_now=True)
client_id = db.StringProperty(verbose_name = "Client ID", default="")
def __unicode__(self):
return self.note_title
I want to show only code but instead of that it is showing image in
descrption field.

and the code contains image url.

On Fri, Mar 27, 2015 at 2:41 PM, aRkadeFR  wrote:

>  Hello,
>
> You could provide us more information when asking for
> help please. Your template and view code at least.
>
> I guess your problem is in your HTML but to be sure, please
> dump your information at the POST request to see what
> is send. Then review your template. Maybe there's a "name"
> attribute on the img tag?
>
> Have a good one
>
> On 03/27/2015 08:36 AM, akash.pa...@ranosys.com wrote:
>
> Hie to all,
> In one of my template i am using text area. The issue is that when i write
> html tags with some image link using img tag, when i am saving this i am
> getting image on the desription field.
>
> Actual-Image is comming
>
> Expected-I want HTML code to be displayed in the discription.
>
> Please suggest
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/597ca45f-a1d9-43a4-a77b-a4ffc29d1b69%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/597ca45f-a1d9-43a4-a77b-a4ffc29d1b69%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/6bheSzmXFGc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/55151EC7.3090403%40arkade.info
> <https://groups.google.com/d/msgid/django-users/55151EC7.3090403%40arkade.info?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Best Regards,*
Akash Patni
Software Engineer




*[image: ranosys] <http://ranosys.com/>  [image: facebook]
<https://www.facebook.com/ranosys>[image: twitter]
<https://twitter.com/ranosys>[image: linkedin]
<https://www.linkedin.com/company/741079?trk=prof-exp-company-name>[image:
googleplus] <https://plus.google.com/+Ranosys> Head Office: Oxley Bizhub,
#06-48 | 73 Ubi Road 1 | Singapore - 408733Tel: +65 66331556  |  HP: +65
98573420Global Offices:San Francisco, USA | Jaipur, India | Bikaner, India*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANSMZiRzDaCqCJG-QF-t6Bk6ckKsk4fgZFcTq%3DbgVYNPVrHiMg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Textarea taking htnml tags

2015-03-29 Thread Akash Patni
*Hi,*
*This my template*
{% block content %}



  

View Notes
See your notes details.
  
  

{% for i in result %}

Note Title
{{i.note_title}}



Note
 *{{i.note}}*





Beneficiaries

{% if all_nominees %}
{% for nominee in all_nominees %}
{% if nominee.1 %}
{{nominee.0.first_name}} {% if nominee.last_name
%}{{nominee.last_name}}{% endif %} {% if nominee.0.is_charity %}(charity){%
else %}(individual){% endif %}

{% endif %}
{% endfor %}
{% else %}
No beneficiaries at the moment.
{% endif %}





Action

Edit
Delete



  {% endfor %}

{% endblock %}


On Fri, Mar 27, 2015 at 11:30 PM, aRkadeFR  wrote:

>  Hey,
>
> He doubled post. A thread already exists about this called:
> "textarea showing image instead of code"
>
>
>
> On 03/27/2015 03:54 PM, Filipe Ximenes wrote:
>
> Can you send us the code of the view and the template of this form?
>
> On Fri, Mar 27, 2015 at 3:27 AM,  wrote:
>
>> Hie to all,
>> In one of my template i am using text area. The issue is that when i
>> write html tags with some image link using img tag, when i am saving this i
>> am getting image on the desription field.
>>
>> Actual-Image is comming
>>
>> Expected-I want HTML code to be displayed in the discription.
>>
>> Please suggest
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/32bb3e0a-1eb1-46d1-94fe-4135c7c916df%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/32bb3e0a-1eb1-46d1-94fe-4135c7c916df%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
>  --
>
>
> *Filipe Ximenes *+55 (81) 8245-9204
>
> *Vinta Software Studio *http://www.vinta.com.br
>   --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAA-QWB3OPdmK11XzPFf--2MBT6evTDu-RuRrPArem1PbZT2FmA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAA-QWB3OPdmK11XzPFf--2MBT6evTDu-RuRrPArem1PbZT2FmA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/cpx4qG6daPU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/55159AA1.9070605%40arkade.info
> <https://groups.google.com/d/msgid/django-users/55159AA1.9070605%40arkade.info?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Best Regards,*
Akash Patni
Software Engineer




*[image: ranosys] <http://ranosys.com/>  [image: facebook]
<https://www.facebook.com/ranosys>[image: twitter]
<https://twitter.com/ranosys>[image: linkedin]
<https://www.linkedin.com/company/741079?trk=prof-exp-company-name>[image:
googleplus] <https://plus.google.com/+Ranosys> Head Office: Oxley Bizhub,
#06-48 | 73 Ubi Road 1 | Singapore - 408733Tel: +65 66331556  |  HP: +65
98573420Global Offices:San Francisco, USA | Jaipur, India | Bikaner, India*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANSMZiQo%3DM0RaBbawUNrsvO%2BLZpTQD%3DHtXCZsJDjnUE8zCFjRw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Textarea taking htnml tags

2015-03-30 Thread Akash Patni
hi
for removing html tags i have used the following function but it is not
working...Please suggest

class NotesForm(forms.Form):
''' Notes '''
note_title=forms.CharField(label="Note Title *:",max_length=100)
note=forms.CharField(widget=forms.Textarea,label="Note:",required=False)
def clean(self):
from django.utils.html import strip_tags
cleaned_data = super(NotesForm, self).clean()
cleaned_data['note'] = strip_tags(cleaned_data.get('note'))
return cleaned_data

and this is my html

 

  {% for field in form %}
  {%if field.name == 'note' %}
  
  {{ field.label_tag }}
  {{ field}}
  
  {% else %}
  
  {{ field.label_tag }}{{ field }}
{% for error in field.errors %}
{{ error }}
{% endfor %}

{% endif %}
{% endfor %}


I had also used striptag filter and this is also not working...

On Mon, Mar 30, 2015 at 9:11 AM, Akash Patni 
wrote:

> *Hi,*
> *This my template*
> {% block content %}
>
> 
>
>   
>  src="/site_media/images/digital-assets-note-icon.png" alt="Notes" />
> View Notes
> See your notes details.
>   
>   
>
> {% for i in result %}
> 
> Note Title
> {{i.note_title}}
> 
> 
> 
> Note
>  *{{i.note}}*
>
> 
> 
>
> 
> Beneficiaries
> 
> {% if all_nominees %}
> {% for nominee in all_nominees %}
> {% if nominee.1 %}
> {{nominee.0.first_name}} {% if nominee.last_name
> %}{{nominee.last_name}}{% endif %} {% if nominee.0.is_charity %}(charity){%
> else %}(individual){% endif %}
> 
> {% endif %}
> {% endfor %}
> {% else %}
> No beneficiaries at the moment.
> {% endif %}
> 
> 
> 
>
> 
> Action
> 
>  href="/user/notes/edit?id={{i.key}}">Edit
>  href="/user/notes/delete?id={{i.key}}" onclick="return
> deleteConfirmation();">Delete
> 
> 
> 
>   {% endfor %}
>
> {% endblock %}
>
>
> On Fri, Mar 27, 2015 at 11:30 PM, aRkadeFR  wrote:
>
>>  Hey,
>>
>> He doubled post. A thread already exists about this called:
>> "textarea showing image instead of code"
>>
>>
>>
>> On 03/27/2015 03:54 PM, Filipe Ximenes wrote:
>>
>> Can you send us the code of the view and the template of this form?
>>
>> On Fri, Mar 27, 2015 at 3:27 AM,  wrote:
>>
>>> Hie to all,
>>> In one of my template i am using text area. The issue is that when i
>>> write html tags with some image link using img tag, when i am saving this i
>>> am getting image on the desription field.
>>>
>>> Actual-Image is comming
>>>
>>> Expected-I want HTML code to be displayed in the discription.
>>>
>>> Please suggest
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/32bb3e0a-1eb1-46d1-94fe-4135c7c916df%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/32bb3e0a-1eb1-46d1-94fe-4135c7c916df%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>>  --
>>
>>
>> *Filipe Ximenes *+55 (81) 8245-9204
>>
>> *Vinta Software Studio *http://www.vinta.com.br
>>   --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAA-QWB3OPdmK11XzPFf--2MBT6evTDu-RuRrPArem1PbZT2FmA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA-QWB3OPdmK11XzPFf--2MBT6evTDu-RuRrPArem1PbZT2FmA%40mail.gmail.com?utm_medium=em

TIMEZONE

2015-04-08 Thread akash . patni
Hi to all ,

Previously my settings.py file was having time zone as

TIME_ZONE = 'America/Chicago'

now i have changed to 
TIME_ZONE = 'Europe/London'

that not getting reflected means date and time are getting stored in 
database as of previous timezone...


Please suggest.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2f325769-40db-480d-afbc-336dc948878e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


No exception supplied error while resizing image by using blobproperty

2015-05-19 Thread akash . patni
Hi guys,
I am resizing image using blobproperty but it s giving BadImageError with 
no exception supllied.

Here is my code for resizing:

*bg_image = request.FILES['bg_image'].read(*)

*obj_partner.bg_image = db.Blob(images.resize(bg_image,1400,758)) // 
error line*

and i am uploading image which is less then 1Mb and whose resolution is 
(1400 x 762)

and the field i am taking is Filefield.

Please reply...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4a2a1c33-3501-4d9f-8f4f-a821fa0f7f56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.