Re: One to Many+foreign key Query: best way to build the optimal result

2009-06-25 Thread Sam Walters
Thanks for the help.

I think you are on the right track however i could not get this to work.
Maybe an example query using cursor.execute would help so you can see what i
am trying to do.

def sqlAllEventsMenu():
cursor = connection.cursor()
cursor.execute("""
SELECT events_event.id, events_event.start, events_event.title,
events_location.state_id, events_location.name
FROM events_event LEFT JOIN events_location
ON events_event.id = events_location.id
""")
return convertToDictionary(cursor)


On Fri, Jun 19, 2009 at 4:11 PM, BenW  wrote:

>
> I'm not sure I completely understand the problem, but I'll give it a
> stab:
>
> events = Event.objects.filter(start__gte=datetime.today())
> locations = Location.objects.filter(location__in=events)
>
> results = [
>   {'start': loc.location.start, 'title': loc.location.title, 'id':
> loc.location.id, 'state_id': loc.state.id, 'name': loc.name} \
>   for loc in locations.iterator()
> ]
>
> render_to_response('template.htm', {'results': results})
>
> I run a query similar to this one on a 50,000 record table and it only
> takes ~0.30 seconds, and that includes Json serialization!
>
> On Jun 17, 5:00 pm, Sam Walters  wrote:
> > Here is the essentials from my models.py file:
> >
> 
> > class Event (models.Model):
> > contact = models.CharField(max_length=100)
> > email = models.CharField(max_length=100)
> > url = models.CharField(max_length=100)
> > title = models.CharField(max_length=100)
> > start = models.DateTimeField('date time when')
> > end = models.DateTimeField('date till')
> >
> > class Location (models.Model):
> > name = models.CharField(max_length=50)
> > state = models.ForeignKey(State)
> > location = models.ForeignKey(Event)
> >
> 
> > This is a One-to-Many Relationship where an Event can have one or more
> > Locations.
> >
> > The problem i need to solve is in the 'views.py' I want to be able to
> > query 'Event' such that i retrieve an arbitrary subset of events AND
> > any associated Locations and return only the relevant fields to the
> > template layer.
> >
> > The most standard use for this database will be to get all events from
> > today into the future and their associated locations. On average there
> > would be say 25 event rows returned and perhaps 27 locations as some
> > events have more than one location.
> >
> 
> > e_future = Event.objects.filter(start__gte = datetime.today())
> >
> 
> > having readhttp://docs.djangoproject.com/en/dev/topics/db/queries/
> >
> > i realise i can use a reverse foreign key to access an item in the
> > Location table:
> >
> 
> > for e in e_future:
> > e_location=e.location_set.all()
> >
> 
> > From here it gets messy as i have to deal with the individual event
> > elements 'e' out of a queryset 'e_future' and then reassemble the
> > elements back into a queryset *i dont know how to do this* so my
> > method can return the selected columns:
> >
> 
> > e_future_subset = e_future.values('start', 'title','id',)
> > e_location_subset = e_location.values('state_id', 'name',)
> >
> 
> > Then i have to combine the two objects 'e_future_subset' and
> > 'e_location_subset' (which i believe are dictionaries) and return the
> > result.
> >
> 
> > e_all = e_future_subset + e_location_subset
> > return render_to_response('events.html', { 'e_all': e_all,})
> >
> -

Help using the django queries API to select columns from multiple tables

2009-06-28 Thread Sam Walters
Hi
I am using django 1.0 to redevelop a website.
I have read http://docs.djangoproject.com/en/1.0/topics/db/queries/ and cant
work out how to do my query except using raw sql. It would be great to be
able to use the django query api so i can stack queries more easily.

Just one working example would be enough for me to be able to figure out the
rest of the syntax i need.
In this case the model is using a ForeignKey relationship between two
tables, thus is a one to many relationship.

the model.py code exists here:
http://pastebin.com/m7ddf3bb8

the views.py code exists here:
http://pastebin.com/m78daa247

I would like to be able to replace the customer sql cursor.generate methods.

Any help would be appreciated and allow me to discover a lot more about
django queries.

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



Re: Help using the django queries API to select columns from multiple tables

2009-06-29 Thread Sam Walters
Hi Daniel
Thank you very much for your help.
The reasons why the foreign key is in the other table is because an event
can have multiple locations, its unusual however the Aviation industry has
an event which will fly from location A to B. Yes it seems counter-intuitive
at first glance.

The other reason is If do move the foreign key to the Events table then i
cant get the admin.py to work. The admin has to  be able to edit all the
fields (in effect see columns from multiple tables using inlines) from the
same page:

in admin.py:

class LocationInline(admin.StackedInline):
model=Location
extra = 0

class EventAdmin(admin.ModelAdmin):
inlines = [PeriodInline, LocationInline, InviteGroupInline,
CategoryInline,]
list_display = ('added','title','email',)
list_per_page = 50
list_filter = ('added','start','end',)
search_fields = ('contact', 'email', 'phoneBH', 'phoneAH', 'phoneFax',
'phoneM', 'url','title','description')

admin.site.register(Event, EventAdmin)

Nevertheless if there is no way to make the foreign key relationship work
with the current schema then I will move it as you have suggested.

Do you know how to build the admin.py to circumvent this issue?


On Mon, Jun 29, 2009 at 6:51 PM, Daniel Roseman wrote:

>
> On Jun 29, 4:57 am, Sam Walters  wrote:
> > Hi
> > I am using django 1.0 to redevelop a website.
> > I have readhttp://docs.djangoproject.com/en/1.0/topics/db/queries/andcant
> > work out how to do my query except using raw sql. It would be great to be
> > able to use the django query api so i can stack queries more easily.
> >
> > Just one working example would be enough for me to be able to figure out
> the
> > rest of the syntax i need.
> > In this case the model is using a ForeignKey relationship between two
> > tables, thus is a one to many relationship.
> >
> > the model.py code exists here:http://pastebin.com/m7ddf3bb8
> >
> > the views.py code exists here:http://pastebin.com/m78daa247
> >
> > I would like to be able to replace the customer sql cursor.generate
> methods.
> >
> > Any help would be appreciated and allow me to discover a lot more about
> > django queries.
>
> You don't need to explicitly join the tables - that's the whole point
> of having a foreignkey field in the model. However, there is one
> problem. It seems like your foreign key is on the wrong model. Surely
> each event has a single location, but a location can have many events?
> In which case, the FK should be from event to location.
>
> class Event (models.Model):
>
>location = models.ForeignKey(Event)
>
> Now, you can get the events like this:
>
> events = Event.objects.filter(start__gte=datetime.datetime.now
> ()).select_related()
>
> and iterate through in your template:
>
> {% for event in events %}
>{{ event.title }} - {{ event.location.name }}
> {% endfor %}
>
> The select_related() on the initial query is optional, but will get
> all the joined location data in one query and so cut down on database
> access.
> --
> DR.
> >
>

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



Re: Best distro for django

2009-07-03 Thread Sam Walters
It should not matter. Any modern Linux Distro which supports the
dependencies will be no different.

The only conceivable way this question makes sense is if you want to make
install or deployment easy. In which case use something thats based on a
debian, fedora type distro where there is heaps of help/tutorials for things
like installing web server packages. So the issue becomes one of package
manager choice.

Keyboard Issues? Would be easier to solve the keyboard issue without
switching distro, ubuntu community is great for these things.

On Sat, Jul 4, 2009 at 8:31 AM, Dhruv Adhia  wrote:

> I ve been PC user for almost a decade, getting enough frustration , I
> shifted to mac osx and I am happy with it. Much less configuration required.
> I ve just installed Linux Ubuntu yesterday. Lets see how it goes with
> Linux.
>
> Cheers,
>
>
> On Fri, Jul 3, 2009 at 2:41 PM, Evandro Viana  wrote:
>
>> Debian or Slackware
>> more
>>
>> the best for developer is OSX
>>
>>
>>
>> On Fri, Jul 3, 2009 at 6:28 PM, Tim Chase > > wrote:
>>
>>>
>>> > Looking for opinion of the best distro for a developer machine for
>>> > django.
>>> >
>>> > I'm on ubuntu now, its going ok. I'm having keyboard issues, and
>>> > wondering if I should put the time in on fixing it, or just ditch it
>>> > for say, pc-bsd, if thats what the cool django kids are using.
>>>
>>> I've done Django development on multiple OSes and found 3 tiers
>>> of experience:
>>>
>>> Top Tier: any Linux or BSD I've played with (Debian, Ubuntu,
>>> OpenBSD).  I expect other variants will be equally facile (Red
>>> Hat, Suse, Slack, Gentoo, PC BSD, FreeBSD, etc)
>>>
>>> Mid Tier:  Mac OS X -- Doable, but a few more hoops to jump
>>> through.  Easiest since Python2.5's added built-in sqlite3 which
>>> previously you had to build yourself
>>>
>>> Bottom Tier:  Win32.  It's feasible (especially once Python2.5
>>> added sqlite3), but I've found this a notably more painful
>>> experience than on the other two tiers of platforms.
>>>
>>>
>>> I haven't tinkered with Solaris in *years* so I don't know
>>> whether that would be top- or middle-tier.
>>>
>>>
>>> However, once you've got the base configuration done, development
>>> is pretty easy no matter where you do it.
>>>
>>> My $0.02
>>>
>>> -tim
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>
>
> --
> Dhruv Adhia
> http://thirdimension.com
>
>
>
> >
>

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



AttributeError when trying to save and access models

2009-07-14 Thread Sam Walters
Hi Django world
I keep getting problems accessing and storing data in foreignkey and
one-to-one relationships.
Error is basically of the form:
 "AttributeError
Exception Value: 'DirectoryAdmin' object has no attribute 'abbrev'"

The models.py file is here:
http://pastebin.com/mcc4ee45
The SQL it produces is here:
http://pastebin.com/m5b70bce5

I don't think the problem is in here but you can see what I am trying to
achieve. At the moment i am just trying to save multiple records in 'class
DirectoryType' which relate through a foreignkey to Directory.

MAIN CULPRIT:
Views.py
http://pastebin.com/m10eac87f

I seem to be able to .save() new instances of Directory, DirectoryAdmin,
DirectoryType

However i cant get Directory to associate with multiple instances of
DirectoryType or even DirectoryAdmin.
At a more fundamental level the .add() method says:

'DirectoryType' object has no attribute 'add'

And if i try to see an attribute in another table:

 var = dirdir.admin.abbrev #error: 'DirectoryAdmin' object has no attribute
'name'

However i seem to be able to access the database for id's.
var = dirdir.admin.id #works

Any help would be greatly appreciated as i dont know what is going wrong
beyond this.

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



Help building a custom RadioSelect widget.

2009-08-03 Thread Sam Walters

Hi fellow Django users.

This is the first time necessity has required me to look at overriding
functionality in the django code.

I need to replace the  and  tags in a choicefield using radio
buttons with  tags as my project has very specific formatting
requirements for this form.

I basically don't know much about overloading in python and of course
this would not help with overloading the
Django RadioSelect class so it will instantiate an overloaded version
of the RadioFieldRenderer class to return different tags.

Here is the code, i dont know if im close or not.
http://pastebin.com/m67363386

Any help completing/explaining this would be greatly appreciated and
open the floodgates towards understanding how to do this for all sorts
of pythonic/django overloading scenarios.

cheers

-Sam

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



Re: Help building a custom RadioSelect widget.

2009-08-04 Thread Sam Walters

Thanks David

This example is exactly what i was hoping for.
I hope something like this gets put into a tutorial because i guess
many people would need to control exactly what their form looks like.

Cheers

-Sam

On Tue, Aug 4, 2009 at 11:00 PM, David De La Harpe
Golden wrote:
>
> Sam Walters wrote:
>
>> Any help completing/explaining this would be greatly appreciated and
>> open the floodgates towards understanding how to do this for all sorts
>> of pythonic/django overloading scenarios.
>>
>
> I had to do something similar a while back -
> http://python.pastebin.com/f7a905977
>
> Proved unexpectedly involved because also wanted to use it for model
> fields with choices specified - the form field used if you supply
> choices on modelfields is hardcoded in django.  Was going to
> raise a bug about it, but turns out it's bug #9245 ...
>
>
> >
>

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



Re: Django documentation site is SLOW

2009-08-07 Thread Sam Walters

Hi
Its probably not the browser. I am using firefox 3.5 on an eee pc and
the documentation is fine. This is with Javascript disabled using
noscript however i just turned it on again and no noticable difference
in top readings

*You should look at the install addons of firefox, eg: some plugin
which is slowing it.
*save the page and view it offline see if there is still an issue.
*CSS+cheap video card. This is unusual however some sites really run
slow on very old video cards. Try removing the css from a docs
page+save it runoffline.

I just cant see it being firefox unless its not configured properly.
Especially considering eee pc atom cpu is puny compared too even a p4.
:)



On Fri, Aug 7, 2009 at 10:09 PM, Mirat Bayrak wrote:
> without javascript ?
>
>
> >
>

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



Re: Editors of choice

2009-09-10 Thread Sam Walters

Vim in conjunction with Git - most powerful + extensible editor out
there in my humble opinion.

On Thu, Sep 10, 2009 at 7:46 PM, boyombo  wrote:
>
> Vim + pydiction + django.vim
>
> On Sep 10, 1:31 pm, eka  wrote:
>> Vim + RopeVim + Omincompletion + taglist + tasklist + python_fn
>>
>> On Sep 10, 8:30 am, slafs  wrote:
>>
>> > Vim
>> > with omnicompletion (CTRL+X, CTRL+O), filetype=htmldjango, TList and
>> > NERDTree
>>
>> > Regards
>>
>> > On Sep 9, 9:31 am, Benjamin Buch  wrote:
>>
>> > > I second that.
>>
>> > > > Vim
> >
>

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



One to Many+foreign key Query: best way to build the optimal result

2009-06-17 Thread Sam Walters


Here is the essentials from my models.py file:

class Event (models.Model):
contact = models.CharField(max_length=100)
email = models.CharField(max_length=100)
url = models.CharField(max_length=100)
title = models.CharField(max_length=100)
start = models.DateTimeField('date time when')
end = models.DateTimeField('date till')

class Location (models.Model):
name = models.CharField(max_length=50)
state = models.ForeignKey(State)
location = models.ForeignKey(Event)

This is a One-to-Many Relationship where an Event can have one or more
Locations.

The problem i need to solve is in the 'views.py' I want to be able to
query 'Event' such that i retrieve an arbitrary subset of events AND
any associated Locations and return only the relevant fields to the
template layer.

The most standard use for this database will be to get all events from
today into the future and their associated locations. On average there
would be say 25 event rows returned and perhaps 27 locations as some
events have more than one location.

e_future = Event.objects.filter(start__gte = datetime.today())

having read http://docs.djangoproject.com/en/dev/topics/db/queries/

i realise i can use a reverse foreign key to access an item in the
Location table:

for e in e_future:
e_location=e.location_set.all()

>From here it gets messy as i have to deal with the individual event
elements 'e' out of a queryset 'e_future' and then reassemble the
elements back into a queryset *i dont know how to do this* so my
method can return the selected columns:

e_future_subset = e_future.values('start', 'title','id',)
e_location_subset = e_location.values('state_id', 'name',)

Then i have to combine the two objects 'e_future_subset' and
'e_location_subset' (which i believe are dictionaries) and return the
result.

e_all = e_future_subset + e_location_subset
return render_to_response('events.html', { 'e_all': e_all,})


As you can see I have been researching the solution and i'm stuck only
on a couple of points.
Surely this is one of the most common requirements for a django setup
where the 'model.py' describes a number of related tables 'one-to-
many' 'one-to-one' or 'many-to-many' relationships, a query (or number
of queries) are made and results are returned from multiple tables
based on an entry's 'id' and accessed through foreign-key pointers.

Any help would be greatly appreciated as I seem to have a handle on
everything else in my django project.

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



help, insert into a foreign key produces unusual 'invalid keyword argument' error

2009-10-15 Thread Sam Walters

Hi, im using django 1.0+mysql
I get an unexpected error:
"'event' is an invalid keyword argument for this function"
I get using a django view which used to work for moving data into the
mysql db by saving a foreign key
instance of 'Event' in 'Category'.

1. The model is:

class Event (models.Model):
added = models.DateTimeField()
addedBy = models.IntegerField()
contact = models.CharField(max_length=100)
email = models.CharField(max_length=100)
phoneBH = models.CharField(max_length=30)
phoneAH = models.CharField(max_length=30)
phoneFax = models.CharField(max_length=30)
phoneM = models.CharField(max_length=30)
url = models.CharField(max_length=100)
title = models.CharField(max_length=100)
description = models.TextField()
def __unicode__(self):
return u"%s %s %s %s %s %s %s %s %s %s %s %s"%(self.added,
self.addedBy, self.contact, self.email, self.phoneBH, self.phoneAH,
self.phoneFax, self.phoneM, self.url, self.title, self.cost,
self.description)


class Category (models.Model):
event = models.ForeignKey(Event)
name = models.CharField(max_length=40)
def __unicode__(self):
return u"%s"%(self.name)

2. The piece of code which produces the error in the view:

>>   events_category = Category(name=new_event_tag, event=events_event)
events_category.save()
#note events_event is just a saved instance of Event()

3. The behaviour of the error is such that if i rename the 'Category'
model to something else eg: 'Category2', drop the table and then
syncdb and run it again then i dont get the error. However if it is
called 'Category' then for some reason it does not work. Of course the
downside here is id have to go through and rename all usage of the
Category model in my views to the new class which with my project will
take a long time.


4. here is the error, its the usual sort of thing you get trying to
insert the wrong variable name into the model only it is the correct
name. I am familiar with what django docs say about the error and it
should be recognising the Foreign key 'event' being in Category but it
doesnt! I just hope im forgetting something easy
-
Request Method: GET
Request URL:http://127.0.0.1:8000/admin/eventmigrate/
Exception Type: TypeError
Exception Value:

'event' is an invalid keyword argument for this function

Exception Location:
/var/lib/python-support/python2.5/django/db/models/base.py in
__init__, line 265
Python Executable:  /usr/bin/python
Python Version: 2.5.2
-

5. I have a feeling something is wrong with mysql or django manage.py
is not building the table properly... any troubleshooting advice would
go a long way to helping me :)

In addition here is what "python manage.py inspectdb" says about Category:

-
class EventsCategory(models.Model):
id = models.IntegerField(primary_key=True)
event_id = models.IntegerField()
name = models.CharField(max_length=120)
class Meta:
db_table = u'events_category'

cheers
---sam

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



Mod_wsgi from source + centos 4.8 compile issue

2009-11-05 Thread Sam Walters

Hi
I am trying to get mod_wsgi installed on a production server.
Apache: 1.3.37
Kernel: 2.6.17.13-vs2.0.2.1vs-1.00
Os: CentOS 4.8

Following instructions from:
http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide

at the point with:
./configure --with-apxs=/usr/local/apache/bin/apxs
--with-python=/usr/local/bin/python2.5

then: 'make' produces the error:
---
/usr/local/apache/bin/apxs -c -I/usr/local/include/python2.5 -DNDEBUG
 mod_wsgi.c -L/usr/local/lib/python2.5/config -lpython2.5 -lpthread
-ldl  -lutil
gcc -DLINUX=22 -DHAVE_SET_DUMPABLE -I/usr/include/gdbm
-DMOD_SSL=208128 -DUSE_HSREGEX -DEAPI -fpic -DSHARED_MODULE
-I/usr/local/apache/include -I/usr/local/include/python2.5 -DNDEBUG
-c mod_wsgi.c
In file included from /usr/local/include/python2.5/Python.h:8,
 from mod_wsgi.c:113:
/usr/local/include/python2.5/pyconfig.h:942:1: warning:
"_POSIX_C_SOURCE" redefined
In file included from /usr/include/sys/types.h:27,
 from /usr/local/apache/include/ap_config.h:46,
 from /usr/local/apache/include/httpd.h:30,
 from mod_wsgi.c:34:
/usr/include/features.h:190:1: warning: this is the location of the
previous definition
gcc -shared -o mod_wsgi.so mod_wsgi.o
-L/usr/local/lib/python2.5/config -lpython2.5 -lpthread -ldl -lutil
---
What sort of problem is occurring here?

I have installed centos 'Development Tools' as I have never had much
luck compiling anything on an RPM red hat style system (usually an
unusual compile error).
I cant find an apache source to download using yum (the compile may need it)

With debian the package is something like 'apache2-src' .

I can produce more verbose output of the packages already installed if needed.

cheers

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



Re: Performance monitoring

2009-12-09 Thread Sam Walters
You can always place some more performance testing code inside your views:

import time
t = time.time()
search_time=0.00
#
#place some code which hits the database here
#
search_time+=time.time()-t
search_time="%.3f"%(search_time)

This does not test the memory footprint of your application though.
Put all your db calls into a unit test sort of framework is what i did
when developing a search engine for the site im developing.



On Thu, Dec 10, 2009 at 3:53 PM, Andy McKay  wrote:
> On 09-12-09 8:43 PM, Kegan Gan wrote:
>> Thanks for reply, Andy.
>>
>> I am aware of django-debug-toolbar. I am looking something to run with
>> production.
>>
>> How do people monitor Django application performance in production
>> environment today?
>
> Hmm I guess if I knew what you were looking for I could help more. Like
> I say I've run a sql query recording tool, its v. simple. But most of
> the time I rely on system tools like munin or monit.
> --
>   Andy McKay, @clearwind
>   Training: http://clearwind.ca/training/
>   Whistler conference: http://clearwind.ca/djangoski/
>
> --
>
> 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.




Need help: customise a multi-key dictionary sort to put None objects at the end.

2009-12-16 Thread Sam Walters
Hi I have been reading stuff like:

http://wiki.python.org/moin/SortingListsOfDictionaries

I want to sort a list of dictionaries (alphanumeric values) by
multiple keys (achieved with code below). However I would like to
customise the comparator to put empty objects last.

eg:

def orderBasedOnDepartment(items):
return sorted(items, key=lambda
items:(items['department'],items['suburb'],items['state'],items['distanceNm']))

for instance if the dictionary containing key: department = None
then I would like it placed after everything else instead of before.

Changed from:

None
A
Aa
Ab
C
D

To:

A
Aa
Ab
C
D
None

Any help would be appreciated so I can have a day off for christmas.

-sam

--

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: Need help: customise a multi-key dictionary sort to put None objects at the end.

2009-12-17 Thread Sam Walters
Thanks Daniel
Yes, it was multiple keys not just 'department'.
Will have a go and do some more reading on lambda.

cheers

-sam

On Thu, Dec 17, 2009 at 8:38 PM, Daniel Roseman  wrote:
> On Dec 17, 6:23 am, Sam Walters  wrote:
>> Hi I have been reading stuff like:
>>
>> http://wiki.python.org/moin/SortingListsOfDictionaries
>>
>> I want to sort a list of dictionaries (alphanumeric values) by
>> multiple keys (achieved with code below). However I would like to
>> customise the comparator to put empty objects last.
>>
>> eg:
>>
>> def orderBasedOnDepartment(items):
>>     return sorted(items, key=lambda
>> items:(items['department'],items['suburb'],items['state'],items['distanceNm 
>> ']))
>>
>> for instance if the dictionary containing key: department = None
>> then I would like it placed after everything else instead of before.
>>
>> Changed from:
>>
>> None
>> A
>> Aa
>> Ab
>> C
>> D
>>
>> To:
>>
>> A
>> Aa
>> Ab
>> C
>> D
>> None
>>
>> Any help would be appreciated so I can have a day off for christmas.
>>
>> -sam
>
> Not entirely clear what you're doing - is it just department=None you
> want last, or should None go last whatever key it is associated with?
>
> Anyway, the trick here is to remember that there's nothing special
> about a lambda, you can use a normal function as a key just as well.
> So:
>
> def sort_none_last(item):
>    key = []
>    nones = []
>    for k in ('department', 'suburb', 'state', 'distanceNm'):
>        if item[k] is None:
>            none.append(None)
>        else:
>            key.append(item[k])
>    key.extend(nones)
>    return tuple(key)
>
> sorted(items, key=sort_none_last)
>
> --
>
> 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: django with mod_wsgi on centos

2010-05-10 Thread Sam Walters
Yes, +1 to forgetting to update permissions at some stage of the game.

Best approarch to all this stuff is to make an interactive bash script
so wen you update a production server you just run the script.
Or document the steps, its often the smaller obvious steps which catch
people out.


On Mon, May 10, 2010 at 10:42 PM, Ivan Uemlianin  wrote:
> Dear All
>
> The nginx/fastcgi set up is now working (there's an easy-to-follow
> howto on the django advent site [1]).
>
> Embarrasingly I may have stumbled upon what was getting me 403s with
> mod_wsgi, and it's nothing to do with apache or mod_wsgi.  After
> setting up nginx with fastcgi I got the same 403.  Although the
> "mysite" directory and everything under it had permissive permissions,
> the user's home directory was 700:
>
> /home/siteuser/mysite/    775
> /home/siteuser/           700
>
> I changed the latter to 775 to and everything went smoothly.  I didn't
> test it but apache/mod_wsgi will probably work too now.  Doh!
>
> @Tom thanks for your suggestion.  When I used to use apache (LOL) I
> would generally have the django app outside of DocumentRoot.  I think
> changing permissions as above would fix things.  Otherwise I don't see
> why an apache config set up that works on ubuntu would raise 403s on
> centos (just checked: on the ubuntu machine /home/siteuser/ was 775).
>
> Best wishes
>
> Ivan
>
> [1]  http://djangoadvent.com/1.2/deploying-django-site-using-fastcgi/
>
> On May 10, 10:25 am, Tom Evans  wrote:
>> On Mon, May 10, 2010 at 9:39 AM, Ivan Uemlianin  wrote:
>> > Dear Kenneth
>>
>> > Thanks for your suggestion.
>>
>> > I tried
>>
>> >    $ chmod -R a+x mysite
>>
>> > (where mysite is the django site directory)
>>
>> > and stopped and started apache, but no effect.
>>
>> > I'm finding nginx a lot easier to work with than apache, especially
>> > CentOS' apache.  My plan now is to get rid of apache altogether and
>> > have nginx talk to django directly via fastcgi (e.g., [1]) (will also
>> > give me an excuse to try out git instead of svn).  If you don't hear
>> > back from me in a day or two, it worked.
>>
>> > With thanks and best wishes
>>
>> > Ivan
>>
>> > [1]  http://code.djangoproject.com/wiki/ServerArrangements#nginx
>>
>> Good luck with setting up your pure nginx configuration. Your apache
>> configuration did not work because you had not granted apache access
>> to the required on disk folders.
>>
>> You didn't mention this in your configuration, but you must allow
>> access to your DocumentRoot in your vhost:
>>
>> 
>>   ServerName foo
>>   DocumentRoot /path/to/foo/htdocs
>>   
>>     Order allow,deny
>>     Allow from all
>>   
>>   WSGIScriptAlias /app/ /path/to/foo/run/app.wsgi
>> 
>>
>> 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 
>> athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: how to display an image inside Django

2010-05-12 Thread Sam Walters
Specifically what do you want to do?

1. Write a form to upload and display an image?
2. Dynamically display/generate an image? eg:
http://effbot.org/zone/django-pil.htm
3. hyperlink an image from a templates folder or media folder? (with
either django test server or a production server)



On Tue, May 11, 2010 at 9:10 PM, ravi krishna  wrote:
> Hi,
> I am a beginner in Django .
> Can somebody tel me how to display an image in django...
> if anyone has the right tutorial for beginners, please share with me..
> --
> Regards,
> Rav!
>
> --
> 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: Google maps like app for Django for small area?

2010-06-02 Thread Sam Walters
http://geodjango.org/



On Thu, Jun 3, 2010 at 11:35 AM, Stodge  wrote:
> Is there a Django app (or SDK/API/technology/etc) that can recreate
> Google maps for a small area (say 60 square miles) with all maps
> stored locally on the server? 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.



Nginx-fcgi setup guidance needed to render certain views with HTTPS.

2010-07-01 Thread Sam Walters
Hi Django Users

I have been looking to make some of my views secured by SSL, i have
made a certificate for testing.

For the views which require https i rewrite the url and redirect using
a decorator.
In theory this should redirect and nginx will server the views through https.

Instead what i find is the "The page isn't redirecting properly"
Looking at firebug its looping over and over again with a GET request
to https://url.com/payments/

Which seems to indicate the nging.conf entry for my /payments/
location is not configured correctly.

Im new to the https stuff so if anyone could take a look and give me
tips it would be greatly appreciated.

http://pastebin.com/Jauysm9C

cheers

sam_w

-- 
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: Nginx-fcgi setup guidance needed to render certain views with HTTPS.[solved]

2010-07-19 Thread Sam Walters
Just to conclude this post.

I was following a guide:
http://www.redrobotstudios.com/blog/2009/02/18/securing-django-with-ssl/

After a long day.

Concequently the nginx.conf had a rewrite rule(below) which passed to
the url dispatcher... which got a view with a decorator which rewrote
the header. Then the nginx.conf rewrote it again thus infinite
redirect loop.

Concequently i decided to just use the nginx.conf rewrite rule to put
the admin and payment url's/sub-url's into HTTPS:

 location ~ ^/payments/(.*)$ {
rewrite (.*) https://www.mydomainname.com/$1 permanent;
   }

location ~ ^/admin/(.*)$ {
rewrite (.*) https://www.mydomainname.com/$1 permanent;
   }

So now the site works, transitions between HTTP and HTTPS easily
without needing to code for it using a decorator (or similar) in
django.

Problem solved.




On Fri, Jul 2, 2010 at 12:48 PM, Sam Walters  wrote:
> Hi Django Users
>
> I have been looking to make some of my views secured by SSL, i have
> made a certificate for testing.
>
> For the views which require https i rewrite the url and redirect using
> a decorator.
> In theory this should redirect and nginx will server the views through https.
>
> Instead what i find is the "The page isn't redirecting properly"
> Looking at firebug its looping over and over again with a GET request
> to https://url.com/payments/
>
> Which seems to indicate the nging.conf entry for my /payments/
> location is not configured correctly.
>
> Im new to the https stuff so if anyone could take a look and give me
> tips it would be greatly appreciated.
>
> http://pastebin.com/Jauysm9C
>
> cheers
>
> sam_w
>

-- 
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: do QuerySet joins still suck?

2010-08-10 Thread Sam Walters
I dont think they do.

The only time i use raw sql + joins is for performance... eg:

When you have a model and for each instance of that model it has a
reverse foreignkey relationship where you would have to call:
_set.all()
in a for loop thus making heaps of sql queries.

There are 3rd party addons for that:
http://code.google.com/p/django-selectreverse/
Does a good job of avoiding the n+1 problem for most situations.

Hope this helps

cheers

sam.




On Wed, Aug 11, 2010 at 4:36 PM, Daniel Roseman  wrote:
> On Aug 11, 2:28 am, Phlip  wrote:
>> >  orders = Order.objects.filter(
>> >    pk=42,
>> >    order_items__product='whiteboards'
>> >    )
>>
>> > Is this not what you want?
>>
>> We made a feeb attempt at that and gave up. Thanks! I will try it next.
>>
>> The next question, if it works, will be how to values_list() a field
>> from a child record; it might follow that notation.
>>
>> Could I trouble you for its home page? Googling for [django queryset
>> join] gives zillions of newbs trying simple queries...
>
> http://docs.djangoproject.com/en/1.2/topics/db/queries/#lookups-that-span-relationships
>
> --
> 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.
>
>

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



Help with Geodjango+Postgres to find a Point, variance in decimal places

2010-08-24 Thread Sam Walters
Hi fellow Django developers

I have Lat/Lng points stored in my db:

class Airfield(models.Model):
point = models.PointField(srid=4326)

I noticed when i query on my development server with postgresql i DONT
have to have the EXACT number of decimal places to find that point.
(what i want)
However on the production server if i ask for a point then i have to
give the exact same number with the same number of decimal places.
(undesired)

Production server is postgresql-8.3 where as my development server is
postgresql-8.4

Obviously the db backend is behaving differently.

8.4:
-32.67 == -32.6667
8.3:
-32.67 !=  -32.6667

How would i solve this issue with the geodjango/django ORM?
I dont want to have to change the db to 8 decimal places and try and
standardise things if possible.
I want to find matching points regardless of wether they are 8,9,10
decimal places.


Eg:

>>> Airfield.objects.get(airfield_name="Luskintyre")


8.3:
>>> lat1 = -32.6667
>>> long1 = 151.4167
>>> destination = Point(lat1, long1)
>>> Airfield.objects.get(point=destination)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.5/site-packages/django/db/models/manager.py",
line 132, in get
return self.get_query_set().get(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py",
line 341, in get
% self.model._meta.object_name)
DoesNotExist: Airfield matching query does not exist.

8.4:
>>> lat1 = -32.6667
>>> long1 = 151.4167
>>> destination = Point(lat1, long1)
>>> Airfield.objects.get(point=destination)


cheers

sam_W

-- 
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: Help with Geodjango+Postgres to find a Point, variance in decimal places

2010-08-25 Thread Sam Walters
Thanks for the replies.

No its not 32 bit/64 bit issue. (both 64 bit and its not a floating
point issue anyway)

Correct: I dont need to *have* the problem except some of the
requirements in the project require passing of 8 decimal place
lat/longs in the url.
I was hoping not to have to take steps to either:
*change the db side to hold only 8 dec place points
or
*change the javascript front end to deal with variable dec place numbers.

If there was something in the geodjango ORM i missed i hoped someone
would pick it up and point me in that direction.

Search radius instead of a finite point is not possible unfortunately.
Plus if im dealing with a dataset where im evaluating 500+ points
(upper bounds of my projected workload)
I would need the answer evaluated as quickly as possible, radius
calculation would be slower (how much slower depends on the algorithm
used and other variables).

If there's no option I will probably go with changing the code to
handle variable length points on the javascript side.

Thanks for your help.

cheers

sam_W


On Wed, Aug 25, 2010 at 9:40 PM, J. Cliff Dyer  wrote:
> Is one server 32 bit, while the other is 64 bit?  It may be that on the old 
> server, your representations of the number were precise enough to be 
> identical, but on the new server, there is enough precision in the database 
> to represent different numbers.
>
>
>
> "Reinout van Rees"  wrote:
>
>>On 08/25/2010 02:57 AM, Sam Walters wrote:
>>> Hi fellow Django developers
>>>
>>> I have Lat/Lng points stored in my db:
>>>
>>> class Airfield(models.Model):
>>>      point = models.PointField(srid=4326)
>>>
>>> I noticed when i query on my development server with postgresql i DONT
>>> have to have the EXACT number of decimal places to find that point.
>>> (what i want)
>>> However on the production server if i ask for a point then i have to
>>> give the exact same number with the same number of decimal places.
>>> (undesired)
>>>
>>> Production server is postgresql-8.3 where as my development server is
>>> postgresql-8.4
>>>
>>> Obviously the db backend is behaving differently.
>>>
>>> 8.4:
>>> -32.67 == -32.6667
>>> 8.3:
>>> -32.67 !=  -32.6667
>>
>>Obviously, this is a problem.
>>
>>But: do you need to *have* the problem?  I mean, why would you look up
>>the airfield in the DB, grab x/y and then try to grab the same one back
>>again with the exact coordinates?
>>
>>Normally, searching by coordinates would mean clicking on a map which
>>results in a DB query with a location plus a margin around that location.
>>
>>=> Can you work with a "search radius" in your query?
>>
>>
>>Reinout
>>
>>--
>>Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
>>Programmer at http://www.nelen-schuurmans.nl
>>"Military engineers build missiles. Civil engineers build targets"
>>
>>--
>>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.
>>
>>
>
> --
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>
> --
> 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: ip to distance mapping

2010-08-26 Thread Sam Walters
I have used geoip in conjunction with the rest of the geodjango
functionality. However you shouldnt have to deal with all the extra
complexity of geodjango (which isnt too bad one you get used to it ;).

Basically the process involves querying 2 IP's , getting a 'Point' for
each and then calculating the distance between them. Where the
distance is an arc length.

http://docs.djangoproject.com/en/dev/ref/contrib/gis/geoip/

cheers

sam_w

On Fri, Aug 27, 2010 at 7:13 AM, Bobby Roberts  wrote:
> I'm needing an easy way to convert a client IP to a geo location and
> then get the distance from that lat/long to a fixed lat/long
> coordinate.  Is there anything out there that can do this with
> django.  I've been looking at geodjango but that looks pretty dang
> complicated and i'm not even sure it will do what i'm needing.
>
> --
> 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: Strange 404s

2010-10-06 Thread Sam Walters
I concurr.

I have seen:
/phpMyAdmin/scripts/setup.php
/phpmyadmin/
/user/soapCaller.bs

I guess there are security holes in old versions of phpmyadmin. Some
sort of content management with setup.php left unconfigured/unsecured
so the bots are just checking out all of those url's.

sam_w

On Thu, Oct 7, 2010 at 8:51 AM, Daniel Roseman  wrote:
> On Oct 6, 10:32 pm, Scot Hacker  wrote:
>> We have enabled the option to have 404 requests automatically emailed
>> to admins. It works well, but sometimes we get strange reports like
>> this:
>>
>> > Referrer:http://ourdomain.edu/forums/software/
>> > Requested URL: /forums/software/
>> > User agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
>> > IP address: 94.29.103.134
>>
>> What's strange about it is that the referring 
>> URLhttp://ourdomain.edu/forums/software/
>>    *does not exist* - we removed it more than a year ago. So I can see
>> why the requested URL is 404, but don't understand how a non-existent
>> URL can be considered to be the referrer. Is this evidence of some
>> kind of bot activity that fakes the referrer?
>>
>> Anyone seeing anything similar?
>>
>> Scot
>
> Yes, there are all sorts of bots around, and the referrer is easy to
> fake - it's just an HTTP header. I quite frequently get reports with
> referrers that have never even existed on my site.
> --
> 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.
>
>

-- 
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: Iterating tree-like data structures with django

2010-10-07 Thread Sam Walters
Also for all your tree related needs there is Django Treebeard:

https://tabo.pe/projects/django-treebeard/



On Thu, Oct 7, 2010 at 2:51 AM, Cesar Canassa  wrote:
> I had the same issue a few months ago.
> My only answer to you is that is not worth to develop this all for self.
> There is a great django library called django-mptt that does all the heavy
> lifting for you. It's very fast, has many helper functions and even admin
> integration! I suggest that you check it out.
> Regards,
> Cesar Canassa
>
> 2010/10/6 Paweł Roman 
>>
>> Yuck, in_bulk() is useless! I thought it would return a nice
>> dictionary just as expected, but instead it makes me deliver a list of
>> keys first. Why?
>>
>> Eventually I wrote something more usable:
>>
>>    mydict = {}
>>    for model in MyModel.objects.all().iterator():
>>        mydict[model.id]=model
>>
>> Correct me if I'm wrong but this is hundred times more useful than
>> current in_bulk() implementation.
>>
>>
>> On Oct 6, 5:31 pm, Paweł Roman  wrote:
>> > OK, I've got it. It's in_bulk() :) Nevermind the question.
>> >
>> > On Oct 6, 5:27 pm, Paweł Roman  wrote:
>> >
>> > > I have a model which has a tree-like structure (not exactly a FK on
>> > > self but we can assume that's the case).
>> >
>> > > I want to visualise this tree using all records from the db. It seems
>> > > impossible to do with QuerySet, if I have say 100 records (100 nodes
>> > > in the tree) and I try building the tree recursively django will
>> > > execute a SELECT for each node so it will hit the db 100 times to
>> > > build the tree.
>> >
>> > > I thought I could pull the data in one query using objects.all() and
>> > > then build the whole tree by iterating objects in memory. But again,
>> > > the structures returned by QuerySet are not the best for this purpose.
>> > > I can get either list of dictionaries or list of tuples. No
>> > > dictionary! So, to get a list of child nodes for each node I'd have to
>> > > iterate thru the whole collection which is not efficient at all. I
>> > > can't find a way to immediately lookup already fetched records by id!
>> >
>> > > Am I missing something? Iterating tree-like data structures seems
>> > > something quite common problem and someone must have done it already
>> > > 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.
>>
>
> --
> 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: Where is everything on ubuntu 10.10

2010-11-19 Thread Sam Walters
Read up on how linux programs work the file system becomes intuitive.

Also try this:
python -c "from distutils.sysconfig import get_python_lib; print
get_python_lib()"



cheers

sam_w

On Fri, Nov 19, 2010 at 3:08 AM, Kenneth Gonsalves  wrote:
> On Thu, 2010-11-18 at 06:10 -0800, sheeptick wrote:
>> The site-packages directory is empty, so where did django go?
>
> ubuntu guys have something called dist-packages
> --
> regards
> Kenneth Gonsalves
>
> --
> 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.



Project optimisation stage: Advice to boost speed of database queries across tables?

2009-12-29 Thread Sam Walters
Hi
I have reached the optimisation stage of my project.
I am trying to work out how to reduce the turnaround time for my queries.
I implemented 'db_index=True'  for the fields where i determined there
should be a performance boost by indexing that particular field.
This has not really improved the speed of the queries.

Worst case senario is that my website will have to display about 500
out of 6000 entries in the db.

Each entry bridges a many-to-many relationship with another table and
also follows a reverse one-to-one which will return a set of related
entries. Often the query takes 12-14 seconds from start to finish.
(and 4-5 seconds to display around 100 results)
The major performance penalty thus far has been measured to be when
the MySQL statements for these queries are executed.
The many-to-may and one-to-many components only return 1-3 related
records at most for each entry and they always hit indexes so that
part of the design is optimised.

I have been using the following tools:

print connection.queries
import time
and looking at the raw MySQL to see whatother optmisations could be made.
use of MySQL EXPLAIN

Anyway, here are the details:

*in views.py the method that packages the results from the mysql query:
http://pastebin.com/m3eef56e5

*the models associated with this from two applications: 'directory' and 'common'
http://pastebin.com/m3868a1fc
http://pastebin.com/m18ec3765

*python manage.py sqlall directory && python manage.py sqlall common:

http://pastebin.com/m63a50593
http://pastebin.com/m6f958cda

As far as I can tell indexes are working and the queries should be fast.

Here is the MySQL per iteration (will execute 500 times for my worst
case scenario which takes 12 seconds on average)

SELECT `common_addresstype`.`id`, `common_addresstype`.`adrtype` FROM
`common_addresstype` WHERE `common_addresstype`.`id` = 1;
SELECT `common_addresstype`.`id`, `common_addresstype`.`adrtype` FROM
`common_addresstype` WHERE `common_addresstype`.`id` = 2;
SELECT `common_addradmin`.`id`,
`common_addradmin`.`surfaceMail_works`,
`common_addradmin`.`addr_enabled` FROM `common_addradmin` WHERE
`common_addradmin`.`id` = 1;
SELECT `common_address`.`id`, `common_address`.`airfield_id`,
`common_address`.`country_id`, `common_address`.`addresstype_id`,
`common_address`.`addradmin_id`, `common_address`.`location_id`,
`common_address`.`street1`, `common_address`.`street2`,
`common_address`.`user_lat_dec`, `common_address`.`user_long_dec`,
`common_address`.`zoom` FROM `common_address` INNER JOIN
`common_address_directory` ON (`common_address`.`id` =
`common_address_directory`.`address_id`) WHERE
`common_address_directory`.`directory_id` = 4267;

Last but not least Explain for the above MySQL for 1 instance of 500 entries.

mysql> EXPLAIN SELECT `common_addresstype`.`id`,
`common_addresstype`.`adrtype` FROM `common_addresstype` WHERE
`common_addresstype`.`id` = 1;
++-++---+---+-+-+---+--+---+
| id | select_type | table  | type  | possible_keys | key
   | key_len | ref   | rows | Extra |
++-++---+---+-+-+---+--+---+
|  1 | SIMPLE  | common_addresstype | const | PRIMARY   |
PRIMARY | 4   | const |1 |   |
++-++---+---+-+-+---+--+---+

mysql> EXPLAIN SELECT `common_addresstype`.`id`,
`common_addresstype`.`adrtype` FROM `common_addresstype` WHERE
`common_addresstype`.`id` = 2;
++-++---+---+-+-+---+--+---+
| id | select_type | table  | type  | possible_keys | key
   | key_len | ref   | rows | Extra |
++-++---+---+-+-+---+--+---+
|  1 | SIMPLE  | common_addresstype | const | PRIMARY   |
PRIMARY | 4   | const |1 |   |
++-++---+---+-+-+---+--+---+
1 row in set (0.00 sec)

mysql> EXPLAIN SELECT `common_addradmin`.`id`,
`common_addradmin`.`surfaceMail_works`,
`common_addradmin`.`addr_enabled` FROM `common_addradmin` WHERE
`common_addradmin`.`id` = 1;
++-+--+---+---+-+-+---+--+---+
| id | select_type | table| type  | possible_keys | key
 | key_len | ref   | rows | Extra |
++-+--+---+---+-+-+---+--+---+
|  1 | SIMPLE  | common_addradmin | const | PRIMARY   |
PRIMARY | 4   | const |1 |   |
++-+--+---+---+-+-+---+--+---+
1 row in set (0.00 sec)


mysql> EXPLAIN SELECT `common_address`.`id`,
`common_address`.`airfield_id`, `common_address`.`

Re: Project optimisation stage: Advice to boost speed of database queries across tables?

2009-12-30 Thread Sam Walters
Thanks for the replies.

Yes, there is the option of going to raw MySQL. However the project
requirements mean i can't use raw SQL. (portability, readability)
>From what i can see using django's db API i have to execute the
queries 500 times.
I am very familiar with the query documentation and i know that
select_related will prevent foward facing foreign keys translating to
an individual sql queries which hit the db and would slow it down.

Fact is even when i dont use 'select_related' the major performance
problem occurs with the 'many-to-many' and 'reverse foreign' keys
(some 75% of the performance penalty for my package method is with
these) and only 20% can be solved by select_related.

To be specific about how the multiplicities unfold:

search_querySet is a Directory.objects.filter(...

for s in search_querySet:
address_info = s.address_set.all() #.select_related(depth=2) -
yes i can/will put select related here but it really does not help
that much 20% tops
#address_info is usually 2-3 rows from an address table
for a in address_info:#.select_related(depth=2):
if a.addresstype.adrtype == 'Physical' and
a.addradmin.addr_enabled == True:
#further reduction in the number of rows which we need to
get values from.
related_phone=a.phone_set.all()
related_email=s.email_set.all()
#phones and emails are a small number of rows 2-3 tops

It is these lines which produce the performance hit.
I cant see a way of using django's query language to avoid having to
descend into each of the 500 'directory' objects because of the
necessity to get all rows from the related tables in phones an emails
and to inspect the type of 'address' object.

thanks for the ideas. will continue testing and looking for answers

-Sam

On Thu, Dec 31, 2009 at 2:41 AM, Nick Arnett  wrote:
>
>
> On Wed, Dec 30, 2009 at 7:15 AM, Adam Playford 
> wrote:
>>
>> I'm not an expert on this, but a few thoughts.
>>
>> First, if I'm reading your message right, it sounds like your problem
>> probably isn't with the query, but with how many times you're running
>> it.
>
> I'll echo that... the problem is not the database - the queries are as good
> as it gets.  The problem is running them repeatedly.
>
> If all else fails, I'd replace those queries that execute 500 times with raw
> SQL that uses the IN operator to get the required rows.
>
> E.g.: SELECT `common_addresstype`.`id`, `common_addresstype`.`adrtype` FROM
> `common_addresstype` WHERE `common_addresstype`.`id` IN (1,6,8,52,173)
>
> I imagine there's an ORM query that will do the same thing, but I know MySQL
> far better than I know Django.
>
> Nick
>
> --
>
> 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: Project optimisation stage: Advice to boost speed of database queries across tables?

2010-01-03 Thread Sam Walters
Hi Tomasz
Yes, i have followed a raw sql approach now im looking at my test data
to see which objects have multiple rows and cleaning that up.

Its a shame that '__in' has limited use under these scenarios:

directories = search_querySet.distinct()
addresses = Address.objects.filter(directory__in=directories)
addresses.values('directory__id', . *some other relevent fields*)

this certainly allows me to select the related sets of addresses for
each directory however i need to be able to relate each address object
back to its directory (by id would be great) trying to get the
directory 'id' packaged in the values() gives me an error saying
invalid field even though 'directory' is listed as a valid field.
If i could do that then i could iterate through each dictionary and
zip related items together based on their directory id's or something
nice like that.

"
Re those VIEWs, they are SELECTs with JOINs, which effectively
produce up to a few rows for single object (e.g. if you have person
with 3 phone numbers,
you're getting 3 rows), but it turns out to be much more efficient to
process/merge
that in Python code than to issue hundreds of SQL queries.
"

Yes this seems to be the best way, do you have any links where i can
see how various people have implemented this? Would be good to write a
'pythonic' solution


cheers

-sam
2010/1/4 Tomasz Zieliński :
> On 31 Gru 2009, 01:56, Sam Walters  wrote:
>
>> for s in search_querySet:
>>         address_info = s.address_set.all() #.select_related(depth=2) -
>> yes i can/will put select related here but it really does not help
>> that much 20% tops
>>         #address_info is usually 2-3 rows from an address table
>>         for a in address_info:#.select_related(depth=2):
>>             if a.addresstype.adrtype == 'Physical' and
>> a.addradmin.addr_enabled == True:
>>             #further reduction in the number of rows which we need to
>> get values from.
>>             related_phone=a.phone_set.all()
>>             related_email=s.email_set.all()
>>             #phones and emails are a small number of rows 2-3 tops
>>
>> It is these lines which produce the performance hit.
>> I cant see a way of using django's query language to avoid having to
>> descend into each of the 500 'directory' objects because of the
>> necessity to get all rows from the related tables in phones an emails
>> and to inspect the type of 'address' object.
>>
>
> I solved very similar problem by creating database VIEWs with data I
> needed,
> wrapping those VIEWs with unmanaged Django models and then using
> simple .filter(...)-s.
>
> Re those VIEWs, they are SELECTs with JOINs, which effectively
> produce up to a few rows for single object (e.g. if you have person
> with 3 phone numbers,
> you're getting 3 rows), but it turns out to be much more efficient to
> process/merge
> that in Python code than to issue hundreds of SQL queries.
>
> --
> Tomasz Zielinski
> http://pyconsultant.eu
>
> --
>
> 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: Project optimisation stage: Advice to boost speed of database queries across tables?

2010-01-07 Thread Sam Walters
Thanks Koen
I had suspected such things would exist but couldnt find them.
I will take a look at this. Looks like a neat addon which would
greatly help my project turnaround time.

cheers
Sam

On Wed, Jan 6, 2010 at 11:07 PM, koenb  wrote:
>
> On 31 dec 2009, 01:56, Sam Walters  wrote:
>> Thanks for the replies.
>>
>> Yes, there is the option of going to raw MySQL. However the project
>> requirements mean i can't use raw SQL. (portability, readability)
>> From what i can see using django's db API i have to execute the
>> queries 500 times.
>> I am very familiar with the query documentation and i know that
>> select_related will prevent foward facing foreign keys translating to
>> an individual sql queries which hit the db and would slow it down.
>>
>> Fact is even when i dont use 'select_related' the major performance
>> problem occurs with the 'many-to-many' and 'reverse foreign' keys
>> (some 75% of the performance penalty for my package method is with
>> these) and only 20% can be solved by select_related.
>>
>> To be specific about how the multiplicities unfold:
>>
>> search_querySet is a Directory.objects.filter(...
>>
>> for s in search_querySet:
>>         address_info = s.address_set.all() #.select_related(depth=2) -
>> yes i can/will put select related here but it really does not help
>> that much 20% tops
>>         #address_info is usually 2-3 rows from an address table
>>         for a in address_info:#.select_related(depth=2):
>>             if a.addresstype.adrtype == 'Physical' and
>> a.addradmin.addr_enabled == True:
>>             #further reduction in the number of rows which we need to
>> get values from.
>>             related_phone=a.phone_set.all()
>>             related_email=s.email_set.all()
>>             #phones and emails are a small number of rows 2-3 tops
>>
>> It is these lines which produce the performance hit.
>> I cant see a way of using django's query language to avoid having to
>> descend into each of the 500 'directory' objects because of the
>> necessity to get all rows from the related tables in phones an emails
>> and to inspect the type of 'address' object.
>>
>> thanks for the ideas. will continue testing and looking for answers
>>
>> -Sam
>>
>> On Thu, Dec 31, 2009 at 2:41 AM, Nick Arnett  wrote:
>>
>> > On Wed, Dec 30, 2009 at 7:15 AM, Adam Playford 
>> > wrote:
>>
>> >> I'm not an expert on this, but a few thoughts.
>>
>> >> First, if I'm reading your message right, it sounds like your problem
>> >> probably isn't with the query, but with how many times you're running
>> >> it.
>>
>> > I'll echo that... the problem is not the database - the queries are as good
>> > as it gets.  The problem is running them repeatedly.
>>
>> > If all else fails, I'd replace those queries that execute 500 times with 
>> > raw
>> > SQL that uses the IN operator to get the required rows.
>>
>> > E.g.: SELECT `common_addresstype`.`id`, `common_addresstype`.`adrtype` FROM
>> > `common_addresstype` WHERE `common_addresstype`.`id` IN (1,6,8,52,173)
>>
>> > I imagine there's an ORM query that will do the same thing, but I know 
>> > MySQL
>> > far better than I know Django.
>>
>> > Nick
>>
>
> You can take a look at apps like django-selectreverse [1] or django-
> batch-select [2] for some ideas to make this kind of optimisations
> easier.
>
> Koen
>
> [1] http://code.google.com/p/django-selectreverse/
> [2] http://github.com/lilspikey/django-batch-select
>
> --
> 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: autocomplete widget

2010-01-11 Thread Sam Walters
Hi
The widget source code is here, its pretty easy to see wats going on,
if im dealing with forms i spend a lot of time in here:
http://code.djangoproject.com/browser/django/trunk/django/forms/widgets.py

And the docs are here:
http://docs.djangoproject.com/en/1.1/ref/forms/widgets/#ref-forms-widgets
http://docs.djangoproject.com/en/1.1/ref/forms/fields/#ref-forms-fields
http://docs.djangoproject.com/en/1.1/ref/forms/api/#ref-forms-api

cheers
sam

On Sun, Jan 10, 2010 at 5:13 AM, nameless  wrote:
> Thank you it's very useful.
> Now I need to create a new widget in django but I don't know where is
> the documentation about widget.
>
>
> On Jan 9, 4:42 pm, "esatterwh...@wi.rr.com" 
> wrote:
>> What I do for auto completers ( in general ) is point the widget at a
>> URL that returns JSON objects and the parse the objects client side.
>> For the user object your function might look like this:
>>
>> from django.utils import simplejson
>> from django.contrib.auth.models import User
>> from django.http import HttpResponse
>>
>> def ajax_get_users(request):
>>  users  = User.objects.filter(username__istarstswith = request.POST
>> ['q'])
>>  return HttpResponse(simplejson.dumps([dict(username=u.username,
>> id=u.pk) for u in users]), mimetype='text/javascript'))
>>
>> should get something that looks like this
>>
>> [
>>    {username:'username',id:4},
>>    {username:'username2',id:5}
>> ]
>>
>> [urls.py]
>> url(r'^/member/search/$', 'path.to.views.ajax_get_users',
>> name="myapp_ajax_user_search"),
>>
>> if you have your widget set up to include the needed javascript that
>> should be it. Honestly, the JS parts is more difficult than the django
>> part.
>>
>> Hope that makes sense
>> On Jan 8, 1:46 pm, nameless  wrote:
>>
>> > Hi at all, I am looking for a working simple example on autocomplete
>> > widget for foreign key in Django. I have found many example but I
>> > don't understand and doesn't work.
>>
>> > This is my model:
>>
>> > class profile(models.Model):
>>
>> > user = models.ForeignKey(User, unique=True)
>>
>> > class profileForm(ModelForm):
>>
>> > user = forms.CharField(widget=AutoCompleteWidget())
>>
>> > class Meta:
>> >     model = profile
>>
>> > I wish an AutoCompleteWidget working for this example.
>>
>> > Could anyone help me pleaseee ?
>>
>>
>
> --
> 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: Looking for Lead Django Developer in LA please call 310 571 JOBS

2010-01-24 Thread Sam Walters
Is it just me or is asking for 5+ years for django unlikely.

http://en.wikipedia.org/wiki/Django_%28web_framework%29
"released publicly under a BSD license in July 2005"



On Mon, Jan 25, 2010 at 2:13 PM, James Matthews  wrote:
> People should research before posting. But I always enjoy these posts.
>
> On Fri, Jan 22, 2010 at 7:09 PM, James Bennett 
> wrote:
>>
>> On Fri, Jan 22, 2010 at 6:48 PM, CerenGuven  wrote:
>> > 3-5+ years Django/Python development experience
>>
>> If you manage to find someone with 5+ years' Django experience, do let me
>> know.
>>
>> (meanwhile, job postings should go to djangogigs.com)
>>
>>
>> --
>> "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.
>>
>
>
>
> --
> http://www.astorandblack.com/
>
> --
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-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: AJAX Autocompletion Field

2010-02-13 Thread Sam Walters
There probably isnt a good whole tutorial. Which looks at the
operation from client side to server side...
You should read about writing your own autocomplete field in JS.
And for server side look at writing a view which returns a JSON or
list of options which corresponds with the JS / JS framework you are
using.

I dont think there is a best practice, basically all autocomplete
forms are a hack made to look like a menu appearing under a form
field.

Below is an example using prototype/ scriptalicious client side.

Read:

http://wiki.github.com/madrobby/scriptaculous/ajax-autocompleter

Django Forms Component:

class MyForm(forms.Form):
myAutocompleteField = forms.CharFIeld(max_length=80, required=True,
widget=forms.TextInput(attrs={'autocomplete':"off",
"onkeyup":"nameOfJavascriptMethod('arg1', 'arg2', this.value);",
'size':'35'}))

Template Part of a form template:


Turning on Javascript will help
you complete this field by providing suggestions!



{{form.myAutocompleteField}}





{{form.myAutocompleteField.errors}}

Javascript:

function postcodeLocationEvent(txtfieldid, resultsdivid, value)
{
new_url = '/findmyautocompletestr/';
new Ajax.Autocompleter(txtfieldid, resultsdivid, new_url,
{
method: 'post',
paramName: 'locationinput',
minChars: 3,
parameters: {'locationinput':value},
indicator: 'indicator1'
});
}

View:

def getLocationViaSuburbOrPostcode(request):
#basically whatever you model is storing, some access query
probably using startswith or contains
loc_af = postcodeorsuburbfind(request) # would be
Model.objects.filter(somefield__istartswith=.POST['someParameter']).values('')

places = []
places.append('')
if loc_af is None:
return HttpResponse(status=500)
if len(loc_af) is 0:
return HttpResponse(status=500)
for l in loc_af:
if l.has_key('airfield_name'):
if l.has_key('ycode'):
#in this example just formatting html to be compliant
with the scriptalicious API for autocompleter

places.append('%s,%s,%s,%s'%(l['airfield_postcode'],l['airfield_name'],l['ycode'],l['state__state_abbrev']))
else:

places.append('%s,%s,ALA,%s'%(l['airfield_postcode'],l['airfield_name'],l['state__state_abbrev']))
else:

places.append('%s,%s,%s'%(l['postcode'],l['suburb'],l['state__state_abbrev']))
places.append('')
return HttpResponse(places)

Thats absically it.

You can choose to write your own JS for the autocompleter, its a lot
of work, i wrote my own but current project is using
prototype+scriptalicious so i dont bother using it.

cheers

-sam



On Sun, Feb 14, 2010 at 9:46 AM, Jon Loeliger  wrote:
> Folks,
>
> For likely the umpteenth time, can someone recommend a good
> AJAX auto completion tutorial or example that I might use
> to crib-together a text-field selection that would otherwise
> be a very large drop-down selection field?
>
> My use case would be essentially like having a table full
> of say, recipie ingredients, and letting the user select
> which one to add into a recipe.  I'd like to have the user
> simply start typing a few first characters and then let an
> autocompleter search for matches and present them to the user.
> The source of the matches would be a "Name" TextField in
> some model.
>
> What is the current Best Practice or even Good Advice? :-)
> Pros and cons for jQuery or extjs or something else?
> A good "How To" or a pointer to a write up?
>
> Thanks,
> jdl
>
> --
> 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: Job opportunity - Newcastle, NSW, Australia

2010-02-23 Thread Sam Walters
Hi Peter

If you want someone who is very good at python/django you could also
try contacting the people here:

http://www.newcastlelug.org/wiki/doku.php

cheer

sam_w


On Mon, Feb 22, 2010 at 4:15 PM, Peter  wrote:
> Hi all
>
> Please see:
>
> http://tinyurl.com/djangojob
>
> for a job being advertised by NSW Rural Doctors Network in Newcastle,
> NSW, Australia.
>
> Thanks.
>
> Peter J Williams
> Information Manager
> NSW Rural Doctors Network
> Head Office
> Suite 19, Level 3
> 133 King Street
> Newcastle NSW 2300
> Telephone: (02) 4924-8000
> Facsimile: (02) 4924-8010
> Mailto:pwilli...@nswrdn.com.au
> Web: http://www.nswrdn.com.au
>
> --
> 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: Many to Many...so many queries

2010-03-19 Thread Sam Walters
Yes, this conversation hits the nail on the head.

'select related' only works with forward facing keys.

http://code.google.com/p/django-selectreverse/ is a resonably good
piece of code to improve performance:

using a structure like:

class model1(model.Models)   1<* class model2(model.Models)
model1
= models.foreignkey(model1)
1<* class
model3(model.Models)
model1
= models.foreignkey(model1)
etc...

where your view/template code is:

for x in model1.objects.all()
#stuff
for y in x.model2_set.all()
#stuff
for y in x.model3_set.all()
#stuff

Gets awfully slow as you add modelX_set.all or scale it up to thousands of rows.

eg:
where model1 is 945 rows in the sql db:

time taken:  1.023
SQL queries:  1883

using select related:

time taken:  0.493
SQL queries:  21

I have not tried select related performance where there may be another
model with a reverse foreignkey facing model2.
I don't know how well it will face a multi level reverse foreign
key/many to many db structure.

Also don't forget to look at indexing for certain fields where
appropriate it can be a good performance improver:

http://docs.djangoproject.com/en/1.1/ref/models/fields/#db-index

cheers
sam_w




On Fri, Mar 19, 2010 at 5:15 AM, koenb  wrote:
> On 18 mrt, 10:12, bruno desthuilliers 
> wrote:
>> On Mar 18, 8:42 am, koenb  wrote:
>>
>> > Take a look at something like django-selectreverse [1] for inspiration
>> > on how to reduce your querycount for M2M relations.
>>
>> > Koen
>>
>> > [1]http://code.google.com/p/django-selectreverse/
>>
>> I must be missing the point, but it looks seriously like reinventing
>> the wheel ? How is it better than using select_related ???
>
> Select_related only populates forward one-to-many relationships
> (foreignkeys).
> It does not work for many-to-many relationships or reverse one-to-many
> relationships (the XX_set descriptors on the other side of fk's).
> You can not load those in one and the same query, but you can load all
> those objects in one single query instead of N extra queries.
> That is what selectreverse helps you to do. Look at the example on the
> introduction page of the project to see what kind of queries I mean.
>
> Koen
>
> --
> 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.



Django + Raw SQL: not returning a M2M key set of related values properly.

2010-03-25 Thread Sam Walters
http://pastebin.com/dFW6MdBm

Hi
I have a raw MySQL query which im using for performance reasons.
It works great except under one condition. When i want to apply  a
filter based on a directories related table 'tags'. In SQL i use this:
`directory_directorytag`.`name` = '%s'

now typically i would want to see if the directory is associated with
the tag im after. And then get the entire set of tags including the
match.
It follows my models such that its a basic many-to-many relationship.

eg django orm:
for a in Directory.objects.filter(directorytag__name__exact=''):
v = a.directorytag_set.all().values('name')

the directory may have a set of tags 'tags'Apple, Pear, Nectarine etc.

However my SQL query only returns the exact match 'Apple' and none of
the other tags in the set.

Yes i normally end up with a nice list of dictionaries, there are
duplicates the results for the other keys eg:
[{... 'keya':'valuea', 'tag':'apple' ...},{... 'keya':'valuea',
'tag':'pear' ...}]
which i transform to:
[{... 'keya':'valuea', 'tag':['apple','pear'] ...}]
That is not an issue. The issue is in the WHERE clause as soon as i
search for a tag it literally only returns the results with just that
tag not the entire group.

I was searching all evening and was not able to see an easy way to fix this.
Attempted to use outer/right joins however i dont know enough about
MySQL in particular to work it out.

Any help would probably save me most of tomorrow ;) I have to get it
solved some time. And raw sql seems to be the best as far as
performance and minimising hits on db.

cheers

sam

-- 
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: Project optimisation stage: Advice to boost speed of database queries across tables?

2010-03-25 Thread Sam Walters
I also read a good article. As it turns out im using a lot of inner joins:

http://www.caktusgroup.com/blog/2009/09/

This  was quite handy.
My processis usually build it to be as fast as possible in raw SQL
then go back in and try and makre it with the ORM.

"I've read your description and it doesn't mention how often your data
changes. If it's not too often, you might want to consider simply
caching the whole results or parts of it. You'll then have to add a
bit of code to regenerate the cache every time the data changes."

Yes actually in some of the scenarios the data is quite static,
however im doing a lot of stuff with lat/long coordinates now so it
means i have a bunch of keys in the results dict returned which are
all dynamic, per click values and need to be recalculated a lot.
Note: I have taken your advice on board for some of my views Philippe.

Cheers

Sam_W


On Fri, Jan 8, 2010 at 12:18 AM, Philippe Raoult
 wrote:
> Hi Sam,
>
> I've read your description and it doesn't mention how often your data
> changes. If it's not too often, you might want to consider simply
> caching the whole results or parts of it. You'll then have to add a
> bit of code to regenerate the cache every time the data changes. It
> looks to me like you have one query for selecting which entries to
> print, then many repetitive queries to find information about each
> entry. If you had a per-entry cache then you would probably be down to
> one main query plus a lot of cache lookups.
>
> Also you were on the right track when using addresses =
> Address.objects.filter(directory__in=directories). I've often used
> that kind of queries to reduce (1 + many queries) down to (2 + lots of
> dictionnary operations)
>
> Hope that helps.
>
> Regards,
> Philippe
>
>
> On 7 jan, 11:39, Sam Walters  wrote:
>> Thanks Koen
>> I had suspected such things would exist but couldnt find them.
>> I will take a look at this. Looks like a neat addon which would
>> greatly help my project turnaround time.
>>
>> cheers
>> Sam
>>
>> On Wed, Jan 6, 2010 at 11:07 PM, koenb  wrote:
>>
>> > On 31 dec 2009, 01:56, Sam Walters  wrote:
>> >> Thanks for the replies.
>>
>> >> Yes, there is the option of going to raw MySQL. However the project
>> >> requirements mean i can't use raw SQL. (portability, readability)
>> >> From what i can see using django's db API i have to execute the
>> >> queries 500 times.
>> >> I am very familiar with the query documentation and i know that
>> >> select_related will prevent foward facing foreign keys translating to
>> >> an individual sql queries which hit the db and would slow it down.
>>
>> >> Fact is even when i dont use 'select_related' the major performance
>> >> problem occurs with the 'many-to-many' and 'reverse foreign' keys
>> >> (some 75% of the performance penalty for my package method is with
>> >> these) and only 20% can be solved by select_related.
>>
>> >> To be specific about how the multiplicities unfold:
>>
>> >> search_querySet is a Directory.objects.filter(...
>>
>> >> for s in search_querySet:
>> >>         address_info = s.address_set.all() #.select_related(depth=2) -
>> >> yes i can/will put select related here but it really does not help
>> >> that much 20% tops
>> >>         #address_info is usually 2-3 rows from an address table
>> >>         for a in address_info:#.select_related(depth=2):
>> >>             if a.addresstype.adrtype == 'Physical' and
>> >> a.addradmin.addr_enabled == True:
>> >>             #further reduction in the number of rows which we need to
>> >> get values from.
>> >>             related_phone=a.phone_set.all()
>> >>             related_email=s.email_set.all()
>> >>             #phones and emails are a small number of rows 2-3 tops
>>
>> >> It is these lines which produce the performance hit.
>> >> I cant see a way of using django's query language to avoid having to
>> >> descend into each of the 500 'directory' objects because of the
>> >> necessity to get all rows from the related tables in phones an emails
>> >> and to inspect the type of 'address' object.
>>
>> >> thanks for the ideas. will continue testing and looking for answers
>>
>> >> -Sam
>>
>> >> On Thu, Dec 31, 2009 at 2:41 AM, Nick Arnett  
>> >> wrote:
&

Re: can django be used in destop application?

2011-08-23 Thread Sam Walters
Seriously why bother?

http://www.wxpython.org/

The whole front end of django is too web-centric. So the only thing
that might be of use is if you have an existing web application which
heavily uses the django ORM and you want back end consistency with a
desktop GUI application that shares thee same database.

Writing an application with wx-python is less time consuming than
dealing with css+html you wont have the same issues to consider when
thinking about security. wx-python  is a 2-3 week learning curve to
become proficient and lots of tutorials out there.



On Wed, Aug 24, 2011 at 5:50 AM, h3  wrote:
> Django is modular enough that most of its parts could probably be
> replaced with desktop oriented
> modules, like rendering QT templates instead of HTML templates.. which
> is great.
>
> If not you can probably use a embed browser engine (like webkit) and
> run your app like a website
> locally and get somewhat the look and feel of a desktop application.
>
> That said, your real problem will arise when your application will
> need to do things that doesn't adhere to
> the REST api. Then you'll need to find a way to save your application
> state and that's pretty much
> when shit will hit the fan IMHO.
>
> If the desktop application(s) you want to build are all easily
> translatable for the web (using a REST api that is),
> I think it's theoretically possible. But try to do anything out of
> this scope and you will bitten at every corners.
>
> In other words, not really worth the troubles.
>
> regards,
>
> Max
>
>
> On Aug 23, 1:36 pm, "Cal Leeming [Simplicity Media Ltd]"
>  wrote:
>> Curious concept, using Django for a desktop application.
>>
>> Can't think of any reason why you couldn't at least try it :)
>>
>> Cal
>>
>> On Tue, Aug 23, 2011 at 3:49 PM, Andy McKay  wrote:
>>
>> > On 2011-08-23, at 4:17 AM, smith jack wrote:
>>
>> > > i mean not use django for web site development, but for desktop
>> > application,
>> > > it seems its orm can be used in destop application, isn't it?
>>
>> > Yes.
>> > --
>> >  Andy McKay
>> >  a...@clearwind.ca
>> >  twitter: @andymckay
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups
>> > "Django users" group.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> >http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Django Development environment

2011-08-27 Thread Sam Walters
Ok lets see. At the moment:

Editor:
vim + http://code.google.com/p/trespams-vim/
sometimes gedit or kate

Editor console *this has been really useful:
yakuake

Debug client-side:
firebug, yslow, a windows computer with ie7

Version system:
git

OS:
develop on apto-sid (debian unstable), deploy on debian or some sort
of redhat style os.

DB (depends on project):
mysql, postgres+spatial, sql-lite

Webserver:
apache 1.3, apache 2.2, nginx

Method of deployment:
Fcgi or wsgi

VIrtualisation:
vserver guests

Its not perfect but iv'e got used it.
Also lots of different extras i put into projects like south or
reverse-select, jinja but that depends on the project.

Interestingly on the three GUI systems i use kde, xfce and gnome as
most of my stuff is done in yakuake.

cheers
sam_w



On Sun, Aug 28, 2011 at 4:33 AM, Steven Elliott Jr
 wrote:
>
> On Aug 27, 2011, at 11:17 AM, Simon Connah  wrote:
>
>>
>> On 27 Aug 2011, at 04:44, Steven Elliott Jr wrote:
>>
 On Fri, 2011-08-26 at 15:07 +0100, Simon Connah wrote:
> Mercurial or Git (depends on whether the project is open source or not)
>>>
>>> Kenneth,
>>>
>>> I think he means whether or not the repository will be public or private. 
>>> Github (git) does not offer private repos unless you pay whereas bitbucket 
>>> (mercurial) gives you 5 private ones for free as well as the option for 
>>> creating public ones. I personally am a big BitBucket fan as I find it much 
>>> much easier to manage and also a bit faster.
>>>
>>> Best,
>>> Steve
>>
>> Correct. Although Bitbucket offers unlimited private repos. It just limits 
>> you to 5 users...
>
> Right, sorry that's what I was going for but I brain spasm'd on the iPhone. 
> Bitbucket has gotten a lot better since Atlassian took it over.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Django Development environment

2011-08-28 Thread Sam Walters
Ok :)
Thankyou.

Yes ill try something like that when i have the time later this year!

On Sun, Aug 28, 2011 at 7:31 PM, Simon Connah  wrote:
>
> On 28 Aug 2011, at 04:41, Sam Walters wrote:
>
>> Debug client-side:
>> firebug, yslow, a windows computer with ie7
>
> Rather than using a separate computer with IE 7 I tend to just spin up an 
> Amazon EC2 instance running Windows Server 2003 or Windows Server 2008 for a 
> couple of hours. It makes everything so much easier when it comes to testing.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Using gedit for django development

2011-09-15 Thread Sam Walters
Yes. I mostly use vim+yakuake. I really like gedit and have used it
for large projects too.

Notably: I will try this gedit-django-project pluggin as it never
hurts to know your way around multiple IDE's.

sam_w

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



Re: Using IGNORABLE_404_URLS

2011-09-28 Thread Sam Walters
I second this. Not something you would implement in django. Would
handle that with the web server front end. Eg: i used to get requests
to phpmyadmin login url requests (i assume thats because that software
is a security issue). So i got nginx to return a minimal 404 message
instead of the full 404 page.


On Thu, Sep 29, 2011 at 1:50 PM, Kurtis Mullins
 wrote:
> Hey, I don't think I'll be able to help you much with figuring this out in
> Django-land. I do have one suggestion though. You could manually block these
> using your front-end server (Nginx, Apache, etc...) so that way it doesn't
> even reach Django. Not only would this be a hypothetically easy fix, you'd
> save yourself some server load as well.
>
> On Wed, Sep 28, 2011 at 2:01 PM, shacker  wrote:
>>
>> Our Django sites get literally hundreds of bogus 404 requests per day. For
>> example:
>>
>> Referrer: http://domain.edu/
>> Requested URL: /signup/
>> User agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;)
>> IP address: 168.9.86.2
>>
>> The "referrer" line is a lie because nowhere on our site do we point to
>> "/signup" . I've given up trying to figure out how these things are
>> generated or how to block them. But I would like to limit the number of
>> daily emails to just the actual/legit 404s. So I started
>> using IGNORABLE_404_URLS, per:
>>
>> https://docs.djangoproject.com/en/dev/howto/error-reporting/#errors
>>
>> IGNORABLE_404_URLS = (
>>    re.compile(r'\.(php|cgi)$'),
>>     re.compile(r'^/forums'),
>>     re.compile(r'^/signup'),
>>     re.compile(r'/src/'),
>>     re.compile(r'/pdf/'),
>> )
>>
>> Unfortunately this seems to have no effect. Shouldn't the regex pattern
>> there catch the bogus request domain.edu/signup ? Or is this not working
>> because the way the requests are being submitted somehow bypasses Django's
>> ability to catch it as an error? I'm just not clear what's going on here.
>>
>> Thanks.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/django-users/-/7xxDzuRZue4J.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Easiest Way to Deploy Django?

2013-02-23 Thread Sam Walters
Hi
Helping people get started at work with PostgreSQL ad the most common
problem coming from MySQL users is they have trouble connecting to the
database:
setting up hg_hba.conf and some of the basic operations are different
to MySQL which confuses them.

I dont think there is an easiest way. Nginx+fcgi script but it depends
on your deployment. Setting up static files to be handled outside of
django is the other major stumbling block.

A starting point:
*read nginx documentation (a howto tutorial)
*read postgresql documentation
*look at writing fcgi init scripts so you can /etc/init.d/fcgi
stop|start|restart
*use manage.py sqlall  to see what django is doing with the SQL
*and the connection.cursor to see what your ORM is doing in RAW SQL

hope this helps.


On Fri, Feb 22, 2013 at 9:32 PM, Shawn Milochik  wrote:
> To answer the original question, my vote is for nginx + gunicorn.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django-newsletter, cron job not working

2013-04-17 Thread Sam Walters
Hi
In addition to the previous advice i would also check /etc/init.d/cron to
see if the daemon is running.

make sure you have the correct date+time settings in your shell eg: 'date'
command.

also run some sort of primitive debug command like:
* * * * * touch "/tmp/$(date +\%d-\%m-\%Y-\%T)"
for a couple of minutes to see if it executes.

my money is on a path issue though ;)





On Wed, Apr 17, 2013 at 6:42 PM, Shawn Milochik  wrote:

> It's almost certainly an environment issue, such as an issue with your
> PATH or PYTHONPATH.
>
> Just add to the command so that it puts all standard output and standard
> error to a file to read what the message is.
>
> your_command &> /tmp/broken_cron.log
>
> Then rig your cron job to run ASAP and read the log.
>
>
> On Wed, Apr 17, 2013 at 2:38 PM, frocco  wrote:
>
>> Hello,
>>
>> Can someone give me an example of running a cronjob hourly?
>> I am on webfaction and cannot get this working.
>>
>> I tried
>>
>> @hourly /usr/local/bin/python2.7 ~/webapps/ntw/myproject/manage.py runjob
>> submit
>>
>> I get no email
>>
>> If I SSH in and sunit manually, it works fine
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Understanding an existing big web application written in Django

2013-06-06 Thread Sam Walters
Hi

In addition to what has already been said.

Make use of command line search tools. Hoe to search through all the python
files using BASH is a good example.

eg: In one of my projects i have to find all the places where a particular
class is called or instantiated: 'LocationAirfieldLookup'

find . -name '*.py' -exec grep -E -H -n 'import LocationAirfieldLookup'
'{}' \; -print

will return every python file where that is instantiated:
/users/views.py:94:from Aeroclub.common.LocationsUtils import
LocationAirfieldLookup

Very useful.

Firstly, get an idea of what each 'app' eg: polls app in the tutorial is
supposed to do. Where its functionality starts/ends, what common resources
it uses.

Then i look at the various urls.py files with a conventional analoge
notepad nearby to map out some of the important stuff.

I also look at models.py for important parts of the software.(afterall this
is how it uses the DB). Here you may want to use a tool like grep to just
get the class names.
models often have a lot of custom functionality in them. Eg: cusomised
'save' methods etc.

This all really boils down to good documentation practices. If there's good
docs then its easier, otherwise expect to spend a day or two learning to
understand the program.

cheers




On Thu, Jun 6, 2013 at 2:06 PM, si  wrote:

> I have already existing web application code written by a someone else now
> I need to work on it.
> So I am trying to understand the architecture of the various classes and
> interaction. I want to know where jump in and how to understand the
> architecture of the code.
> Urls.py seems to be a good place to start off.
> Thanks for the suggestions.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




What client side html layout tools are people using to speed up template development?

2013-07-29 Thread Sam Walters
Its not specific to django however i have a few small projects on the
horizon where i could really save time spent on the things im not good at:

Graphic design CSS layouts, choosing fonts, colours that look good.

What are the tools people are using for this these days? What are strong
points of the system you are using?

All this stuff will get partiitoned up and placed in my django templates.

I used to use yahoo yui gris css, 960 grid system and a few other things a
couple of years back. I assume there are better things i dont know about
though.

thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: What client side html layout tools are people using to speed up template development?

2013-07-30 Thread Sam Walters
Thanks this should be good enough and better than my previous practices.

Yes i have had a good look at bootstrap, google fonts... I knew about kuler
and was going to try that.

Im hoping to get this front end stuff to take up about 40% of my
development time. I used to work in larger django projects where i only had
to do forms and was mostly dealing with everything but the graphics. Other
people on the projects made them look pretty. For these smaller projects
based on past experineces i spend way too much time like 80% of it making
the graphics.

thanks everyone for the help.


On Tue, Jul 30, 2013 at 12:13 PM, Christian Erhardt <
christian.erha...@mojo2k.de> wrote:

> I totally agree, use bootstrap, google fonts and the color-wheel. You'll
> have a good looking page to start with. Then extend the layout.
>
> Am Montag, 29. Juli 2013 11:35:24 UTC+2 schrieb somecallitblues:
>>
>> Use 
>> http://twitter.github.io/**bootstrap/<http://twitter.github.io/bootstrap/>framework
>>  for your frontend. If you google "django bootstrap" you'll find
>> some apps that will help.
>>
>> For fonts i usually pick Google font that looks good. If you want to use
>> web safe font go to http://cssfontstack.com/
>>
>> As for colors, try 
>> https://kuler.adobe.com/**create/color-wheel/<https://kuler.adobe.com/create/color-wheel/>
>>
>> You can also google something like "20 web designer tools" and you'll get
>> one of those blog posts that lists them all.
>>
>> And if you have time check out this list https://github.com/**
>> dypsilon/frontend-dev-**bookmarks<https://github.com/dypsilon/frontend-dev-bookmarks>.
>> It's truly amazing!
>>
>> Cheers,
>>
>> M
>>
>>
>> On 29 July 2013 19:18, Sam Walters  wrote:
>>
>>> Its not specific to django however i have a few small projects on the
>>> horizon where i could really save time spent on the things im not good at:
>>>
>>> Graphic design CSS layouts, choosing fonts, colours that look good.
>>>
>>> What are the tools people are using for this these days? What are strong
>>> points of the system you are using?
>>>
>>> All this stuff will get partiitoned up and placed in my django templates.
>>>
>>> I used to use yahoo yui gris css, 960 grid system and a few other things
>>> a couple of years back. I assume there are better things i dont know about
>>> though.
>>>
>>> thanks in advance!
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@**googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>>
>>> Visit this group at 
>>> http://groups.google.com/**group/django-users<http://groups.google.com/group/django-users>
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>> .
>>>
>>>
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Script to move django 1.4.3 to 1.5.1

2013-09-01 Thread Sam Walters
The worst change i've had to make was a long time ago when we had to send
CSRF Token with Ajax calls because of a security exploit.
Had to write an entire regular expression and apply it to multiple template
files. Took perhaps 40 minutes.

However i can see some of the really old django snippets out there that
just work could possibly come unstuck and you'd have to fix them.
Understanding python goes a long way to fixing this.



On Sat, Aug 31, 2013 at 8:51 AM, Some Developer
wrote:

> On 31/08/2013 02:14, Dan Gentry wrote:
>
>> I've been using Django since v1.0, and when each major version is
>> released, I run through the release notes to see what I need to change.
>>   Russell is correct that most things will work from one version to the
>> next, but I like to keep as up to date as possible to minimize my risk
>> of hitting a deprecated feature.  Once I build a checklist, I can go
>> through it for each app I support.  Doesn't take too long, and I feel I
>> gain a better understanding of the new features this way.
>>
>
> Yeah this is by far the best way of doing things. Plus it has the
> advantage of becoming familiar with everything that has been added.
>
> The only time I found upgrading a chore was when I had to change all my
> url templates tags to have quotes around the URL name. That took ages.
> Thankfully that sort of change is rare and I really should have used the
> future import to get around it completely.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to 
> django-users+unsubscribe@**googlegroups.com
> .
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at 
> http://groups.google.com/**group/django-users
> .
> For more options, visit 
> https://groups.google.com/**groups/opt_out
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How do you organize your deployment enviroment

2011-05-23 Thread Sam Walters
Hi
I make a shell script as i performs the steps for the first time.
Basically it means learning bash or something similar.

Disadvantage is its pretty inflexible however if its exactly the same
linux distro every time then its not too bad.

cheers

sam_w

On Mon, May 23, 2011 at 5:24 PM, Malcolm Box  wrote:
> I'd heartily recommend chef - chef.opscode.com.
> Large library of scripts for almost any package or tool you're likely to
> want, scales out to lots of nodes but can be run in a simple solo mode for
> small deployments. Only downside is it's ruby but mostly you use the
> configuration language so not really a problem.
> I use Chef plus fabric to automate deployments of hundreds of nodes.
> Malcolm
>
> Sent from my iPhone, please excuse any typos
> On 23 May 2011, at 08:00, DK  wrote:
>
> Hi,
> I am having a django project that  is being frequently deployed on clean
> linux installation. After a few deployments I have noticed that this process
> is very time consuming for me (every time I am preparing run scripts for
> everything, configuring cronjobs, paths to log files, etc) but this could
> be easily automated.
> What are a ready solutions to manage such deployments?
> My typical workflow is:
> 1) install packages on debian/ubuntu via aptitude (like database, etc)
> 2) creating new virtualenv + getting pip
> 3) pip install -r requirements (to setup enviroment)
> 4) fetch django project from code repository
> 5) setup runtime dir (I keep there: run - for pid files, logs, conf - for
> some config variables or scritps, scripts - some starting srcipts)
> 6) setup crontab jobs
> 7) setup webserver + django wsgi to be started
>
> Sure - I can write some custom made installer for that, but wondering if
> there is some generic tool for such things.
> PS. I have heard about fabric, but didn't investigate this tool yet.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: What is the Development Life Cycle of Django App?

2011-07-24 Thread Sam Walters
Hi
Also you can download a project from one of the many sites that have
source code. Look at a git tree and see the commit dates would give an
idea of how long it takes to build a project, how many people were
involved, how specialized their role was etc.

cheers

sam_w

On Sat, Jul 23, 2011 at 3:10 PM, Eyad Al-Sibai  wrote:
> Thanks!
>
> On Sat, Jul 23, 2011 at 4:04 AM, Mike Dewhirst 
> wrote:
>>
>> On 23/07/2011 12:31am, Eyad Al-Sibai wrote:
>>>
>>> What is the Development Life Cycle of Django App? Should I start in
>>> implementing the models or the urls ... or what exactly?
>>
>> Best advice I know is in Practical Django Projects by James Bennett
>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Most stable Linux distribution for Django - Python development

2011-08-01 Thread Sam Walters
If a modern linux OS is crashing then it will likely /var/log whats
going wrong. The phrasing of this issue seems to indicate lack of
experience or familiarity with the linux os or unix model of os.
Thats no problem if you are keen to learn the principles of the OS you
will get better at using the OS and identifying issues.

Now to answer your question specifically:
debian stable branch is a good idea. I assume you will stick to
something and keep it so go for a distro with long term support/longer
release cycle.

http://en.wikipedia.org/wiki/Debian#Stable_ports

Good documentation, forums, community support.

I would avoid rapid release cycle stuff unless you know what you're
doing. Eg: i use apto-sid which is an unstable branch of debian for
some servers but i know what im getting myself into.

I say debian because the package management, runs nearly all the
dependencies that django and a lot of its addons require. Also once
you have built a server stack... eg: nginx+fcgi+django+memcached+mysql
or any web server stack of your choice on a stable distro you will
reduce the pool of possible issues with any of these aformentioned
components to a minimum and the problems can be googled with ease. And
keep doing this for ~5 years until they stop the LTS and it stops
getting security patches. eg: debian etch 2010

Compare this to a rolling release or distro with releases every 6-12
months where kernel is changing and OS has bleeding edge versions and
you will have a larger gaumet of issues. Concequently you will have to
know more and be better at problem solving. Will you have a rollback
plan when the dist-upgrade finishes and something breaks in a new
exciting way?

Obviously you can develop on any flavour of linux shouldnt matter.
Managing a production server is different ballgame.


good luck and i hope this advice helps



On Mon, Aug 1, 2011 at 6:27 PM, Anoop Thomas Mathew  wrote:
> Hi All,
> Firstly, I am not here for a distro war.
> I was using ubuntu 9.10, and then switched to fedora 14 and then to fedora
> 15.
> IMHO, It seems that they all were quite unstable. (Many times it hung up on
> my Dell and HP machines - may be driver issues, still I don't want that
> too.)
> I would really like some recommendation for a linux distro which is much
> stable, but still can support all relevant packages.
> Top recommendations I found around was Debian and OpenSuse.
> Please revert with your suggestions.
> Thanks,
> Anoop Thomas Mathew
> atm
> ___
> Life is short, Live it hard.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Constructing / rendering a complex

2011-08-02 Thread Sam Walters
Hi i dont see what is complex about this.

On Wed, Aug 3, 2011 at 6:35 AM, Michał Sawicz  wrote:
> Hi all,
>
> I'd like to pick your brainz about how would you approach constructing
> and rendering a complex table with headers, row/colspanning cells in a
> most clean way that rids the view of rendering as much as possible.
>

The view 'rendering' as much as possible. So i assume you would rather
have an initial template rendered. then perhaps have views that
deliver data via JSON or something? AJAX+JSON

> Here's roughly what I'm after (incomplete, but you should see what I
> mean):
> http://imageshack.us/f/845/zrzutekranuqv.png/
>
> There are three approaches I can think of:
>
>     1. Construct a complete grid in the view, along with row/colspans
>        that I would simply iterate over and render in the template, but
>        that would make it virtually impossible to change the
>        appearance.

I cant see why it would be impossible to change. Use javascript to
change the table col and rowspans. (why do visual formatting work on
the serverside if you can do it clientside)
at the very least you can have style="display:None" and variious other
CSS rules to help with any dynamic changes to the table.

>     2. Count the cells / rows and compare them with data from the view
>        to decide on how that particular cell should behave, but that
>        makes the template a nightmare.

I dont quite understand this one. If you are comparing data
server-side then submitting data via a form would be recommended.
Where is the data being changed that requires the comparison anyway?

>     3. ID all the cells and change the attributes accordingly, but for
>        rowspanning cells I wouldn't know in the consecutive rows that
>        there in fact was a cell and I might want to repeat it. Maybe I
>        could fill in the complete grid but make the ones that get
>        spanned ignorable in the template through a class.
>

use multiple classes eg  jse a javascript library to
add remove classes select child elements of the DOM im sure the
information doesnt have to be partitioned down the a super fine level
of granularity requiring individual id's for every element does it?

What javascript library do you use? jquery, prototype, dojo etc all
good options to simplify manipulation of DOM elements.

> I'll take all thoughts :)
> --
> Michał (Saviq) Sawicz 
>

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



Re: "Great circle" using the django ORM?

2011-08-12 Thread Sam Walters
Dont know specifically about sql lite.

I have used django orm with postgres spatial db to find points within
a 'convex hull' bounding box shape:


from django.contrib.gis.geos import GEOSGeometry, Polygon, LineString,
Point, LinearRing
from django.contrib.gis.measure import D

coords_in = simplejson.loads(request.POST['coords'])
#add the first point to the end to form a loop
coords_in.append(coords_in[0])
#construct linear ring
lin_ring = LinearRing([ Point(float(item['b']),
float(item['c'])) for item in coords_in ])
#create convex hull
boundaries = lin_ring.convex_hull

#data list to return, calculate airfields in convex hull
data_list = []
for airf in Airfield.objects.filter(point__intersects=boundaries.wkt):
data_list.append([airf.airfield_name, airf.point.x,
airf.point.y, airf.ycode])

Dont take the code as gospel however for performance reasons i found
it fair to specify a segmented convex hull approximating a sphere. Set
the radius from the centre to be x units and find points within this
area. Return the queryset and order by distance from the centre with a
spheroid-arc distance formula eg: Vincenty formula.

Either way i found using forums less django-specific and more math+map
specific was a good approach




On Fri, Aug 12, 2011 at 5:51 PM, Thomas Weholt  wrote:
> Thanks for your detailed reply :-) I'll try to figure it out. So far I
> got a few candidates for a solution but the math functions seem to be
> somewhat different on the different database platforms so I need to
> experiment some more to find one that works on the three major ones (
> sqlite, postgres and mysql - I often use sqlite for development and
> postgres for production myself, but still want to support mysql ).
>
> About the accuracy; my app is suppose to show photos take nearby some
> location so it doesn't have to be dead on. But this should really be a
> reusable app or widget. Seems like more than just me needs this
> functionality. If I get something going I'll look into making it
> generic and reusable. Anybody interesting in helping out making this
> happen please let me know. My experience using math functions in SQL
> like this is close to zero.
>
> Thanks alot for all the replies and interest :-)
>
> Regards,
> Thomas
>
> On Thu, Aug 11, 2011 at 7:51 PM, Bill Freeman  wrote:
>> I've done this sort of thing in the past without the aid of geo-django, 
>> using a
>> reasonably ordinary model.
>>
>> I did it as a two step process, first calculating a bounding box, which is a
>> rectangle in lat/long space.  It is calculated once per search, based on
>> the distance and the coordinates of the distance circle's center (the point
>> from which you are measuring distance).
>>
>> A pair of latitudes that are tangent to the distance circle are easy to come
>> by because the point of tangency is at the same longitude as the circle's
>> center, and because distance in linear with latitude along such a line.
>>
>> Bounding longitudes are harder because their points of tangency are
>> closer to the pole than the circle's center (unless it's on the equator),
>> as well as distance not being linear with longitude change.  But since
>> a distance circle radius through the point of tangency will necessarily
>> intersect the bounding line of longitude at a right angle, you can use
>> one of the spherical right triangle formulas.  I like:
>>   sin(a) = sin(A) * sin(c)
>> where the triangle includes the pole, the point of tangency, and the center
>> of the distance circle; "a" is the angle, measured as seen from the center
>> of the earth, subtended by the side not involving the pole, that is of the
>> distance radius (2*PI*distance/earth_radius); "c", the hypontenuse, is
>> the same thing for the distance between the distance circle's center and
>> the pole, that is, the compliment of the latitude of the distance circle's
>> center; and A is the surface angle subtended at the pole, that is, the
>> difference in longitude (what we're looking for).  Because it would be
>> convenient to work in latitude, rather than compliment of latitude, change
>> the formula to:
>>  sin(a) = sin(A) * cos(lat)
>> therefore:
>>  A = asin(sin(a)/cos(lat))
>> The desired bounding longitudes are then +/- A from the longitude of
>> the distance circle's center's longitude.  It doesn't hurt that the use
>> of cos(lat) has even symmetry, making it clear that you don't have to
>> choose a pole.
>>
>> Now you select candidate database rows satisfying the bounding limits,
>> and only have to calculate actual distance for them, discarding the
>> relatively few that are too far, but within the corners of the bounding box.
>> Some databases support a "BETWEEN" operator, or something like it,
>> but the ORM's range lookup will work.  Be careful, though, if your circle
>> can include 180 degrees of longitude, since then you want longitude to
>> be outside the

Re: Multi widget?

2011-01-03 Thread Sam Walters
Hi,

I think you are looking to override the widget render() method to
build multiple HTML form elements?
Here is a good example:

http://k0001.wordpress.com/2007/11/15/dual-password-field-with-django/

I have built heaps of these things, usually a choicefield + charfield,
charfield + charfield, charfield + datefield etc. Anything where you
want to be able to call clean() on multiple form elements because they
have some sort of interdependant logic.

Also for doing this looking directly at the django source code in
forms, fields and widgets is the best way to understand how it works.


cheers

sam_w

On Tue, Jan 4, 2011 at 2:08 AM, Ilian Iliev  wrote:
> Two widgets to one field? Can you specify this little bit more?
>
> On Mon, Jan 3, 2011 at 12:29 PM, robos85  wrote:
>>
>> Hi,
>> what I want to do, is to add 2 widgets to 1 field. So far I have:
>>
>> content =
>> forms.CharField(widget=forms.Textarea(attrs={'class':'add_editor'}),)
>>
>> But I also want to add some medi to it (tinymce .js files). How can I do
>> that?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-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.
>
>
>
> --
> eng. Ilian Iliev
> Web Software Developer
>
> Mobile: +359 88 66 08 400
> Website: http://ilian.i-n-i.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.
>

-- 
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: Japanese Text Sort Order

2011-01-05 Thread Sam Walters
Hi,
Personally I would map the priority of every character in a dict and
pass this to sorted:

dd = { "cha1": 1,
  "char2": 2,
   "char3": 3,
   "char4": 4,
 }
result = sorted(mylist, key=lambda x:dd[x[0]])


Point being if the db query isnt too slow you could use python.

cheers

sam_w

On Thu, Jan 6, 2011 at 7:10 AM, Seth Gordon  wrote:
> On 01/05/2011 07:57 AM, James Hancock wrote:
>> I think it does the same thing, but I was talking about how you cant set
>> 'ordering' under the Meta class in a model.
>> http://docs.djangoproject.com/en/1.2/ref/models/options/#django.db.models.Options.ordering
>>
>> If
>> I set it to a field of Japanese characters, the ordering comes out wrong. At
>> least not in the desired order.
>> How can I set the data collation for just a few fields? And how can I know
>> which of the Japanese to set it to?
>
> Does the “strcoll” function in Python’s standard “locale” module do the
> right thing when a Japanese locale is set?  If not, can you persuade the
> PyICU package to do the right thing?
>
> If either of these works, then you could slurp your results into a
> Python list and then sort the list using one of these methods.  This
> wouldn’t perform too well, of course, if you had thousands and thousands
> of results and you wanted the database to peel off the top ten... but if
> for some reason collation at the database level isn’t working, doing it
> all at the Python level might be better than nothing.
>
> --
> 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: Django's documention is horrible

2011-01-10 Thread Sam Walters
Hi,
My approach with regard to:

> frameworks I'm used to have at least a well structed API documention listing
> all methods and members of classes with some comment attached to them. They
> also show the class heirachy, quick and simple.

I just look at the source itself for this.


cheers

sam_w

-- 
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: Current Django 1.3 Alpha 2 Documentation as PDF

2011-01-17 Thread Sam Walters
at the very least use mysqldump on you db or a table before you play
with the code.
though depending on what you are doing backup should be even more
structured than ad-hoc sql dumps.

http://www.thegeekstuff.com/2008/09/backup-and-restore-mysql-database-using-mysqldump/

On Mon, Jan 17, 2011 at 10:45 PM, Vovk Donets  wrote:
>
>
> 2011/1/17 ckar...@googlemail.com 
>>
>> Sry for the wrong url. It's now
>> http://g2007.ch/media/static/uploads/django.pdf
>>
>
> Great work, many thanks!
>
> --
> Vovk Donets
>  python/django developer
> skype:  suunbeeam
> icq:      232490857
> mail:    donets.vladi...@gmail.com
> www:   vovk.org.ru
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Google maps

2011-01-29 Thread Sam Walters
Hi

This also depends how server-side oriented you want this to be?

Its good to learn geodjango. (that way if your calculation areas of
polygons, loading layers you can just make this python+server side
instead of writing it in javascript.
Also with lots of ajax related request/response designs some people
look at using dajax or something like that to reduce development time.

cheers

sam_w



On Sat, Jan 29, 2011 at 12:17 AM, Michael  wrote:
> You might take a look at
> https://launchpad.net/ubuntu-django-foundations/map
>
> It's a fairly new project, but is actively being developed.
>
> --
> Michael 
>
> On Thu, 2011-01-27 at 21:23 -0800, roy mukasa wrote:
>> Hey guys does anyone know how i can embed google maps into django? i
>> am new to django but i am trying to develop an app in which i will
>> embed a google map of a particular area.
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: ANN: Django 1.3 released

2011-03-23 Thread Sam Walters
Hi fellow Django users.

Its great news that 1.3 is out.
I have been using the development branch on one machine for a month or
so before this release so fiddling with some of the new features.

Very happy about the class based views.
Static file handling is so-so, *never really had issues with the old
system anyway.
Configurable delete-cascade will save writing my own delete() for some
complex scenarios.
New template tags are all pretty useful too.

Time to start using some of the new features in live projects &
testing existing projects for compatibility errors on 1.3=)

The only 'recent' issue that caused me trouble at first (project is
heavily ajaxed) and with the release of 2.5 i had to fix up the ajax
for csrf headers:

eg: (for prototype js)

function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');

for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].strip();
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue =
decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

function requestPage(event) {
var element = event.element();
var url = '/'+element.identify()+'/';
new Ajax.Updater('content', url, {
method: 'post',
requestHeaders: {'X-CSRFToken':getCookie('csrftoken') },
});
}

Will see how it goes. Very appreciative of the effort to develop any
new version of django.

Cheers

sam_W

On Wed, Mar 23, 2011 at 10:35 PM, Xavier Ordoquy  wrote:
> Hi there
>
> I just checked with Chrome (10.0.648.151 / osx) and it worked with sha & md5.
> The issue seems to be on your side.
>
> Regards,
> Xavier.
>
> Le 23 mars 2011 à 12:01, Chris Matthews a écrit :
>
>> Thanks it was.
>> Chrome consistently downloaded it with only 799,034 bytes. I used Windows 
>> Internet Explorer which downloaded 6,504,003 bytes and the SHA1 is correct 
>> and 7Zip is happy with it.
>> PS: I am not punting Internet Explorer ;-)
>>
>> -Original Message-
>> From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] 
>> On Behalf Of Russell Keith-Magee
>> Sent: 23 March 2011 12:47
>> To: django-users@googlegroups.com
>> Subject: Re: ANN: Django 1.3 released
>>
>> On Wed, Mar 23, 2011 at 6:25 PM, Chris Matthews  wrote:
>>> I must add my SHA1 on Django-1.3.tar.gz is
>>> 63e62f9a4834c1c8dbb591aac4ef2b1b84c5ea63 (on all of the downloads I did).
>>>
>>
>> In which case, there's something going screwy with your downloads. The
>> correct SHA1 for Django-1.3.tar.gz, as documented [1] is:
>>
>> f8814d5e1412bb932318db5130260da5bf053ff7
>>
>> [1] http://media.djangoproject.com/pgp/Django-1.3.checksum.txt
>>
>> A number of people validated this independently during the release
>> process, and I've just revalidated it. There's obviously something
>> going wrong with your download.
>>
>> 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-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: validate user input on templates

2011-03-27 Thread Sam Walters
hey

use:
str.isdigit()
http://www.tutorialspoint.com/python/string_isdigit.htm


what is idDigit() ? is that a call to a method somewhere else.
and arent you trying to validate numberofapples = request.POST['numberofapples']
not playerid?

Personally if this is form data you are trying to validate i'd write a
form class and use the form clean() method to evaluate them as
integerfields:

http://docs.djangoproject.com/en/1.2/ref/forms/fields/
http://docs.djangoproject.com/en/1.2/topics/forms/

Also you can verify using regular expressions *good to get comfortable
with if you're new to django.

cheers

sam_w

On Mon, Mar 28, 2011 at 4:59 PM, django beginner  wrote:
> Hi django experts,
>
> just want to know your opinion on how to validate the user input
> (example: the user input field should be integer, but the user
> accidentally inputs any character), here is my code:
>
> FYI; the numberofapples field is IntegerField
>
> here is my sample code:
>
> def apples_edit(request):
>    if request.POST['id']:
>         id = request.POST['id']
>         numberofapples = request.POST['numberofapples']
>         conn = psycopg2.connect("dbname=my_db user=user password=pass
> host=localhost")
>         cur = conn.cursor()
>
>        try:
>           if isDigit(playerid):
>                pass
>           else:
>                template_name = 'err_template.html'
>                t = loader.get_template(template_name)
>                c = RequestContext(request, {"err_msg":"number of
> apples should be integer, Please correct your input"})
>                return HttpResponse(t.render(c))
>        except ValueError:
>            template_name = 'err_template.html'
>            t = loader.get_template(template_name)
>            c = RequestContext(request, {"err_msg":"number of apples
> should be integer, Please correct your input"})
>            return HttpResponse(t.render(c))
>
>         sql = """ UPDATE my_db SET "numberofapples"='%s' where "id"='%s'
> """ % (numberofapples,id)
>         cur.execute(sql)
>         conn.commit()
>         conn.close()
>
> --
> My problem is that, the error template does not appear after I type in
> any character for numberofapples field.
> What would be the correct code for 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-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: how to create message box in Django?

2011-03-29 Thread Sam Walters
Yes, this is really a client-side related issue.

To try and answer your question what would be involved on the django
side of things:

Basically you want django to deal with any submission from one of
these fields as either a from or modelform so you can run clean() and
validate the input.

Beyond that the 'Message Box' html / scripts can be served dynamically
if need be in the django template system.

If you wanted to be really fancy in how you serve up the html+js form
code you could write/extend forms in some way. In which case looking
at the widgets source at:
http://code.djangoproject.com/browser/django/trunk/django/forms

Is your best bet.

cheers

sam_w

On Wed, Mar 30, 2011 at 2:20 AM, Shawn Milochik  wrote:
> Yeah, this isn't a Django question. But this is what we use:
>
> http://jqueryui.com/demos/dialog/
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: develop to product

2011-03-29 Thread Sam Walters
Hi Yongzhen,

Looks like you're trying to run two mis-configured web servers.

if you're on linux stop the nginx process eg: /etc/init.d/nginx stop
The stuff you've submitted is for apache: Send us the contents of the
apache log file showing the error.

Perhaps *if the error is long* use http://pastebin.com/ instead of
putting the error code into the email.

cheers

sam_w

On Wed, Mar 30, 2011 at 8:40 AM, creecode  wrote:
> Hello Yongzhen,
>
> The first thing you might want to find out is why, apparently, nginx
> is giving you an error when you say that you are using apache/wsgi.
>
> If I had to guess I'd say you might have an nginx server acting as a
> proxy in your stack somewhere.  I'm not an expert though as I've just
> been getting to grips with basic proxying myself.
>
> Check for an nginx error log somewhere... see what that says, if
> there...
>
> On Mar 29, 2:07 pm, yongzhen zhang <4...@live.cn> wrote:
>
>> nginx/0.7.65
>
> Toodle-l..
> creecode
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Need help: request.POST.copy() ?

2011-03-31 Thread Sam Walters
Hi hank23
request.POST would be immutable.

"QueryDict instances are immutable, unless you create a copy() of
them. That means you can't change attributes of request.POST and
request.GET directly."

http://docs.djangoproject.com/en/dev/ref/request-response/


So I'm
> wondering if there is something else going on or if this problem is
> some kind of side effect of using request.POST.copy()?

I dont know what you mean by side-effect.

I copy/instantiate querydicts all the time never had any problems.
Dont forget if you can use python to clone objects :)

cheers

sam_W


On Fri, Apr 1, 2011 at 11:48 AM, hank23  wrote:
> I need to know when I can or should use request.POST.copy() when
> processing screens, as opposed to when not to use it. I've used it
> some, on one screen in particular, which seems to work fine for
> displaying the data that I want to display, when I put the data on the
> screen programatically from within a view. However when I try to alter
> the data manually by keying it in from my keyboard, or selecting an
> option from a dropdown, nothing seems to show up changed the next time
> that submit the form to the view and look at the data posted. So I'm
> wondering if there is something else going on or if this problem is
> some kind of side effect of using request.POST.copy()?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Need help: request.POST.copy() ?

2011-03-31 Thread Sam Walters
Yes, Id really need to see some code to work it out.

A bit hard to work out wether you're returning the request.POST.copy()
and wether this is instantiated in a new form instance and returned.
Eg: if form validation fails.
Or wether you are  having trouble redisplaying the original
request.POST data in a new form or one thats failed evaluation?

Once again would need to see the some code.

>> I actually call sub views from the main view which processes this
>> screen, display the data as shown above as well as capture the changes
>> to the request.POST dictionary like this:
>>
>> title = request.POST['title']

Hmm, dont forget:
http://en.wikipedia.org/wiki/Pass_by_reference

Here is some of my basic code... eg: adding a new param 'IP address'
to request.POST form data for evaluation. This might help.

def contact(request):
from hvv.contact.forms import ContactEmailForm
#form validation: Note: ip address is not form data, is validated
as form and added to formdata by 'getIpAddr()'
if request.is_ajax() and request.POST:
#Note: copy() makes QueryDict Mutable
data = QueryDict(request.POST['form']).copy()
data.update({'ipaddress': getIpAddr(request) })
form = ContactEmailForm(data)
if form.is_valid():
n_email = form.cleaned_data['email']
n_subject = form.cleaned_data['subject']
n_message = form.cleaned_data['message']
n_ipaddr = form.cleaned_data['ipaddress']

saveInDb(n_email, n_subject, n_message, n_ipaddr)
sendEmail(n_email, n_subject, n_message, n_ipaddr)

return render_to_response('contact.html', {
'form':ContactEmailForm(), 'message':'Thankyou. Your message was
sent!.' }, context_instance=RequestContext(request))
else:
return render_to_response('contact.html', { 'form':form },
context_instance=RequestContext(request))
form = ContactEmailForm()
return render_to_response('contact.html', { 'form':form },
context_instance=RequestContext(request))

cheers

sam_w




On Fri, Apr 1, 2011 at 12:30 PM, hank23  wrote:
> Sorry the last example I gave maybe wrong. I think I'm actually
> getting the data back out using the cleaned_data. I'm trying to do
> this from memory, since this is a work problem and I've been
> struggling with it since the middle of this afternoon and it's been
> very frustrating.
>
>
>
> On Mar 31, 8:24 pm, hank23  wrote:
>> Currently I have logic in place that makes a copy of request.POST so
>> it can put data from a record using a key, gotten from the previous
>> bunch of POSTed data, on the screen for display purposes. This all
>> works fine. But when I go in and alter some of the data being
>> displayed then the next time I submit the form the data that I just
>> entered is not displaying in the request.POST dictionary when I look
>> at it. So what am I apparently not doing right to cause the data to be
>> lost? I display the data to the screen after making a copy of
>> request.POST (request.POST.copy()) like this:
>>
>> request.POST['title'] = record.title
>>
>> I actually call sub views from the main view which processes this
>> screen, display the data as shown above as well as capture the changes
>> to the request.POST dictionary like this:
>>
>> title = request.POST['title']
>>
>> After trying to capture the data this way then I try to write it to
>> the database, but nothing new is being saved, so that's why I'm
>> wondering why no new data  is being saved.
>>
>> On Mar 31, 8:07 pm, Sam Walters  wrote:
>>
>>
>>
>> > Hi hank23
>> > request.POST would be immutable.
>>
>> > "QueryDict instances are immutable, unless you create a copy() of
>> > them. That means you can't change attributes of request.POST and
>> > request.GET directly."
>>
>> >http://docs.djangoproject.com/en/dev/ref/request-response/
>>
>> > So I'm
>>
>> > > wondering if there is something else going on or if this problem is
>> > > some kind of side effect of using request.POST.copy()?
>>
>> > I dont know what you mean by side-effect.
>>
>> > I copy/instantiate querydicts all the time never had any problems.
>> > Dont forget if you can use python to clone objects :)
>>
>> > cheers
>>
>> > sam_W
>>
>> > On Fri, Apr 1, 2011 at 11:48 AM, hank23  wrote:
>> > > I need to know when I can or should use reque

Re: noobie cannot get mod_wsgi to import settings

2011-04-03 Thread Sam Walters
Hi
I dont usually deal with Apache+WSGI (usually fcgi + nginx)
However your script:
WSGIScriptAlias /wsgi /var/www/wsgi-scripts

One of my apache sites:
WSGIScriptAlias / /home/hvv00/hvv/wsgi/hvv.wsgi

Point directly this directly to the file.

Note: You wont need to chmod 777 anything



ServerName 
ServerAlias 
ServerAdmin mr.sam...@gmail.com
UseCanonicalName Off


Order deny,allow
Allow from all


WSGIScriptAlias / /home/hvv00/hvv/wsgi/hvv.wsgi

CustomLog /usr/local/apache/domlogs/hvv.com.au combined
BytesLog /usr/local/apache/domlogs/hvv.com.au-bytes_log




Hope that helps.

cheers

sam_W


On Thu, Mar 31, 2011 at 3:02 AM, Sells, Fred
 wrote:
> I've been googling and trying this for 2 days now, I'm sure I'm just
> confused about something basic because it cannot be that hard.  I've
> tried all the hints I found via google and they made sense but no
> success.
>
> I'm running RHEL 6 Python 2.6.5, django 1.2.4 and mod_wsgi 3.2.  I'm
> trying to configure the server so I can deploy independent django sites
> via wsgi.  So my directory structure looks like this:
> /var/www/wsgi-scripts
>        -> myapp.wsgi
>        -> test2.wsgi
>        ...  such that I can drop in any wsgi file to deploy a new app.
>
> I plan to deploy my django sites (totally independent of one another,
> but all related to our intranet) as follows
> /home/djangodeploy
>        -> __init__.py
>        -> mysite1
>        -> mysite2
> 
> I got a basic myapp.wsgi working OK and it prints out sys.path as
> follows:
> /home/djangodeploy
> /usr/lib/python26.zip
> /usr/lib/python2.6
> /usr/lib/python2.6/plat-linux2
> ...snip...
> /usr/lib/python2.6/site-packages/webkit-1.0
> 
> I've made sure apache is the user for all files and even changed
> permissions to 777.  I've remembered to restart apache each time.   I
> tried to import settings.py from the command line to make sure there
> were no syntax errors and it works.  This site worked under the debug
> server also.
> 
> My wsgi.conf file looks like this:
>
> LoadModule wsgi_module modules/mod_wsgi.so
> WSGIScriptAlias /wsgi /var/www/wsgi-scripts
> WSGIPythonPath /home/djangodeploy
> LogLevel info
> WSGISocketPrefix /var/run/wsgi
>
> 
> Order allow,deny
> Allow from all
> 
>
>   ### I'm not sure about this last
> Directory, grasping at straws.
> Order allow,deny
> Allow from all
> 
>
> 
> My wsgi module to launch django looks like this
>
> import os,  sys
> print >>sys.stderr, __file__, sys.path
> #import homeworks  # this did not work
>
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'homeworks.settings' #this did
> not work
> #never gets here
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
> __
>
> And the output of the apache error log looks like this (timestamp and ip
> deleted for brevity):
> ImportError: Could not import settings 'homeworks.settings' (Is it on
> sys.path? Does it have syntax errors?): No module named
> homeworks.settings
>
> /var/www/wsgi-scripts/test2.wsgi ['/home/djangodeploy',
> '/usr/lib/python26.zip', '/usr/lib/python2.6',
> '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk',
> '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload',
> '/usr/lib/python2.6/site-packages',
> '/usr/lib/python2.6/site-packages/gst-0.10',
> '/usr/lib/python2.6/site-packages/gtk-2.0',
> '/usr/lib/python2.6/site-packages/webkit-1.0']
>
> mod_wsgi (pid=2399): Exception occurred processing WSGI script
> '/var/www/wsgi-scripts/test2.wsgi'.
> Traceback (most recent call last):
> File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py",
> line 230, in __call__
>     self.load_middleware()
>   File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py",
> line 33, in load_middleware
>     for middleware_path in settings.MIDDLEWARE_CLASSES:
>   File "/usr/lib/python2.6/site-packages/django/utils/functional.py",
> line 276, in __getattr__
>     self._setup()
>   File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line
> 40, in _setup
>     self._wrapped = Settings(settings_module)
>   File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line
> 75, in __init__
>     raise ImportError("Could not import settings '%s' (Is it on
> sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e))
> [Wed Mar 30 11:46:53 2011] [error] [client 192.168.218.34] ImportError:
> Could not import settings 'homeworks.settings' (Is it on sys.path? Does
> it have syntax errors?): No module named homeworks.settings
>
>
> Would someone be kind enough to show me my mistake.  I've tried all I
> can think of.
>
> --
> You received this message because you are subscri

Re: Documentation Checked But Unclear: How to supress form.errors from views when needed?

2011-04-03 Thread Sam Walters
I dont understand so you render a view with a form once and you get
form errors on the initial view?

Or

Is there a POST/GET with formdata being submitted generating this
issue? *which would be by design as fas as i can tell you want form
verification to work

Note:
http://docs.djangoproject.com/en/1.3/topics/forms/

If you are binding data to a form for a view and rendering it im
pretty sure you will see form errors if you leave fields blank etc.

cheers

sam_w


On Thu, Mar 31, 2011 at 8:10 AM, hank23  wrote:
> I have an edit screen with more than a dozen fields on it of various
> types (text/CharField, select/CharField, date/DateField). When I
> refresh the screen sometimes I want to suppress all of the field
> required errors generated by empty fields prior to the refresh
> actually taking place. So far I have not found anything that works. I
> know in a view that I can check if there are errors for particular
> fields(like this  if form.errors.has_key('title') :
>        titleerrors = len(form.errors['title'] titleerrors =
> str(titleerrors))) and then display the counts on the screen, but I
> have not figured out how to suppress them yet once I know they exist.
> I do not believe that I can suppress them at the form level in
> forms.py, in an overridden clean() method, without suppressing them
> all of the time, which is not my intent. Thanks for the 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-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Do you combine you Django decorators?

2011-04-04 Thread Sam Walters
Hi Andy

I dont combine them... however:
I was using a couple of decorators for almost every view in one
project. Ended up putting them in middleware.
Are these decorators for every view? Maybe you should consider middleware too.

cheers

sam_w

On Mon, Apr 4, 2011 at 3:26 AM, andy  wrote:
> Do you use several Django decorators for your views or do you combine
> the common ones into one or two custom decorators?
>
> This is just something that I have been a bit curious about for a
> while now as I tend to hate using more that one decorator per view. I
> have often thought about combining them. Thought I have not done so as
> yet. I hate looking at it but it seem more flexible nonetheless.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Static/media url in template

2011-04-04 Thread Sam Walters
Yes it already exists {{MEDIA_URL}}

Thats what the settings.py file does...

There is a bunch of stuff you can read about in the docs:

http://docs.djangoproject.com/en/1.3/howto/static-files/

Also for some of my own deployments there are a bunch of static file
servers so i just put these into settings:
{{MEDIA_URL_VIDEO}}
{{MEDIA_URL_IMAGES}}
etc...

Basically its as extensible as you want to make it.

cheers

sam_w


On Tue, Apr 5, 2011 at 8:44 AM, Jon J  wrote:
> Maybe I'm missing something...
>
> I would say I'm relatively familiar with the Django framework by this
> point. I'm mocking up a website, and I want to link static files into
> the base template. Instead of having the url's directly in the
> template, I'd like to call the STATIC_URL variable from within the
> template, so for example I could have
>
> 
>
> instead of
>
> http://www.domain.org/style.css"; />
>
> Is this something that's possible or advisable? How is this problem
> normally handled so I don't have to retype pretty much everything if I
> move my site around? I haven't been able to find anything in the
> documentation regarding this.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Using the same block in a django template to display different information depending on a variable

2011-04-04 Thread Sam Walters
Hey

Block tags dont work like that.

{%if choice1 == 2 %}

{% include "sometemplate.html" %}

{%endif%}

instead of:

 {%if choice1 == 2 %} {%block two%}
> The temperature in {{city}} is {{temperature}}°
>
> {%endblock two%} {% endif %}


I hope that was what you were thinking...
http://docs.djangoproject.com/en/1.3/topics/forms/

There is an example in the form docs.


cheers

sam_w

On Tue, Apr 5, 2011 at 9:34 AM, Ethan Yandow  wrote:
> Hey Mr. Django! I am trying to have different information display in
> the same block depending on a variable "choice" which is simply an
> int. The way I was planning on doing so was going to be something like
> the bellow code:
>
> {% extends "index.html"%} {%block head%}
>
> Welcome to Piss && ink {{user}}
>
> {%endblock head%}
> {%block one%}
> The temperature in {{city}} is {{temperature}}°
>
> {%endblock one%} {%if choice1 == 2 %} {%block two%}
> The temperature in {{city}} is {{temperature}}°
>
> {%endblock two%} {% endif %} {%comment%}{%if choice1 == 2 %} {%block
> two%}
> The temperature in {{city}} is {{temperature}}°
>
> {%endblock%} {% endif %}{%endcomment%} {%block two%} {%csrf_token%} {%
> if new_event %}
> {{new_event}}
>
> {% endif %} {%endblock%}
> Now, the problem I am having is that the template doesn't like that
> there are two blocks of the same name in the template. For some reason
> it doesn't seem to care about the {%if%} statement that is checking
> where the {%block%} is supposed to go. I thought that the {%if%}
> statement would only execute what was inside itself depending on its
> parameters but it doesn't seem to be doing that. It displays
> everything inside the {%if%} no matter what "choice1" is equal too :
> ( Does anyone have any idea how I might be able to fix 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-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Dajaxice and CSRF issues

2011-04-08 Thread Sam Walters
Hi Vincent
Yes.

Look at the HTTP  Headers.
Just in case you need to read the docs on 1.2.5 which identified the
CSRF AJAX issue.

http://www.djangoproject.com/weblog/2011/feb/08/security/

Also looking at the request in firebug you can see the 'X-CSRFToken'
needs to be added as an attribute with the javascript you use.
This is not labour intensive and i was able to do a grep to find and
replace in my files to make them compatible.

Here is the required code in prototype. Could be adapted to the
framework of your choice.

function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');

for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].strip();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue =
decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

function requestPage(event) {
var element = event;//event.element();
var url = '/'+element.identify()+'/';
new Ajax.Updater('content', url, {
method: 'post',
requestHeaders: {'X-CSRFToken':getCookie('csrftoken') },
});
}


On Fri, Apr 8, 2011 at 6:49 PM, Vincent den Boer  wrote:
> We have a site with a lot of static HTML pages and a few Django pages. 
> Dajaxice
> is used on both the static and Django pages to check whether the user is 
> logged
> in and show the login status to the user. The problem is that since the user
> will typically visit the HTML pages first, the user will not have a CSRF 
> cookie
> stored when the first AJAX request is made and Django rejects the request. Is
> there any elegant way to solve this? I've now disabled CSRF protection for all
> AJAX requests, which is not a problem right now since we don't do anything
> dangerous or send sensitive data with AJAX, but could become risk in the 
> future.
>
> Kind regards,
> Vincent
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Is it possible to output a graph from Matplotlib into Django like this?

2011-04-11 Thread Sam Walters
Use python imaging:
http://www.pythonware.com/products/pil/

You can return a response with an image of the graph.

response = HttpResponse(status=200, mimetype="image/gif")
background.save(response, "GIF")
return response

There is no 'best practice for this' Some people i know use flash.
However dynamically generated images is good eg: no browser pluggins

cheers

sam_w


On Tue, Apr 12, 2011 at 1:29 PM, nai  wrote:
>
> I will try to the 2 views method and see how I get on but in it would
> be great if you could answer my questions too!
>
> Why does it go against best practices?
>
> How would one go about doing it anyway?
>
>
> On Apr 11, 6:39 pm, Xavier Ordoquy  wrote:
>> Le 11 avr. 2011 à 12:21, nai a écrit :
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> > This is the give example from Matplotlib for Django:
>>
>> > def simple(request):
>> >    import random
>>
>> >    from matplotlib.backends.backend_agg import FigureCanvasAgg as
>> > FigureCanvas
>> >    from matplotlib.figure import Figure
>> >    from matplotlib.dates import DateFormatter
>>
>> >    fig=Figure()
>> >    ax=fig.add_subplot(111)
>> >    x=[]
>> >    y=[]
>> >    now=datetime.datetime.now()
>> >    delta=datetime.timedelta(days=1)
>> >    for i in range(10):
>> >        x.append(now)
>> >        now+=delta
>> >        y.append(random.randint(0, 1000))
>> >    ax.plot_date(x, y, '-')
>> >    ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
>> >    fig.autofmt_xdate()
>> >    canvas=FigureCanvas(fig)
>> >    response=django.http.HttpResponse(content_type='image/png')
>> >    canvas.print_png(response)
>> >    return response
>>
>> > Is there anyway I can return the image like this `return
>> > render_to_response('template.html', {'graph': > > matplotlib or some other graphing package>}`
>>
>> Hi,
>>
>> Is there any reasons why you couldn't have a view that would just render the 
>> image and the other one that would have a img tag pointing to the first view 
>> ?
>> It is possible to embed an image in the web page, but I'm sure it goes 
>> against the best practices.
>>
>> Regards,
>> Xavier.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Is it possible to output a graph from Matplotlib into Django like this?

2011-04-11 Thread Sam Walters
Hi

How about one view that takes arguments as either POST or GET params?

> You have to bear with me but where does background come from? So I can
> use the save() method from the PIL library is that right?

Ok so you can load a canvas.

Just to illustrate here is a view that puts dots on a map *map is the canvas.

specifically:
   try:
background = Image.open(image_path)
canvas = ImageDraw.Draw(background)
except IOError:
return HttpResponse(status=500)

Below is the full view...
I think this is what you want. Hope its makes things clearer.

def drawAllEvents(request, **kwargs):
import Image, ImageDraw
from datetime import datetime

image_path = getattr(settings,'HOME_DIR')+'templates/images/front.gif'

try:
background = Image.open(image_path)
canvas = ImageDraw.Draw(background)
except IOError:
return HttpResponse(status=500)

if background.mode is not 'P':
return HttpResponse(status=500)

aa = 
Airfield.objects.filter(locality__event__dates__start__gte=datetime.now()).values('airfield_lat_dec','airfield_long_dec')
ll = 
Location.objects.filter(locality__event__dates__start__gte=datetime.now()).values('location_lat_dec','location_long_dec')

#-
def renderdot(latlon):
#scaling relative to aeroclub map (204, 165) in pixels
scale = float(Decimal(10)/Decimal(49))
mx = 120 - 36*scale
my = (-25 - (background.size[1] - 71)*scale)

xcoord1 = round((latlon[1] - mx)/scale);
ycoord1 = background.size[1] - round((latlon[0] - my)/scale);

#bounding box of the ellipse
xcoord2=xcoord1+5
ycoord2=ycoord1+5

canvas.ellipse([(xcoord1,ycoord1),(xcoord2, ycoord2)], fill=0)
#-

for e in aa:
renderdot( (float(e['airfield_lat_dec']),
float(e['airfield_long_dec'])) )
for e in ll:
renderdot( (float(e['location_lat_dec']),
float(e['location_long_dec'])) )

response = HttpResponse(status=200, mimetype="image/gif")
background.save(response, "GIF")
return response




On Tue, Apr 12, 2011 at 2:33 PM, nai  wrote:
> You have to bear with me but where does background come from? So I can
> use the save() method from the PIL library is that right?
>
> And I can do something like this:
>
> return render_to_response('template.html', {'graph':response})
>
> Where graph is just a variable in my django template (and not  src="{{ graph }}" />)
>
> Is that right?
>
> On Apr 12, 12:03 pm, Sam Walters  wrote:
>> Use python imaging:http://www.pythonware.com/products/pil/
>>
>> You can return a response with an image of the graph.
>>
>> response = HttpResponse(status=200, mimetype="image/gif")
>> background.save(response, "GIF")
>> return response
>>
>> There is no 'best practice for this' Some people i know use flash.
>> However dynamically generated images is good eg: no browser pluggins
>>
>> cheers
>>
>> sam_w
>>
>>
>>
>>
>>
>>
>>
>> On Tue, Apr 12, 2011 at 1:29 PM, nai  wrote:
>>
>> > I will try to the 2 views method and see how I get on but in it would
>> > be great if you could answer my questions too!
>>
>> > Why does it go against best practices?
>>
>> > How would one go about doing it anyway?
>>
>> > On Apr 11, 6:39 pm, Xavier Ordoquy  wrote:
>> >> Le 11 avr. 2011 à 12:21, nai a écrit :
>>
>> >> > This is the give example from Matplotlib for Django:
>>
>> >> > def simple(request):
>> >> >    import random
>>
>> >> >    from matplotlib.backends.backend_agg import FigureCanvasAgg as
>> >> > FigureCanvas
>> >> >    from matplotlib.figure import Figure
>> >> >    from matplotlib.dates import DateFormatter
>>
>> >> >    fig=Figure()
>> >> >    ax=fig.add_subplot(111)
>> >> >    x=[]
>> >> >    y=[]
>> >> >    now=datetime.datetime.now()
>> >> >    delta=datetime.timedelta(days=1)
>> >> >    for i in range(10):
>> >> >        x.append(now)
>> >> >        now+=delta
>> >> >        y.append(random.randint(0, 1000))
>> >> >    ax.plot_date(x, y, '-')
>> >> >    ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
>> >> 

Re: Is it possible to output a graph from Matplotlib into Django like this?

2011-04-11 Thread Sam Walters
I mis-read this... basically you have one view and in the template you
are rendering you put HTML:





so that path will call your other views which return content as
content_type='image/png' or whatever specific format you're using.

what i was suggesting is you could have:





So in your urls.py file it would parameratize 'foo' and in your view
method you could produce different responses based on the parameter.
Eg: in an other view i have i can pass lat and long coords as params
and it would put a dot on the map based on where that lat/long points
to.



On Tue, Apr 12, 2011 at 2:19 PM, nai  wrote:
> Actually, could you illustrate how you would go about using 2 views as
> well? Thanks!
>
> On Apr 11, 6:39 pm, Xavier Ordoquy  wrote:
>> Le 11 avr. 2011 à 12:21, nai a écrit :
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> > This is the give example from Matplotlib for Django:
>>
>> > def simple(request):
>> >    import random
>>
>> >    from matplotlib.backends.backend_agg import FigureCanvasAgg as
>> > FigureCanvas
>> >    from matplotlib.figure import Figure
>> >    from matplotlib.dates import DateFormatter
>>
>> >    fig=Figure()
>> >    ax=fig.add_subplot(111)
>> >    x=[]
>> >    y=[]
>> >    now=datetime.datetime.now()
>> >    delta=datetime.timedelta(days=1)
>> >    for i in range(10):
>> >        x.append(now)
>> >        now+=delta
>> >        y.append(random.randint(0, 1000))
>> >    ax.plot_date(x, y, '-')
>> >    ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
>> >    fig.autofmt_xdate()
>> >    canvas=FigureCanvas(fig)
>> >    response=django.http.HttpResponse(content_type='image/png')
>> >    canvas.print_png(response)
>> >    return response
>>
>> > Is there anyway I can return the image like this `return
>> > render_to_response('template.html', {'graph': > > matplotlib or some other graphing package>}`
>>
>> Hi,
>>
>> Is there any reasons why you couldn't have a view that would just render the 
>> image and the other one that would have a img tag pointing to the first view 
>> ?
>> It is possible to embed an image in the web page, but I'm sure it goes 
>> against the best practices.
>>
>> Regards,
>> Xavier.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: syncdb just hangs/tutorial

2011-04-11 Thread Sam Walters
Postgres uses a unix style user model. Its intuitive once you understand it:

I would seriously advise you to read the tutorial for this:

http://www.postgresql.org/docs/manuals/

FInd out the version you are using too.

Specifically:
1.2. Architectural Fundamentals
onwards.

That error just means you dont have user/passwords/groups set up
properly and postgres has wonderful documentation!
cheers

sam_w


On Mon, Apr 11, 2011 at 11:57 PM, L Corbani  wrote:
>
> Shawn,
>
> In fact, it was an issue with my database settings.  I changed the
> host and now it is working.  Thanks for helping me shift my brain a
> bit this morning :)
>
> Lori
>
>
> On Apr 11, 9:31 am, Shawn Milochik  wrote:
>> Try it with sqlite3. If that works, then the problem is probably with
>> your Postgres setup.
>>
>> Try interacting with Postgres using the psql command. It's likely that
>> you have some problem in the configuration.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: how to Generate a 5 character unique alpha-numeric string

2011-04-11 Thread Sam Walters
Hi
If this is a sequence then why not use python list comprehensions,
nest them together and concatenate the different parts into a string.
http://docs.python.org/tutorial/datastructures.html#nested-list-comprehensions

you could even do it with recursive method calls.
Point is. If its not 'random+unique' just 'unique' then this changes
the nature of the problem completely. This is something pthon is
really good at.

cheers

sam_w

On Mon, Apr 11, 2011 at 4:48 PM, GKR  wrote:
> I meant to say not random. serial  eg:
>
>
> ..
> ..
> 2A00A
> 2A00B
> ..
> ..
> ..
> 2A00Z
> 2A010
> 2A011
> ..
> ...
> 2A019
> 2A01A
> 2A01B
> 
> 
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: How to make a dynamic list in Django

2014-01-10 Thread Sam Walters
Hello

With this sort of problem it depends on the dimensions of your data. What
kind of data is associated with a user? Is this just editing a user profile
like the built in django 'user' or is there a lot more?

My approach to this sort of stuff is a straightfoward initial HTTP response
with your template code, the javascript variables are placed into the page
with your template engine. Hence your comment about having a list
(presumably some sort of javascript array that you can work with).

Subsequent changes to the data are gone with AJAX methods in your
javascript to create, delete, update your data structure accordingly.
This is done by using django forms to clean() your fields. You may want to
look at passing ajax to the server and handling it with formsets if the
user is repeating input a variable number of times:
https://docs.djangoproject.com/en/1.6/topics/forms/formsets/

Eg: if you're just beginning using jquery perhaps look at some of the
examples on stackoverflow make a few test examples using ajax GET and POST.

The premise behind this is you want the user to make changes that are saved
as he/she progresses. Hence instantiating a method in javascript that
serializes a form and sends it to your server which does all the usual form
validation sends back any errors which are handled by your method to
produce success/failure.

http://stackoverflow.com/questions/14099038/an-easy-way-to-submit-django-forms-using-ajax-jquery
or
http://stackoverflow.com/questions/7335780/how-to-post-a-django-form-with-ajax-jquery

Hope this helps

cheers

sam



On Fri, Jan 10, 2014 at 2:44 PM, Frank Jaworski wrote:

> Hello,
>
> Essentially I am trying to take some pre-existing data for a user,
> populate a "list" with it, and then add/delete any item I wish from that
> list and display cost and other information for the updated list.  I don't
> want page reloading or anything like that.  I know the concept of
> ajax/jQuery but am not sure how to incorporate it into this type of design.
>  Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/63adb88c-5e11-46b9-b3ee-68e42a5b27e3%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: IntegrityError --- NOT NULL constraint failed: books_book.publication_date

2014-03-26 Thread Sam Walters
Did you perhaps change the schema of the database after you had created it.

Eg: added null=True as a constraint after creating the table?

If so check the db sheme using:
python manage.py sqlall 

It sounds simple enough. You will have to go into the db shell and update
your schema manually.

using

python manage.py dbshell

If you're developing something where the schema is always getting modified
and you dont want to manually update table constraints
look into

django south addon.

hope this helps


On Wed, Mar 26, 2014 at 3:31 PM, Sami Razi  wrote:

>
>  i'm learning django using djangobook , in chapter
> 6, i'm having this error:
>
>   IntegrityError at /admin/books/book/add/
>
>   NOT NULL constraint failed: books_book.publication_date
>
>
> it seems i should set null=True for  publication_date field. but i did it 
> already, this is my models.py:
>
>
> from django.db import models
>
> class Publisher(models.Model):
> name = models.CharField(max_length=30)
> address = models.CharField(max_length=50)
> city = models.CharField(max_length=60)
> state_province = models.CharField(max_length=30)
> country = models.CharField(max_length=50)
> website = models.URLField()
>
> def __unicode__(self):
> return self.name
>
> class Author(models.Model):
> first_name = models.CharField(max_length=30)
> last_name = models.CharField(max_length=40)
> email = models.EmailField(blank=True, verbose_name='e-mail')
>
> def __unicode__(self):
> return u'%s %s' % (self.first_name, self.last_name)
>
> class Book(models.Model):
> title = models.CharField(max_length=100)
> authors = models.ManyToManyField(Author)
> publisher = models.ForeignKey(Publisher)
>publication_date = models.DateField(blank=True, *null=True*)
>
> def __unicode__(self):
> return self.title
>
>
> what am i doing wrong?
> i googled the error message but didn't find a related answer.
> thank you for your help.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/87ef0e56-f90f-4097-8a2c-e747ac874b71%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Decrease amount of identical "Email reports"

2017-01-09 Thread Sam Walters
Hi
Presumably you have had a look at logging docs and its not good enough?
https://docs.djangoproject.com/en/1.10/topics/logging/

With these sort of project requirements the way i have solved this in the
past is to:
*Work out who needs to receive certain messages. Draw a grid with all
useful messages on one axis and all admins of various types on the other.
Tick the grid boxes for who receives what.
*write a model to save 'messages' with timestamps level/seriousness of
critical errors. Basically whatever you think is important.
*use decorators in views to write/save messages to the 'message' model.
(herein you an add logic to remove duplicates, cascade critical errors
straight into sending to admin email accounts as methods within the model
class whatever your approach might be) Run an email queue every 24 hours
that sends aggregated message groups relevant to each admin.
https://docs.djangoproject.com/en/dev/topics/http/decorators/

Implement this for the most common and annoying duplicate messages to start
with.

Always have an admin of some sort that gets all the critical error messages
eg: say 500 'server error' type messages.

Hope this provides some insight.




On Mon, Jan 9, 2017 at 8:53 AM, Nacharov Mikhail  wrote:

> Hi folks and Happy New Year!
>
> I have a high load production site. If I make a mistake (some users
> getting 500 error) all ADMINS will be receiving error emails until bug
> won't be fixed.
> This causes email server load and it's quite annoying reading thouse
> idetical emails sometimes. It's also possible to miss anouther error report
> inside a bunch of identical..
>
> Did somebody know how to decrease amount of identical Email reports?
> 
> Maybe set some timeout for the same message subject would be correct
> decision?
>
> Maybe there is a better way for monitor web server events?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/2b54c365-fb9b-4618-89b5-ba88b18e6487%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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