Re: Deployment

2009-05-07 Thread varikin



On May 6, 11:23 am, joshuamckenty  wrote:
> I'm using Fabric for deployment of my django apps, and I quite like
> it. It's still probably not as feature-rich as capistrano, but it's
> written in python, has a *very* active community right now, and solves
> the problems that I have, anyway. YMMV.http://www.nongnu.org/fab/
>

I second Fabric. I found it very nice to do anything I needed. And all
actions are just python functions (might be callables, I don't know)
so you can make it do almost anything.

You also mentioned SQL and migrations. Are you using a migration
application? I know there are a couple that get a lot of buzz, like
South. From what I hear, it is very good.

Regards,
John
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: please help with FileField(upload_to='foo')

2009-05-07 Thread varikin



On May 6, 9:30 am, djangomax  wrote:
> Thanks! So I just need to replace "forms" with "models and it'll work?

Are you defining a model or are you creating a form? To really be able
to answer that, the code around that one line would be helpful.

The easy answer (but not necessarily correct answer) is if this is in
models.py, it is a model. If this is in another file such as forms.py
or views.py, it is a form and you don't need to specify upload_to. But
that easy answer can be wrong in certain cases.

Regards,
John
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: popping a bigger picture from thumbnail on hover..

2009-05-06 Thread varikin

I think you need to look at a Javascript library like jQuery, YUI,
etc, for the popup. It isn't really a Django app, but having a
Javascript popup on hover of an image. This is something that would
most likely be in your template.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Trouble with Django and jQuery

2009-02-06 Thread varikin


> > The external jQuery script doesn't go through Django, so obviously the
> > template variables aren't parsed. As you have discovered, you can put
> > javascript in the template so that it is parsed. So you already have
> > the answer to your question: use a small script within your template,
> > which sets the values you need from the context and makes them
> > available as global javascript variables. Then your external jQuery
> > script will be able to access the global JS variables which will have
> > the correct values.

Also, you can create a url/view/template that returns Javascript. The
templates doen't need to be HTML, they can be anything.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Getting uploaded file content type in model save

2009-02-05 Thread varikin



On Feb 4, 7:44 pm, Brian Morton  wrote:
> However, I am not sure how to get access to the
> content type reported by the browser for the uploaded file in the
> model save method.  Can you access the request from a model save in
> the admin?

You can get the content type from UploadedFile object[1]. I haven't
used the SimpleUploadedFile, but I am assuming it is a subclass of
UploadedFile. I do this in my form processing (the clean_* methods) on
my forms that take uploaded file. I don't think this is available on
the model save though. On model save, I would suggest just opening the
image in PIL and checking im.format.

-John

[1] 
http://docs.djangoproject.com/en/dev/topics/http/file-uploads/?from=olddocs#uploadedfile-objects


--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Creating test databases. Nose framework

2009-01-28 Thread varikin



On Jan 27, 5:00 pm, Oleg Oltar  wrote:
> So if I have to store a User object in db (with fields (name, email, pass)
> How should I define the fixture? Should I define it in setup?

When I created my fixtures for my tests, I did ran[1]

./manage.py dumpdata auth > auth.json

Then I just edited auth.json to contain what I wanted. I removed all
but one user from the JSON and set the fields as I needed.  Then I
just did the fixture loading as mentioned.  I don't know anything
about Nose to know if this will work for you.

Also, I did set my password to a dummy password before the export so
that the password field in the fixture doesn't contain a real password
I want kept safe. It is encrypted, but no reason to put even an
encrypted password in version control.

[1] http://docs.djangoproject.com/en/dev/ref/django-admin/#dumpdata
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Testing uploads and content types

2009-01-23 Thread varikin


On Jan 23, 1:39 am, Julien Phalip  wrote:
> I have a view which processes a multi-part form and whose behaviour
> varies depending on the content types of the uploaded files. I've
> written some tests for that view as follows:
>
>         post_data = {
>             'name1': 'blah',
>             'file_field1': image_data,
>         }
>         response = self.client.post('/upload/', post_data)
>
> But the problem is that (apparently by design) all files are
> systematically encoded with the content type 'application/octet-
> stream'.
>

> Is there a more concise or more elegant way to do?
>

The UploadedFile[1] object has a field called content_type. So if you
have this in a form:

myfile = request.FILES['some_file']
if myfile.content_type != 'application/zip':
 #raise error

I don't know if this will help you in your test. I hope it does.

[1] 
http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#uploadedfile-objects

John
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Process file after upload

2009-01-08 Thread varikin



On Jan 7, 7:32 am, dmishe  wrote:
> Hey.
>
> I have FielField in my model for user to upload ZIP-archives. I want
> to unpack that zip, place some files in some dirs and delete it just
> after user uploaded it in admin.
>
> How can i do this? Model's save won't work because it gets called
> everytime model is saved regardless of were the file uploaded again or
> not. Custom storage/upload handler seems too complicated for this.

I may not be reading your description right, but it sounds like you
are not really saving this zip file, just processing what is in it,
correct? If that is the case, you don't need it in the model. You
could just create a form and view that take a zip file, unzip it and
do any processing. I do this to upload multiple pictures to a gallery
site.  I then overrode the admin list page for a model to have a
button by "Add Object" called "Add Multiple Objects" which has just
this form instead of the normal add object form.

If you a more complete explanation, let me know. But, if I am reading
your question wrong, this might not work.

Thanks,
John
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Shouldn't blank=True imply null=True?

2009-01-07 Thread varikin



On Jan 7, 5:51 am, tofer...@gmail.com wrote:
> On 07.01-09:47, Malcolm Tredinnick wrote:
> [ ... ]
>
> > This thread is about whether blank=True, null=False (the fourth
> > possibility) ever makes sense for non-text fields.
>
> answer is yes for any field type that accepts an empty string as having
> a meaning.  i currently use this for a couple of custom fields that
> are autogenerated but can be set manually, if desired.  it could also
> happen for innumerate other reasons.
>
> or put more simply '-1' for me.
>

I agree with this. I use null=False, blank=True for some ImageFields
and integers. In both cases, I am generated the this content for the
database, but it is not entered. In the case of the ImageField, an
image is uploaded (an original), then I generate a thumbnail, and a
viewable (a standard sized image).  Technically at this point I don't
need blank=True here because users only upload the original image, but
at some point I can allow them to upload an optional thumbnail and
then use that if supplied or generate it if not.

In the case of an integer, I use it for order of the images. So if a
number is given for an image, it is used, otherwise auto assign the
order number.

I thought this was a common use case with Django.  So that is a -1 for
me.

Thanks,
John
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Ad Management System

2008-11-24 Thread varikin



On Nov 23, 5:26 pm, Nick <[EMAIL PROTECTED]> wrote:
> I'm exploring whether or not to use Django for redesigned website and
> the only thing I haven't really been able to find out is whether there
> is an existing, portable, robust solution for advertising management
> on the site. This would need to control what advertising goes where,
> track its performance, etc. Does this exist yet for Django? Thank you!

I haven't tried it, but there is Django-ads, 
http://code.google.com/p/django-ads/.
--~--~-~--~~~---~--~~
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: serving static file via django

2008-11-19 Thread varikin



On Nov 19, 12:55 am, "David Zhou" <[EMAIL PROTECTED]> wrote:
> On Wed, Nov 19, 2008 at 1:54 AM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > yes..its just a transparent gif...i'm thinking of writing my own view,
> > which will get the visitor data and then just call the static serve
> > method provided by django.
> > just dont know it its ok inproduction env though..
>
> Do you not know which pages the gif will live on?  Why not grab
> visitor data in the views of the pages that use the transparent gif?
>
> --
> ---
> David Zhou
> [EMAIL PROTECTED]

Or gather your metrics in your view then redirect to another url where
the webserver serves it.  Though you have to be sure people won't hit
that url on purpose to bypass this.
--~--~-~--~~~---~--~~
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: Beginner desperately seeking Django experts.

2008-11-15 Thread varikin



On Nov 15, 3:39 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Fri, 2008-11-14 at 22:54 -0800, Innergy wrote:
> > Thanks for reading my question.  I may not be asking all the right
> > questions.
>
> > I am looking for a fast way to build a ecommerce site with many of the
> > qualities of threadless.com.  I was told Django is an excellent
> > language and allows for rapid fast implementation.
>
> > My back ground is not in development. So I am agnostic. I am currently
> > leaning towards Ruby for my project.  How does Django compare to
> > Ruby?  Is Django faster to develop in? Is it as stable as Ruby?
>
> For somebody familiar with and expert in Python, Django will be faster.
> For somebody with Ruby skills, Ruby on Rails will be faster. Neither
> language (Python, Ruby) or web framework (Django, Rails) has any
> significant known stability problems and both programming languages have
> been around since the early- to mid-1990's. Django and Rails are roughly
> equivalent as frameworks; the differences are in the fine-details and I
> don't think any of those are show-stoppers. There are clearly
> trade-offs, since neither framework has everything that everybody wants,
> out of the box, but since they're both built on top of professional
> quality programming languages, it's possible to build any missing pieces
> if the motivation is strong enough.
>
> If you're asking for yourself, just setting our to learn a programming
> language and start development, then that's an entirely different
> question. Learning one of other language will probably take about the
> same amount of time. But I wouldn't be choosing threadless.com as the
> first project in that case and "fast" will not the appropriate word to
> describe the speed it will take to build if you also have to learn the
> programming language and the framework. In that case, you've essentially
> asked the equivalent of "I'm thinking about building a house and I don't
> have a background in construction. Should I use bricks or wood?" It's
> nice to have an end goal to keep you motivated, but there's a learning
> curve involved.
>
> Regards,
> Malcolm

I suggest you take a look at Satchmo, http://www.satchmoproject.com/,
which is an ecommerce application written in Django. I myself have
never used it, but I heard great things about it.

John
--~--~-~--~~~---~--~~
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: saving multiple versions of an uploaded image

2008-11-04 Thread varikin



On Nov 4, 2:33 am, Chris Amico <[EMAIL PROTECTED]> wrote:
> Hi folks,
>
> I'm trying to turn one uploaded image into several: a full-size and
> thumbnail (and more, eventually). Here's the model I'm playing with,
> just for testing:
>
> class TestPhoto(models.Model):
>     "This is only for testing. Delete it later and make a real photo
> model"
>     title = models.CharField(max_length=100)
>     pub_date = models.DateTimeField(auto_now_add=True)
>     full_size = models.ImageField(upload_to="images/photos/%Y/%b/%d")
>     thumbnail = models.ImageField(upload_to="images/photos/%Y/%b/%d",
> blank=True)
>
> Resizing is simple enough using a script off Django Snippets:
>
> def thumbnail(filename, size=(50, 50), output_filename=None):
>     image = Image.open(filename)
>     if image.mode not in ('L', 'RGB'):
>         image = image.convert('RGB')
>     image = image.resize(size, Image.ANTIALIAS)
>
>     # get the thumbnail data in memory.
>     if not output_filename:
>         output_filename = get_default_thumbnail_filename(filename)
>     image.save(output_filename, image.format)
>     return output_filename
>
> That part works like a charm when I run it on save(), and the returned
> files end up exactly where they should be. But how do I get Django to
> recognize that output file as a File object?
>
> I've tried adding another ImageField to the model and using a save()
> method to populated it with the output_filename from thumbnail(). It
> gets the path right, but the url ends up being something like
> MEDIA_URL + self.full_size.path + "thumb.jpg" or media.mydomain.com/
> home/chrisamico/webapps/media/images/photos/2008/Oct/23/
> IMG_0460.thumb.jpg. That's a big 404.
>
> I could write a simple method to create the right url (since it's just
> full_size.url with .thumb.jpg on the end) but that would be repetitive
> for each size.
>
> Thanks as always for the help.

I have been overriding the save method on the model.  I have found
that by the time the save method is called, the file is saved to the
disk already, So I open the original, resize and save to the
thumbnail:

from __future__ import division
import os
import tempfile
import Image
from django.core.files import File

class Picture(models.Model)
name = models.CharField(max_length=200)
original = models.ImageField(upload_to='original')
thumbnail = models.ImageField(upload_to='thumbnail')

def save(self, force_update=False, force_insert=False):
#Open image as PIL Image and get name
orig = Image.open(self.original.path)
name = os.path.basename(self.original.name)

#using future division, calculating height for width of
100 to keep aspect
height = int(100 * orig.size[1] / orig.size[0])

#Resize, open tempfile, and save to temp
thumb = orig.resize((width, height), Image.ANTIALIAS)
thumb_file = tempfile.NamedTemporaryFile('w+b')
thumb.save(thumb_file, 'JPEG')

#Save tempfile to thumbnail
self.thumbnail.save(name, File(thumb_file), False)
thumb_file.close() #tempfile is deleted upon close:)

   super(Picture, self).save(force_update, force_insert)

I hope this is clear enough. I actually have more in this for
specifying the size of the thumbnail and some other processing, but
this is the core of how I do it.
--~--~-~--~~~---~--~~
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: Why is my string not auto escaped?

2008-11-01 Thread varikin



On Oct 31, 8:28 am, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> > > > So if these built in filters are marking my strings safe, inspite of
> > > > unsafe data being passed in, should they not handle escaping as well?
>
> > > The problem seems to be that your filter function doesn't mark itself
> > > with an is_safe attribute (defaulting it to False). So try marking
> > > your filter with is_safe=True which means that your filter doesn't
> > > introduce any HTML unsafe characters by itself (not including the ones
> > > that are already in the input):
>
> > > filterxx.is_safe = True
>
> > > Also, it's easier for people to follow a discussion thread if you
> > > don't top post your responses.
>
> > > -RD
>
> > I don't think setting is_safe is the solution, in fact is sounds like
> > the exact opposite.
>
> It might sound confusing, but is_safe=True is a way for you to
> indicate to Django that your filter does not introduce any unwanted
> characters. See point #1 in the below doc for a more thorough
> explanation:
>
> http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#filt...
>
> > Shabda *wants* Django to escape the results.
>
> Here's an excerpt from the docs for that case:
>
> "1. Your filter does not introduce any HTML-unsafe characters (<, >,
> ', " or &) into the result that were not already present. In this
> case, you can let Django take care of all the auto-escaping handling
> for you. All you need to do is put the is_safe attribute on your
> filter function and set it to True, like so:
>
> This attribute tells Django that if a "safe" string is passed into
> your filter, the result will still be "safe" and if a non-safe string
> is passed in, Django will automatically escape it, if necessary."
>
> -RD

But Shadba's example filter is calling urlize which does introduce
HTML unsafe characters.
--~--~-~--~~~---~--~~
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: Migrate app from MySQL to PostgreSQL

2008-10-31 Thread varikin



On Oct 30, 1:57 pm, "Naitik Shah" <[EMAIL PROTECTED]> wrote:
> I ran into issues with this approach as well - first uniqueness constraints
> were failing, which I managed to fix manually. Next I got ContentType
> matching query issues, which I have not fixed yet.
>
> I was hoping to come up with a generic migration process since I have a few
> other sites on MySQL. But this is my first foray into PostgreSQL, so maybe I
> should just take a simpler approach and write a task specific migration
> script until I'm convinced I should move all my sites to PostgreSQL.
>
> -Naitik
>
> On Thu, Oct 30, 2008 at 12:59 AM, Brot <[EMAIL PROTECTED]> wrote:
>
> > This doesn't work as expected. I tried the migration with dumpdata
> > month ago.
> > The problem is, that mysql and postgres writes another, incompatible
> > boolean values. I believe sqlite and postgres has the same problem!
> > I reworked the dumpdata output-file. In my case this was possible,
> > because the amount of data was not too big
>
> > On 30 Okt., 08:44, David Christiansen <[EMAIL PROTECTED]> wrote:
> > > Why not just dump the data using manage.py dumpdata, switch your
> > > settings file to point to the new DB, run syncdb, and then use
> > > manage.py loaddata to get it all back?  That should be pretty easy.
>
> > > -David Christiansen
>
> > > On Oct 30, 2:39 am, "Naitik Shah" <[EMAIL PROTECTED]> wrote:
>
> > > > I looked around but didn't find anything obvious or simple. This is a
> > live
> > > > Django app with data in MySQL which I want to migrate to PostgreSQL.
> > > > Suggestions? (Before I do my own thing :))
>
> > > > -Naitik

Check out django_extensions app, 
http://code.google.com/p/django-command-extensions/.
It has a command, dumpscript, which creates a python script to
populate the database. That might get ride of the incompatible types.
I haven't tried this myself, but it is worth a shot.
--~--~-~--~~~---~--~~
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: Execute a java program

2008-10-31 Thread varikin



On Oct 30, 5:12 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hi everyone I am newbie to django and I am italian so excuse me for my
> english :P
> I have to execute a java program very simple look something like this:
>
> public class Book {
>     public static void main(String[] args) {
>
>          int year = 2008;
>
>          List list =  Booklist.fetchbook(year);
>          Iterator it = list.iterator();
>
>          while (it.hasNext()) {
>              Book book = (Book) it.next();
>              System.out.println( book.getTitle()  + " " +
> book.getAuthor() );
>             }
>
> } }
>
> and I have to retrieve 2 strings ( book.getTitle() and
> book.getAuthor() ) for use its in django application.
> How Can I do that? Do I have to use JVM ? How ?
>
> thanks :)

Also, take a look at Jython which is Python written on top of the JVM
so you can call Java libraries within Python. Django 1.0 works with
Jython.


--~--~-~--~~~---~--~~
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: Why is my string not auto escaped?

2008-10-31 Thread varikin



On Oct 30, 6:58 am, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> On Oct 30, 1:30 am, shabda <[EMAIL PROTECTED]> wrote:
>
> > So if these built in filters are marking my strings safe, inspite of
> > unsafe data being passed in, should they not handle escaping as well?
>
> The problem seems to be that your filter function doesn't mark itself
> with an is_safe attribute (defaulting it to False). So try marking
> your filter with is_safe=True which means that your filter doesn't
> introduce any HTML unsafe characters by itself (not including the ones
> that are already in the input):
>
> filterxx.is_safe = True
>
> Also, it's easier for people to follow a discussion thread if you
> don't top post your responses.
>
> -RD

I don't think setting is_safe is the solution, in fact is sounds like
the exact opposite. Shabda *wants* Django to escape the results.
Instead, try calling django.utils.html.escape() in your filterxx like
so:

return linebreaks(urlize(escape(data.value)))

This will replace <,>,&,etc with the , , , etc.


--~--~-~--~~~---~--~~
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: What does FieldFile._required_file() do?

2008-10-28 Thread varikin



On Oct 28, 10:05 pm, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
> On Tue, Oct 28, 2008 at 10:31 PM, varikin <[EMAIL PROTECTED]> wrote:
> > try:
> >     object.photo._require_file()
> > except ValueError:
> >      #handle exception
>
> Wow, I never expected anybody to do something like that. :(
>
> > But I just don't know what this does or is suppose to. The way I read
> > it, if self is None, raise ValueError() which calls self.field.name
> > which would be invalid since self is None. Also, since calling this
> > method is done through a FieldFile object (or ImageFieldFile in this
> > case), it can't be None.
>
> Well, it can't be None, but it doesn't necessarily have a valid value.
> "if not self" doesn't actually check to see if it's None, but rather
> checks to see if the filename is blank. This can happen if you have a
> FileField that hasn't yet gotten a file attached to it, such a field
> with blank=True that never got a file in the admin or a new model
> instance created in a view that hasn't attached a file.
>
> The leading underscore means that it's meant to be a private method.
> It's there as a way to make Django's internal code simpler, so we
> didn't have to keep copying that ValueError message in a bunch of
> methods that all require a filename before they can proceed. That code
> you see is somebody checking to see if the field has a file attached
> to it or not. That's not really the best way to go about it though;
> this would be better:
>
> if not self:
>     # handle "exception"
>
> -Gul

I never knew you could do that and it really threw me. Thanks for the
explanation. At least now that I understand it, I can change it to "if
not self" since I have to update the file handling in this app.

Thanks,
John
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



What does FieldFile._required_file() do?

2008-10-28 Thread varikin

I was looking at someone else's code and saw the following code:

try:
 object.photo._require_file()
except ValueError:
  #handle exception

Where object is a model instance and photo is an ImageField attribute.
Can someone tell me what _require_file() does?

Here is the definition of it in django/db/models/fields/files.py
class FieldFile(File):
   def _require_file(self):
if not self:
raise ValueError("The '%s' attribute has no file
associated with it." % self.field.name)

But I just don't know what this does or is suppose to. The way I read
it, if self is None, raise ValueError() which calls self.field.name
which would be invalid since self is None. Also, since calling this
method is done through a FieldFile object (or ImageFieldFile in this
case), it can't be None.

I am sure I am missing some strange tricky bit of Python classes and
objects, but I can't find anything on this.

Thanks,
John
--~--~-~--~~~---~--~~
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: tinymce help

2008-10-26 Thread varikin


On Oct 25, 8:47 pm, Bobby Roberts <[EMAIL PROTECTED]> wrote:
> hi.  I'm using django 1.0 over at webfaction.  I have the following
> setup
>
> /static   (serves js, css, flash, images etc)
> /www   (my django app)
>
> I have tiny_mce loaded to /static/js/tiny_mce/
>
> I have followed the steps at this page:  
> http://code.djangoproject.com/wiki/AddWYSIWYGEditor
> in this order:
>
> 1.  Install tiny_mce on your server some where
> 2.  create a textareas.js file  (placed in /static/js/tiny_mce/)
> 3.  created an admin.py file  in my website located at www/learn/ as
> follows:
>
> from django.contrib.flatpages.models import FlatPage
> from django.contrib.flatpages.admin import FlatPageAdmin as
> FlatPageAdminOld
>
> class FlatPageAdmin(FlatPageAdminOld):
>     class Media:
>         js = ('js/tiny_mce/tiny_mce.js',
>               'js/tiny_mce/textareas.js',)
>
> # We have to unregister it, and then reregister
> admin.site.unregister(FlatPage)
> admin.site.register(FlatPage, FlatPageAdmin)
>
> step3 i'm confused on.  This is for newforms with flatpages per the
> documentation.  It is my  understanding that django 1 uses newforms.
> Why won't the admin show the tinymce in place of text areas?

Try pointing your browser to the js files.  See if you can access
them.  Also, look at the header of the flatpages admin page to see if
the url to the js files are correct.

Is /static/ your MEDIA_URL? I ask all these questions because when you
specify the class Media: js = (...) in an admin.py, Django appends the
MEDIA_URL to the js URL so 'js/tiny_mce/textareas.js' becomes '/static/
js/tiny_mce/textareas.js' if MEDIA_URL = /static/.  If you don't want
your js files to be in MEDIA_URL, set the url to /js/tiny_mce/
textareas.js/ (notice the first slash).

If the URL is correct, does Apache (or other webserver) serve it
correctly?

John
--~--~-~--~~~---~--~~
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: File upload progress bar for Django?

2008-10-21 Thread varikin



On Oct 20, 6:15 pm, Sascha Brossmann <[EMAIL PROTECTED]>
wrote:
> > Is anyone
> > familiar with a django or python tutorial that shows how to implement
> > some kind of file upload progress bar?
>
> Sorry, but the main magic in those uploaders is done via flash, not
> via js or php. AFAIK there is currently no sane (though you may use
> Java ;-)) way to do it otherwise.

I also think some JavaScript libraries offer them to, like jQuery, but
I have tried any of that.
--~--~-~--~~~---~--~~
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: rename or renaming a Django application

2008-10-16 Thread varikin

On Oct 15, 7:17 pm, coderb <[EMAIL PROTECTED]> wrote:
> hi tim, thanks for the quick response.
>
> I will convert your bash commands to my (whisper) "windows"
> equivalents to manually rename all instances. I have tools like
> windows grep etc..
> Doing batch renames, search replaces etc .. should be fine, although
> I'll be confirming before each change until I understand the process.
>
> as you mention it would depend on how I reference things and many
> approaches are different, but maybe in a future release of django
> we'll see something like:
> cd projectdirectory
>
> manage.py renameapp oldname newname
>
> not that I'm complaining, I love django and thanks again for the
> detailed response, a great help.
>
> On Oct 16, 12:40 am, Tim Chase <[EMAIL PROTECTED]> wrote:
>
> > > I've done some coding on the project and within myapp
>
> > > but now I want to rename myapp to a more appropriate name.
>
> > > of course I cant simply rename the generated application directory
> > > name, I would also need to change all references to the myapp.
>
> > > So, then question is, do I need to do this all manually, or is there a
> > > django function or easier way for me to easily rename an application
> > > properly?
>
> > Short answer:  not readily.
>
> > One detail you omit is what platform you're running on.  Your
> > *nix-like systems have some tools to make this a bit easier for
> > you.  It also depends on how interdependent your project and apps
> > are on each other, as well as how you reference things
>
> > After backing up my project (well, checking into my revision
> > control system, mercurial in the current case), I'd just do
>
> >    bash$ cd /path/to/wherever
> >    bash$ find . -name '*.py' -exec sed -i.bak \
> >       -e '/import/s/myapp/mynewapp/' \
> >       -e 's/myapp\./mynewapp\./g' \
> >       {} \;
> >    bash$ sed -i.bak 's/myapp/mynewapp/g' settings.py
> >    bash$ cd ..
> >    bash$ mv myapp mynewapp
>
> > which should catch most of the cases as well as create *.bak
> > files for you to compare and/or restore if something went wrong.
> >   The "find+sed" should catch the following cases:
>
> >    import myapp
> >    from myapp import foo, bar, baz
> >    myapp.Foo.whatever = myapp.SOME_VALUE
>
> > and the last sed call cleans up some of the additional instances
> > of "myapp" in your settings.py file (a glorified search).
>
> > This assumes you'll be rebuilding your database, as your tables
> > are currently named things like "myapp_mymodel".  Other caveats
> > include direct app-model/table references in .extra() calls and
> > places where you use the app-name in strings with no following
> > period (like in the settings.py, thus the extra hand-treatment).
>
> > Additionally, if you follow the sage advice of James, and your
> > "project" just consists of a settings.py and a base urls.py,
> > you'll want to execute the above find+sed statement in your app
> > directory, and the single sed statement in the project directory.
>
> > Those are at least a few of the gotchas that occur to me, but it
> > should ease the process of renaming.
>
> > -tim

Also a nice IDE or proper text editor that refactors or has a find/
replace in multiple files/projects would make this easier.  I have
done this using TextMate in Mac, I know TextPad or Eclipse (with
PyDev) would probably help with this. Of course the biggest thing is
backing up, either through svn, git, etc, or just copying the
directory.
--~--~-~--~~~---~--~~
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: Resizing images when uploading

2008-10-04 Thread varikin



On Oct 3, 4:18 pm, "Juanjo Conti" <[EMAIL PROTECTED]> wrote:
> Hi, I used to use a pre 1.0 svn version of Django. There I had this class:
>
> class Foto(models.Model):
>     descripcion = models.CharField(max_length=30, blank=True,
> verbose_name=u"descripción")
>     imagen = models.ImageField(upload_to='imagenes', verbose_name=u"foto")
>     inmueble = models.ForeignKey(Inmueble)
>
>     
>
>     def _save_FIELD_file(self, field, filename, raw_contents, save=True):
>         '''
>         Se reescribe el metodo de la clase padre para definir el
> nombre de archivo con
>         el que se guardará la imagen en el sistema de archivos. Se
> utilizan enteros crecientes.
>         '''
>         if TESTING:
>             field.upload_to = 'tests_dest'
>         filename = Foto._cambio_de_nombre(filename)
>         raw_contents = Foto._ajustar_tamanio(raw_contents)
>         super(Foto, self)._save_FIELD_file(field, filename, raw_contents, 
> save)
>
> The  _save_FIELD_file method was redefined to change the file name and
> resize it. Now in 1.0 I can rename the filename with a callable to use
> as upload_to ImageField argument:
>
> def _upload_to(instance, filename):
>     intancia.imagen. raw_contents = Foto._ajustar_tamanio(raw_contents)
>     filename = Foto._cambio_de_nombre(filename)
>     if TESTING:
>         return os.path.join('tests_dest', filename)
>     return os.path.join('imagenes', filename)
>
> but I don't know where I have to put my code to resize the image
> before it gets saved. Can anyone help me?
>
> Thanks,
>
> Juanjo

I have been overriding the save method on the model.  I have found
that by the time the save method is called, the file is saved to the
disk already, So I open the original, resize and save to the
thumbnail:

class Picture(models.Model)
name = models.CharField(max_length=200)
original = models.ImageField(upload_to='original')
thumbnail = models.ImageField(upload_to='thumbnail')

def save(self, **kwargs):
orig = Image.open(self.original.path)
name = os.path.basename(self.original.name)
height = int(100 * orig.size[1] / orig.size[0])

thumb = orig.resize((width, height), Image.ANTIALIAS)
thumb_file = tempfile.NamedTemporaryFile('w+b')
resized.save(thumb_file, 'JPEG')
self.thumbnail.save(name, File(thumb_file), False)
thumb_file.close()

   super(Picture, self).save(**kwargs)

I have to save the resized image to a temp file because
self.thumbnail.save takes a django.core.files.File object which takes
an python file object in the constructor.  I would love to be able to
use an in memory object instead of a temp file, but that isn't in
possible yet.

John
--~--~-~--~~~---~--~~
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: Admin UI Problems

2008-10-03 Thread varikin



On Oct 2, 4:14 am, jordanwlee <[EMAIL PROTECTED]> wrote:
> when installing django-cms make sure to COPY the
> /projectname/media/admin/cms files (admin.css cmslayout.css
> DateTimeShortcuts.js etc..) to
> /django_trunk/django/contrib/admin/media/
> into a "cms" folder
> so it looks like:
> /django_trunk/django/contrib/admin/media/cms

This does not sound like the correct solution.  You not need to put
your files in Django trunk.  I think it is probably just an issue with
configuring your web server to serve the files under /project/media/
admin/cms, or something along those lines.

If you were just looking for help configuring Django-CMS specifcally,
I would ask for help there since they would know the specifics of it.
Django itself is not a CMS, just a framework.  Django-CMS is a CMS
written using Django.
--~--~-~--~~~---~--~~
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: Django and CSS

2008-08-28 Thread varikin

MEDIA_ROOT is the local path to the files on the server.  One place
this is used is with uploading files.  So uploaded files will be
placed in MEDIA_ROOT/some-upload-dir.  I don't know about other uses,
though.

John
--~--~-~--~~~---~--~~
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: Pre-populating an integer field with a count of model objects

2008-08-22 Thread varikin



On Aug 21, 11:29 am, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Aug 21, 4:42 pm, Brandon Taylor <[EMAIL PROTECTED]> wrote:
>
> > Hi everyone,
>
> > I have a column, 'position', which is a PositiveIntegerField, to allow
> > my end-user to order records with. I would like to pre-populate the
> > field when creating a new record, with the count of the model objects
> > + 1.
>
> > The models documentation says 'default' can be a value or a callable,
> > but using self.objects.count() + 1 doesn't work, because 'self' hasn't
> > been defined.
>
> > Can anyone point me to an example of how I can accomplish this?
>
> > TIA,
> > Brandon
>
> 'self.objects.count() + 1' isn't a callable, it's an expression, which
> you can't use here. (A callable is a function object, or a class with
> __call__ defined.)
> However, unfortunately even a callable probably wouldn't help you
> here, as the implementation calls it without any parameters. It's
> really just for things like inserting the current time, which doesn't
> need parameters. 
> Seehttp://www.djangoproject.com/documentation/models/field_defaults/
>
> You can achieve what you want by overwriting save() on the model:
>
> def save(self):
>     if not self.position:
>         self.position = self.objects.count() + 1
>     super(YourClassName, self).save()
>
> --
> DR.

Couldn' t why do you need a function with a parameter?  Wouldn't a
function like this work:

class Widget(models.Model):
... some fields
position = models.PositiveIntegerField(default=getNextPosition)

def getNextPosition():
return Widget.objects.count() + 1

Thanks,
John

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---