Re: How to save/link/rename thumbnail in model

2008-10-21 Thread mcordes

Hello,

I'd suggest you also consider this app: http://code.google.com/p/sorl-thumbnail/
. It makes it very simple to have thumbnails of various sizes
associated with your image fields.

-Matt


On Oct 21, 2:10 am, krylatij <[EMAIL PROTECTED]> wrote:
> You can define image upload path at runtime (check manual for
> ImageField)
>
> def get_photo_path(instance, filename):
>     return 'static/upload_to/photos/%s' % instance.name
>
> class ProductImage(models.Model):
>     name = models.CharField(max_length=50)
>     file = models.ImageField(upload_to= get_photo_path)
>     ...
>
> In my projects i don't use additional field for thumbnails
> Because i need thumbnails in different sizes
> So i use property for that
>  # If i don't allready have thumbnail in this size i generate it
>  def _get_thumb_url(self, folder, size):
>         if not self.photo:
>             return '#'
>         upload_to = path.dirname(self.photo.path)
>         tiny = path.join(upload_to, folder,
> path.basename(self.photo.path))
>         tiny = path.normpath(tiny)
>         if not path.exists(tiny):
>             import Image
>             im = Image.open(self.photo.path)
>             im.thumbnail(size, Image.ANTIALIAS)
>             im.save(tiny, 'JPEG')
>         return path.join(path.dirname(self.photo.url), folder,
> path.basename(self.photo.path)).replace('\\', '/')
>
>   def get_thumb_url(self):
>         return self._get_thumb_url('thumb_40_40', (40,40))
>
>  def thumb(self):
>         link = self.get_thumb_url()
>         if link is None:
>             return 'NO IMAGE'
>         else:
>             return ' alt="tiny thumbnail image"/>' % (self.photo.url, link)
>  thumb.allow_tags = True
>
> So if i need thumbnail in my template i write this:
> {{ my_model.thumb }}
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



FormWizard with multiple forms / page

2008-10-02 Thread mcordes

Hello,

I'd like to make a wizard using the FormWizard class that has multiple
django Forms (and just a single html form) per page. It doesn't look
like this is supported out of the box. Has anyone done something like
this before? Any tips or other approaches I might try?

-Matt
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: A Newbie question: Need advice on how to create generic html templates with models

2008-09-25 Thread mcordes

Hi,

I'm not sure generic views are the answer. It sounds to me like you're
asking about reducing duplication in the templates themselves by
creating something you can reuse. That something is a template tag
(http://docs.djangoproject.com/en/dev/howto/custom-template-tags/). I
think you probably want an 'inclusion tag' and then you'd load and
call it on your various pages.

-Matt


On Sep 25, 7:24 pm, Karthik Krishnan <[EMAIL PROTECTED]> wrote:
> Thanks for replying Daniel. I wanted to know if I can use generic
> views for web application form objects. I would like to use them to
> avoid duplication on html pages.
>
> On Sep 25, 1:20 pm, Daniel Roseman <[EMAIL PROTECTED]>
> wrote:
>
> > On Sep 25, 8:51 pm, Karthik Krishnan <[EMAIL PROTECTED]> wrote:
>
> > > I know this may be a stupid question but please bear with me. Here is
> > > my problem
>
> > > In views.py I have a multiple methods, where each method is mapped to
> > > a unique model. There may be multiple methods mapped to the same
> > > model. But no method in views.py is mapped to multiple models.
>
> > > For a GET/POST request, we have mapped a form object to the request
> > > method. To display the form on the HTML page, we have to do
> > > {{form.as_p}} or {{form.as_ul} and so on.. But we have to display it
> > > differently with div tags using css files.
>
> > > If I have to do it individually, then I would have to this as follows
>
> > > Name {{form.name} and so
> > > on...
>
> > > Question 1 : Is there a way we can do it?
>
> > > The reason I am asking this is because we have 20 html forms and we
> > > would like to make it as automated as possible by invoking this
> > > method. What I am hoping for is something like this. Ideally this is
> > > what I hope to do.
>
> > > In my urls. py I could define the model
>
> > > ulr.py
>
> > > urlpatterns = patterns('',
> > >     (r'^login/$', views.object_list, {'model': models.User}),
> > >     (r'^customers/([A-Za-z0-9].*/$', views.object_list, {'model':
> > > models.Customer}),
> > > )
>
> > > In My views.py, I could return the same key for any number of models,
> > > only my template would change
>
> > > def login(request, model):
> > >     user = model.objects.filter(username = 'abcedf')
> > >     return render_to_response('success.html', {'form', user})
>
> > > def getCustomer(request, customer_name model):
> > >   customer = model.objects.filter(name = customer_name)
> > >  return render_to_response('success.html', {'form', customer})
>
> > > In my success html page
>
> > > I would display them as
>
> > > {{form.as_div}}
>
> > > Any help/suggestions would be more than welcome.
>
> > I'm not entirely sure I follow, but it sounds like Django's generic
> > views would do the trick.
> > Seehttp://docs.djangoproject.com/en/dev/ref/generic-views-
> > specifically the section on create/update views. That does the view/
> > form part for you, allowing you simply to define the URL in your
> > urls.py and give it a template. Is that what you're after?
>
> > --
> > DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Logging exceptions using mod_python

2008-09-13 Thread mcordes

Hello,

The mod_python deployment doc says:  "When you use Apache/mod_python,
errors will be caught by Django -- in other words, they won't
propagate to the Apache level and won't appear in the Apache
error_log". Is there a way to force errors to be recorded in the
error_log? Failing that is there a way to get django to log errors to
a file directly?

-Matt


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: auth context processor setup

2008-06-22 Thread mcordes

That was it. Thanks!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: auth context processor setup

2008-06-22 Thread mcordes

I seem to already have the auth middleware enabled too. From what I'm
seeing, generic views _do_ have the user object available in their
templates. It's just my custom views that don't automatically have
this. It's easy enough for me to pass in the request.user object from
each of my templates, but I really thought I wouldn't need to do this.

-Matt
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



auth context processor setup

2008-06-21 Thread mcordes

Hello,

Is there anything I need to do to enable the auth context processor
other than adding "django.core.context_processors.auth" to
TEMPLATE_CONTEXT_PROCESSORS in my settings.py?

I'd like to be able to access the 'auth user' object in my various
templates, which from what I understand this processor is supposed to
be injecting it, but it doesn't seem to be working.

my settings.py file contains:

TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
)


and in my template I'm using:

{{user}}

Is there anything else I need to get this to work?  Any suggestions?

-Matt

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---