Re: Ok to load many .js files to support lots of interactive widgets?

2010-01-14 Thread Margie Roginski
Thanks Daniel,

I will look into Yahoo YSlow.  Is there a particular tool/toolset
that you have used/recommend for doing the combining?

Margie


On Jan 14, 2:37 pm, Daniel Roseman  wrote:
> On Jan 14, 8:01 pm, Margie Roginski  wrote:
>
>
>
> > As I've learned more about jquery/javascript, I've added more and more
> > jquery interactive widgets to my app (which is sort of like a ticket
> > tracking app).  I'm wondering if having too many .js files is a bad
> > thing (or a good thing)?
>
> > Here's an example to make my question more understandable.  I have
> > form similar to the admin changelist form, where the user views all of
> > their tasks.  Each task has a lot of info available but I don't want
> > it to display it all in the form itself.  For example, a task has a
> > "result" field, and instead of just rendering the result field (which
> > can be long), I provide a link that shows the date the result was
> > entered.  When the user clicks on the link, they get a tooltip popup
> > that displays the result.
>
> > My django widget looks like this:
>
> > class ChangeList_DisplayResultWidget(ChangeList_ToolTipWidget):
>
> >     class Media:
> >         js = ('js/jquery.js',
> >               "js/cluetip/jquery.cluetip.js",
> >               "js_custom/task_changelist_helpers/result_widget.js",
> >               )
>
> >         css = {'all' : ('js/cluetip/jquery.cluetip.css',)}
>
> > The contents of result_widget.js is quite small, just this:
>
> >   $(document).ready(function() {
> >       $('.changelist_result').cluetip({sticky:true,
> >             closePosition: 'top',
> >             closeText:'',
> >             showTitle:false,
> >             leftOffset:'-300px',
> >             activation:'click',
> >             cluetipClass: 'jtip',
> >             onShow: function(e) { $('#cluetip a').attr({'target':
> > '_blank'}); return true; }
> >       });
> >   });
>
> > My question is - is it ok to have a lot of little .js files like
> > this?  I find that keeping the .js code associated with my widgets in
> > separate files is very nice, because then if I reuse the widget on
> > some other page, it is well-encapsulated.  IE, I get just the .js for
> > that widget, and no additional .js code.  But since I have a very
> > interactive web app with a variety of widgets that have different
> > behaviors, I am finding that I have a lot of .js files getting
> > included.
>
> > In my page that is similar to django's admin change list, I now have
> > 25 .js files.  That includes various good-sized jquery packages
> > (jquery.js, autocomplete, datePicker, cluetip, filter), plus my
> > little .js snippets like that shown above, that use those packages,
> > plus some custom .js I have written, plus some code I use from the
> > admin app (core.js, actions.js, getElemetnsByselector.js).
>
> > Sorry if I'm going into too much detail - just wanted to give folks a
> > flavor of what I'm doing.  The users are very happy so I don't think
> > I'm going overboard on the UI side, but I'm just wondering if there
> > are issues associated with they way I am organizing the .js, or if
> > what I'm doing is a good way to go.
>
> > I am doing client side caching of the files, and so far things seem
> > fast.  I'd like to hear input from anyone with more experience on
> > whether this is a good organization or if there is some preferable way
> > to go.
>
> > Margie
>
> This isn't a Django question of course, but applies more generally to
> web apps.
>
> Best practise is not to have lots of small JS files. This is because
> most browsers limit the number of requests they can make to the same
> domain at once, so the files can't be loaded in parallel. What we tend
> to do is combine the files into a single one - there are various
> projects around that will do that for you. You can then include that
> combined JS file in your pages, rather than the 25 small ones.
>
> You may find it useful to test your site against the Yahoo YSlow
> analyzer, an add-in for the Firebug extension for Firefox. It gives
> lots of good advice about this sort of thing.
> --
> DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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.




following relationships forward in queries

2010-01-14 Thread Michael Thon
I have an Model with a field that is a oneToOne relationship with a model in 
another app:

class SensePost (models.Model):
feedjackpost = models.OneToOneField(Post, blank=True, null=True)
...

I'm trying to to write a filter query that uses fields in the related model:

senseposts = SensePost.objects.filter(processed=True, 
feedjackpost__date_created__exact=date)

but that filter throws this error:

Exception Type: FieldError
Exception Value:
Cannot resolve keyword 'date_created' into field. Choices are: feedjackpost, 
id, processed, raw_text, topic

So I guess there is something basic about the query syntax that I don't 
understand?
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: query related question

2010-01-14 Thread Shawn Milochik

On Jan 14, 2010, at 11:53 PM, E. Hakan Duran wrote:

> Thanks a lot for the quick response.
> 
> On Thursday 14 January 2010 23:08:43 Shawn Milochik wrote:
> 
>> ...
>> woman = Woman.objects.get(lastname__exact = 'Test')
>> couple = Couple.objects.get(couple = woman.couple)
>> 
>> Note that this is making the assumption that there is only one woman with
>> that last name, and that there is only one couple with this woman in it.
> 
> And that may not be the case. In my example, there are 2 women with the same 
> last name and I would like to get their couple ids individually, which will 
> then enable me to get their relevant info from Couple model. Do you think it 
> is possible to do that?

women = Woman.objects.filter(lastname__exact = 'Test')

Then return that in the context, and you can iterate through 'woman' in your 
template, referring to woman.firstname, woman.couple.address1, etc.

> 
>> I don't know if you just made this up as an example, but if it's something
>> that you're actually working on, it seems like making a Woman and Man
>> model isn't a very good idea because there's so much duplication. Just
>> have a Person model with a 'sex' field, and you have have a foreign key to
>> itself labeled 'partner' or something. No need for a separate 'couples'
>> table. If you really need the address info, there should be an Address
>> model. After all, you may have other things (businesses, etc.) that also
>> have addresses which will require the same validation. It gets really ugly
>> really fast when you have 'address1, address2, city, state, and zip' in a
>> bunch of different models. Possibly with different field lengths and other
>> stuff.
> 
> Thanks for the really very useful suggestions. I didn't think it that way 
> really, but how about duplicate home addresses for the man and woman living 
> together? Wouldn't there be a lot of redundant data that way? Would you mind 
> recommending me some documentation to learn about foreign key to itself? I am 
> not sure that I understand how it is set up.

Multiple addresses: Easy. Many-to-many relationship is one option, or a generic 
foreign key in the Address model.
Foreign key to self: partner = models.ForeignKey('self', null=True, 
related_name='spouse')
http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey

> 
>> Also, I don't know what you mean by not having a technical background, but
>> if you mean you have no application design or programming experience, then
>> I urge you to hire someone to do this, unless this is just something
>> you're doing to teach yourself to program (and if so, welcome!). Despite
>> the fact that Python and Django are far less daunting to learn than other
>> tools, they still require programming ability to do at all, and a lot of
>> experience to do well. Nothing personal -- I just wanted to point out that
>> database design and application design are definitely not trivial and
>> shouldn't be done by someone with no experience if this is something
>> needed by your business.
> 
> Thanks for the fair warning Shawn. I cannot agree more. Although this looks 
> like a business database set up, I have no intention to use it in a business 
> setting. This will probably be my hobby project that I develop in my spare 
> time over several months probably. I am well aware of the risks of collecting 
> and storing personal information, let alone putting them on an online server 
> without the expertise and experience of programming and security. Even if I 
> believed I had those qualities, I would still not attempt to do that with 
> this 
> kind of information. I am just challenging myself with a very difficult task 
> for 
> my level, to learn python and django and gain some comfort in using them. I 
> truly appreciate your sincere and rightful warnings.


Cool. Everyone starts the same way. Or they should -- learning by having a goal 
and figuring out how to achieve it. 

> 
> Regards,
> 
> Hakan


-- 

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.



Resolver404 exception in Django on Google App Engine?

2010-01-14 Thread Kumar McMillan
Is anyone else getting this on Google App Engine?  I have seen it
across different versions of Django (1.0 to 1.1.1) but it only happens
intermittently.  I am using the latest Google App Engine Django code
and although I'm not sure it's a bug in their code I submitted an
issue here (where you can see the traceback)

http://code.google.com/p/google-app-engine-django/issues/detail?id=155

: {'path':
u'djdb/track/search.txt'}

Is anyone else getting this?  the path obviously works and I only see
this error about once a day on a site with 1 request every 5 secs on
average.

Any pointers as to what internal state might be out of sync?  Maybe I
need to adjust the startup script somehow.


thanks in advance,
Kumar
-- 
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: query related question

2010-01-14 Thread E. Hakan Duran
Thanks a lot for the quick response.

On Thursday 14 January 2010 23:08:43 Shawn Milochik wrote:

> ...
> woman = Woman.objects.get(lastname__exact = 'Test')
> couple = Couple.objects.get(couple = woman.couple)
> 
> Note that this is making the assumption that there is only one woman with
>  that last name, and that there is only one couple with this woman in it.

And that may not be the case. In my example, there are 2 women with the same 
last name and I would like to get their couple ids individually, which will 
then enable me to get their relevant info from Couple model. Do you think it 
is possible to do that?

> I don't know if you just made this up as an example, but if it's something
>  that you're actually working on, it seems like making a Woman and Man
>  model isn't a very good idea because there's so much duplication. Just
>  have a Person model with a 'sex' field, and you have have a foreign key to
>  itself labeled 'partner' or something. No need for a separate 'couples'
>  table. If you really need the address info, there should be an Address
>  model. After all, you may have other things (businesses, etc.) that also
>  have addresses which will require the same validation. It gets really ugly
>  really fast when you have 'address1, address2, city, state, and zip' in a
>  bunch of different models. Possibly with different field lengths and other
>  stuff.

Thanks for the really very useful suggestions. I didn't think it that way 
really, but how about duplicate home addresses for the man and woman living 
together? Wouldn't there be a lot of redundant data that way? Would you mind 
recommending me some documentation to learn about foreign key to itself? I am 
not sure that I understand how it is set up.

> Also, I don't know what you mean by not having a technical background, but
>  if you mean you have no application design or programming experience, then
>  I urge you to hire someone to do this, unless this is just something
>  you're doing to teach yourself to program (and if so, welcome!). Despite
>  the fact that Python and Django are far less daunting to learn than other
>  tools, they still require programming ability to do at all, and a lot of
>  experience to do well. Nothing personal -- I just wanted to point out that
>  database design and application design are definitely not trivial and
>  shouldn't be done by someone with no experience if this is something
>  needed by your business.

Thanks for the fair warning Shawn. I cannot agree more. Although this looks 
like a business database set up, I have no intention to use it in a business 
setting. This will probably be my hobby project that I develop in my spare 
time over several months probably. I am well aware of the risks of collecting 
and storing personal information, let alone putting them on an online server 
without the expertise and experience of programming and security. Even if I 
believed I had those qualities, I would still not attempt to do that with this 
kind of information. I am just challenging myself with a very difficult task 
for 
my level, to learn python and django and gain some comfort in using them. I 
truly appreciate your sincere and rightful warnings.

Regards,

Hakan


signature.asc
Description: This is a digitally signed message part.


Re: Underscores vs. Numbers

2010-01-14 Thread Wiiboy
Well, to solve this, I'm planning to subclass the "get_available_name"
method in django.core.files.storage.Storage to do exactly what it does
now, except add a number instead of underscores.

Any reason not to do this?
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Querysets returns wrong result when using threading.

2010-01-14 Thread James Bennett
On Thu, Jan 14, 2010 at 10:26 PM, Kieran Brownlees  wrote:
> Basic example of format:
> Main Thread: print objects.all()
> Spawned Thread: print objects.all() -- same as main thread
> Main Thread: objects.create(newObj)
> Main Thread: print.objects.all() -- correct queryset, original + new
> Spawned Thread: print objects.all() -- only contains the original
> objects, not the new one?

This would be the expected result with the default transaction
isolation of most databases, and has nothing to do with threading.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."
-- 
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.




Querysets returns wrong result when using threading.

2010-01-14 Thread Kieran Brownlees
Hello All,

Using Django 1.1.1. Today I found some very strange behaviour when
trying to use theading, from what I understand it is different from
the notes on trac of querysets not being thread safe.

Basic issue trying to execute queries while in a thread always returns
an original query. Probably best explained with an example (bit rushed
by time at the end of the day! Sorry for the non generic example.):

http://pastebin.com/m63211552

Basic example of format:
Main Thread: print objects.all()
Spawned Thread: print objects.all() -- same as main thread
Main Thread: objects.create(newObj)
Main Thread: print.objects.all() -- correct queryset, original + new
Spawned Thread: print objects.all() -- only contains the original
objects, not the new one?

Full output (also shown in pastebin)
test: []
In thread
threadTest: []
Thread waiting
Creating new db entry
test: [,
]
threadTest: []

Thank you,
Kieran


-- 
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: query related question

2010-01-14 Thread Kevin Monceaux
E. Hankan,

On Thu, Jan 14, 2010 at 10:53:31PM -0500, E. Hakan Duran wrote:

Take the following with a grain, or three, of salt.  I'm a little rusty.  I
converted a web site to Django back in the pre-1.x days and am just getting
back to tinkering with Django to enhance the functionality of said site.
So, I'm sort of a semi-newbie myself.

This is untested, but I think you're aiming for something along the lines
of:

> view.py:
> ...
> def index(request):
>women_list = Woman.objects.filter(lastname__exact='Test')
>return render_to_response('kimlik/index.html', {'women_list': women})
> 
> 
> index.html:
> ...
> {% if women %}
> 
> {% for woman in women %}
>   {{ woman.lastname }}, {{ woman.firstname }}, {{ woman.dob }}, {{ 
> woman.email }}, {{ woman.couple.city }}
> {% endfor %}
> 
> {% else %}
> No couple is available.
> {% endif %}



-- 

Kevin
http://www.RawFedDogs.net
http://www.WacoAgilityGroup.org
Bruceville, TX

What's the definition of a legacy system?  One that works! 
Si hoc legere scis nimium eruditionis habes.
Longum iter est per praecepta, breve et efficax per exempla!!!

-- 
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: query related question

2010-01-14 Thread Shawn Milochik
Your couple_query returns a queryset. Even if there's only one result, you're 
not getting just the one woman, but a queryset object. I think you want 
something more like:

woman = Woman.objects.get(lastname__exact = 'Test')
couple = Couple.objects.get(couple = woman.couple)

Note that this is making the assumption that there is only one woman with that 
last name, and that there is only one couple with this woman in it.

I don't know if you just made this up as an example, but if it's something that 
you're actually working on, it seems like making a Woman and Man model isn't a 
very good idea because there's so much duplication. Just have a Person model 
with a 'sex' field, and you have have a foreign key to itself labeled 'partner' 
or something. No need for a separate 'couples' table. If you really need the 
address info, there should be an Address model. After all, you may have other 
things (businesses, etc.) that also have addresses which will require the same 
validation. It gets really ugly really fast when you have 'address1, address2, 
city, state, and zip' in a bunch of different models. Possibly with different 
field lengths and other stuff.

Also, I don't know what you mean by not having a technical background, but if 
you mean you have no application design or programming experience, then I urge 
you to hire someone to do this, unless this is just something you're doing to 
teach yourself to program (and if so, welcome!). Despite the fact that Python 
and Django are far less daunting to learn than other tools, they still require 
programming ability to do at all, and a lot of experience to do well. Nothing 
personal -- I just wanted to point out that database design and application 
design are definitely not trivial and shouldn't be done by someone with no 
experience if this is something needed by your business.

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




query related question

2010-01-14 Thread E. Hakan Duran
Hi all,

I don't have a technical background, so please be gentle with me.

I have two models with a ForeignKey relation: "couple" and "woman". I am 
trying to set up a query that lists the women with lastname='Test' along with 
some of their information from the "woman" model as well as some from "couple" 
model. I am trying to use the examples in the tutorial / documentation 
sections but I couldn't get two different datasets from two different models 
displayed together. Briefly, I would like to display lastname, firstname, date 
of birth and email fields from the "woman" model, and city field from the 
"couple" model for these ladies with a last name of Test (n=2). Any tips on 
how to accomplish this will be very much appreciated. Please see related info 
below, which BTW does not work:

--
models.py:

class Couple(models.Model):
couple_name = models.CharField(max_length=100)
entry_date = models.DateField('Date Entered')
home_address1 = models.CharField(max_length=200)
home_address2 = models.CharField(max_length=200)
city = models.CharField(max_length=100)
state = models.CharField(max_length=2, null=True)
country = models.CharField(max_length=100, default="United States")
home_phone = models.CharField(max_length=20)
def __unicode__(self):
return self.couple_name

class Woman(models.Model):
couple = models.ForeignKey(Couple, unique=True)
lastname = models.CharField(max_length=100)
firstname = models.CharField(max_length=100)
middle_initial = models.CharField(max_length=1, null=True)
ssn = models.PositiveIntegerField('SSN')
dob = models.DateField('Date of Birth')
cell_phone = models.CharField(max_length=20, null=True)
email = models.EmailField(null=True)


view.py:
...
def index(request):
   couple_query = Woman.objects.filter(lastname__exact='Test')
   cn = Couple.objects.get(id__exact=woman.id)
   return render_to_response('kimlik/index.html', {'couple_query': 
couple_query, 'cn': cn})


index.html:
...
{% if couple_query %}

{% for woman in couple_query %}
  cn = Couple.objects.get(id__exact=woman.id)
  {{ woman.lastname }}, {{ woman.firstname }}, {{ woman.dob }}, {{ 
woman.email }}, {{ cn.city }}
{% endfor %}

{% else %}
No couple is available.
{% endif %}


signature.asc
Description: This is a digitally signed message part.


Re: Best way to track user presence

2010-01-14 Thread Shawn Milochik
Use the built-in session timeout. Probably a good idea in any case, to  
protect your data and user privacy.


If they don't log out, they time out.

If you trust your users to have scripting enabled, you can even put a  
JavaScript function on a timer to sent the browser to your logout URL.  
It's just a nice-to-have, though -- the session timing out handles all  
contingencies.


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




Re: Best way to track user presence

2010-01-14 Thread Brian Neal
On Jan 14, 7:30 pm, E17  wrote:
> Hi,
>
> in my Django application I need a way to track logged users presence.
>
> User gets an 'online' status when he/she logs in and 'offline' status
> when logs out, it's pretty simple. But what is the best way to handle
> non-logged-out sessions? One need to periodically check all sessions
> on last activity age and make some decisions depending on that age -
> i.e. set user status to 'away' of 'offline'.
>
> I wouldn't like to use cron, as running full python execution stack is
> quite expensive in terms of performance. For the same reason I don't
> like to run this code on [every] request handlers.
>
> Seems to me like better solution would be to use some outer deamon or
> deamon-like proces that would handle this functionality. I've googled
> out at least 2 solutions for that - django-cron (http://
> code.google.com/p/django-cron/) and a standalone Django Cron Jobs
> Daemon (http://www.djangosnippets.org/snippets/1348/).
>
> What is a better way or I missed something else?
>
> Thank you

Use some middleware to keep track of the last time you see a logged in
user.

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




Best way to track user presence

2010-01-14 Thread E17
Hi,

in my Django application I need a way to track logged users presence.

User gets an 'online' status when he/she logs in and 'offline' status
when logs out, it's pretty simple. But what is the best way to handle
non-logged-out sessions? One need to periodically check all sessions
on last activity age and make some decisions depending on that age -
i.e. set user status to 'away' of 'offline'.

I wouldn't like to use cron, as running full python execution stack is
quite expensive in terms of performance. For the same reason I don't
like to run this code on [every] request handlers.

Seems to me like better solution would be to use some outer deamon or
deamon-like proces that would handle this functionality. I've googled
out at least 2 solutions for that - django-cron (http://
code.google.com/p/django-cron/) and a standalone Django Cron Jobs
Daemon (http://www.djangosnippets.org/snippets/1348/).

What is a better way or I missed something else?

Thank you

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




Problem with ManyToMany Relationship and related_name

2010-01-14 Thread HWM-Rocker
Hi,

I am relatively new with Django but I like what I have seen so far.

why does this not work?

class Tag(models.Model):
text = models.CharField(max_length=200)
children = models.ManyToManyField('self', blank=True, null=True,
symmetrical=True, related_name='parents')
synonyms = models.ManyToManyField('self', blank=True, null=True)

What i want is a symmetrical link to the same project, like a linked
list with the difference that these is a many to many relationship.
Since there is also something like synonyms treebear and mptt are not
usefull for me.

Is there another possibility to achieve this. i thought about to
create a second element called parents and overwrite the add function
for them. To guarantee that there is a symmetrical. but i don't know
how to pass it trough, do i have to check if it is already in the
other before i add to prevent infinite loop or is there a better to do
it?

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.




Problem when trying to validate a field in a ModelAdmin which has inline forms

2010-01-14 Thread Gabriel Reis
Hi people,

I am having some problem to validate a data in my application. I will try to
simply the model in here to help you guys to understand the problem.
I have 2 models:

class Clip(models.Model):
is_approved = models.BooleanField(default=False)
language = models.ForeignKey(Language)

class ClipDescription(models.Model):
clip = models.ForeignKey(Clip)
text = models.TextField()
language = models.ForeignKey(Language)

I am editing via ModelAdmin. I defined a ClipModelAdmin class as above
(simplified):

class ClipAdmin(admin.ModelAdmin):
inlines = [
ClipDescriptionInline
]


So, as you can see, both Clip and ClipDescription are edited in the same
page (using the 'inlines' feature).

But the rule is: if the user trigger the 'Save' action, the attribute
Clip.is_approved can be True only if there is a ClipDescription instance
associated to the Clip instance, having the same language. For example, if I
have a clip with id=1, language=english and is_approved=True, it can be
saved only if there is a clip description with clip_id=1, language=english.
If not, I want to show the error message 'Cannot approve this clip without
having a description in English' in the form.

I have already read the official documentation and tried to work with
validators, tried to define a ModelForm and its clean_is_approved method,
among other workarounds. And I still couldn't make this work. The problem is
at the clean_is_approved context I couldn't figure out how to get access to
the form data that is being entered at that moment, to retrieve the Clip
descriptions.

I don't if I was clear enough, I can give more details. Any ideas and
suggestions will be very appreciated.

Thank you very much for your attention.

Kind regards,

Gabriel


Gabriel de Carvalho Nogueira Reis
Software Developer
+44 7907 823942
-- 

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: Ok to load many .js files to support lots of interactive widgets?

2010-01-14 Thread Daniel Roseman
On Jan 14, 8:01 pm, Margie Roginski  wrote:
> As I've learned more about jquery/javascript, I've added more and more
> jquery interactive widgets to my app (which is sort of like a ticket
> tracking app).  I'm wondering if having too many .js files is a bad
> thing (or a good thing)?
>
> Here's an example to make my question more understandable.  I have
> form similar to the admin changelist form, where the user views all of
> their tasks.  Each task has a lot of info available but I don't want
> it to display it all in the form itself.  For example, a task has a
> "result" field, and instead of just rendering the result field (which
> can be long), I provide a link that shows the date the result was
> entered.  When the user clicks on the link, they get a tooltip popup
> that displays the result.
>
> My django widget looks like this:
>
> class ChangeList_DisplayResultWidget(ChangeList_ToolTipWidget):
>
>     class Media:
>         js = ('js/jquery.js',
>               "js/cluetip/jquery.cluetip.js",
>               "js_custom/task_changelist_helpers/result_widget.js",
>               )
>
>         css = {'all' : ('js/cluetip/jquery.cluetip.css',)}
>
> The contents of result_widget.js is quite small, just this:
>
>   $(document).ready(function() {
>       $('.changelist_result').cluetip({sticky:true,
>             closePosition: 'top',
>             closeText:'',
>             showTitle:false,
>             leftOffset:'-300px',
>             activation:'click',
>             cluetipClass: 'jtip',
>             onShow: function(e) { $('#cluetip a').attr({'target':
> '_blank'}); return true; }
>       });
>   });
>
> My question is - is it ok to have a lot of little .js files like
> this?  I find that keeping the .js code associated with my widgets in
> separate files is very nice, because then if I reuse the widget on
> some other page, it is well-encapsulated.  IE, I get just the .js for
> that widget, and no additional .js code.  But since I have a very
> interactive web app with a variety of widgets that have different
> behaviors, I am finding that I have a lot of .js files getting
> included.
>
> In my page that is similar to django's admin change list, I now have
> 25 .js files.  That includes various good-sized jquery packages
> (jquery.js, autocomplete, datePicker, cluetip, filter), plus my
> little .js snippets like that shown above, that use those packages,
> plus some custom .js I have written, plus some code I use from the
> admin app (core.js, actions.js, getElemetnsByselector.js).
>
> Sorry if I'm going into too much detail - just wanted to give folks a
> flavor of what I'm doing.  The users are very happy so I don't think
> I'm going overboard on the UI side, but I'm just wondering if there
> are issues associated with they way I am organizing the .js, or if
> what I'm doing is a good way to go.
>
> I am doing client side caching of the files, and so far things seem
> fast.  I'd like to hear input from anyone with more experience on
> whether this is a good organization or if there is some preferable way
> to go.
>
> Margie

This isn't a Django question of course, but applies more generally to
web apps.

Best practise is not to have lots of small JS files. This is because
most browsers limit the number of requests they can make to the same
domain at once, so the files can't be loaded in parallel. What we tend
to do is combine the files into a single one - there are various
projects around that will do that for you. You can then include that
combined JS file in your pages, rather than the 25 small ones.

You may find it useful to test your site against the Yahoo YSlow
analyzer, an add-in for the Firebug extension for Firefox. It gives
lots of good advice about this sort of thing.
--
DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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.




How to pass raw sql results (cursor.fetchall()) to the template?

2010-01-14 Thread Ken
Newb question here.  How do I pass raw sql results to my template?
The sql results contains a two column queryset with several rows .

Below doesn't work.  How do I make this work?  Do I need to parse the
results into an array and then pass to the template?

IN THE VIEW:
cursor = connection.cursor()
cursor.execute("query goes here")
results = cursor.fetchall()

return render_to_response('template.html', {'results': results})

IN THE TEMPLATE:
{% for result in results %}
{{ result[0] }} is a big {{ result[1] }}
{% endfor %}


-- 
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: Insert AUTOMATICALLY random string in username field

2010-01-14 Thread Eric Chamberlain

On Jan 14, 2010, at 6:45 AM, nameless wrote:

> 
> 
> I want username field is automatically filled with this value:
> 
> username = str(n);
> 
> where n is a number of 10 digits ( autoincremented or random ).
> 
> .
> 
> I tried to add this in save method:
> 
> username = str(random.randint(10,99))
> 
> but there is a collision problem when n is the same for 2 users
> ( although rare initially ).
> 
> .
> 
> How do I do this ?
> 

We did something like:

def register_user(email, password, first_name=None, last_name=None, 
agree_to_eula=True):

def generate_username():
"""Generate a random 30-character username. Username can only be 
alphanumeric or underscore."""
return ''.join([choice(string.letters + string.digits + '_') for i in 
range(30)])

email = email.strip()
if not email_re.search(email):
raise InvalidEmailAddressExcept

if len(password.strip()) < 6:
#TODO: pass password length info back to exception, so it's not hard 
coded in two locations
raise InvalidPasswordExcept

try:
user = authenticate_user(email,password,agree_to_eula)
except AuthenticationFailedExcept:
raise AccountExistsAuthenticationFailedExcept
except UserNotFoundExcept:
# we need to create this user
while True:
try:
user = User.objects.create_user(username=generate_username(),
  email=email, password=password)
except IntegrityError:
# this means the username already exists loop and try again 
with a new username
continue
else:
# we successfully created the user, leave the loop
break

if first_name:
user.first_name = first_name
if last_name:
user.last_name = last_name
user.save()
profile = Profile(user=user)
if agree_to_eula:
profile.agree_to_eula()
profile.save()
else:
profile = user.get_profile()

return {'user': user,}

-- 
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: Text Search using Python

2010-01-14 Thread Gabriel Falcão
There is a Django abstraction to whoosh:

http://haystacksearch.org/

On Thu, Jan 14, 2010 at 12:36 PM, Mark (Nosrednakram)
 wrote:
> Hello,
>
> I've been using whoosh and find it very easy to implement.  Whoosh has
> good documentation on static file indexing and  django related
> documentation is available.
>
> Whoosh Specific
>  http://whoosh.ca/
>  http://files.whoosh.ca/whoosh/docs/latest/index.html
>
> Django Related
>  http://www.arnebrodowski.de/blog/add-full-text-search-to-your-django-project-with-whoosh.html
>  http://projects.django-development.com/trac/dd_devel/wiki/dd_search_wiki
>
> The last link is some code I threw together that uses multiple indexes
> so you could set one up for static files as well as for django based
> if you want/need both.  I would probably write a manager for indexing
> static media that would take an OS path and base URL to prepend to it
> and run it when needed.  If you want to try whoosh feel free to ask me
> questions.
>
> Mark
>
> On Jan 14, 4:04 am, Amit Sethi  wrote:
>> Hi , I have  a project with a few static html pages , I wish to search these
>> static html using a django search app . Most of the tutorials I saw are
>> focused on searching django models but none I could see concentrates on
>> indexing static html pages . Can some one guide be to a library /tutorial
>> etc for searching and indexing static pages in a project .
>>
>> --
>> A-M-I-T S|S
>
> --
> 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.
>
>
>
>



-- 
:wq

Atenciosamente
__
Gabriel Falcão

Jabber: gabrielfal...@jabber-br.org
Blog: http://www.nacaolivre.org
-- 
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.




Ok to load many .js files to support lots of interactive widgets?

2010-01-14 Thread Margie Roginski
As I've learned more about jquery/javascript, I've added more and more
jquery interactive widgets to my app (which is sort of like a ticket
tracking app).  I'm wondering if having too many .js files is a bad
thing (or a good thing)?

Here's an example to make my question more understandable.  I have
form similar to the admin changelist form, where the user views all of
their tasks.  Each task has a lot of info available but I don't want
it to display it all in the form itself.  For example, a task has a
"result" field, and instead of just rendering the result field (which
can be long), I provide a link that shows the date the result was
entered.  When the user clicks on the link, they get a tooltip popup
that displays the result.


My django widget looks like this:

class ChangeList_DisplayResultWidget(ChangeList_ToolTipWidget):

class Media:
js = ('js/jquery.js',
  "js/cluetip/jquery.cluetip.js",
  "js_custom/task_changelist_helpers/result_widget.js",
  )

css = {'all' : ('js/cluetip/jquery.cluetip.css',)}

The contents of result_widget.js is quite small, just this:

  $(document).ready(function() {
  $('.changelist_result').cluetip({sticky:true,
closePosition: 'top',
closeText:'',
showTitle:false,
leftOffset:'-300px',
activation:'click',
cluetipClass: 'jtip',
onShow: function(e) { $('#cluetip a').attr({'target':
'_blank'}); return true; }
  });
  });

My question is - is it ok to have a lot of little .js files like
this?  I find that keeping the .js code associated with my widgets in
separate files is very nice, because then if I reuse the widget on
some other page, it is well-encapsulated.  IE, I get just the .js for
that widget, and no additional .js code.  But since I have a very
interactive web app with a variety of widgets that have different
behaviors, I am finding that I have a lot of .js files getting
included.

In my page that is similar to django's admin change list, I now have
25 .js files.  That includes various good-sized jquery packages
(jquery.js, autocomplete, datePicker, cluetip, filter), plus my
little .js snippets like that shown above, that use those packages,
plus some custom .js I have written, plus some code I use from the
admin app (core.js, actions.js, getElemetnsByselector.js).

Sorry if I'm going into too much detail - just wanted to give folks a
flavor of what I'm doing.  The users are very happy so I don't think
I'm going overboard on the UI side, but I'm just wondering if there
are issues associated with they way I am organizing the .js, or if
what I'm doing is a good way to go.

I am doing client side caching of the files, and so far things seem
fast.  I'd like to hear input from anyone with more experience on
whether this is a good organization or if there is some preferable way
to go.

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




inline formset

2010-01-14 Thread Frédéric Burlet

Hi,

I'm a bit stuck with inline formset. I missed something.
I'm using django 1.1.1.

I have a model:

class Address(models.Model):
street = ...
number = ...
...

class Person(models.Model):
first_name = ...
last_name =
address = models.ForeignKey(Address)
...

Based on this model, I would like to have one form to add a person and her 
address. In order to achieve this, I'm using inline formset.

As far as I understood, formset allows to add multiple form on a page and 
inline formset is an extension that allows to play with related objects.

I written the following view (based on the documentation located at [1])

[1] http://docs.djangoproject.com/en/1.1/topics/forms/modelforms/#inline-
formsets

def add_person_form(request):

address = Address()
PersonFormSet = inlineformset_factory(Address, Person, max_num = 1, 
can_delete = False)

if request.method == 'POST':
formset = PersonFormSet(request.POST, request.FILES, instance = 
address)
if formset.is_valid():
formset.save()
return redirect('/person')
else:
formset = PersonFormSet(instance = address)
return render_to_response('person/add_form.html', { "formset": formset } )


My template looks like (simplified version):


 {{ formset }}


This only displays the person but not the address.

Extra question: if I want to display the fields in a given order, let's say: 
first_name, last_name, and then all fields from Address object followed by the 
remaining fields from Person. What is the best way of doing it ?

Thanks for your support,

Frédéric Burlet.



signature.asc
Description: This is a digitally signed message part.


Re: Filter on forms.ModelChoiceField(queryset=Image.objects.filter())

2010-01-14 Thread Tom Evans
On Thu, Jan 14, 2010 at 6:39 PM, GoSantoni  wrote:
> Hi
>
> Is it possible to use extra filter on a ModelChoiceField?
>
> Tried several strategies:
>
> if photo.member == user:
>    url = forms.ModelChoiceField(queryset=Image.objects.filter())
>
> or
>    url = forms.ModelChoiceField(queryset=Image.objects.filter
> (member__id=1))
>
> or
>
> if Image.objects.filter(member__id=1):
>     url = forms.ModelChoiceField(queryset=Image.objects.filter
> (member__id=1))
>
> All fail to filter on the member / user
>
> Thanks
>

The technique I use to do forms like this is to add the queryset in
the constructor, passing in whatever I need to filter it.

Eg:

class AttachmentForm(forms.Form):
  name = forms.CharField(max_length=32)
  url = forms.ModelChoiceField(queryset=Image.objects.none())
  def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user')
super(forms.Form, self).__init__(*args, **kwargs)
self.fields['url'].queryset = Image.objects.filter(user=self.user)


Cheers

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: Insert AUTOMATICALLY random string in username field

2010-01-14 Thread Tom Evans
On Thu, Jan 14, 2010 at 6:34 PM, nameless  wrote:
> uuid is too long for username field ( max 30 characters ). "n" should
> be a number of 10 digits :)
>
>

Er, a UUID is a 128 bit number. In its standard 'for humans' format it
is represented as 36 character hexadecimal string (ie 288 bits), but
how you pack that into your database is your concern - here is a way
to ensure a 24 character ascii UUID:

>>> import base64
>>> import uuid
>>> print base64.b64encode(uuid.uuid4().bytes)
y1WjDxxOT0KQVe4Jkwuj2g==
>>> print len(base64.b64encode(uuid.uuid4().bytes))
24

although django will still barf on that, it wont accept '/', '=' or
'+' as part of a username - a really pointless and arbitrary
validation rule imo.

Cheers

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: Filter on forms.ModelChoiceField(queryset=Image.objects.filter())

2010-01-14 Thread Daniel Roseman
On Jan 14, 6:39 pm, GoSantoni  wrote:
> Hi
>
> Is it possible to use extra filter on a ModelChoiceField?
>
> Tried several strategies:
>
> if photo.member == user:
>     url = forms.ModelChoiceField(queryset=Image.objects.filter())
>
> or
>     url = forms.ModelChoiceField(queryset=Image.objects.filter
> (member__id=1))
>
> or
>
> if Image.objects.filter(member__id=1):
>      url = forms.ModelChoiceField(queryset=Image.objects.filter
> (member__id=1))
>
> All fail to filter on the member / user
>
> Thanks

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




permalinks from cron job

2010-01-14 Thread eric.frederich
My django urls work nicely when browsing around, clicking things, and
when my views generate emails.  They all have the appropriate prefix.

In apache's conf file I have the following...

WSGIScriptAlias /apps /export/home/web/docs/django/my_site/apache/
django.wsgi

My urls look like https://mydomain.com/apps/some_app/

I looked dug around django's code and saw that the magic was happening
between urlresolvers.py and the wsgi handler setting the appropriate
prefix '/apps'.

So, my question is how do I get the /apps prefix into my urls when
running outside of the web (i.e. via a cron job).

Is there some setting somewhere to set the prefix?
Can it be set via an environment variable?
How to I get the reverse function in urlresolvers to add /apps to my
url like it does when run through wsgi?

Thanks,
~Eric
-- 
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.




import error on dateutil.parser

2010-01-14 Thread newspaper-django-lackey
I'm attempting to use python-dateutil to parse the date output from
Feedparser, but continue to get an error when importing the parser.

I'm building a quick filter in a timeutil.py file in a templatetag
folder on the pythonpath

from dateutil.parser import parse
def parsefeedtime(value):
"""Use this to parse the date info out of feedparser when using
the parse_feed or include_feed tags"""
date_published = parse(value)
return date_published

I continue to get the error

"Could not load template library from django.templatetags.timeutiladd,
No module named parser"

I've installed the dateutil via commandline, I deleted the egg and
reinstalled using easy_install, but I keep getting the error.

When I run the function from the python interpreter, it work
perfectly.

>>> from dateutil.parser import parse
>>> value='Thu, 14 Jan 2010 16:51:27 GMT'
>>> x = parse(value)
>>> print x
2010-01-14 16:51:27+00:00

I have no idea why it would work from the python interpreter, but not
from a django templatetag file.

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: Text Search using Python

2010-01-14 Thread esatterwh...@wi.rr.com
I've been working on 2 sites that use full text search on a wiki-like
system where users use a WYSIWYG/html editor. This, obviously, doesn't
apply to flatpages, but the poblem/solution might be of help.

The problem is, if you try tindex/search html, you get a lot terrible
results. For example, if you were searching for the word class,
virtually ever document would come up as result because of the html
class="" bit.

The solution we are using was an off shoot of the wiki-app from pinax.

We use google's diff_match_patch library alot.here is the basic
rundown

1. Get HTML content from a from submitted by user.
2. use django's defaultfilter striptags to strip the html tags
3. used diff_match_patch to create a patch between the plain text and
html
4. save the plain text as the content on the document model
5. save a text version of the patch on the document model
6. index the plain text when you search for strings, this will be what
the search is performed on

An instance method that accepts no parameters ( so it can be used in
templates ) is used to recreate the HTML from the patch and plain text
and that is displayed when a user wants to view the page. As of yet,
we haven't seen an difference in performance when rendering pages.

While, I'm not certain, I'm not so sure that flatpages would allow you
to do this. And the solution is probably a bit more complicated than
what one would want to do for just indexing static pages. I maybe
wrong, but I don't think you will be index full HTML content and only
search the plain text with out doing some kind of conversion of the
HTML first.

This does, however, depend on how you set up your templates for
flatpages. I have had flat pages that extend a base template and just
render out plain text into generic  container. If you were to do
that, then you could index the flatpage content as it would only be
plain text. this could be done fairly easily with django's orm.

end ramble.

On Jan 14, 5:04 am, Amit Sethi  wrote:
> Hi , I have  a project with a few static html pages , I wish to search these
> static html using a django search app . Most of the tutorials I saw are
> focused on searching django models but none I could see concentrates on
> indexing static html pages . Can some one guide be to a library /tutorial
> etc for searching and indexing static pages in a project .
>
> --
> A-M-I-T S|S
-- 
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: Insert AUTOMATICALLY random string in username field

2010-01-14 Thread Tom Evans
On Thu, Jan 14, 2010 at 2:45 PM, nameless  wrote:
>
>
> I want username field is automatically filled with this value:
>
> username = str(n);
>
> where n is a number of 10 digits ( autoincremented or random ).
>
> .
>
> I tried to add this in save method:
>
> username = str(random.randint(10,99))
>
> but there is a collision problem when n is the same for 2 users
> ( although rare initially ).
>
> .
>
> How do I do this ?
>
> Thanks ^_^
>

Use a version 4 UUID instead. If you generate 1 billion version 4
UUIDs a second for 100 years, you have ~ 50% chance of a collision.
They are also built in to later versions of python (2.5+):

>>> import uuid
>>> print uuid.uuid4()
92d6a4f4-918d-4a9b-8251-3150c88c62e7


Cheers

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.




Documentation for graphic designers

2010-01-14 Thread Zee
I'd like to know if there is manual or "How to Guide"  for graphic
designers working with django.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 Cache

2010-01-14 Thread Hinnack
why dont you use localurl
http://code.google.com/p/django-localeurl/

so you have the language automatically in the URL and you do not need to
change anything...

--

Hinnack

2010/1/14 vitor torres 

> Hi. I'm building blog and I want to cache the main page wich is a
> archive_index generic view and I want to be able to choose between
> languages wich means that I must do different cache depending on the
> language. So I tried to use the the decorator @vary_on_headers('Accept-
> language') in my urls.py but I had an error: 'MethodDecoratorAdaptor'
> object has no attribute 'has_header'. Could someone please tell me
> what am I doing wrong or if it feaseable to do that with a generic
> view.
>
> --
> 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: Insert AUTOMATICALLY random string in username field

2010-01-14 Thread Shawn Milochik

Do a Google search on 'mysql' and 'sequences.'

Also, have a look at MySQL's last_insert_id() function. Maybe that's  
all you need to use an autonumber as a sequence.


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




Re: Insert AUTOMATICALLY random string in username field

2010-01-14 Thread nameless
Sequences are best solution for me but I don't know how to implement
its in django+mysql.
I tought also to use id as username but I don't know how do this :-\

Could you explain me how do pleaseee ?
Thank you


---
On Jan 14, 4:16 pm, Shawn Milochik  wrote:
> There are a bunch of ways you can do it. As a previous poster said, you can 
> take 10 digits of the current timestamp. However, be wary of daylight saving 
> time changes (if you have them on your server), and the possibility of any 
> conflict if you change servers, have a backup server, or ever expand to 
> multiple servers for your application.
>
> A possibility, if you're open to alphanumeric strings, is a uuid, 
> specifically uuid4 or uuid1. Check out the documentation to see if they'd 
> work for you. If you don't care to necessarily limit it to 10 characters, and 
> you don't mind alpha-numeric characters, then just use a uuid4 and you're 
> done.http://docs.python.org/library/uuid.html
>
> Yet another possibility is to use the capability of your database to create 
> sequences. If you're using Postgres, it has a SEQUENCE which you can create, 
> and always ask it for the next one. You can start a sequence at any number 
> you like, in order to get the size you want. We do something similar for 
> generating customer numbers. We have a sequence, and we use it appended to a 
> static set of digits for the particular program the customer is in. So, for 
> example, all customers in program X would have a customer number of 10 digits 
> starting with '1001' and ending with an incremental number. There are ways to 
> do this with other databases. Worst-case you can create a table with an 
> auto-increment key and just use its primary key for your next digit.
>
> One more, but not last nor least, is to have your model generate the string 
> you want by one of the means above, or something completely different, then 
> override the save() of your model to check to ensure that this key doesn't 
> exist already. This is less than ideal, but maybe there's a case to be made 
> for it. Just throwing it in as an option.
>
> 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.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Django Cache

2010-01-14 Thread vitor torres
Hi. I'm building blog and I want to cache the main page wich is a
archive_index generic view and I want to be able to choose between
languages wich means that I must do different cache depending on the
language. So I tried to use the the decorator @vary_on_headers('Accept-
language') in my urls.py but I had an error: 'MethodDecoratorAdaptor'
object has no attribute 'has_header'. Could someone please tell me
what am I doing wrong or if it feaseable to do that with a generic
view.
-- 
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: decimal is not json serializable.

2010-01-14 Thread Simon Brunning
2010/1/14 Meenu :
> Hello all,
>
> I'm following the "Serializing Django objects" documentation and have
> a view pretty much verbatim from the docs:
>
>        if xhr:
>            return HttpResponse(simplejson.dumps(form_data),
> mimetype='application/javascript')
>
> When I test the above view using the Django shell, it works, but when
> I try it via a browser request, I get this:
>
> Decimal("44.048708") is not JSON serializable
>
> Any help will be appreciated.

You can override the JSON encoder's behaviour, something like (untested):

class MyJsonEncoder(simplejson.JSONEncoder):
"""JSON encoder which understands decimals."""

def default(self, obj):
'''Convert object to JSON encodable type.'''
if isinstance(obj, decimal.Decimal):
return "%s" % obj

return super(MyJsonEncoder, self).default(self, obj)

The simplejson.dumps() method takes an optional cls keyword argument -
that's where you plug MyJsonEncoder in.

-- 
Cheers,
Simon B.
-- 
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.




Underscores vs. Numbers

2010-01-14 Thread Wiiboy
I noticed when I upload multiple files to my website with the same
name, Django adds underscores to the file names.  But doesn't that
seems like it's less efficient than adding numbers to the end, (i.e.
myfile (1).txt)?  And on some OSs, a file name can be too long, which
could cause problems.

Anyone know why they chose to use underscores?
-- 
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.




Two Email Backends

2010-01-14 Thread Thomas Guettler
Hi,

we code intranet applications which run in the internal net
of the customers.

I would like to have two email connections:

 1. smtp host of customer
 2. machine local smtp for exception emails

Up to now I use the settings
file for the machine local smtp and create a own
connection if my application sends mail. But somehow
I don't like this.

How do you handle this?


Documentation:
  http://docs.djangoproject.com/en/dev/topics/email/

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
-- 
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: Insert AUTOMATICALLY random string in username field

2010-01-14 Thread Shawn Milochik
There are a bunch of ways you can do it. As a previous poster said, you can 
take 10 digits of the current timestamp. However, be wary of daylight saving 
time changes (if you have them on your server), and the possibility of any 
conflict if you change servers, have a backup server, or ever expand to 
multiple servers for your application.

A possibility, if you're open to alphanumeric strings, is a uuid, specifically 
uuid4 or uuid1. Check out the documentation to see if they'd work for you. If 
you don't care to necessarily limit it to 10 characters, and you don't mind 
alpha-numeric characters, then just use a uuid4 and you're done.
http://docs.python.org/library/uuid.html

Yet another possibility is to use the capability of your database to create 
sequences. If you're using Postgres, it has a SEQUENCE which you can create, 
and always ask it for the next one. You can start a sequence at any number you 
like, in order to get the size you want. We do something similar for generating 
customer numbers. We have a sequence, and we use it appended to a static set of 
digits for the particular program the customer is in. So, for example, all 
customers in program X would have a customer number of 10 digits starting with 
'1001' and ending with an incremental number. There are ways to do this with 
other databases. Worst-case you can create a table with an auto-increment key 
and just use its primary key for your next digit. 

One more, but not last nor least, is to have your model generate the string you 
want by one of the means above, or something completely different, then 
override the save() of your model to check to ensure that this key doesn't 
exist already. This is less than ideal, but maybe there's a case to be made for 
it. Just throwing it in as an option. 

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




Re: decimal is not json serializable.

2010-01-14 Thread Shawn Milochik
You could always convert decimals to strings. There's probably a better 
solution out there, but this should at least be a quick-fix.

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




Re: A question about database models

2010-01-14 Thread Jani Tiainen
On Thu, 2010-01-14 at 03:25 -0800, ifcho wrote:
> Hi,
> 
> I'm very new to Django, and I'm sorry if the question is really dumb.

Kind of a dumb question... See why:

> So I have a database model for a drivers (rally car driver), and I
> have database model for the results. As you know a rally car team is
> of two - a driver and co-driver. And so I have:
> class EntryList(models.Model):
> .
> the_driver = models.ForeignKey(Drivers)
> the_co_driver = models.ForeignKey(Drivers)
> .
> here is where I get the following error:
> manage.py validate
> Error: One or more models did not validate:
> mysite.entrylist: Accessor for field 'the_driver' clashes with related
> field 'Drivers.entrylist_set'. Add a related_name argument to the
> definition for 'the_driver'.

Did you read what error says?

> mysite.entrylist: Accessor for field 'the_co_driver' clashes with
> related field 'Drivers.entrylist_set'. Add a related_name argument to
> the definition for 'the_co_driver'.

Again, did you actually read what it said again?

> after commenting the_driver, or the_co_driver, the error is gone.

And if you didn't guessed yet, you have to still add "related_name"
argument for field definition. What it means can be found at django
documentation:



-- 

Jani Tiainen


-- 
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: Insert AUTOMATICALLY random string in username field

2010-01-14 Thread Stephen Emslie
How about a timestamp?

  import time
  name = str(time.time())

On Thu, Jan 14, 2010 at 2:45 PM, nameless  wrote:

>
>
> I want username field is automatically filled with this value:
>
> username = str(n);
>
> where n is a number of 10 digits ( autoincremented or random ).
>
> .
>
> I tried to add this in save method:
>
> username = str(random.randint(10,99))
>
> but there is a collision problem when n is the same for 2 users
> ( although rare initially ).
>
> .
>
> How do I do this ?
>
> 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.



Insert AUTOMATICALLY random string in username field

2010-01-14 Thread nameless


I want username field is automatically filled with this value:

username = str(n);

where n is a number of 10 digits ( autoincremented or random ).

.

I tried to add this in save method:

username = str(random.randint(10,99))

but there is a collision problem when n is the same for 2 users
( although rare initially ).

.

How do I do this ?

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: A question about database models

2010-01-14 Thread Tom Evans
On Thu, Jan 14, 2010 at 11:25 AM, ifcho  wrote:
> Hi,
>
> I'm very new to Django, and I'm sorry if the question is really dumb.
>
> So I have a database model for a drivers (rally car driver), and I
> have database model for the results. As you know a rally car team is
> of two - a driver and co-driver. And so I have:
> class EntryList(models.Model):
> .
>    the_driver = models.ForeignKey(Drivers)
>    the_co_driver = models.ForeignKey(Drivers)
> .
> here is where I get the following error:
> manage.py validate
> Error: One or more models did not validate:
> mysite.entrylist: Accessor for field 'the_driver' clashes with related
> field 'Drivers.entrylist_set'. Add a related_name argument to the
> definition for 'the_driver'.
> mysite.entrylist: Accessor for field 'the_co_driver' clashes with
> related field 'Drivers.entrylist_set'. Add a related_name argument to
> the definition for 'the_co_driver'.
>
> after commenting the_driver, or the_co_driver, the error is gone.
>

The error messages instruct you where you have gone wrong; if you have
multiple foreign key references to the same model within a single
model, each one must have a distinct related_name argument.

See 
http://docs.djangoproject.com/en/1.1/ref/models/fields/#django.db.models.ForeignKey.related_name

Cheers

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.




A question about database models

2010-01-14 Thread ifcho
Hi,

I'm very new to Django, and I'm sorry if the question is really dumb.

So I have a database model for a drivers (rally car driver), and I
have database model for the results. As you know a rally car team is
of two - a driver and co-driver. And so I have:
class EntryList(models.Model):
.
the_driver = models.ForeignKey(Drivers)
the_co_driver = models.ForeignKey(Drivers)
.
here is where I get the following error:
manage.py validate
Error: One or more models did not validate:
mysite.entrylist: Accessor for field 'the_driver' clashes with related
field 'Drivers.entrylist_set'. Add a related_name argument to the
definition for 'the_driver'.
mysite.entrylist: Accessor for field 'the_co_driver' clashes with
related field 'Drivers.entrylist_set'. Add a related_name argument to
the definition for 'the_co_driver'.

after commenting the_driver, or the_co_driver, the error is gone.
-- 
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.




Can't connect to MySQL server

2010-01-14 Thread Hans.Rauch
Hi,

we have two separate django- and mysql-servers. Most of the time we
got no problems. From time to time we get an email with the following
error-message: OperationalError: (2003, "Can't connect to MySQL server
on '..' (4)"). If we call the submitted link, where the error occured,
we don't have any problems.

I think, I have to tune my.cnf; but I don't know which parameter is
best.

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




decimal is not json serializable.

2010-01-14 Thread Meenu
Hello all,

I'm following the "Serializing Django objects" documentation and have
a view pretty much verbatim from the docs:

if xhr:
return HttpResponse(simplejson.dumps(form_data),
mimetype='application/javascript')

When I test the above view using the Django shell, it works, but when
I try it via a browser request, I get this:

Decimal("44.048708") is not JSON serializable

Any help will be appreciated.

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: Text Search using Python

2010-01-14 Thread Mark (Nosrednakram)
Hello,

I've been using whoosh and find it very easy to implement.  Whoosh has
good documentation on static file indexing and  django related
documentation is available.

Whoosh Specific
  http://whoosh.ca/
  http://files.whoosh.ca/whoosh/docs/latest/index.html

Django Related
  
http://www.arnebrodowski.de/blog/add-full-text-search-to-your-django-project-with-whoosh.html
  http://projects.django-development.com/trac/dd_devel/wiki/dd_search_wiki

The last link is some code I threw together that uses multiple indexes
so you could set one up for static files as well as for django based
if you want/need both.  I would probably write a manager for indexing
static media that would take an OS path and base URL to prepend to it
and run it when needed.  If you want to try whoosh feel free to ask me
questions.

Mark

On Jan 14, 4:04 am, Amit Sethi  wrote:
> Hi , I have  a project with a few static html pages , I wish to search these
> static html using a django search app . Most of the tutorials I saw are
> focused on searching django models but none I could see concentrates on
> indexing static html pages . Can some one guide be to a library /tutorial
> etc for searching and indexing static pages in a project .
>
> --
> A-M-I-T S|S
-- 
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: Send and Receive SMS from a django app

2010-01-14 Thread Alessandro Ronchi
On Thu, Jan 14, 2010 at 12:26 PM, Daniel Hilton wrote:

>
> You'll need a GSM modem though.
>


Perfect!

Are all RSR232 GSM modems compatible with pygsm, or everyone needs a
proprietary or different library to be used?

-- 
Alessandro Ronchi

http://www.soasi.com
SOASI - Sviluppo Software e Sistemi Open Source

http://hobbygiochi.com
Hobby & Giochi, l'e-commerce del divertimento
-- 

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: Test fixtures loaded ~100 times faster by overwriting BaseDatabaseCreation.create_test_db + question

2010-01-14 Thread Russell Keith-Magee
On Thu, Jan 14, 2010 at 4:43 PM, Piotr Czachur  wrote:
> Guys,
> I was really unhappy to see how slow fixtures are loaded before every
> test. I'm not talking about initial_data stuff that is loaded just in
> beginning, and then reset by rollback. Fixtures used for unit tests
> are loaded on demand (fixtures = [f1, f2]), and this is really slow,
> because thousands of SQL queries going to database (SELECTs, SELECTs,
> INSERTs).
> For my small test suite (130 tests) and small fixtures (15 items) I've
> recorded ~16000 queries to database - I was really blown away by this
> number. 99% of this queries was related to fixtures loading.

We are well aware of the speed problems associated with fixture setup
and teardown during testing. We're open to any practical suggestions
on how to speed them up.

> So I came to conclusion that I can load my all fixtures just after
> initial_data fixtures are loaded at beginning, so database rollback
> can be used by Django test infrastructure to reset database state in a
> fraction of second.

This might work for your particular test suite, but it isn't that
simple in the general case. More details in a moment.

> Question:
> Like you see I decorated and overwrote create_test_db, but what I
> don't like here is that I had to add "setup_environ(settings)" to
> prevent getting exception, because Django was not initialized at this
> moment.
> execute_manager(settings) also runs setup_environ(settings) so it is
> run twice.
> Is there a better place/time to execute such overwriting? ...because I
> see this little tricky.

Yes - rather than dynamically monkeypatching, write a custom test
runner [1] that calls into your customized create/destroy routines.

[1] http://docs.djangoproject.com/en/dev/topics/testing/#defining-a-test-runner

> P.S.
> The side effect was that I have to remove all "fixture = [a,b,c]" from
> my tests, because I have all fixtures loaded at beginning before tests
> are run - but I cannot see this as a problem.

This is a little more than a 'side effect' - it's a fundamental change
to the expectations of test cases. The major reason to use fixture=[]
notation is to allow every test case to have it's own test fixtures.

This isn't just a good idea - it's a fundamental requirement for
certain types of tests. For example, consider a simple suite with two
tests that validate that an article list displays correctly. The first
test validates that the list displays when articles are defined; the
second test validates that error text is displayed when no articles
are defined. The test fixture requirements for the two tests cannot be
accommodated in a single set of suite-wide test fixtures.

As I said, we're more than happy to look at any proposal to improve
the speed of testing in Django, but those changes can't come at the
cost of fundamentally changing what it means to write a test.

Yours,
Russ Magee %-)
-- 
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: Text Search using Python

2010-01-14 Thread Shawn Milochik

On Jan 14, 2010, at 6:04 AM, Amit Sethi wrote:

> Hi , I have  a project with a few static html pages , I wish to search these 
> static html using a django search app . Most of the tutorials I saw are 
> focused on searching django models but none I could see concentrates on 
> indexing static html pages . Can some one guide be to a library /tutorial etc 
> for searching and indexing static pages in a project .
> 
> -- 
> A-M-I-T S|S
> -- 


A possibility (I don't know how feasible this is) would be to import the 
content of those HTML files into Django Flatpages. If the projects you 
discovered just require a Django model of some kind, you should be good to go.

Otherwise, it sounds like, as in your subject line, you're just going to be 
using Python's string methods to search plain text. If the same static 
documents are going to be searched over time, then you could cache their 
contents in a database. Maybe then you can apply some of the clever ideas 
people have put into Django-specific search tools, but you might have to 
implement some of them in your own search code, rather than using a 
Django-specific project as-is.

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




Re: Send and Receive SMS from a django app

2010-01-14 Thread Daniel Hilton
2010/1/14 Alessandro Ronchi :
>
>
> On Wed, Jan 13, 2010 at 2:29 PM, tback  wrote:
>>
>> Hi Alessandro,
>>
>> yes, it's possible to send sms messages (I use this myself every day)
>> and to receive sms messages (that's an assumption).
>> The easiest way is through a sms gateway.
>> http://www.celltrust.com/ is a provider that advertisises two way
>
> I cannot use an SMS gateway for my app (I must use a SIM and an hardware
> modem).
>
> Does RapidSMS include SMS receiving?
>
> Thanks in advance.

Yep take a look at this:

http://www.rapidsms.org/code/architecture/

You'll need a GSM modem though.

Cheers,
Dan

>
>
>
> --
> Alessandro Ronchi
>
> http://www.soasi.com
> SOASI - Sviluppo Software e Sistemi Open Source
>
> http://hobbygiochi.com
> Hobby & Giochi, l'e-commerce del divertimento
>
> --
> 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.
>
>



-- 
Dan Hilton

www.twitter.com/danhilton
www.DanHilton.co.uk

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




Text Search using Python

2010-01-14 Thread Amit Sethi
Hi , I have  a project with a few static html pages , I wish to search these
static html using a django search app . Most of the tutorials I saw are
focused on searching django models but none I could see concentrates on
indexing static html pages . Can some one guide be to a library /tutorial
etc for searching and indexing static pages in a project .

-- 
A-M-I-T S|S
-- 

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: Send and Receive SMS from a django app

2010-01-14 Thread Alessandro Ronchi
On Wed, Jan 13, 2010 at 2:29 PM, tback  wrote:

> Hi Alessandro,
>
> yes, it's possible to send sms messages (I use this myself every day)
> and to receive sms messages (that's an assumption).
> The easiest way is through a sms gateway.
> http://www.celltrust.com/ is a provider that advertisises two way
>

I cannot use an SMS gateway for my app (I must use a SIM and an hardware
modem).

Does RapidSMS include SMS receiving?

Thanks in advance.



-- 
Alessandro Ronchi

http://www.soasi.com
SOASI - Sviluppo Software e Sistemi Open Source

http://hobbygiochi.com
Hobby & Giochi, l'e-commerce del divertimento
-- 

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: Only Email + Password ( without username )

2010-01-14 Thread nameless
I want to use "id" as identifier for each user. So every user will
have an url like this:

http://www.example.com/827362

I don't want username for my project.
So, if I can't delete it, I think to insert email in username field
and I don't want another identifier in username field as random
strings :P
In this case I don't have to create a custom backend.
Is a good idea in your opinion ?


-

On Jan 14, 11:12 am, Alexander Dutton  wrote:
> On 14/01/10 09:51, nameless wrote:> I am asking whether is a good solution to 
> having 2 fields with the
> > same value ( username and email ) because both are required.
> > Or is there another solution ?
>
> This depends on whether you don't want distinct usernames hanging
> around, or you simply want people to be able to log in using their
> e-mail address.
>
> My inclination in the latter case would be to automatically generate
> usernames as random strings, but not expose them. You can then create a
> custom authentication backend[0] which uses the email address in place
> of the username.
>
> Usernames are good things to have around to refer to people, as e-mail
> addresses can change and usernames generally don't. If user details are
> to be exposed in some way (e.g.  by activity feeds or to other users)
> you want some sort of immutable identifier for each user.
>
> Again, the approach you take depends on what you're trying to do and who
> your audience is.
>
> Alex
>
> [0]http://docs.djangoproject.com/en/dev/ref/authbackends/
-- 
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: Only Email + Password ( without username )

2010-01-14 Thread Alexander Dutton
On 14/01/10 09:51, nameless wrote:
> I am asking whether is a good solution to having 2 fields with the
> same value ( username and email ) because both are required.
> Or is there another solution ?
>   
This depends on whether you don't want distinct usernames hanging
around, or you simply want people to be able to log in using their
e-mail address.

My inclination in the latter case would be to automatically generate
usernames as random strings, but not expose them. You can then create a
custom authentication backend[0] which uses the email address in place
of the username.

Usernames are good things to have around to refer to people, as e-mail
addresses can change and usernames generally don't. If user details are
to be exposed in some way (e.g.  by activity feeds or to other users)
you want some sort of immutable identifier for each user.

Again, the approach you take depends on what you're trying to do and who
your audience is.

Alex

[0] http://docs.djangoproject.com/en/dev/ref/authbackends/
-- 
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: Only Email + Password ( without username )

2010-01-14 Thread nameless

I am asking whether is a good solution to having 2 fields with the
same value ( username and email ) because both are required.
Or is there another solution ?
-- 
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.




Only Email + Password ( without username )

2010-01-14 Thread nameless


I want a Registration Form with only email + password. I am thinking
to insert automatically email in username field. So, for eash user, I
will have this:

username: exam...@example.com

password: mypassword

email: exam...@example.com

Of course email + password will be used in login process.

Is it a good solution ? Or is there a more sofisticated solution ?

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: again a group by problem...

2010-01-14 Thread Benjamin Wolf

Hi Russ,
thank you so much for your answer - it works fine, and it's really easy.
I really have to think different next time ;)
Greets,
ben


Am 14.01.2010 01:05, schrieb Russell Keith-Magee:

On Thu, Jan 14, 2010 at 7:56 AM, Bw.  wrote:
   

Hi guys,

I'm trying to realize a simple sql query in django for hours and I
don't get it.

Description:
We have 'salesman' and 'disposals'.
1 salesman has N disposals.
Now I need the average discount every salesman has given.
In mysql this query gives me the correct recordset:

SELECT salesman.first_name, AVG(disposal.discount)
FROM disposal
LEFT JOIN salesman ON (salesman.id = disposal.salesman_id)
GROUP BY salesman_id

In django i tried something like this:
sm = Disposal.objects.annotate(avg_discount=Avg('discount')).values
('avg_discount','salesman__first_name')
 

In order to render this as a Django query, you need to stop thinking
about the SQL, and start thinking about the problem in terms of the
objects you want. If you ask for Disposal.objects then you're
saying that you want Disposal objects to be returned. However, what
you actually want is a list of Salesmen, each of which has a
collection of Disposals. So - ask for Salesmen:

Salesman.objects.annotate(avg_discount=Avg('disposal__discount')

This will return a list of salesmen objects, each of which has been
annotated with the average discount that they have offered on the
Disposal objects that are related to them.

Yours,
Russ Magee %-)
   


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




Test fixtures loaded ~100 times faster by overwriting BaseDatabaseCreation.create_test_db + question

2010-01-14 Thread Piotr Czachur
Guys,
I was really unhappy to see how slow fixtures are loaded before every
test. I'm not talking about initial_data stuff that is loaded just in
beginning, and then reset by rollback. Fixtures used for unit tests
are loaded on demand (fixtures = [f1, f2]), and this is really slow,
because thousands of SQL queries going to database (SELECTs, SELECTs,
INSERTs).
For my small test suite (130 tests) and small fixtures (15 items) I've
recorded ~16000 queries to database - I was really blown away by this
number. 99% of this queries was related to fixtures loading.
So I came to conclusion that I can load my all fixtures just after
initial_data fixtures are loaded at beginning, so database rollback
can be used by Django test infrastructure to reset database state in a
fraction of second. Before my modification my 130 unit tests run in 80
seconds, and after this in 1 second! How huge difference! I just
couldn't believe it, but it's a fact: rollback is so much faster that
bunch of SELECTs and INSERTs. Here is my patch to manage.py script:
 http://dpaste.com/143558/ =
--- manage.py   (created by Django)
+++ manage.py   (local)


-from django.core.management import execute_manager
+from django.core.management import execute_manager, setup_environ
try:
import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the
directory containing %r. It appears you've customized things.\nYou'll
have to run django-admin.py, passing it your settings module.\n(If the
file settings.py does indeed exist, it's causing an ImportError
somehow.)\n" % __file__)
sys.exit(1)

+
+def decorate_create_test_db(function):
+def decorated_create_test_db(self, verbosity=1,
autoclobber=False):
+returned = function(self, verbosity, autoclobber)
+from django.core.management import call_command
+# settings.TEST_FIXTURES = list of fixtures for all tests
+call_command('loaddata', *settings.TEST_FIXTURES,
verbosity=verbosity, interactive=False,
database=self.connection.alias)
+return returned
+return decorated_create_test_db
+
+
 if __name__ == "__main__":
+setup_environ(settings) # Without it, this import yields
exception
+from django.db.backends import creation
+# Overriding class method from outside is ugly, but it's just for
unit testing so I can live with that
+creation.BaseDatabaseCreation.create_test_db =
decorate_create_test_db(creation.BaseDatabaseCreation.create_test_db)
 execute_manager(settings)



Question:
Like you see I decorated and overwrote create_test_db, but what I
don't like here is that I had to add "setup_environ(settings)" to
prevent getting exception, because Django was not initialized at this
moment.
execute_manager(settings) also runs setup_environ(settings) so it is
run twice.
Is there a better place/time to execute such overwriting? ...because I
see this little tricky.


P.S.
The side effect was that I have to remove all "fixture = [a,b,c]" from
my tests, because I have all fixtures loaded at beginning before tests
are run - but I cannot see this as a problem.
-- 
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.