Re: Create socket server in django

2011-09-20 Thread Preston Holmes


On Sep 20, 12:07 am, Micke  wrote:
> Thank you for your quick reply!
>
> My socket server is ready, but I dont know where to import it in
> django so it starts when django starts?

You are going to run your socket server in a different python process
than Django.  Django is based on more of a CGI request-response cycle
and doesn't mesh well with a socket server.

However you can access the DB and Django models from inside your
socket server.  Think about it as importing parts of Django in your
socket server, then serving views of that data from the Django process

-P

>
> br
> Mikael
>
> On Sep 19, 11:38 pm, Andy McKay 
> wrote:
>
>
>
> > You could write a Python process that starts up a Socket Server and imports
> > all the Django stuff, just like the current server does for HTTP. Then
> > there's no need to "send the data to django". Might help:
>
> >http://docs.python.org/library/socketserver.html
>
> > On Mon, Sep 19, 2011 at 2:00 PM, Micke  wrote:
> > > Hi,
> > > Im new to Django and need some help in the right direction.
>
> > > I will create a socket server, that should recive raw udp data and put
> > > it in a database. After that Django should present the data in a
> > > customized view.
>
> > > Is it possible to create the server in Django, like in the views file,
> > > so it starts up when django starts? So I can use the in data and use
> > > orm to put it in db. Or do I need to do a separate server, that sends
> > > data to django after it recieves it?
>
> > > Thanks
> > > Mikael
>
> > > --
> > > 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.

-- 
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: Virtualenv and Django in Production

2011-09-20 Thread Preston Holmes
How you use a virtualenv in production depends on all the parts of
your production stack.  If you are using mod_wsgi, search mod_wsgi +
virtualenv, gunicorn, etc

You might also consider one of the new "platform-as-a-service" hosting
options that basically solve this for you.

-P

On Sep 19, 10:55 pm, adrian s  wrote:
> Hi all, I've been using virtualenv as recommended in my development
> environments.
>
> I am now migrating a project which was not using virtualenv, to another
> server and now
> have the opportunity to use it in production.
>
> I've spent a while googling this subject and I'm not sure what the best
> practice is.
> Is it common to run a production django deployment with apache behind
> virtualenv? If so,
> could anyone steer me in the proper direction for getting this setup with
> the wsgi file...
>
> Or, is virtualenv best for just testing isolated environments, and running
> production
> with the existing global space (I feel naive typing this out, so I must be
> wrong (: )
>  as is (isn't there more overhead with virtualenv anyhow?)
>
> I hope I made sense.
>
> If anyone has any relevant docs that clarify this (maybe my searches stink)
> I'd love to read
> over what there is so I may make an appropriate call.
>
> Adrian

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



django-packagemaker a paster tool for making reusable apps

2011-03-30 Thread Preston Holmes
I've just pushed an initial release of a tool that will hopefully make
it easier to make apps more easily shareable.

The idea is something like this:

manage.py startapp gets you a start, but once you get something to the
point where you might want to share it, now you've got to wrap it up
in all the packaging.  This means copying and pasting boilerplate for
a setup.py, setting up the dist layout, etc.

This is also required if you want to use your app via pip
requirements.

This tool uses paste script to automate much of this process and can
be used as an alternative to startapp

https://github.com/ptone/django-packagemaker

The template is opinionated about a few things, and this is just a
start, feedback and contributions welcomed.

-Preston

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



representing a possible future object in a form?

2010-11-15 Thread Preston Holmes
This is a cart/horse pattern I run now and then, and while I can think
of several sort of ugly ways to do it, I'm wondering if someone has a
clean solution in Django.

I'm going to use a gradebook as an example.  The goal is to present a
user with a grid of lets say students and assignments to enter
grades.  The models would be

- Students

- Assignments

- Grades (a M2M between students and assignments)

Now on the grade entry form, with multiple students and assignments,
the grades don't yet exist for all students, and may not all be
entered.  How does one generate the form for the possibilities,
without pre-creating all the empty grades.

It would be nice to use modelform here, but it seems that that the
only way to do it is just with a form and then create objects for
grades that get filled out in the view.  How do others solve this
problem of representing a "possible future" object in a form that is
then only optionally created if filled out.

-Preston

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Nesting related object in formset

2010-10-13 Thread Preston Holmes
I'm pretty comfortable with the concept of mixing multiple objects in
one form.  But I have a case where I have a model formset and want to
add a form field that represents a field from a related model, such
that the related model can be created if it is filled out.

As a simple example:

I have a person object and a related pet object

I have a person formset, and I want to have a field in each form:
"pet's name".  If that is filled out, I want to create a pet object in
the related object manager.

The closest I've found is 
http://yergler.net/blog/2009/09/27/nested-formsets-with-django/

which deals with a nested formset.  I'm wondering if there is
something simple to deal with just a nested object represented by a
single field.

-Preston

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Mutli-column composite keys

2010-09-20 Thread Preston Holmes


On Sep 19, 1:50 pm, "J. P. Smyth"
 wrote:
> Someone here wrote:
>
> "Mutli-column composite keys are not currently supported by Django.
> Adding support for multi-column keys (primary or otherwise) is
> something that has been long discussed, and there is agreement that it
> is a desirable feature"
>
> My problem is that I absolutely must have multi-column keys to create
> a unique primary key.
>
> My primary table consists of a name and part of another column.  Other
> tables are derived from this main table.
>
> I have no idea of how to overcome this obstacle. The table consists of
> the names of companies which are repeated so they're not unique.  The
> entity that would make for a unique key is the name of a company and
> the product id.
>
> Does anyone have a suggestion how I can achieve this unique primary
> key in Django without resorting to creating another column with the
> company name plus the product id?

You don't really say why the default of an integer autofield (Django's
default PK) won't work for you.

Given that, by your own admission, you don't know where to start with
multi-column keys, your not likely to have a pleasant time hacking
into Django's core to do something unsupported in the ORM layer.

-Preston

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Tying a model to a specific database using the model's meta data?

2010-09-18 Thread Preston Holmes
On Friday, September 17, 2010, Stodge  wrote:
> I have a bunch of models and I want to specify which models (tables)
> are stored on which PostgreSQL database. I've read the documentation
> and I know I can use the using() function. I'm just wondering this
> can't be specified in the model's meta data:
>
>     class Meta:
>         using = 'db_name'
>
> or:
>
>
>     class Meta:
>         db_server = 'db_name'
>
> Where the db_name maps to the name specified in settings.py. I'm
> adding in Django support to an existing application so this would
> avoid littering my code with using() function calls. I know I could
> use a database router but that seems like overkill when it makes more
> sense to define the database in the model's meta data. Any ideas why
> this is?

Tying this to your app/model makes it very un-reusable. While a router
is at the project level.

-Preston
>
> 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-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Filter for non-True NullBooleanField

2010-09-11 Thread Preston Holmes


On Sep 10, 2:43 pm, Christos Jonathan Hayward
 wrote:
> P.S. Setting:
>
> .filter(is_invisible__in = [False, None])

how about:

.exclude(is_invisible__exact = True)

>
> is not working as intended; I seem to be getting no matches when I should be
> getting matches.
>
> On Fri, Sep 10, 2010 at 4:19 PM, Christos Jonathan Hayward <
>
>
>
>
>
> christos.jonathan.hayw...@gmail.com> wrote:
> > How can I filter for instances having a NullBooleanField that is not True
> > (i.e. is either False or a null)?
>
> > --
> > [image: Christos Jonathan Hayward] 
> > Christos Jonathan Hayward, an Orthodox Christian author.
>
> > Author Bio  • 
> > Books
> >  • *Email * • 
> > Facebook
> >  • LinkedIn  • 
> > Twitter
> >  • *Web * • What's 
> > New?
> > I invite you to visit my "theology, literature, and other creative works"
> > site.
>
> --
> [image: Christos Jonathan Hayward] 
> Christos Jonathan Hayward, an Orthodox Christian author.
>
> Author Bio  • 
> Books
>  • *Email * •
> Facebook
>  • LinkedIn  •
> Twitter
>  • *Web * • What's
> New?
> I invite you to visit my "theology, literature, and other creative works"
> site.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: django-simple-freinds: template tags and Friendship request

2010-09-09 Thread Preston Holmes


On Sep 9, 5:11 am, justin jools  wrote:
> Hi Muhuk,
>
> I am using django-simple-friends app, much easier to setup than django-
> friends.
> but need a little help and was hoping for some guidance.
>
> I have set up friends_list.html no problem:
>  Friend List
> Friends for {{ user }}
>   
>   {% for friends in friends_list %}
>   {{ friends.username }}
>   {% endfor %}
>   
>
>  and understand how to send friend request via url:
>
>  http://127.0.0.1:8000/friends/add/jim
>
>  but I am having problems listing friend requests:
>
>  {{ friendship_requests.incoming }} spits out (below) and I coudn't
> work how to remove the [< >]
>
> or access the User sending the friend request.
>
>  []

what you are seeing with  the <> is a representation of a
FriendshipRequest 

You need to iterate over the requests in a for loop and then access
each requests from_user

look at the template docs on using a for loop for more on that.

-Preston


>
> So I figured this is wrong to do it.
> So I tried templatetags:
>
> {% load friends_tags %}
> {% add_to_friends 3 %}
>
> which works, and redirects to _add_to.html
> which I'm guessing should have a message like You have made a friend
> request to User _
> don't know how to get User being sent to.
> Do you have a working example or can you help me clear up these
> issues. Thanks for your help
>
> Sincerely,
> JusinJools

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: upload_to vs FileSystemStorage

2010-09-09 Thread Preston Holmes


On Sep 8, 5:04 am, Dave  wrote:
> Hi everyone,
>
> I've found in documentation usage of custom file storage. There it is
> like that 
> (http://docs.djangoproject.com/en/1.2/topics/files/#the-built-in-files...
> ) -
>
> from django.db import models
> from django.core.files.storage import FileSystemStorage
>
> fs = FileSystemStorage(location='/media/photos')
>
> class Car(models.Model):
>     ...
>     photo = models.ImageField(storage=fs)
>
> Notice there is no upload_to attribute in ImageField. I suppose, it's
> quite obvious, because I will set it by attribute location in
> initializing FileSystemStorage object fs. But if I'll do it this way
> it'll rise an error - Error: One or more models did not validate:
> app.mymodel: "image": FileFields require an "upload_to" attribute.
>
> What am I missing? Or is it possiblle to have upload_to somehow set to
> an empty string? So the location would be the same as it is declared
> in the file storage object initialization.

You've basically answered your question - if you read the docs for
FileField you will see upload_to is a required field.  It defines path
relative to storage root.  so empty string or '/' should do it.

-Preston

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: PayPAL-IPN-request doesn't call the view

2010-09-09 Thread Preston Holmes


On Sep 8, 11:47 pm, Max_  wrote:
> Hello,
> I created a website, using the IPN-Function.
> Everything worked fine at first - the notification view was called and
> the signal was sent.
> But now (without any changes on the code), the IPN-Request from PayPAL
> doesn't call the IPN-view anymore. The Request is logged in the apache
> access-log but with an internal server error (500) response.
> (216.113.191.33 - - [08/Sep/2010:14:25:43 +0200] "POST /payPalNotify/
> HTTP/1.0" 500 25992 "-" "-").
> Same problem if I set another view (even an empty view) as notifiy-
> url. It works (the request is logged with a HTTP200 response), if I
> let PayPAL respond to a php-File. It seems like the wsgi-handler can't
> handle the PayPAL-Request. The error.log somtimes logs:
> [Wed Sep 08 16:19:20 2010] [error] [client 216.113.191.33] mod_wsgi
> (pid=2699): Exception occurred processing WSGI script '/usr/local/
> django/binner/apache/django.wsgi'.
> [Wed Sep 08 16:19:20 2010] [error] [client 216.113.191.33] IOError:
> failed to write data
> The website is running on a Ubuntu 10.4LTS-Server/Django 1.2.1/wsgi
> Has anyone else experienced this problem? Any Ideas?
>
> WSGI-Handler:
> import os
> import sys
> import django.core.handlers.wsgi
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'binner.settings'
>
> sys.path.append('/usr/local/django')
> sys.path.append('/usr/local/django/binner')
> sys.path.append('/usr/local/django/binner/templates')
>
> application = django.core.handlers.wsgi.WSGIHandler()

you don't say whether you've tried just loading the notification view
in your browser (simulate PayPals response)

-P

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Advice needed on bundling applications

2010-09-07 Thread Preston Holmes


On Sep 7, 1:45 am, Benedict Verheyen 
wrote:
> Hi,
>
> i've written a calltracking application for my company and other apps will 
> follow soon.
> Now, i would want a central way to access them and to assign rights on who 
> can see
> and run what application.
> The dashboard or access panel will be very simple: icons that link to the 
> application and based
> on the user, some apps will not be visible.
>
> I'm not sure as to what is the better approach.
> i'm thinking of making a new project "dashboard" where i have a simple
> model containing info like app name, icon, position on the dashboard and so 
> on.
> Easy enough.
>
> However, in my calltracking i have all the logic of usermanagement (login, 
> logout).
> Do i copy this to my dashboard and remove it from the calltracking app so you
> always have to login via the dashboard?
> Or do i just copy it to the dashboard?
>
> Another possibility is to make the dashboard the project and the calltracking 
> an app in that project?
> Is it possible to both use them as projects but still have one way to login 
> so that if a user
> is logged in on the dashboard, he/she is automatically logged in when 
> accessing the
> calltracking?

If you want user auth - then all your apps should be in one project -
such that your company == your project

The alternative is to use some other auth backend, such as LDAP - then
each project can reference that one auth directory.

-Preston

>
> Thanks for any insights,
> Benedict

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Generate a daily serial/batch/lot number

2010-09-06 Thread Preston Holmes


On Sep 6, 2:39 am, kmpm  wrote:
> First of all to everyone, thanks for all good suggestions so far.
>
> Regarding UUIDs, one of the business requirements (which I don't
> control) is that the identifier that is to be used on barcodes and
> what not is to be in the format "YYMMDD" where  is the number
> we are talking about. So UUID would be great and unique, as well would
> the automatic pk/id from the model itself as that is unique enough.
> But I need a rolling number per day and nothing else.

what about a simple function that does something as low tech as
checking a lock file.  If you had multiple front end servers, this
could be a running process on a server using semaphore lock.

-Preston

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Chat application in Django

2010-09-04 Thread Preston Holmes


On Aug 31, 4:31 am, Shamail Tayyab  wrote:
> Hi,
>
>    I am working on a chat application in Django, how can I ensure that I
> do not have to poll the server for any chat data.
>
> Possible approaches that I've been to:
>
> 1. BAD - use polling.
>
> 2. Use long polling - bad approach afa browser support is concerned.
>
> 3. Using sockets in flash - makes the application flash dependent.
>
> Is there some good way to do this? Or if there is something Django
> specific? Something like HTTPBinding or any 3rd party tested libraries?
> I am expected to provide support till IE6. :-(

You might want to check out: http://hookbox.org/

-Preston

>
> Correct me if I am wrong, flash is available on 95% of the systems, this
> approach looks like safest bet, is it good to go?
>
> Btw, how does Gmail and FB chat works?
>
> 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-us...@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.



choices based on existing entries

2010-05-11 Thread Preston Holmes
Filemaker has a pattern where you can set the choices of a field to be
the indexed contents of that field.

Along with an "Other..." choice option to add a new value.

This is a very handy way of having user modified choices for a given
field.

Now I can think of several ways to do this in a form field init, but
it seems like there should be a more reusable way to do it with a
custom field type or mixin by overriding get_choices on the field
object.

Has anyone done something like this?

-Preston

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



permissions like widget to add users to groups

2010-04-27 Thread Preston Holmes
Has anyone adapted the interfaced used for adding permissions to a
group/user to allow one to add users to a group?

How reusable is the CSS/JS?

-Preston

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: How to use CommaSeperatedIntegerList with CheckboxSelectMultiple

2010-04-26 Thread Preston Holmes


On Apr 26, 2:28 am, Kevin Renskers  wrote:
> I also used the multiple select field found 
> onhttp://www.djangosnippets.org/snippets/1200/
> with success, until I updated Django to the 1.2 beta release. It now
> longer works, always giving the validation error. I have no clue how
> to fix this, so I was hoping you found the answer to your problem and
> can share it?
>
> I have a tuple with (string, not integer) choices, and want to show
> the user a multiple select field. The choices should be saved as a
> comma separated string in the database.

The issue with the custom field is that it does not implement a
'validate' func

I believe all I did to get it working was add:

def validate(self, value, model_instance):
return


>
> Cheers,
> Kevin
>
> On Apr 3, 5:30 pm, ben  wrote:
>
>
>
>
>
> > Either I don't understand how CheckboxSelectMultiple works or there is
> > a bug in Django 1.2. I have tried the following custom multi select
> > fields I have found around the web.
>
> >http://www.djangosnippets.org/snippets/1200/http://www.davidcramer.ne...
>
> > Out of desperation I tried using a ManyToMany field and all produce
> > the same validation error when used with either CheckboxSelectMultiple
> > or SelectMultiple.
>
> > 'Select a valid choice. [u'1', u'2', u'3', u'4'] is not one of the
> > available choices.'
>
> > This happens regardless of the number of choices, types of the choices
> > tuple values, or the model field type.
>
> > Can anyone point me to an example that demonstrates how to properly
> > use these fields.
>
> > Thanks,
> > Ben
>
> > On Apr 2, 5:19 pm, Bill Freeman  wrote:
>
> > > I know that I used (some revision of) that snippet a while back.
>
> > > Realize that what it stores is a string, containing digits and commas.
>
> > > The to_python and get_db_prep_value methods are responsible for
> > > converting between that database single string and a list of strings,
> > > not integers.  You can use any string (that doesn't contain comma) to
> > > represent a choice (db value).  I had two character ID flags (easier to
> > > read in pgadmin).  It did work, but I forget the details (I eventually 
> > > went
> > > to multi to multi and the one end of many to one relationships).  So I
> > > expect that the DB side of your choice tuples must be strings.
>
> > > Bill
>
> > > On Fri, Apr 2, 2010 at 3:37 PM, ben  wrote:
> > > > Sorry. I pasted code that I was experimenting with. I thought maybe
> > > > the validation code was looking for strings because that is what the
> > > > error code said it was looking for. Before that I had been using
> > > > integers and that doesn't seem to work either. I am wondering if this
> > > > is a bug in Django 1.2. I hunted around on Django snippets as Bill
> > > > Freeman suggested and found the following 
> > > > codehttp://www.djangosnippets.org/snippets/1200/
> > > > for a custom multiple selection field.
>
> > > > I inserted it into my app and it doesn't want to validate the
> > > > selection either. In fact it returns a validation error message
> > > > similar to what I received from CommaSeperatedIntegerField and
> > > > CheckboxSelectMultiple. "Value [u'1'] is not a valid choice."
>
> > > > Not sure what is going on. Any insights would be appreciated.
>
> > > > On Apr 2, 3:06 pm, orokusaki  wrote:
> > > >> The problem is that you're using '1' instead of 1. The comma
> > > >> separated integer list is expecting integers not strings. The reason
> > > >> you're seeing u'1' is because it's being turned from a string to a
> > > >> unicode object.
>
> > > >> Try this instead:
>
> > > >> SOME_CHOICES =  ((1, 'ch1'),(2, 'ch2'), (3, 'ch3'),(4, 'ch4'))
>
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups "Django users" group.
> > > > To post to this group, send email to django-us...@googlegroups.com.
> > > > To unsubscribe from this group, send email to 
> > > > django-users+unsubscr...@googlegroups.com.
> > > > For more options, visit this group 
> > > > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Disabling Messaging

2010-03-23 Thread Preston Holmes


On Mar 23, 8:20 am, jrs  wrote:
> Is there a flag somewhere which will allow me to disable django
> messaging?
>
> Thanks

You give too few details.  The messaging system is something that is
opt in, you have to create messages, and then display them in your
template.  Are you trying to alter an existing system?  Removing
references to messages in your templates is the fastest way to disable
them without incurring other breakage in the apps.

-Preston

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: how can i use manage.py as a command in script file

2010-03-16 Thread Preston Holmes


On Mar 15, 10:27 pm, pyleaf  wrote:
> I want to use manage.py as a command in script file.
> e.g,
>
> >> python manage.py shell
> >>from testproject.testapp.models import Testee
> >>from testproject.others.modules import utils
> >>utils.do(Testee)
>
> Above are commands in command window manually.
> but, how to make these like :
> #my_script.py
> #!/usr/local/bim/python
> from testproject.testapp.models import Testee
> from testproject.others.modules import utils
> utils.do(Testee)
>
> i dont know how to import manage.py

see, and comments attached

http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/


>
> thank you!
> --
> Believing is Everything.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: A bit of a modeling question

2010-03-16 Thread Preston Holmes


On Mar 16, 3:21 am, ALJ  wrote:
> This is a bit of a modeling question that I am struggling to get my
> head around. How would you model this scenario?
>
> I have to record expenses that are of 3 different types.
>
> 1. Fixed - The name of the expense and unit amount are fixed. For
> example, "inconvenience allowance" of £30 per day.
> 2. Classified - The name of the expense is fixed, but the actual unit
> amount isn't. For example "Hotel expenses". The actual unit amount
> will depend on the hotel they stay at. They'll need to enter that
> themselves.
> 3. Unclassified - The name of the expense and the amount is arbitrary.
> So they may have an expense we haven't thought of before but it needs
> to go in.
>
> Of course I'll need to create a summary that tots up the total
> expenses for the particular event.

whether you subclass a base model, or simply have a "type" field on
your expense object is going to depend on the details and nuance of
the rest of your business logic in your app.  I would only say that
simple is better unless you have a reason or need for the complexity.

Given that the fields between them are identical, I would probably
just use a "type" choice field and have the interface adapt as needed.

-Preston

>
> Would the best way of doing this be:
>
> a) Have a base model and then build on that for the 3 different
> scenarios?
> b) Have three different tables and then do a union on them?
>
>
>
> Just for interest ... this is where I got so far, but am now stumped
>
> class CostType(models.Model):
>     name = models.CharField("Name", max_length=30) 'e.g. commission,
> subsistence ...
>
> class CostItem(models.Model):
>     name = models.CharField("Name", max_length=50) 'e.g. product x,
> inconvenience allowance, ...
>     cost_type = models.ForeignKey(CostType, verbose_name="Type")
>
> class Rate(models.Model):
>     cost_item = models.ForeignKey(CostItem, verbose_name="Item")
>     valid_from = models.DateField("From")
>     valid_till = models.DateField("Till")
>     unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
> decimal_places=2)
>
> 'Costs with a fixed description and unit amount
> class FixedCostList(models.Model):
>     markettingevent= models.ForeignKey(Event)
>     rate = models.ForeignKey(Rate)
>     units = models.IntegerField()
>
> 'Costs with a fixed description but arbitrary amount
> class StructuredCostList(models.Model):
>     markettingevent= models.ForeignKey(Event)
>     cost_item = models.ForeignKey(CostItem, verbose_name="Item")
>     unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
> decimal_places=2)
>     units = models.IntegerField()
>
> 'Costs with both a arbitrary description and amount
> class OtherCostList(models.Model):
>     markettingevent= models.ForeignKey(Event)
>     description = models.CharField("Name", max_length=30)
>     unit_amount = models.DecimalField("Price Per Unit", max_digits=5,
> decimal_places=2)
>     units = models.IntegerField()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: dynamically excluding fields in admin form

2010-02-28 Thread Preston Holmes


On Feb 28, 12:21 pm, Simon Davies  wrote:
> figured out how to do it using the get_form method like this:
>
> class AccessoryStockOrderAdmin(admin.ModelAdmin):
>     form = AccessoryStockOrderForm
>     def get_form(self, request, obj=None, **kwargs):
>         form = super(AccessoryStockOrderAdmin, self).get_form(request,
> obj, **kwargs)
>         if obj == None:
>             del form.base_fields['cancelled']
>     return form
>

If it is just the add_view you want to change another way is to modify
the add_view method:

def add_view (self, *args, **kwargs):
self.exclude =
('primary_phone','primary_email','primary_address')
return super(ContactAdmin, self).add_view(*args, **kwargs)

But I found doing this I needed to explicitly reset exclude to None
for other views - as it was being remembered somewhere.

-Preston

> On 28 Feb, 13:00, Simon Davies  wrote:
>
>
>
> > Hi
>
> > I have a model which I access from the admin application.  I want to
> > exclude some fields dynamically.
>
> > My model looks like this:
>
> > class StockOrder(models.Model):
> >         number_of_items_pending_order =
> > models.PositiveIntegerField(max_length=5, default=1)
> >         number_of_items_ordered = models.PositiveIntegerField(max_length=5,
> > default=1)
> >         number_of_items_delivered = 
> > models.PositiveIntegerField(max_length=5,
> > default=1)
> >         order_date = models.DateTimeField(auto_now_add=True,
> > verbose_name=u'Date ordered')
> >         confirmed = models.BooleanField(default=False)
> >         confirmed_date = models.DateTimeField(verbose_name=u'Date 
> > confirmed',
> > null=True, blank=True)
> >         cancelled = models.BooleanField(default=False)
> >         cancel_date = models.DateTimeField(verbose_name=u'Date cancelled',
> > null=True, blank=True)
> >         completed = models.BooleanField(default=False)
> >         completion_date = models.DateTimeField(verbose_name=u'Date
> > completion', null=True, blank=True)
>
> > I want to exclude some fields depending on the state of others.  So if
> > completed is True I don't want to see the confirmed or cancelled
> > flags.
>
> > The options to exclude fields I understand are:
>
> > 1: ModelAdmin.exclude attribute  in admin.py.  I can't see how this
> > can be manipulated dynamically however.
>
> > 2.  I create my own Modelform and set the form attribute in admin.py
> > to the modelform, the modelform will look something like this:
>
> > class StockOrderForm(ModelForm):
> >     class Meta:
> >         model = StockOrder
> >         exclude = ('cancelled',)
>
> > However I run into the same problem as in 1, how can I manipulate the
> > exclude parameter.  Is it possible to do so in __init__?
>
> > Thanks
>
> > Simon

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 new Thread in a view?

2010-02-18 Thread Preston Holmes


On Feb 17, 9:36 am, justind  wrote:
> I have an unusual Django application. I was wondering if someone could
> offer advice to the best way to handle a requirement. This isn't a
> standard application (and might not even seem like a good use of
> Django, but that's beside the point.)
>
> Redhat, Python 2.4, Django 1.1, mod_wsgi.
>
> In a view, I need to open a socket, send a message to a piece of
> hardware,then close the socket and return the view. However, the
> hardware takes n milliseconds to do its thing, and if the socket
> closes while its doing its thing (even if its received its entire
> message), it stops what its supposed to do, which is bad.
>
> The hardware is fire and forget. It doesn't return a response. There's
> no need to keep the view waiting, except I need to keep that socket
> open so it continues.

So there is no way to know how long to keep the socket open? If so
than in your view there is nothing better than to time.sleep some
arbitrary time.

It sounds like you want to have the code that communicates with the
server in its own process.

Your Django view would then communicate with this process and the
process would keep the socket open to the hardware all the time.

There are a number of choices to communicate with your process - but
you could use named pipes, sockets (local server), or a message_queue
like rabbitMQ/Celery

-Preston

>
> As a stopgap meaure, I've just been using time.sleep to hold the view.
> This works, but its hideous.
>
> I tried running all the socket communication in a seperate deamon
> thread, but this didn't change anything. When the view returned, the
> socket closed, the hardware stopped.
>
> What is a better solution to this problem? Actually, I feel like I
> can't solve it because I lack an understanding at what's happening
> where Django touches Apache and I'd like to fill that gap, so in
> addition to help with this particular problem, descriptions of what's
> going on at apache/mod_wsgi process level and how that interacts with
> me spawning threads etc (or pointers to docs) would help me out and be
> appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Single Login for two different applications?

2010-02-09 Thread Preston Holmes

On Feb 9, 3:43 am, djangonoob  wrote:
> Hello,
>
> I have the following problem which I hope someone could shed some
> light on.
>
> In my project I have the main site with login. I now implemented a
> questionnaire app  that also requires a login. It would be great if
> someone could help me to take the first login from the main site and
> also enter that info into the questionnaire app. The reason is because
> the user doesnt have to enter the same credentials twice. The main
> site redirects to the questionnaire first and both use the same DB.
>
> Could anybody please explain or point me in the right direction I
> would be grateful thank you.


Historically this would be done with an external authentication tool
like LDAP that Django would refer to.

However now it might be possible with > 1.2b to stick your users in
their own database.  I don't know much about how Django does its auth
sessions/cookies/caches and what tables need to be consolidated there.

-Preston


>
> Regards

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: entering scores (one model) for a list of students (another model)

2010-02-05 Thread Preston Holmes
Assuming you want to create a score per class - you should have
students go to a form that:

creates a student and first score if student does not already exist

creates a score for the student for that class and date

Basically the students should be creating the 'blank' scores when they
come in.

-Preston


On Feb 5, 5:35 am, Tim Arnold  wrote:
> On Feb 4, 4:07 pm, Tim Arnold  wrote:
>
>
>
>
>
> > I'm creating a form that students fill in as they arrive at class.
> > Just name, email, etc.
> > When the class is over I want to display a form for the teacher to
> > enter the grades.
>
> > So, no problem on the students entering their info, I just have a
> > Student model.
> > I have a Score model that has the score and a ForeignKey to the
> > student.
>
> > That makes sense to me, but I'm have bunches of trouble figuring out
> > how to display the form to the teacher
>
> > I want a list of student names with an  form for each grade. So
> > I'm figuring a formset is what I need, based on the Score model. But I
> > don't get how to associate the student with the score the teacher
> > enters.
>
> > thanks for any pointers.
> > --Tim Arnold
>
> To make my question more clear, what I don't know how to do is to
> display the student objects on the same page as a list of Score forms
> and connect each entered score to the Student object.
> thanks,
> --Tim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: How to customize form styled by django-uni-form?

2009-12-15 Thread Preston Holmes


On Dec 15, 12:02 pm, Continuation  wrote:
> This is a question about django-uni-form. But I figure many people
> here may have experienced with django-uni-form so I'd try asking here.
>
> I'm using django-uni-form to style my form using the filter my_form|
> as_uni_form:
>
> 
>       
>            {{ my_form|as_uni_form }}
>            
>                 
>            
>        
> 
>
> It looks really good. But I need to customize it.
>
> For example, one of the field "percentage" of the form is of the type
> IntegerField. It is being rendered as an .
>
> The problem is that the text box is really wide, I'd like to make it
> only 2 character wide.
>
> Also I want to add a percentage sign "%" right after the text box so
> that users know they if they put in the number "10" in the text box,
> it means 10%.
>
> Is there anyway to do that with django-uni-form?

These aren't related to the use of uni-form

This is just a matter of using the right widget with attributes, and
labels and help text in your models/forms:

http://docs.djangoproject.com/en/1.1/ref/forms/widgets/

-Preston

>
> Thanks for your help.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




aggregation puzzle

2009-12-12 Thread Preston Holmes
I've hit a case where I want to use aggregation, but I think I'll have
to end up using a for loop.

I have items.  They have an estimated cost and an actual cost

They may have one, the other, or both defined.

They are both DecimalFields

I can get the sum of the estimated cost with a simple aggregate like:

qs.aggregate(Sum('estimated_cost'))['estimated_cost__sum']

and I can define a model method/property to return the "best cost"

return self.actual_cost or self.estimated_cost

However, I can't seem to figure out how to get this best cost into a
aggregate to use in a view.

So is it back to looping over the queryset in this case?

-Preston

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Should empty formsets call their own clean method?

2009-12-11 Thread Preston Holmes
Well something wonky is going on.

>From my readthrough of the code, it *should* get called on empty
formsets:

is_valid calls total_form_count to get a loop count
total_form_count should be positive even if forms are blank

is_valid then accesses form.errors inside that loop
(django.forms.formsets.py 1.1.1 #237 if bool(self.errors[i]))

accessing form.errors should run _get_errors()
which calls full_clean()
which calls clean()

What about if you do

formset3.is_valid()

then

formset3._errors

this will access the current errors without triggering the full_clean

If it is None - than validation is not triggering an access to the
property function as it should

-Preston


On Dec 11, 7:36 am, Tom Evans  wrote:
> On Tue, Dec 1, 2009 at 5:02 PM, Tom Evans  wrote:
> > On Tue, Dec 1, 2009 at 4:14 PM, Tom Evans  wrote:
> >> Hi all
>
> >> We encountered a strange issue today. When a user submits a formset
> >> that is empty, we call is_valid() on the formset, expecting the
> >> clean() method to be called. We then subsequently get errors later on,
> >> because the formset did not call self.clean(), and therefore it did
> >> not populate the fields we require on the formset.
> >> 
>
> > Raised ashttp://code.djangoproject.com/ticket/12295
>
> > Cheers
>
> > Tom
>
> Can I get some feedback on this please?
>
> TIA
>
> Tom

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: How to execute linux command in django view

2009-12-11 Thread Preston Holmes


On Dec 11, 10:40 am, Kashif Azeem  wrote:
> Thank you Shawn for the reply now i have another problem i.e. on executing
> some commands like 'vgs' or 'lvs' it didnt executed and the warning
> generated as "Running as a non-root user. Functionality may be unavailable".
> Any idea how to solve this user issue please?

Any subprocess started from django will run as the user of the
webserving process.

mod_wsgi lets you run in daemon mode as a specified user but you would
never run a web process as root.

"Daemon processes may if required also be run as a distinct user
ensuring that WSGI applications cannot interfere with each other or
access information they shouldn't be able to."

If you need to run a set number of commands, you'll have to edit your
sudoers file to allow those commands (out of this list's scope)

Depending on your project, you may want to run django behind a
cherrypy wsgi server that you can run as a user created for the
project.

-Preston

>
> --
> Kashif
>
>
>
>
>
> On Fri, Dec 11, 2009 at 10:07 PM, Shawn Milochik  wrote:
> > The proper way to do that is to use the subprocess module.
>
> >http://docs.python.org/library/subprocess.html
>
> > If you don't want to do much reading, you'll just want to look at section
> > 18.1.3.1, which gives the way to call a simple shell command the way you'd
> > do with backticks in Perl.
>
> > However, since you mentioned fdisk, maybe you're actually wanting to
> > interact with the shell command. That's more complicated, but can be done
> > with the "communicate" method of a subprocess.
>
> > Shawn
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com > groups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> -Kashif

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: many permission sets for same user

2009-12-11 Thread Preston Holmes


On Dec 10, 8:41 am, Adonis  wrote:
> Hi,
>
> I am trying to figure out the best way to do this.
> I have built a django application where users are members in projects.
> Thus, i need to assign users different permission sets that correspond
> to different projects. The django core permission system cannot solve
> this by itself. I took a look at django-autority extenion which seems
> able enough to solve this but could not figure out how to do this.
>
> {% ifhasperm [permission_label].[check_name] [user] [*objs] %}
>     lalala
> {% else %}
>     meh
> {% endifhasperm %}
>
> in the example above, i can check a permission of a user in an object
> (e.g a project in my app).
> I would need multiple views of auth_user_user_permissions such as:
> project1_user1_permset1, project2_user1_permset3 etc.
>
> Any suggestions will be appreciated!

There are some details about your implementation I have to guess at,
but what about using a many2many with a through object.

So you have Project objects, and your User objects

Projects have a m2m to Users through a ProjectMember object and that
contains what permissions the user has.

All the views that need to check the permissions should be able to
look up that object and act accordingly.

http://docs.djangoproject.com/en/dev/topics/db/models/#intermediary-manytomany

-Preston

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Issue with Django form when submitted using jQuery form plugin

2009-12-11 Thread Preston Holmes


On Dec 10, 11:02 am, jul  wrote:
> hi,
>
> when submitting my form using jQuery form plugin, the request received
> by the target view is different than that received when the form is
> submitted in the standard way (with no javascript), and my Django
> template does not render as expected. When submitted in the standard
> way, the template renders the form errors (the "form.
> [field_name].errors), while it doesn't when submitted via javascript.
> Using the javascript submit, how can I get a request allowing to
> render the template as it does using the standard submit?

The page itself does not get the response from the submit, only the
handler defined by the 'success' option does.  You don't show any code
for a showResponse function.

The way I would do this is create a view that handles the form
validation, and then returns a simple json object containing a status
and replacement form HTML - so (in very quick pseudo code)

function showResponse(responseObj)
if responseObj['status'] == OK:
redirect to success page or otherwise display OK, hide the form,
whatever
else if responseObj['status'] == error:
$("#my-form-selector").html = responseObj['form-with-errors']

Your view would create a json dict returned not through a rendered
template, but directly with HttpReponse object

-Preston


> The code and the diff between the request objects received in both
> cases are shown below.
>
> thanks
> jul
>
> javascript code:
>
> *
> var is_geocoded = false;
> var interval;
>
> $(function(){
>
>     $("#submit").click(function() {
>         var options = {
>             beforeSubmit:  getPosition,  // pre-submit callback
>             success:       showResponse  // post-submit
> callback
>         };
>
>         // bind form using 'ajaxForm'
>         $('#addresto').ajaxForm(options);
>     });
>
> });
>
> function getPosition() {
>
>     var geocoder =  new GClientGeocoder();
>     var country = $("#id_country").val();
>     var city = $("#id_city").val();
>     var postal_code = $("#id_postal_code").val();
>     var street_number = $("#id_street_number").val();
>     var street = $("#id_street").val();
>     var address = street_number+", "+street+", "+postal_code+", "+city
> +", "+country;
>
>     geocoder.getLatLng( address, function(point) {
>
>         if (point) {
>
>             $("#id_latitude").val(point.lat())
>             $("#id_longitude").val(point.lng())
>             is_geocoded = true;
>         } else {
>             is_geocoded = true;
>         }
>     });
>
>     interval = setInterval("doSubmit()", 500);
>
>     return false;
>
> }
>
> function doSubmit() {
>
>     if (is_geocoded) {
>         $("#addresto").ajaxSubmit();
>         clearInterval(interval);
>     }}
>
> *
>
> Django template code:
>
> *
> 
>
> Name:{{form.name.errors}}
> {{ form.name }} 
> Country:{{form.country.errors}}
> {{ form.country }} 
>
> 
>
>  value="Submit" />
> 
> *
>
> Here's the difference between the request objects received by the view
> with standard submit and with javascript submit:
>
> *
> x...@xxx:~$ diff javascript_submit standard_submit
> 7c7
> <  'CONTENT_TYPE': 'application/x-www-form-urlencoded; charset=UTF-8',
> --->  'CONTENT_TYPE': 'application/x-www-form-urlencoded',
>
> 24c24
> <  'HTTP_ACCEPT': '*/*',
> --->  'HTTP_ACCEPT': 
> 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
>
> 28d27
> <  'HTTP_CACHE_CONTROL': 'no-cache',
> 33d31
> <  'HTTP_PRAGMA': 'no-cache',
> 36d33
> <  'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
> 70c67
> <  'wsgi.input': ,
> ---
>
>
>
> >  'wsgi.input': ,

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Raise error based on both form and inline_formset

2009-12-11 Thread Preston Holmes


On Dec 10, 9:05 am, cerberos  wrote:
> I'm building a library system and have models Member, Loan and
> LoanItem (relationships as you'd expect), and an inline formset to
> enter a new loan (Loan and LoanItems).
>
> A member can borrow up to 6 books at a time, so my form contains 7
> individual forms (1 loan and 6 loan items), I need to get the member
> from the loan and the number of loan items from the loan items forms
> then raise an error if the items already loaned + the number of new
> loan items entered is greater than 6.
>
> I can raise errors based on the form or the formset but not both
> together, is this possible? What do I subclass to add the custom clean
> method?

checking whether an item is loaned is easy enough to do in the clean
method of an individual loanitem form.

but validation done with form combinations has to be done in the view
since a clean method can't span across different form/formset objects.

If you want to return the error as if it were a form error, you can
inject your error into the validated form by accessing its _errors
property - there are some examples here:

http://docs.djangoproject.com/en/dev/ref/forms/validation/#described-later

-Preston

Since a clean method only applies
>
> Here's my unfinished view
>
> def loan_add_form(request,template_name='resources/
> loan_add_form.html'):
>
>     loan = Loan()
>     LoanItemFormset = inlineformset_factory
> (Loan,LoanItem,formset=LoanItemBaseModelFormSet,can_delete=False,extra=6,ex 
> clude='date_returned')
>
>     if request.method == 'POST':
>
>         loan_form = forms.LoanForm(request.POST,instance=loan)
>         loan_item_formset = LoanItemFormset
> (request.POST,request.FILES,instance=loan)
>
>         if loan_form.is_valid() and loan_item_formset.is_valid():
>             loan_form.save()
>             loan_item_formset.save()
>
> #            request.user.message_set.create(message="Confirmation
> message.")
> #            return HttpResponseRedirect('/somepath')
>
>     else:
>         loan_form = forms.LoanForm(instance=loan)
>         loan_item_formset = LoanItemFormset(instance=loan)
>
>     context = {
>         'loan_form': loan_form,
>         'loan_item_formset': loan_item_formset,
>     }
>
>     return render_to_response(template_name, context,
> context_instance=RequestContext(request))

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Separate views for form display and handling

2009-12-11 Thread Preston Holmes


On Dec 11, 5:20 am, Aaron  wrote:
> On Dec 10, 6:04 pm, aa56280  wrote:
>
> > if form.is_valid():
> >   # do something and redirect
> > else:
> >   render_to_response('foo.html', {'form' : form'})
>
> Would that leave the URL as displayed in the browser the same as the
> one for the form handling view?

It will send a http redirect header, you can pass along your cleaned
data at that point.

See the docs for the shortcut:
http://docs.djangoproject.com/en/dev/topics/http/shortcuts/#redirect

-Preston

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




making RequestContext the default context_instance

2009-12-10 Thread Preston Holmes

Is there a way to make this the default at the project level?

I see a number of tricks out there for making it easier to do within
your own views, but I'm using an auth check in django-navbar, so I
need the full context on every page, and not all reusable apps I'm
using are passing the RequestContext from their views.

As a corollary:

Should all reusable apps default to using RequestContext
context_instance in their views? If not - why not?

-Preston

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: model design problem

2009-12-07 Thread Preston Holmes


On Dec 7, 8:56 am, Daniel Goertzen  wrote:
> Thanks for the reply Bill.  The problem I had with that approach is that
> after creating the product I have to worry about creating red and green
> ports.  Likewise, upon deletion, I have to mop up the ports.  Looking
> through the documentation, I did not find a way to bury this behavior in the
> Model.

I think you misunderstand - I think the suggestion is, and I agree
with it, is to have your specific Products represented as instances in
the database, not as code objects.

If the products are similar enough - have one "Product" model with
fields like, name, modelnumber etc

Then have one "Port" Model, that might have fields like "color" etc

Then you create an instance of a product and related port instances in
the database, not in model code.

Yes you have to define the unique combinations, but you have to do
this once somewhere.

Any place you need to refer to that product model, you use a
foreignkey to that product _instance_ in the database.

-Preston

>
> Hmm, abstract base class for the ports is an interesting idea.  Could be
> useful at template time.
>
> Dan.
>
>
>
>
>
> On Mon, Dec 7, 2009 at 10:07 AM, Bill Freeman  wrote:
> > I'm not clear on what you need to store, so I'll assume that you have
> > individual
> > data to store for each port of each type, and it is unrelated to data
> > stored for
> > another instance of the same or a different product.
>
> > What comes to mind is that there is a "Product" model and a "Port" model
> > (or if
> > red and green ports carry different fields, both a "RedPort" and a
> > "GreenPort"
> > model).  Ports have a foreign key relationship on Products.  Now an
> > assortment
> > of Port instances can be assigned to a Product instance.  Django will
> > created
> > an accessor (or accessors) on the Product model for obtaining a query set
> > of
> > the Port instances associated with a given Product instance.  (If you want
> > separate RedPort and GreenPort models, but they share a lot of behaviours
> > and/or fields, you may want to look at Django's abstract base class
> > mechanism,
> > but it takes a bit to get right, in my experience.)
>
> > On Mon, Dec 7, 2009 at 10:12 AM, Dan  wrote:
> > > I am relatively new to django and relational databases, and need some
> > > Model advice.
>
> > > I have a family of network products each with a different combination
> > > of ports.. I will call them red ports and green ports.  For example,
> > > product A will have its own Model and could have 2 red ports and 1
> > > green port.  Product B is similar, but has only 3 green ports.
> > > My current approach is to use an abstract base Model, and then create
> > > Models for products A and B that contain all needed fields, for
> > > example:
>
> > > class A(basemodel):
> > >   Port1_redfield1 = ...
> > >   Port1_redfield2 = ...
> > >   ...
> > >   Port2_redfield1 = ...
> > >   Port2_redfield2 = ...
> > >   ...
>
> > > Yuck, not very DRY at all.  I also tried to create a red port Model
> > > and green port Model and use one to one fields to connect them to
> > > products.  The problem with this is that I could not figure out how to
> > > encapsulate the ports; I always had to worry about creating, linking
> > > and deleting port objects when dealing with products.  Not acceptable.
>
> > > I also thought about other tricks like generating my models.py file
> > > from a generator program, and dynamic insertion of attributes into
> > > existing classes.  I really would rather not go there.
>
> > > So, my question:  Is there a nice DRY way to get the kind of
> > > structured composition that I want?
>
> > > Side question: Is there another python ORM that could address my need
> > > better?
>
> > > Thanks,
> > > Dan.
>
> > > --
>
> > > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com > groups.com>
> > .
> > > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com > groups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Daniel Goertzen
> -
> d...@networkintegritysystems.com (work)
> daniel.goert...@gmail.com (home)
> -
> 1 204 272 6149 (home/office)
> 1 204 470 8360 (mobile)
> -

--

You received this message because you are subscribed to 

Re: How to get timeuntil tag to display minutes?

2009-12-05 Thread Preston Holmes
Not simply. The design of the tag to drop smaller time frames the
further out you are.

The source is all there for you to copy and modify into your own
custom filter, but that may be more than you want to bother with...

-Preston


On Dec 4, 3:22 pm, Continuation  wrote:
> I use the timeuntil tag in my template:
>
> (( object.end_time|timeuntil }}
>
> where end_time is a DateTimeField.
>
> What I got is output like "2 days, 23 hours"
>
> Is there any way to get timeuntil to display minutes as well?
>
> 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-us...@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: What apps do besides provide views?

2009-12-05 Thread Preston Holmes


On Dec 3, 12:02 pm, Wayne Koorts  wrote:
> >> > remember that an app can do a lot more than provide views.
>
> >> Explain this one to me.  AFAICS, its just http request/response all the 
> >> way down and this is basically done by getting a
>
> > An app can expose views, indeed. It can also expose models - one of
> > the most important parts of an application -, templatetags, filters,
> > forms, fields, widgets etc. FWIW, the views are perhaps one of the
> > less important thing an app has to offer - and obviously the most easy
> > to factor out, cf genericviews. Models, OTHO, are really the core. If
> > you end up writing most of your code in views, then you more than
> > probably failed to identify what belongs to the model and what belongs
> > to the views. The fact that "views" are a mandatory part of the
> > request-response cycle doesn't mean they are the most important part
> > of the app.
>
> Can anyone point out a section in the docs (or anywhere else actually)
> the Django "app" concept?  I've had a look through the docs but
> haven't been able to find anything specifically about that.

This is not very well documented in official docs, and is really a bit
amorphous.

I like to think of an app is to Django as a Class is to Python.

That it is an encapsulation of code including attributes (models) and
methods (views) that provide some sort of defined value when combined
with other Classes (apps) to make a project.

-Preston

>
> Regards,
> Wayne

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Where to store repetitive form logic?

2009-12-05 Thread Preston Holmes


On Dec 4, 6:43 pm, jwpeddle  wrote:
> Not having any luck with this. Surely there's a simple example out
> there somewhere of view agnostic DRY form logic.

The old thread you point to still makes sense.

A redirect can only happen in response to a request

a request is handled by a view

It sounds like you need a view in your comment app that just handles
comment posts in an agnostic way and redirects back to the page object
that holds the comments.

-Preston

>
> On Dec 4, 10:43 am, jwpeddle  wrote:
>
>
>
> > That is definitely one approach I hadn't considered, and just might
> > work in my situation.
>
> > On Dec 4, 10:13 am, Heigler  wrote:
>
> > > I think the way is build your own generic view if you have customized
> > > things like that comment tag.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: What exactly does order_with_respect_to do?

2009-11-30 Thread Preston Holmes


On Nov 29, 4:50 pm, Continuation  wrote:
> In the doc (http://docs.djangoproject.com/en/dev/ref/models/options/
> #order-with-respect-to) it is mentioned that  order_with_respect_to
> marks an object as "orderable" with respect to a given field.
>
> What exactly does that mean? Can someone give me an example of how
> this could  be used?
>
> The doc's example is:
>  order_with_respect_to = 'question'
>
> How is that different from
> ordering = ['question']

order_with_respect_to uses the Question classes' ordering, where just
ordering would use the string representation of that question.

So using the example of questions and answers from the docs

if Question had a 'sequence' field, and Question meta.ordering was set
to use sequence, the answers would use that sequence.  If using
ordering instead of order_with_respect_to, then the questions would be
in alphabetical question order.

At least thats how I understand it.

-Preston

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: streaming response, missing something simple

2009-11-29 Thread Preston Holmes


On Nov 28, 11:07 pm, Preston Holmes <pres...@ptone.com> wrote:
> My expectation was that it was possible to 'stream' a response back to
> a browser from a view, where that response is 'trickled' onto the
> browser page.  I had done this a while back in cherrypy and it worked
> as expected.
>
> a super simple view demonstrates the issue.  Instead of a series of
> numbers marching onto the page, there is a delay and then the whole
> response is written to the page.  I had disabled commonmiddleware to
> avoid any chance that I was hitting #7581
>
> Is this some limitation of runserver?
>
> from django.http import HttpResponse
> import time
>
> def streamer():
>     for x in range(50):
>         yield str(x)
>         time.sleep(.2)
>
> def writeback (request):
>     return HttpResponse(streamer(), mimetype="text/plain")
>
> insight welcome
>
> -Preston

Answering my own question in case anyone else runs into this.  It is
an issue with Safari buffering the first 1K

So all you need to do to fix it is add a line like:

yield ''.ljust(1024,'\0')

in the generator before your loop.

-Preston

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




streaming response, missing something simple

2009-11-28 Thread Preston Holmes
My expectation was that it was possible to 'stream' a response back to
a browser from a view, where that response is 'trickled' onto the
browser page.  I had done this a while back in cherrypy and it worked
as expected.

a super simple view demonstrates the issue.  Instead of a series of
numbers marching onto the page, there is a delay and then the whole
response is written to the page.  I had disabled commonmiddleware to
avoid any chance that I was hitting #7581

Is this some limitation of runserver?

from django.http import HttpResponse
import time

def streamer():
for x in range(50):
yield str(x)
time.sleep(.2)

def writeback (request):
return HttpResponse(streamer(), mimetype="text/plain")

insight welcome

-Preston

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Accessing model instance on pre_save signal

2009-11-25 Thread Preston Holmes
I'm a bit confused on a few points here.  The upload_to field
attribute should be atomic to the imagefield - it doesn't rely on
related models.

your change_upload_to creates a new screenshot - but doesn't connect
it to the current WebProject instance.  Is that what you are trying to
do?

s = ScreenShot(project=instance)

Is there a reason your WebProject is not defined when you create a
screenshot in your view?

Something about this seems like it is making it more complicated than
it needs to be. but details are lacking t

-Preston

On Nov 24, 5:52 pm, neridaj  wrote:
> Hello,
>
> I'm trying to change the upload_to attribute of an ImageField so that
> it is in the format "web_projects/year/slug/". The problem I am having
> is that the ForeignKey model is getting saved before the related
> ScreenShot model is able to call it's save method to change upload_to.
> I'm trying to use a pre_save signal to reverse the order of saving but
> I'm not sure how to access the current instance of the ScreenShot
> model to call it's save method. Thanks for any suggestions.
>
> class ScreenShot(models.Model):
>         project = models.ForeignKey(WebProject)
>         image = models.ImageField(upload_to="web_projects/%Y/")
>         page_title = models.CharField(max_length=250, help_text="Maximum 250
> characters.")
>
>         def __unicode__(self):
>                 return self.page_title
>
>         def save(self):
>                 self.image.upload_to="web_projects/%Y/"+self.project.slug
>                 super(ScreenShot, self).save()
>
> def change_upload_to(sender, **kwargs):
>         s = ScreenShot() # not sure how to access current instance
>         s.save()
>
> pre_save.connect(change_upload_to, sender=WebProject)

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Alternative model without Database

2009-11-24 Thread Preston Holmes


On Nov 24, 1:28 am, Elyrwen  wrote:
> Hello,
>
> I' ve been recently interested in Djagno framework and I am at the
> point of choosing it as the framework for my project. My application
> will not use database, but will use webservices to get data and then
> process it.
>
> I need a substitute for the Django model layer. Precisely I need a
> class that would parse a wsdl (this I am doing with suds) and then
> call the remote methods. There should be one instance of this class
> served by all requests to
> avoid parsing wsdl for evey request - sort of a singleton class that
> would keep parsed stubs. It is possible to place such shared class in
> Django? Can you point me to some solutions that avoid parsing wsdl
> with each new request?

Is there a reason your app can not use a database?

Depending on how often your wsdl data changes, you could map a
response to a django model object and then check to see if it exists
(essentially using the ORM as a wsdl cache).  Or you could use
Django's cache framework itself:

http://docs.djangoproject.com/en/1.1/topics/cache/#the-low-level-cache-api

The former would let you have more class like access to the data (with
methods etc), while the latter is more pure key/value.

-Preston

>
> Maybe there is yet another way to obtain it with Django?
>
> Best regards,
> PS

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Filtering using several parameters

2009-11-23 Thread Preston Holmes


On Nov 23, 8:51 am, Aizen  wrote:
> Hi,
>
> I'd like to implement filtering for my app...currently, the filtering
> I have is stateless and so I can't add onto whatever value the user
> last selected.  I've also implemented each filter separately, so I'd
> like to know how I can condense the five filters into one.  

There are a couple of confounding points in your question.

First question is about combining your filters.  The solution there
seems to be to factor out your query building code out of your views
and return the the resulting queryset.  Then, these can be chained
together in any of your views just like any other queryset.

The other question seems to be about "refining" a filter?  That is
confining a filter operation to an existing found set, and have that
functionality spread across multiple requests.  You basically will
need to figure out a way to pass this along between requests, using
either hidden form fields, or session framework.

I started to work on adding this as a feature to Alex Gaynor's django-
filter, but got bogged down working out some details.  Either way you
should check out that project as it would at least make your existing
implementation easier.

http://github.com/alex/django-filter

-Preston

> The code
> for my filters is as follows:
>
> def year_filter(request, year):
>    vehicle_query = Vehicle.objects.filter(
>         common_vehicle__year__year__exact=year
>         ).exclude(status__status='Incoming')
>
>    vehicle_list = vehicle_query.order_by(
>         'common_vehicle__series__model__manufacturer__manufacturer',
>         'common_vehicle__series__model__model',
>         'common_vehicle__year'
>    )
>
>    vehicle = paginate(request, vehicle_list)
>
>    year_count = vehicle_query.order_by(
>         '-common_vehicle__year__year')
>         .values('common_vehicle__year__year')
>         .annotate(count=Count('id')
>    )
>    make_count = vehicle_query.order_by(
>       'common_vehicle__series__model__manufacturer__manufacturer')
>       .values
> ('common_vehicle__series__model__manufacturer__manufacturer')
>       .annotate(count=Count('id')
> )
>     style_count = vehicle_query.order_by(
>        'common_vehicle__body_style__style')
>        .values('common_vehicle__body_style__style')
>        .annotate(count=Count('id')
> )
>     color_count = vehicle_query.order_by(
>        'exterior_colour__exterior_colour')
>        .values('exterior_colour__exterior_colour')
>        .annotate(count=Count('id')
> )
>
>     return render_to_response('vehicles.html', {
>       'vehicle': vehicle,
>       'make_count': make_count,
>       'year_count': year_count,
>       'style_count': style_count,
>     })
>
> def make_filter(request, make):
>    vehicle_query = Vehicle.objects.filter(
>       common_vehicle__series__model__manufacturer__manufacturer=make)
>       .exclude(status__status='Incoming')
>
>    vehicle_list = vehicle_query.order_by(
>       'common_vehicle__series__model__manufacturer__manufacturer',
>       'common_vehicle__series__model__model',
>       'common_vehicle__year'
>    )
>
>    vehicle = paginate(request, vehicle_list)
>
>    year_count = vehicle_query.order_by(
>         '-common_vehicle__year__year')
>         .values('common_vehicle__year__year')
>         .annotate(count=Count('id')
>    )
>    make_count = vehicle_query.order_by(
>       'common_vehicle__series__model__manufacturer__manufacturer')
>       .values
> ('common_vehicle__series__model__manufacturer__manufacturer')
>       .annotate(count=Count('id')
>    )
>     style_count = vehicle_query.order_by(
>        'common_vehicle__body_style__style')
>        .values('common_vehicle__body_style__style')
>        .annotate(count=Count('id')
>     )
>     color_count = vehicle_query.order_by(
>        'exterior_colour__exterior_colour')
>        .values('exterior_colour__exterior_colour')
>        .annotate(count=Count('id')
>     )
>
>     return render_to_response('vehicles.html', {
>       'vehicle': vehicle,
>       'make_count': make_count,
>       'year_count': year_count,
>       'style_count': style_count,
>     })
>
> def series_filter(request, model):
>    vehicle_query = Vehicle.objects.filter(
>       common_vehicle__series__series=model)
>       .exclude(status__status='Incoming')
>
>    vehicle_list = vehicle_query.order_by(
>       'common_vehicle__series__series',
>       'common_vehicle__series__model__model',
>           'common_vehicle__year')
>
>    vehicle = paginate(request, vehicle_list)
>
>    year_count = vehicle_query.order_by(
>         '-common_vehicle__year__year')
>         .values('common_vehicle__year__year')
>         .annotate(count=Count('id')
>    )
>    make_count = vehicle_query.order_by(
>       'common_vehicle__series__model__manufacturer__manufacturer')
>       .values
> ('common_vehicle__series__model__manufacturer__manufacturer')
>       .annotate(count=Count('id')
>     )
>     style_count = 

Re: Model inheritance - filtering base model only

2009-11-22 Thread Preston Holmes
Perhaps there is a more efficient way, but in my quick test, one can't
filter() a queryset based on __class__ of the model, but seems one can
manually filter it afterwords:

qs = Player.objects.all()
for i,obj in enumerate(qs):
if obj.__class__ != Player:
del(qs[i])



On Nov 22, 4:32 pm, lfrodrigues  wrote:
> Hello,
>
> I have these models:
>
> class Player(models.Model):
>     .
>
> class PlayerM(Player):
>     ...
>
> If I do PlayerM.objects.all() e get all PlayerM objects and for
> Player.objects.all() I get all Player and PlayerM as expected.
>
> How can get only the objects of type Player (only retrieve the objects
> that were created with Player() constructor)?
>
> Regards,
>
> Luis

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Question on how to update an existing record when using ModelForm

2009-11-22 Thread Preston Holmes


On Nov 22, 4:47 pm, Micah Vivion  wrote:
> Greetings,
>
> I have a question on how to update an existing row in my database when one of 
> the fields is my primary key. I am using ModelForm and Django-Piston - my 
> main goal here is to have RESTful Post send to my webservice. I am able to 
> have initial Posts be sent correctly (i.e. that Primary key value doesn't 
> exist yet). The problem is when I want to update a value where the Primary 
> key already exists -  f.is_valid() it fails because "this UniqueIdentifier 
> already exists". How can I do form validation using ModelForms to update an 
> existing row?

You want to use the instance argument to the ModelForm constructor:

http://docs.djangoproject.com/en/1.1/topics/forms/modelforms/#the-save-method

-Preston

>
> models.py:
>
> from django.db import models
> class DeviceModel(models.Model):
>     uniqueIdentifier = models.CharField(primary_key=True, max_length=100)
>     deviceToken = models.CharField(max_length=100)
>
> forms.py
>
> from django import forms
> from models import DeviceModel
> class DeviceModelForm(forms.ModelForm):
>     class Meta:
>         model = DeviceModel
>
> handlers.py
>
> class DeviceHandler(BaseHandler):
>     allowed_methods = ('POST', 'GET', 'DELETE',)
>     def create(self, request):
>         f = DeviceModelForm(request.POST)
>         if f.is_valid():
>             new_object = f.save()
>             return new_object
>         return rc.BAD_REQUEST
>
> urls.py
>
> from django.conf.urls.defaults import *
> from piston.resource import Resource
> from api.handlers import DeviceHandler
>
> device_handler = Resource(DeviceHandler)
>
> urlpatterns = patterns('',
>     (r'^api/$', device_handler, {'emitter_format': 'json'}),
> )

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Automatic swapping of field data?

2009-11-19 Thread Preston Holmes
There are some details left out of how you want this to look.

The lower the level you try to make an object self protecting, the
trickier it's going to be.

The sweet spot I think here is a custom manager that adds a protect
filter, and perhaps a subclass of ModelForm if you need this in
forms.  The custom manager method would take a user obj as a
parameter, then loop through the objects in the queryset and modify
protected fields as needed.

http://www.djangoproject.com/documentation/models/custom%5Fmanagers/
http://www.djangosnippets.org/snippets/562/

On Nov 18, 4:17 pm, Doug Blank  wrote:
> Django users,
>
> I have data that needs to be handled in two different manners,
> depending on if the user has certain permissions or not. For example,
> if a record is marked "private" and a user is not permitted, I want to
> substitute the word "PROTECTED" for a particular field's value.
>
> Now, of course I realize that each and every place I refer to
> table.fieldname I could wrap a protection around that, either in my
> Python code, or in my templates.
>
> What I'm really looking for is something closer to the model code so
> that I can be assured that no private data accidentally slips out.
> Does Django have any built in support that does this, or could be
> adapted to do this?
>
> Any ideas appreciated!
>
> -Doug

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: @login_required decorator sends me to the wrong URL

2009-11-19 Thread Preston Holmes
http://docs.djangoproject.com/en/1.1/ref/settings/#login-url

There are going to be some other places you will have to be careful
running django on a path other than /

-Preston


On Nov 19, 7:11 am, Stodge  wrote:
> I added the @login_required decorator to my view but it redirects me
> to:
>
> http://localhost/accounts/login
>
> whereas the URL for my site is:
>
> http://localhost/test/accounts/login
>
> This is on Apache. Did I forget to configure something in settings.py?
>
> 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-us...@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=.




Re: same model field times in query result. How?

2009-11-18 Thread Preston Holmes
Its not clear how you differentiate one measure as speed or another as
dir.  Assuming only one has a link to another measure then you could
do something like:

results = Measurand.objects.exclude(entry__isnull=True).select_related
()

for speed in results:
speed_avg = speed.avg_value
dir_avg = speed.entry.avg_value

This first selects all measurements, excludes those that don't have a
link to another measurement, then fetches information about the
related measurements into the queryset.

-Preston



On Nov 17, 2:33 pm, tom  wrote:
> Hi,
>
> i want to have the same model-field 2x in the query result.
>
> The model.py is:
> class Measurand(models.Model):
>     """
>     A Model for measurement data
>     """
>     entry = models.ForeignKey(Entry)
>     avg_value = models.FloatField(help_text='the average measurement
> value', db_index=True, blank=True, null=True)
>     def __unicode__(self):
>         return 'Measurand:' + str(self.avg_value)
>
> My raw-sql looks like:
> cursor = connection.cursor()
>         cursor.execute(""" SELECT speed.avg_value, dir.avg_value
>                        FROM data_measurand AS speed LEFT JOIN
>                        data_measurand AS dir
>                        ON speed.entry_id=dir.entry_id;
>                        """, locals() )
>         row = cursor.fetchall()
>
> How can i do this with the django-orm?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Default sort order in admin

2009-11-16 Thread Preston Holmes


On Nov 16, 8:31 am, Zeynel  wrote:
> Thanks!
>
> I noticed that using
>
> class Lawyer(models.Model):
>     ...
>     ordering = ('last',)
>
> did not work.
>
> But this worked
>
> class Lawyer(models.Model):
>     ...
>     class Meta:
>         ordering = ('last',)
>
> copied fromhttp://www.djangoproject.com/documentation/models/ordering/
>
> What is the correct way actually?

If you notice - you are looking at two ways of doing it, depending
whether you want the ordering to be applied to just the model
(django.models.Model) or the ModelAdmin
(django.contrib.admin.ModelAdmin).

regular models use Meta class for ordering - ModelAdmin classes use an
ordering attribute.

The modeladmin docs say : "If this isn't provided, the Django admin
will use the model's default ordering."

so they are both "correct"

-Preston


>
> On Nov 16, 10:22 am, Karen Tracey  wrote:
>
>
>
> > On Mon, Nov 16, 2009 at 10:11 AM, Zeynel  wrote:
> > > Hi,
>
> > > Is there a way to change the default sort order in admin of my sqlite
> > > db? At this point it sorts the table in the order entered (last
> > > entered item first).
>
> >http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...
>
> > Karen

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Django on Dreamhost internal server error

2009-11-16 Thread Preston Holmes
do you have error templates defined?

http://docs.djangoproject.com/en/dev/topics/http/views/#customizing-error-views

-Preston


On Nov 16, 12:55 pm, Alessandro Ronchi 
wrote:
> If I put Debug = False in my django settings.py I receive an internal
> server error with no explanation.
>
> I'm using mod_passenger.
>
> What can cause the problem? Is there any way I can debug the error or
> get more information? Dreamhost cannot answer me, maybe someone got
> similar esperience.
>
> --
> Alessandro Ronchi
>
> SOASI
> Sviluppo Software e Sistemi Open 
> Sourcehttp://www.soasi.comhttp://www.linkedin.com/in/ronchialessandro

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: updating parent model on inline creation

2009-11-13 Thread Preston Holmes


On Nov 13, 5:13 pm, Preston Holmes <pres...@ptone.com> wrote:

> if submission.status == "submitted" and submission.reviews.count > 0:
> submission.status = "pending review"
>

> Are there even simpler ways to do this that I haven't thought of?

answering myself - sorry:

I should just put that logic in the review.save method - no signal
needed

>
> -Preston

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




updating parent model on inline creation

2009-11-13 Thread Preston Holmes
I'm setting up a conference website where a submission will have one
or more "reviews"

I've got the reviews set as inlines for submissions in the admin

The submission model has a "status" field that needs to go through
steps like "submitted" and "pending review"

What I'd like to do is when the first review is created via the
inline, update the status on the parent submission model.

I thought of two ways to do this.

The first more complicated way would be to right my own view for this
with subclassed formset handling that would do this.

The second idea which I now am liking better should also work:

register a funciton for post_save signals on the submission model, and
then (in pseudo code)

if submission.status == "submitted" and submission.reviews.count > 0:
submission.status = "pending review"

If this were a busy site - the signal based system might be heavy on
the database, but this is a project where we will never see real load.

Are there even simpler ways to do this that I haven't thought of?

-Preston

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Model Theory 101 - Video Sharing App

2009-11-13 Thread Preston Holmes


On Aug 26, 4:17 pm, thornomad  wrote:

>
> Caveats: I would like to keep the original "synced" data in its own
> field and the "approved" data (as edited) in separate field.  I
> imagine that the data first gets brought into the "edit" field, admin
> may make changes and save, but the "originating" data will remain
> separate and continue to be updated (synced).

Create a copy of the data in a new record - don't duplicate the fields

Have a field on the model that designated whether its original or
edited

have a self relation based on URL that links the synced and edited
versions

>
> This means I need at least
>
> I am stuck, though, on the most appropriate/logical approach to this
> app.  Some approaches I've considered.
>
> [1] My first thought is to create base model "Video" (with the main
> fields) and then create child models like YoutubeVideo and VimeoVideo
> and BlipVideo ... when the user submits a url, would do a regex on it
> in the view, and send it through the appropriate child class.  I could
> then grab the base Video model in my views (not having to distinguish
> the type of video) and use a "leaf" technique 
> (eg,http://www.djangosnippets.org/snippets/1031/) to run the child's
> "sync" or "update" command.  CONS: seems tacky and not easy to build
> on.  The leaf technique isn't working when I override the save()
> function in leaf models.
>
> [2] Perhaps create only a single model and then create separate
> classes/functions to handle the the syncing of data based on the
> URLField data ... so, perhaps when Video.update() is called, it would
> run the logic then to see what kind of url it has, and how to update
> it.  CONS: I thought maybe I could just create a ForeignKey field to a
> non-model group of classes with common functions (update, sync,
> etc) ... but I am not sure how, or if, I can do that.

You don't need to have your syncing code be in django models - you can
just write a python module that given a URL, will return a dictionary
of data representing the common fields you are interested in.  You
model would just use that.  There is probably an undocumented dict
like behavior on models that would allow you to update() the model
given a dict - but I'm just speculating.

>
> [3] Outsourcing.
>
> Hope this makes sense and folks have some feedback about how they
> might approach this.  I would like this to be easily expandable -- for
> example, add YouTube and Vimeo support to start, and easily add other
> sites without having to "hack" it.

What I'm proposing is you have one model, it calls one entry point in
a 'non-django' set of python code.  This code either returns a valid
dictionary, or raises some exception like "URL not handled"  You can
add to that python code as much as you like as you go without having
to change the model or django code.

-Preston

>
> I know this is a huge question, but am interested in your "Design
> Approach" thoughts ...
>
> Thanks,
> Damon

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: admin.site.register() - help

2009-11-11 Thread Preston Holmes
You should change:

admin.site.register(PageAdmin)

to:

admin.site.register(FlatPage, PageAdmin)

also I don't see where you are using a generic relation - so the class
for your inline should be admin.StackedInline not
generic.GenericStackedInline

-Preston

On Nov 11, 8:37 pm, neridaj  wrote:
> it looks like the admin.AdminModel object is causing the error in this
> inline definition
>
> class PageAdmin(admin.ModelAdmin):
>     inlines = [
>         KeywordInline,
>     ]
>
> admin.site.register(PageAdmin)
>
> 'MediaDefiningClass' object is not iterable
>
> when I comment that out the blog.Categories class is available in the
> admin.
>
> On Nov 11, 8:09 pm, Kenneth Gonsalves  wrote:
>
>
>
> > On Thursday 12 Nov 2009 9:36:11 am Zeynel wrote:
>
> > > Sorry, I am a beginner but I noticed that in my models the indent of
> > > unicode is indented like this:
>
> > > class SearchKeyword(models.Model):
> > >     keyword = models.CharField(max_length=50)
> > >     page = models.ForeignKey(FlatPage)
> > >     def __unicode__(self):
> > >         return self.keyword
>
> > > I have no idea if this will cause an error, though.
>
> > does this post have anything to do with the subject of the previous post? if
> > not, it is a good idea to start a new thread with a proper subject line. I 
> > do
> > not see any error in indentation, but the best way to check is to press
> > 'compile' on your ide and see if any errors show - indentation errors will
> > show.
> > --
> > regards
> > Kenneth Gonsalves
> > Senior Project Officer
> > NRC-FOSShttp://nrcfosshelpline.in/web/

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Can I change the restriction on "username" without breaking anything?

2009-11-11 Thread Preston Holmes


On Nov 11, 4:38 pm, "Richard E. Cooke"  wrote:
> My client wants to use e-mail addresses for user names.
>
> the contrib.auth application does not have a restriction in its
> model.  But the form code has put a regex on the field that disallows
> the ampersand (@).

fyi ampersand == &

>
> What would be the easiest way to override that form field definition
> so its global?
>
> And is there something someplace that will break if user names are e-
> mail addresses?

Have you checked these resources:
http://tinyurl.com/yc2q3rd


>
> Thanks in advance.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: AssertionError: Response didn't redirect as expected: Response code was 200 (expected 302)

2009-11-11 Thread Preston Holmes
Does your fixture result in a valid form?

if the form.is_valid() line doesn't pass, then you would get a 200
from the render to response...

-Preston


On Nov 11, 4:38 pm, Eesti Mate  wrote:
> When I'm testing my form with assertRedirects I get the following error 
> message:
>
> AssertionError: Response didn't redirect as expected: Response code was 200 
> (expected 302)
>
> Don't know what/when/where went wrong. It seems that I'm missing some crucial 
> point(s).
>
> Thanks for your pointers & your time!
> Eesti
>
> Here are the relevant lines of test.py, views.py, urls.py and the 'runserver' 
> output (when I run the app):
>
> #tests.py:
> r = self.client.post(reverse('example_form'), example_form_fixture)
> self.assertRedirects(r, reverse('form_redirection'))
>
> #views.py:
> def example_form_view(request):
>         if request.method == 'POST':
>                 form = example_form(request.POST)
>                 if form.is_valid():
>                         form.save()
>                         return 
> HttpResponseRedirect(reverse('form_redirection'))
>                 else:
>                         form = example_form()
>         return render_to_response('example_form/example_form.html', {'form': 
> form})
>
> def form_redirection_view(request):
>         return render_to_response('example_form/form_redirection_page.html')
>
> #example_form/urls.py:
> urlpatterns = patterns('',
>         url(r'^example_form/$', 
> 'sandbox.example_form.views.example_form_view', name='example_form'),
>         url(r'^form_redirection/$', 
> 'sandbox.example_form.views.form_redirection_view', name='form_redirection')) 
>  
>
> #'runserver':
> Django version 1.1.1, using settings 'sandbox.settings'
> Development server is running athttp://127.0.0.1:8000/
> Quit the server with CONTROL-C.
> [12/Nov/2009 01:25:38] "POST /example_form/example_form/ HTTP/1.1" 302 0
> [12/Nov/2009 01:25:38] "GET /example_form/form_redirection/ HTTP/1.1" 200 60

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: problems registering models in admin

2009-11-11 Thread Preston Holmes
Is the admin in your installed apps in settings.py?

http://docs.djangoproject.com/en/1.1/intro/tutorial02/#activate-the-admin-site
Add "django.contrib.admin" to your INSTALLED_APPS setting.

-Preston

On Nov 11, 5:19 pm, neridaj  wrote:
> I'm working on a standalone app and when I try to add it to the admin
> index it does not show up using:
>
> from django.contrib import admin
> from blog.models import Category
>
> admin.site.register(Category)
>
> Thanks,
>
> J

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: How to handle this race condition?

2009-11-10 Thread Preston Holmes

another option if you want to stay in just python and are on a POSIX
system is to use system file locking to ensure you don't get
concurrent calls to your updated function.

http://docs.python.org/library/fcntl.html#fcntl.lockf

-Preston

On Nov 9, 10:17 pm, Continuation  wrote:
> Thanks Christophe and Kenneth!
>
> Let me make sure I understand this:
>
> If I write this vew function:
>
> @transaction.commit_on_success
> def update_high_bid(request):
> 
> cursor = connection.cursor()
>         cursor.execute("SELECT high_bid FROM auctionapp_auction WHERE
> id=%s
> FOR UPDATE", [auction.id])
>         returned_rows = cursor.fetchall()
>         high_bid = returned_rows[0][0]
>         if new_bid > high_bid:
>             auction.high_bid = new_bid
>             auction.save()
>
> The entire function will be wrapped within a transaction.
> SELECT FOR UPDATE will acquire a row-level lock
> and that lock will not be released until the function update_high_bid
> () returns successfully, or until the function raises an exception and
> the whole transaction is rolled back.
>
> Is that right?
>
> Thanks.
>
> On Nov 10, 12:45 am, Christophe Pettus  wrote:
>
>
>
> > On Nov 9, 2009, at 9:34 PM, Continuation wrote:
>
> > > Also does django middleware acquire database lock on my behalf, or do
> > > I need to explicitly perform the locking?
>
> > In the example code, it's the SELECT ... FOR UPDATE that acquires the  
> > lock.  Django doesn't currently have any explicit knowledge of  
> > locking, so you need to drop down to the custom SQL level to issue the  
> > right statement to acquire the lock on the row.
>
> > The example I wrote assumed you were using PostgreSQL as the backend;  
> > you can get all sorts of details about locking in PostgreSQL here:
>
> >        
> > http://www.postgresql.org/docs/8.4/interactive/explicit-locking.html#...
> > --
> > -- Christophe Pettus
> >     x...@thebuild.com
--~--~-~--~~~---~--~~
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: User class, change name of fields(like username with login name)

2009-11-09 Thread Preston Holmes



On Nov 9, 7:49 am, NMarcu  wrote:
> Hello all,
>
>    I have a list of all users. My head table is made with the fields
> from User class. So look like this:
>
> username           first name             last name
> superuser status
>
> I want to make this head table editable. How can I change the caption
> of the field, not the name of it. By ex: is_superuser field is build
> like this:
>
> is_superuser = models.BooleanField(_('superuser status'),
> default=False, help_text=_("Designates that this user has all
> permissions without explicitly assigning them."))
>
> In my table is list superuser status not is_superuser, this is good.
> How can I change: "superuser status" in something else from a view.

To make something this dynamic, you will need a model for your label,
with some way to key it to the column you want to use it for - I can't
think of a clean way to change the verbose name of the classes
dynamically as the objects are instantiated per request.  A simple, if
somewhat brittle way to do it, would be to use the __name__ of the
model in question and use that as a key to look up the label to use in
your form.

-Preston

--~--~-~--~~~---~--~~
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: Making the case for Django (vs. Drupal)

2009-11-01 Thread Preston Holmes



On Oct 31, 8:44 am, shacker  wrote:
> At the university where I work, there is a LOT of momentum behind
> Drupal. A large and active users group, and dozens of departmental
> sites running it. I've succeeded in building a few departmental sites
> with Django but still feel like it's an uphill battle convincing
> managers to agree to go with a relative unknown, both in terms of
> language (Python) and platform. Things like the announcement that
> whitehouse.gov switched to Drupal just cement the deal in many
> managers' minds.
>
> I'd like to put together a summary sheet and blog post summarizing all
> the reasons why I feel Django is the better choice for many sites, to
> try and help make the "sale" to managers. I have my own set of reasons
> but am not going to include them in this message. I'm especially
> interested in hearing from people who have done development in both
> Django and Drupal (or WordPress or Joomla, or other). Would be
> interested in hearing comments on things like:
>

I helped produce a med-large site in drupal for a local non-profit.
This was at the tail of Drupal 5, and haven't used it a ton since, but
had set up several smaller drupal sites before then.

There are going to be lots of "it depends"

> - Overall development time

For a basic CMS site - Drupal will be faster and more full featured
out of the box.

Page design time is going to be about the same either way

> - Ease of making changes to templates

Implementing templates for Django is easier as they are just simple
files and the inheritance system is simple - there are books about
doing templates in Drupal


> - Ease of finding 3rd party functionality (modules vs. reusable apps)
Both have the problem of often complex dependencies.  The biggest
problem with Drupal is its relatively fast moving core - so that
modules for the "current version" are hard to find, or often
abandoned.  Also Drupal modules almost always seem to do 80% of what
you need.


> - Ease of building data models that reflect the needs of the
> organization

Depends on the complexity - for relatively "flat" data, Drupal's CCK
is usable by non devs to create custom content types, and the Views
module allow for simple generic_view style pages.  When it comes to
more complex objects, Django's ORM is far superior.


> - Ease of finding other developers to take on a project when someone
> leaves

In my experience it was hard to find any Drupal devs who wanted to do
small fixes, or maintenance.  Everyone was looking for the big fish of
bigger full site design with more $$$ involved.

> - User friendliness (admin and editorial interface)

While both can have a decent staff-admin UI, Django's user-admin UI
can be made much more clear and focused.  Where Drupal has its single
biggest advantage, is that a technical user, a sys-admin etc, can get
Drupal up and running.  Someone doesn't have to know PHP AT ALL to get
drupal going.  This is because Drupal has a decent admin-UI - where
modules are pretty much drop in, activate and configure.

Setting up even a basic Django site REQUIRES someone who has some
programming skills, even if thats just a matter of setting up the
settings.py file.

What happens is that non-developer/technical decision makers will
evaluate Drupal and think that all their needs will be met out of the
box.  When they find out they aren't, they need to hire developers,
and then those developers have to massage existing modules to
customize and tweak.  Then at some point they have this monster of
hodgepodge code.  But its that entry point that is the key to Drupal's
popularity.

What Django needs IMHO is an admin UI for Pinax. Pinax project plans
to do this "someday".  When Pinax can have a web-based install, with
an admin UI to enable/disable pluggable apps - Django will experience
huge win.  Because the same thing will happen as does for Drupal,
there will be technical users who evaluate pinax and think it can do
everything for them.  At some point they will need a custom app - they
HIRE a django dev.  That Django dev writes a well done reusable app -
and often with the blessing of the hiring company, releases that into
the world.  Let this process continue and you can see that eventually
the Django app universe will grow.

I don't think people appreciate how much Drupal development is spawned
by this existence of a usable entry point for Drupal by non-
developers. (and that it has 1-click installs on hosts, and in general
uses the far more common infrastructure of PHP-MySQL)

> - Ease of getting the system to do highly custom tasks

Django just wins this so hands down.  Here is part of the reason why.
Drupals assumptions translate into your code having to jump through a
lot of hoops - where as in Django, you make the assumptions and you
make the hoops.

> - Ease of upgrades
> - Security
>
> etc. etc. - anything at all. Please indicate whether it's OK to quote
> you (I can paraphrase you if not)
>
> Thanks in advance,
> 

Re: Display Certain Fields of the Model Formset As Text

2009-10-30 Thread Preston Holmes



On Oct 30, 12:00 pm, Bill Freeman  wrote:
> Yet another option is to write a widget that subclasses the existing
> one, and adds
> disabled='disabled' to the dictionary that will be used to populate
> the attributes
> (usually the 'attrs' argument, I think, and you will have to handle
> the possibility
> that you will be passed None instead of a dict).

When using widget.attr how does one specify a attr that is name only,
not key/value.

The disabled key is not a k/v attr:



-Preston

>
> Bill
>
> On Fri, Oct 30, 2009 at 1:47 AM, Anthony Simonelli
>
>
>
>  wrote:
>
> > Hello,
>
> > I am using a Model Formset because there are two foreign keys in my Model 
> > and it makes it easy to create forms with them preselected from data in my 
> > model:
>
> > class ForecastActualSum(models.Model):
> >    sales_rep = models.ForeignKey(SalesrepGrpname)
> >    customer = models.ForeignKey(Customer)
> >    item = models.CharField(max_length=200)
> >    actual = models.FloatField(null=True, blank=True)
> >    forecast = models.FloatField(null=True, blank=True)
> >    plan = models.FloatField(null=True, blank=True)
>
> > When using a model formset, all the fields are displayed and are editable, 
> > but I just want the 'forecast' field to be editable and the rest of the 
> > fields to be displayed.  Is there any way to display the fields as text 
> > rather than as input fields?  I've also tried sending the corresponding 
> > ForecastActualSum objects along with the formset to the template to be 
> > displayed along side formset, but I can't iterate both at the same time to 
> > make them line up like a table.  Anyone have any ideas?  Maybe model 
> > formset is not the way to go?
>
> > Anthony
--~--~-~--~~~---~--~~
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: django can't access site-packages when inside fastcgi on dreamhost

2009-10-29 Thread Preston Holmes



On Oct 27, 9:07 pm, Jacob Fenwick  wrote:
> Wow, big surprise that someone else is having shared hosting issues with
> dreamhost eh?
>
> I'm importing a library I installed in site-packages in a module in a django
> app. When I call this django project, it returns with the error:
>
> ImportError: No module named lxml

When you say you installed in site-packages in a module in a django
app - where exactly is lxml installed?  Are you using a virtualenv?
What steps have you done to check and ensure that the lxml module is
available in your Python path?

-Preston

>
> The django project is hosted on the fcgi.py version of fastcgi on dreamhost.
>
> Now, I know that django is not usually having a problem accessing the
> library, because if I go into the django shell and type import lxml, I can
> import the module.
>
> Also, if I type ./dispatch.py, I get a correct 200 OK response.
>
> But for some reason, when I call the site from a web browser, it causes
> django to not be able to access the library.
>
> The site-packages are stored inside of a virtualenv generated directory
> structure.
>
> The permissions on the dispatch.fcgi file, the fcgi.py file, the directories
> leading up to and include site-packages, and django are (mostly) 755.
>
> Has anyone encountered this? Or does anyone have some insight into how to
> solve this problem?
>
> Thanks for any help provided,
>
> Jacob
--~--~-~--~~~---~--~~
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: Internal error on dreamhost when debug=False

2009-10-29 Thread Preston Holmes

Well you've gotten farther than I have.

I can get passenger_wsgi working with hello world, and cherrypy

I can get those working with any combination of virtualenv etc

But with django I get the not too helpful Premature end of script
headers even with apache LogLevel set to debug.

-Preston


On Oct 29, 7:10 am, Alessandro Ronchi 
wrote:
> I don't know why this site:http://www.portaleaziende-bih.com/
>
> works with debug=True, but If I put debug =False it gives a 500 internal
> error.
>
> I'm using mod_passenger on dreamhost. Logs just says
> [Thu Oct 29 07:02:38 2009] [error] [client x] Premature end of script
> headers: internal_error.html
>
> What can I check to find the problem?
>
> --
> Alessandro Ronchi
>
> SOASI
> Sviluppo Software e Sistemi Open 
> Sourcehttp://www.soasi.comhttp://www.linkedin.com/in/ronchialessandro
--~--~-~--~~~---~--~~
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: Behaviour of related objects

2009-10-25 Thread Preston Holmes



On Oct 25, 2:55 pm, Bojan Mihelac  wrote:
> Hi all,
>
> given an many_to_one doctests with Reporter/Article models, the
> following example would fail with "IntegrityError:
> many_to_one_article.reporter_id may not be NULL":
>
> >>> r = Reporter(first_name='John', last_name='Smith', 
> >>> email='j...@example.com')
> >>> a = Article(headline="This is a test", pub_date=datetime(2005, 7, 27), 
> >>> reporter=r)
> >>> r.save()
> >>> a.save()
>
> For me, expected behaviour would be that since article knows it is
> related to reporter it should check reporter's primary key on save.
>
> Am I wrong?

But a is being created before r has an id  - just move the r.save()
line up one.

-Preston

>
> thanks,
> Bojan
--~--~-~--~~~---~--~~
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: Interesting code abstraction Challenge

2009-10-24 Thread Preston Holmes

I think a base class with subclasses is the best approach.

Define as much common behavior as possible, set up defaults for those
fields needed by your outbound API

How are you handling the branching lookup of what subclass to use?
You might name the subclasses in some way that they can be derived
from the partner URL - or some other way that intelligently selects
the subclass for you

I assume you've looked at django-piston

-Preston


On Oct 24, 7:43 am, Jason Beaudoin  wrote:
> Anyone else have thoughts on this, with respect to design
> considerations, implementing in python versus using some of django's
> tools.. ?
>
>
>
> On Fri, Oct 23, 2009 at 8:22 AM, Jason Beaudoin  
> wrote:
> > 2009/10/23 kmike :
>
> >> Maybe you don't have enough information to make an abstraction right
> >> now. If so I suggest to actually implement several API's in a dumb
> >> way. After that it'll be clear what are the differences and what are
> >> the common parts so making a good abstraction will be easier.
>
> > I've implemented each of the APIs enough (standalone) to know a lot of
> > the differences. Where I'm struggling is envisioning the proper
> > abstraction and implementation with python / django code to tie it all
> > together.
>
> > My current idea is to setup a Request class, then create specific
> > subclasses of this, overriding the default methods, writing conversion
> > methods, and defining additional fields. But "seeing" the python code
> > around this has yet to come.
>
> > As I've never really implemented this type of abstraction (and I
> > imagine others have), I'm really interested in what has been done /
> > known solutions to the general problem / do I have the right idea /
> > any source folks can suggest / etc..
>
> > Thanks for taking the time to read about my situation!
>
> > ~Jason
--~--~-~--~~~---~--~~
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: Advantages of using ManyToManyField(Bar, through='Foo_Bar') syntax vs not declaring a ManyToManyField at all

2009-10-24 Thread Preston Holmes

The way I think of the value of the "through" table approach is when
you want to attach information to the relationship that does not
belong on either model.

I like a band/musician example.

A person can be a part of many bands

A band has many people

so here we have a classic M2M

But a person is part of a band as a "member"

so you would create a "member" through table that would hold things
like:

instruments_played
start_date
end_date

These are things about that person in that band that don't belong on
the person or band object.

You might have relationships from this member table to other objects
like songs etc

-Preston

On Oct 22, 7:57 am, Monika Sulik  wrote:
> Hi,
>
> I was wondering what exactly are the advantages of having code like
> this:
>
>
>
> class Foo (models.Model):
>     bar_m2m = models.ManyToManyField(Bar,through='Foo_Bar')
>
> class Bar (models.Model):
>     pass
>
> class Foo_Bar (models.Model):
>     foo = models.ForeignKey(Foo)
>     bar = models.ForeignKey(Bar)
>     x = models.IntegerField()
>
>
>
> over having the same code, but having the Foo class like so:
>
>
>
> class Foo (models.Model):
>     pass
>
>
>
> In both cases I can use foo.foo_bar_set and bar.foo_bar_set (assuming
> foo is a Foo Object and bar is a Bar Object). Why would I need the
> bar_m2m variable?
> I'm probably missing something pretty obvious, but if someone could
> point out the answer to me that would be great :)
>
> Monika
--~--~-~--~~~---~--~~
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: Replicating Google Groups in Django

2009-10-24 Thread Preston Holmes


It doesn't seem like it would be that hard to combine django-
extensions export_emails command with Mailmans sync_members script
inside a cron job or a URL triggered script.

Usage: /usr/share/mailman/bin/sync_members [options] -f file listname

-Preston

On Oct 23, 6:06 am, Julien Phalip  wrote:
> Hi,
>
> On one site I'm considering the possibility of replicating the (basic)
> functionality of Google Groups in Django. The idea is:
>
> - There would be 5 different mailing lists. Users can subscribe to one
> or more lists.
> - People can purely use emails to access the lists.
> - All the emails can then also be seen via a web interface.
>
> I've been thinking of using Mailman to leverage all the email
> management part. But now I'm not sure how to reliably sync the Mailman
> subscription system with django.contrib.auth.
>
> I don't think there's any straight forward to do this. Would you have
> any advice to get me started?
>
> Thanks!
>
> Julien
--~--~-~--~~~---~--~~
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: I don't even know where to begin writing this template-tags

2009-01-21 Thread Preston Holmes

It may not be as pretty as a parseable param array, but what about
just having all your args in a single JSON string. Are your template
authors savvy enough?

-Preston


On Jan 20, 3:32 pm, Andrew Ingram  wrote:
> I'm building a simple banner/promotion system for a site. Aside from a
> few date-related fields, a banner consists of:
> - an image
> - a target url
> - the image dimensions
> - some tags (using django-tagging)
>
> I'm trying to figure out how to build a template-tag to allow me to
> display a number of banners based on their properties.
>
> i.e
>
> {% get-banners max-width='450' max-height='100' min-height='50'
> match-any='foo, bar' match-all='homepage' limit='2' as banners %}
>
> {% for banner in banners %}
>   
> {% endfor %}
>
> The only way I can see to do this is to write a hideous parser function,
> made worse by the fact that almost all of the arguments are optional.
> This would take about 5 minutes in Rails (and I don't like Rails), it
> would take about 10 minutes in Tapestry (a Java framework which I
> despise). So I'm hoping there's a nice elegant way of doing this in
> Django because the only approach I can think of is very unappealing.
>
> Regards,
> Andrew Ingram
--~--~-~--~~~---~--~~
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: ForeignKeys and select_related

2009-01-18 Thread Preston Holmes

So just for completeness, here is the bit about avoiding the inner for
loop in this situation:

On Jan 17, 8:40 am, ptone  wrote:

> matching_torrents = Torrent.objects.filter(name__icontains='x360')
> my_data = []
> for a_torrent in matching_torrents:
>     info_objects = a_torrent.torrentInfo_set.all()
>     seeds = []
>     for a_info in info_objects:
>         seeds.append(a_info.seed)
>     my_data.append((a_torrent.name,seeds))
>

http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-fields

my_data = []
for a_torrent in matching_torrents:
 torrent_info = a_torrent.torrentInfo_set.values
('seeds','leeches')
 my_data.append((a_torrent.name, torrent_info))



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