beginner model question - two tables without foreign keys (myslq - myisam)

2009-03-16 Thread Norman

How to perform such simple query:

select p.text, b.title from books b, phrase p where p.book_id = b.id

on tables

books{
id : int,
title: varchar
}

phrase{
id : int,
book_id : int,
text: varchar
}

but using django models?


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



middleware cache problem

2009-07-21 Thread Norman

Hi all,

I cache my view that show a list of stories, but I have also small
voting button (like digg). Voting is done be middleware class (it
reads user IP), so I can ask for view with list of stories and tell
that this list shall be cached and I have to ask middleware for vote
results.

Unfortunaltely when cache is ON my middleware voting class isn't asked
for voting results.

What can I do to mix cache from view and live results from my
middleware voting class?

regards, Normanek
--~--~-~--~~~---~--~~
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: middleware cache problem

2009-07-21 Thread Norman

per-view cache is not a solution because I need only a method to
retrieve fresh (not cached) data from middleware.

I wanna take cached list of stories and not cached vote results for
it.

regards, Norman



On Jul 21, 3:13 pm, Michael  wrote:
> On Tue, Jul 21, 2009 at 9:02 AM, Norman  wrote:
>
> > Hi all,
>
> > I cache my view that show a list of stories, but I have also small
> > voting button (like digg). Voting is done be middleware class (it
> > reads user IP), so I can ask for view with list of stories and tell
> > that this list shall be cached and I have to ask middleware for vote
> > results.
>
> > Unfortunaltely when cache is ON my middleware voting class isn't asked
> > for voting results.
>
> > What can I do to mix cache from view and live results from my
> > middleware voting class?
>
> From the per-site cache 
> docshttp://docs.djangoproject.com/en/dev/topics/cache/#the-per-site-cache:
>
> New in Django 1.0: Please, see the release
> notes<../../releases/1.0/#releases-1-0>
> If a view sets its own cache expiry time (i.e. it has a max-age section in
> its Cache-Control header) then the page will be cached until the expiry
> time, rather than CACHE_MIDDLEWARE_SECONDS. Using the decorators in
> django.views.decorators.cache you can easily set a view's expiry time (using
> the cache_control decorator) or disable caching for a view (using the
> never_cache decorator). See the using other
> headers<#controlling-cache-using-other-headers> section
> for more on these decorators.
>
> So all you need to do is make the cache on the view different (never_cache
> decorator might be good here).
>
> Read more on that page for the per-view cache.
>
> Hope that helps,
>
> Michael
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Comments & Forum app (all in one)

2009-03-27 Thread Norman

Hi,

Is there any app that can be used as comment - under blog entries -
and as forum - to see all blog comments ( /forum).

regards, Normanek
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



where can I find email alert functionality

2009-10-06 Thread Norman

hello,

I look for  email alert functionality, where readers sign up to get
notifications when news happens. But I can't find any suitable django
app.

So where can I find something like this?

Any snippet or source code?

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



django ngnix multihost on single django instance

2010-04-01 Thread Norman
Hi,

I'm trying to test simple portal with two apps and two sub domains
mysite.com and blog.mysite.com, but I cant find any example of ngnix
configuration file on local ubuntu server.


So my question is - how to setup ngnix and django to test such
multihost on single django instance and local pc?

best regards, Nomek

-- 
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: New to django and python. error following tutorial w/ the shell

2008-05-05 Thread Norman

Kenneth Gonsalves escribió:
> 
> On 06-May-08, at 9:37 AM, Jason Ourscene wrote:
> 
>>   def __unicode__(self):
> 
> def __unicode__(self):   <- space after 'def'. If you use a  
> python editor it will find errors like this
> 
and what editor do you use?
some advice?

-- 
Norman F. Sáez
Ingeniería Civil Informática
Universidad Técnica Federico Santa María
Valparaíso, Chile.

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



Re: How do I know, in a unit test, the user authenticated after login?

2008-07-16 Thread Norman Harman

Florencio Cano wrote:
> Hi,
> I would like to know how I can retrieve the user id of the user
> authenticated in the auth subsystem after login in a test.
> 
> class CrearCarteraTestCase(TestCase):
>   fixtures = ['/fixtures/initial_data.xml']
> 
>   def setUp(self):
>   self.client = Client()
>   
>   def testCrearCarteraCorrectamente(self):
>   self.client.login(username='pepe', password='test') 
>   
>   response = self.client.post('/carteras/', {
>   'cartera_nombre':'micartera',
>   'submit':'Crear'
>   })
>   
>   carteras_before = 
> Cartera.objects.filter(usuarioID=self.client.user)
>   self.assertTemplateUsed(response, 
> 'Carteras/listado_carteras.html')
>   carteras_after = 
> Cartera.objects.filter(usuarioID=self.client.user)
>   self.assertTrue(len(carteras_after) == len(carteras_before) + 
> 1)
> 
> What I want to do is test the the "Cartera" (Portfolio) was created
> correctly but self.client.user do not exist.

from django.contrib.auth import User

user = User.objects.get(username='pepe')
carteras_before = Cartera.objects.filter(usuarioID=user.id)

> Is this the best way of testing an object creation?

It's reasonable.

I'd probably just use count instead of len(), it should be faster and 
more clearly indicates what you are testing.  I'd also use assertEqual 
instead of assertTrue for clarity.

before_count = Cartera.objects.filter(usuarioID=user.id).count()
...
self.assertEqual(after_count, before_count + 1) 

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: How to deal with two distinct UserProfile model ?

2008-07-16 Thread Norman Harman

Hades_L wrote:
> Hello,
> I'm having trouble dealing with User module. In my application, I have
> two types of users who should be able to log in.
> The first one is an Employee, so I have a code like this:
> class Employee(models.Model):
>someFields = ...
>...
>user = models.ForeignKey(User)
> 
> and the other model is a Client:
> class Client(models.Model):
>otherFields...
>user = models.ForeignKey(User)
> 
> In my settings.py file I define AUTH_PROFILE_MODULE as myapp.Employee.
> 
> So you see the problem here, I can't associate my client's profile
> with the User model. I could manage myself to deal with this without
> using get_profile decorator, but if someone ever had a similar issue,
> i'd love to know how he design his application to have a beautiful
> solution (only one model for Employee and Client ?). :)

I'd guess having only one model is the "correct" answer most of the 
time.  Can't really say what's best without knowing more about your 
project.  But, here are a few ideas to consider.

Have only one user_profile model and use the auth permissions / groups 
system to distinguish between client/employee. 
http://www.djangoproject.com/documentation/authentication/#permissions

Have only one (lite) user_profile model and use contenttypes framework 
to "connect" employee records to Employee Model and clients to Client 
Model. http://www.djangoproject.com/documentation/contenttypes/

Ditch/copy Django's auth and roll your own/modify it to work they way 
you need.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: ImageFiled Uploads

2008-07-16 Thread Norman Harman

Dane Hesseldahl wrote:
> How do I get to the image when the avatar field has an image uploaded 
> through it?

http://www.djangoproject.com/documentation/upload_handling/

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: accessing an attribute for the first item in a template context

2008-07-16 Thread Norman Harman

Hani wrote:
> Hi,
> 
> I'm a newbie and am having a an issue accessing the attribute for a
> variable.  I did a search (django documentation and here) and found
> nothing. If this has been covered before, please direct me to the
> correct thread.
> 
> I currently pass a context to my template and it works fine. For
> example, I can do:
> 
> {% for s in objectlist %}
>   User name is: {{s.user_name}}
> {% endfor %}
> 
> But, I can't do this:
> User name is: {{ objectlist.0.user_name }}
> 
> What I'm trying to do is access the first user in the list and then
> access the user_name attribute for that user.  BTW, {{objectlist.0}}
> does work.
> 
> My current solution is to return the first user (first item in the
> objectlist) as part of the context like this:
> 
>   return render_to_response('app/apptemplate.html",{'objectlist'}:
> objectlist, 'firstobject':objectlist[0]})
> 
> However, this seems counter-intuitive. I should be able to just
> explicitly grab the first item and access it's attributes in the
> template.
> 
> Is there  a better way? How do I do this?
> Thanks,
> Hani

I was gonna say the template . notation does not support numerical 
indexes, but the docs say it does. 
http://www.djangoproject.com/documentation/templates/#variables  I did a 
short simple test and it does in fact.  This is on newforms admin 
branch.  Probably works with trunk as well.

Is this new?  I really thought numerical indexing did not work.

Are you not using trunk?  If not you should be, and if so there must be 
something else going on (username instead of user_name?) as this

 > User name is: {{ objectlist.0.user_name }}

should work as you expect.
-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Why 2 servers to serve dynamic and static content?

2008-07-17 Thread Norman Harman

eka wrote:
> Hi,
> 
> I'm new to django, and reading around, found out that it's better to
> have 2 different web servers for django and static content. How is so?

It's scalability issue.  Each process of a server setup to serve dynamic 
content (using mod_python for instance) typically uses much more memory 
than a server tuned to serving just static content.  So, for example 
(made up numbers) with X memory you can run Y simultaneous dynamic 
servers or 10*Y static ones.  That means you can handle 10 times the 
(static)traffic.

And when you're a huge successful site you might only need 1-2 machines 
to serve static content were as you'll have many, many serving dynamic 
content.

Another reason would be to split static content from your regular 
hosting provider to something like a CDN or Amazon S3.  Which might be 
cheaper / faster than your regular hosting provider.


> And in deployment, how should this be? I mean, should I have 2 apache
> instances? or use another web server for static content or...?

If I was bothering with serving static and dynamic content separately I 
wouldn't use apache to serve the static content.  Use something 
lightweight and fast like nginx or lighttpd.  And depending on your 
situation you can get rid of apache all together and have the 
nginx/lighttpd proxy to something like wsgi or fastcgi django.

On the other hand if I didn't expect a moderate amount of traffic I 
might skip the whole splitting dynamic/static content issue until and if 
I run into scalability issues.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: keeping a list of objects sorted

2008-07-17 Thread Norman Harman

jelle wrote:
> Hi,
> 
> I'm using the tagging app to construct a view where the most recent
> articles by tag are shown, ordered by date.
> To do so I use the following code:
> 
> all_tags = set([i.name for i in Tag.objects.all()])
> articles = []
> for i in all_tags:
> qs = TaggedItem.objects.get_by_model( Article, i )
> if qs:
> articles.append(qs.latest('date'))
> 
> articles = sorted(articles, key=operator.attrgetter('date'))
> 
> When running this in the shell, it results in the wanted ordering.
> When rendered in html, I loose this precise ordering.

If you use the same code in your view as above then the ordering should 
not change.

How are you displaying in template?  Should be using something like

{% for article in articles %}
stuff
{% endfor %)


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: keeping a list of objects sorted

2008-07-17 Thread Norman Harman

jelle wrote:
> Hi Norman,
> 
> Yep, I'm just looping through the list.
> Pretty awkward, right?

Yes, very.  Is the html output order seemingly random? or is there some 
pattern to it?  Cn you post the code for the view?  I'm guessing there 
is a typo or something similar going unnoticed.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Heavy database query (max 32 tables problem)

2008-07-18 Thread Norman Harman

Deniz Dogan wrote:
> Hey.
> 
> I have a model Course and then I have django.contrib.auth.models.User.
> Users and courses are related through M2M, so a user can register for
> many courses and a course can register multiple users. Now, given a
> potentially very long list of users, I want to retrieve all the
> courses for which all of those users have registered. Currently I have
> implemented it in this manner:
> 
> courses = Course.objects.all()
> for user in users:
>   courses = courses.filter(users=user)
> courses = courses.distinct()
> 
> As you might expect, I get the "maximum 32 tables in a join" error
> when having a very long list of users. How would I go about doing what
> I want here?

http://www.djangoproject.com/documentation/db-api/#in

user_ids = [u.id for u in users]
# or user_ids = User.objects.values_list("id", flat=true)
courses = Course.objects.filter(users__id__in=user_ids)

I've used 'in' with a many hundreds ids.  Have no idea how performant it 
is compared to other solutions.


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Trouble with regex

2008-08-18 Thread Norman Harman

Fernando Rodríguez wrote:
> Hi,
> 
> I have the following regexes on my django app urls.py:
> 
> urlpatterns = patterns('',
>
># List of all resumes for a given Career
>(r'(?P[-\w]+)/$', career_list),
>
># List of all resumes for a given jss
>(r'/jss/(?P[-\w]+)/$', jss_list),
>)
> 
> On my django project I have:
> 
> urlpatterns = patterns('',
> # Access to the resume templates
> (r'^resumes/', include('agbo.resume_templates.urls')),
> )
> 
> Whenever I try to call the second view (jss_list) with a url such as
> localhost:8000/resumes/jss/no-experience/ I get into trouble.
> 
> Instead of calling the second, django calls the first one and the group
> "career" contains "no-experience".  It looks like the "/jss/" is being
> ignored, but I don't know why. :-?
> 
> 
> If I try a url that doesn't exist, I get some interesting information:
> 
> -- Page not Found error 
> Using the URLconf defined in resume_templates_biz.urls, Django tried
> these URL patterns, in this order: 
> 
>  1. ^admin/doc/
>  2. ^admin/(.*)
>  3. ^resumes/ (?P[-\w]+)/$
>  4. ^resumes/ /jss/(?P[-\w]+)/$
> 
> The current URL, resumes/, didn't match any of these.
> ---
> 
> The url patterns 3 and 4 have a space  between "^resumes/" and the rest.
> I have no idead where that space is coming from or if it's the cause of
> the error mentioned above.

I'm fairly certain the space indicates an urls came from an "include". 
The spaces are not really part of regex.

One problem is the jss regex should not start with / since your resumes 
ends with one.

Another problem is your regex's don't include ^ match start of text. 
Without you t run into problems with regex doing partial match at end of 
string. Just like you are having your example.

Since you omit the match start your 1st urls matches:
   /resumes/jss/no-experience/
and
   /resumes/anything/at/all/ending_with_a_word_and_a_slash/word/

In latter case career would be word


Your urls should be like this:
   (r'^(?P[-\w]+)/$', career_list),
   (r'^jss/(?P[-\w]+)/$', jss_list),


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
It's August!  Keep your cool with the Statesman.  Check out our hot
deals in print and online for back-to-school savings and more!

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



Re: django deploymennts

2008-08-19 Thread Norman Harman

Robin wrote:
> Hello,
> 
> I am trying to decide which tool should I use to deploy my django
> based application, and I have some candidates and want to know what
> are your opinion about this. My deployments will be in more than one
> server.
> 
> First I though about Capistrano, but I don't want to install/learn
> another language, so I look at some of the python based deployment
> tools. I found this ones:

Installing is trivial (apt-get/yum install ruby).  Learning Ruby is not 
necessary Having zero ruby knowledge(I still do) I was able to hack onto 
the Capistrano built in deployment recipes to do some very different 
than normal things.

Capistrano has a lot of batteries included, I highly recommend 
reconsidering looking at it.

> * Paver : http://www.blueskyonmars.com/projects/paver/
> * Vellum: http://www.zedshaw.com/projects/vellum/
> * Fabric: http://pypi.python.org/pypi/Fabric/0.0.3:
> * zc.buildout: http://pypi.python.org/pypi/zc.buildout

 > Does any of you have experience or pros-cons about any of this tools
 > or any other ?

buildout isn't really for deployments, I didn't get past reading about 
it before i decided it was not tool I'd want to use for deployment

> My deployment procedure will be, I hope, an easy one:
> 
> * download the version I want to deploy of the project (from
> subversion)
> * update database if needed
> * restart application server if needed

Deployments (or deployment procedures) are never as clean as one hopes.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
It's August!  Keep your cool with the Statesman.  Check out our hot
deals in print and online for back-to-school savings and more!

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



Re: Redirecting to different page depending on user authentication

2008-08-20 Thread Norman Harman

ad777 wrote:
> Hi there,
> 
> I am new at django and I was wondering what is the best way of
> redirecting users to their own customized page after they get
> authenticated.  I have extended the user model to include a unique
> user id for each user... is it somehow possible to use this?

The user model already had a unique user id!  It sounds like you should 
read through the django documentation 
http://www.djangoproject.com/documentation/ and / or django book 
http://www.djangobook.com/


There are probably several ways depending on what you want to do exactly.


Redirecting users:

The standard way to redirect is to return an HttpResponseRedirect from a 
view.  But the authentication system has a few alternatives see 
http://www.djangoproject.com/documentation/authentication/#authentication-in-web-requests
 
and look for the "next" parameter.


User Customized pages:

The request instance that each view receives has a request.user 
attribute which is the current user (could be anonymous) see 
http://www.djangoproject.com/documentation/authentication/#users

This can be used to customize the view for the user in whatever way you 
desire.


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
It's August!  Keep your cool with the Statesman.  Check out our hot
deals in print and online for back-to-school savings and more!

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



Re: Renaming of mailing lists to avoid user confusion

2008-08-20 Thread Norman Harman

Malcolm Tredinnick wrote:
> Because over the last three years, this group has done an *excellent*
> job at providing help and support. And, yes, I have the credibility to
> make that claim: I have never posted a request for support on this list
> and have posted the most number of mails to the list of anybody over the
> years. 
> 
> Moving from something available as a mailing list to a web forum will
> fragment and reduce the audience.
> 
> Malcolm

As a lng time reader of django-users I can attest to how helpful it 
and Malcolm's post were/are.

A large part of my Django knowledge is due to this list and esp Malcolm, 
thanks btw.  And I'm now happily contributing back answering whatever 
posts I can when I have the time.  But checking a couple times a day 
it's rare to find post that hasn't already been answered.


I don't see what problem is trying to be solved.

The legion of Django users is ever growing.  So much so it's now 
relatively easy to get a Python dev job due in large part I believe to 
Django's popularity and successes(at least I got one).  Besides 
excellent base documentation, there are free books, blogs, 
cookbook/snippet site, IRC, and mailing lists.  Help is abundant and in 
many forms.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
It's August!  Keep your cool with the Statesman.  Check out our hot
deals in print and online for back-to-school savings and more!

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



Re: Reverse URL Questions

2008-08-21 Thread Norman Harman

On Thu, Aug 21, 2008 at 1:50 AM, Rodney Topor <[EMAIL PROTECTED]> wrote:
> Second: Doesn't the use of get_absolute_url() somehow violate the
> separation of URLs from models?

I think so.

I have found named urls 
http://www.djangoproject.com/documentation/url_dispatch/#naming-url-patterns 
  url tag in 
templateshttp://www.djangoproject.com/documentation/templates/#url and 
reverse() in views/models/other to be excellent solution and the best 
way to handle this.

Define your urls once in one place, your urls.py file.  Change them and 
magically everything else just works.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
It's August!  Keep your cool with the Statesman.  Check out our hot
deals in print and online for back-to-school savings and more!

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



Re: Init Parameter Trouble

2008-08-21 Thread Norman Harman

Robert wrote:
> Hello all,
Can we see your view code please?

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
It's August!  Keep your cool with the Statesman.  Check out our hot
deals in print and online for back-to-school savings and more!

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



Re: Help needed: too complex for me

2008-08-21 Thread Norman Harman

space0x42 wrote:
> Hi all
hi,

I bet your getting an error since the labels property has no "setter" 
only a getter and you are trying to assign to it.

I'd probably try to rewrite the models with proper model fields instead 
of that label.  But, might not be an option nor good option for someone 
new to Django

An alternative is to write the setter.  This is how I'd do it(I learned 
properties before the @decorator syntax and so use old style syntax)

def _prop_get_labels(self):
#code that gets labels
def _prop_set_labels(self, labels):
#code that sets labels
labels = property(_prop_get_labels, _prop_set_lables, doc="""lables!""")

Then your assignment
article.labels = labels
won't throw an exception, at least not for same reason ;)

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
It's August!  Keep your cool with the Statesman.  Check out our hot
deals in print and online for back-to-school savings and more!

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



Re: custom widget necessary?

2008-08-25 Thread Norman Harman

peter_g wrote:
> Hi!
> 
> I have datetime fields like "createdate" or "modified" in some of my
> models.
> Do I need to create custom widgets if i want their time and date to
> be displayed in the admin area (change-form) and not the default
> editable representation (text fields, with "now" etc. shortcuts)?
> 
> Like, e.g.
> 
> Created: 08/25/2008 09:20am
> 
> Do you have links to examples?

http://www.djangosnippets.org/snippets/937/


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
It's August!  Keep your cool with the Statesman.  Check out our hot
deals in print and online for back-to-school savings and more!

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



Re: Calling attributes from other models

2008-08-25 Thread Norman Harman

Matt Berg wrote:
> I apologize, I realize this is probably documented somewhere.
> 
> Say I have 2 models.
> 
> Artist and Album
> 
> Album has a foreign key to Artist.
> 
> I want to do a list_display of Albums something like this...
> 
>   list_display = ('album','release_date','artist')
> 
> This works fine and displays the info under the key for Artist.  What
> I would like to do is access some of the other attributes of Artist.
> Trying artist.hometown and artist[hometown] doesn't work.

One way to do this is to create helper functions.

def _get_artist_hometown(self):
return self.artist.hometown


list_display = ('album','release_date',_get_artist_hometown)

There're different options see 
http://www.djangoproject.com/documentation/admin/#list-display

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
It's August!  Keep your cool with the Statesman.  Check out our hot
deals in print and online for back-to-school savings and more!

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



Re: Modules path when importing models

2008-08-25 Thread Norman Harman

Alexis Bellido wrote:
> I'm reading the Django book and playing with the  'mysite' test site,
> in many parts I've noticed something like this in views.py:
> 
> from mysite.models import Event, BlogEntry
> 
> I was wondering if it's good practice using 'mysite.models' (which
> seems to be an 'absolute path' for importing) or if it would be better
> using just:
> 
> from models import Event, BlogEntry
> 
> (which seems to be a 'relative path' because usually views.py is in
> the same directory than models.py).
> 
> Could somebody explain a little about the best way to do the imports?

I believe, nay I know, relative imports are evil.  It's easy to get 
confused which models "from models" represents.  Esp when/if there are 
multiple models.py in your Python path.  Maybe not with models.py but it 
happens, believe me I've wasted too much time on it.  Just don't do it.

But it's also wrong to tie apps to a particular site.  This is bad:

   from mysite.myapp.models import

Your models views, etc should be under myapp not mysite.  and the 
directory(ies) were all your apps are should be on python path. Then

   from myapp.models import blah.

For maximun portability and flexibility mysite should not appear in any 
import.

For my projects I create a directory like /web/www.example.com/python, I 
put that directory on the Python Path and put all my apps plus 
settings.py file in that directory.


some reading http://www.b-list.org/weblog/2007/nov/09/projects/
and 
http://www.pointy-stick.com/blog/2007/11/09/django-tip-developing-without-projects/
-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
It's August!  Keep your cool with the Statesman.  Check out our hot
deals in print and online for back-to-school savings and more!

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



Re: Building ORM relations without saving...

2008-08-29 Thread Norman Harman

Koen Bok wrote:
> I'd like to build object relations (Model classes) without saving them
> to the database to predict a price for a specific order. Let's say I
> have this:
> 
> class Order(Model):
>   id = models.AutoField(primary_key=True)
>   number = models.IntegerField()
> 
>   def total(self):
>   return sum([p.price for p in self.product_set])
> 
> class Product(Model):
>   id = models.AutoField(primary_key=True)
>   order = models.ForeignKey(Order)
>   price = models.DecimalField()
> 
> order = Order(number=1)
> 
> # Now the nex line throws an error if we did not save the order here
> order.product_set.create(Product(price=20.0))
> 
> assert order.total() == 20.0

That would be very hard i think(relations work with primary keys and 
typically primary keys are only exist after save.

An alternative solution is to make a method that takes a set of products 
and produces total for them.


I'd proly put sum_products in an OrderManager or maybe ProductManger but 
not bothering with that here.

class Order(Model):
id = models.AutoField(primary_key=True)
number = models.IntegerField()

def total(self):
return sum_products(self.product_set)

def sum_products(self, products):
# maybe some other logic here such as customer discount, tax 
calc, etc.
return sum([p.price for p in products])


def test_sum_products(self):
   order = Order(number=1)
   product_list = [Product(price=20.0), ]
   self.assertEqual( 20.0, order.sum_products(product_list) )




-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: Apache httpd conf with mod_python

2008-09-08 Thread Norman Harman

[EMAIL PROTECTED] wrote:
> Setting our Apache server at work, got everything installed. In the
> httpd.conf there's quite a bit of content, do I need that content, or
> should I just replace it with what I need for Django?

You probably don't need all of it.  But I doubt anything will work if 
you get rid of all of it.  You need to add what Django requires.

But, it sounds like you don't know/understand Apache conf files which 
you probably should.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: How to prevent URL HTML encoding?

2008-09-12 Thread Norman Harman

Ross wrote:
> I setup a URL that accepts any number of characters and the '+'
> symbol, which works just fine.
> 
> /search/pets/dog+cat
> /search/pets/turtle
> /search/pets/turtle+cat+mouse
> 
> All of those URLs go to the same view. The view splits the third
> argument on the '+' symbol and uses the list to do some work. The
> problem is, when I call render_to_response to display the template,
> Django encodes the '+' symbols in the URL. The user's address bar
> shows '/search/pets/dog%2Bcat' instead of preserving the '+' symbols.
> 
> Is there a way to prevent that?

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe

http://docs.djangoproject.com/en/dev/topics/templates/#id2


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: Accessing field names and data from a queryset in a generic template

2008-09-12 Thread Norman Harman

SnappyDjangoUser wrote:
> I am a new django user so please excuse my naive question.
> 
> I have a generic view function (see below) which is used to perform a
> query on one of many tables (depending on the "model" argument) and
> then render the results to a single template file (object_list.html)
> 
> def item_list(request, model='device'):
> # determine which table
> TableName = ModelNameDictionary[model]
> order_by_field = OrderByFieldDictionary[model]
> 
> # Get a list of all entires for this object
> if order_by_field == '':
> latest_object_list = TableName.objects.all()
> else:
> latest_object_list =
> TableName.objects.all().order_by(order_by_field)
> 
> # Get the number of objects.
> paginator = Paginator(latest_object_list, 0)
> result_count = paginator._get_count()
> 
> t = loader.get_template('object_list.html')
> c = Context({
> 'ObjectName': NameDictionary[model],
> 'latest_object_list': latest_object_list,
> 'result_count': result_count,
> })
> return HttpResponse(t.render(c))
> 
> I am planning on using a generic template (object_list.html) to print
> the data in a tabular format.  How can I access the database field
> names and the data if I don't know which table was queried and is
> being renderd?  Below is pseudo code from object_list.html that I am
> looking for help filling in
> 
> {% if latest_object_list %}
> 
> 
> 
> {% for header in latest_object_list %}
> {{ header.field_name }}
> {% endfor %}
> 
> 
> 
> {% for item in latest_object_list %}
> 
> {% for column in item %}
> {{ item.column_data }}
> {% endfor %}
> 
> {% endfor %}
> 
> 
> {% else %}
> No {{ ObjectName }} are available.
> {% endif %}


I assume the field names are different for different models or you 
shouldn't be asking this question...


There are several ways I can think of:


Create methods in models (or do this in view) that return a list of the 
field names you want displayed and another that returns the field's 
values in the same order.  Access them via loops in template.


Create base template and extend that with model specific templates. 
Each of which knows how to display the columns for a particular model.

 > {% for item in latest_object_list %}
 > 
{% block columns %}{% endblock %}
 > 
 > {% endfor %}


The model speciific templates would be just the
{% extend base_template %}
{% block columns %}
   {{ item.column_one }}
   {{ item.column_two }}
   {{ item.column_etc }}
{% endblock %}
part customized for each model.  In the view select the correct template 
like so:

   t = loader.get_template('%s_list.html' % model.__name__)


Create a wrapper aka "interface" or "proxy" that translates a standard 
set of fieldnames into the model specific fieldnames.  So as far as the 
template is concerned there is only one type of "model", the proxy one.








-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: Problem with named paths

2008-09-17 Thread Norman Harman

Brandon Taylor wrote:
> Hello everyone,
> 
> I'm using named paths as such:
> 
> url(r'^[-\w]+/(?P[-\w]+)/$', 'render_page',
> name='nested_page_link'),
> url(r'^(?P[-\w]+)/$', 'render_page', name='page_link'),
> 
> The only difference between these two urls is that some pages in this
> site can be nested under another page. So, I would like to be able to
> use one view action to render the page, as all I really need to pass
> to the action is the 'page_slug':
> 
> def render_page(request, *args, **kwargs):
> return render_to_response('dynamic_page.html', {'page_slug' :
> kwargs['page_slug']})
> 
> 
> But, this throws an error:
> 
> Reverse for 'crider_law.nested_page_link' with arguments '(u'who-we-
> are', u'how-we-are-different')' and keyword arguments '{}' not found.
> 
> What am I doing wrong?

Do you use {% url %} tag in that template 'dynamic_page.html'?

and I think it's better not to use *args, **kwargs unless there is a 
good reason.  They tend to hide bugs.

def render_page(request, page_slug):
  return render_to_response('dynamic_page.html', 
{'page_slug':page_slug})

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: Reusable views from a template - How?

2008-09-17 Thread Norman Harman

WillF wrote:
> 
> 
> 
> David Durham, Jr. wrote:
>>
>> On Wed, Sep 17, 2008 at 1:35 PM, WillF <[EMAIL PROTECTED]> wrote:
>>> I have written a login view as I have followed the tutorial but how do I
>>> reuse this view in multiple pages of the site?
>>>
>>> Is there a way to render this particular view as part of a template, so I
>>> could have the login form (or anything for that matter) be displayed on
>>> every single page?
>> Have you read up on template inheritance?
>> http://docs.djangoproject.com/en/dev/topics/templates/#id1
>>
>>
> 
> I've read that part, I can see how that would work if I statically define
> the form. But right now I have
> a view defined that pushes out the LoginForm to my template. So say I have
> another view which populates the links dynamically... How do I incorporate
> both of these with inheritance, I could have one block for login and one
> block for links, but then how do the Login and Links views (where I'm
> passing the forms) fit into this picture?  
> 
> Perhaps I'm missing something.


If I understand you correctly... I don't think there's anything that 
automerges your forms.  You have to do it by "hand".

If two forms need the same logic I put that in it's own function and 
then call that function from each of the views.


function add_links_to_context(context):
   magical_stuff

function links_only_view(request):
   context = RequestContext()
   add_links_to_context(context)
   render_to_response(...

function links_n_form(request):
   context = RequestContext()
   # action of this form points to handle_form view
   context["form"] = MyForm()
   add_links_to_context(context)
   render_to_response(...

function handle_form(request, where_to_redirect_to):
   form handling logic here
   HttpRedirect(where_to_redirect_to)


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: Can not under stand the error obtained when validating a model.py

2008-09-17 Thread Norman Harman

Karthik Krishnan wrote:
> The stack trace is given below
> 
> Traceback (most recent call last):
>   File "manage.py", line 11, in 
> execute_manager(settings)
>   File "c:\tools\Python25\Lib\site-packages\django\core\management
> \__init__.py",
>  line 340, in execute_manager
> utility.execute()
>   File "c:\tools\Python25\Lib\site-packages\django\core\management
> \__init__.py",
>  line 295, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "c:\tools\Python25\Lib\site-packages\django\core\management
> \base.py", lin
> e 77, in run_from_argv
> self.execute(*args, **options.__dict__)
>   File "c:\tools\Python25\Lib\site-packages\django\core\management
> \base.py", lin
> e 87, in execute
> translation.activate('en-us')
>   File "c:\tools\Python25\Lib\site-packages\django\utils\translation
> \__init__.py
> ", line 73, in activate
> return real_activate(language)
>   File "c:\tools\Python25\Lib\site-packages\django\utils\translation
> \__init__.py
> ", line 43, in delayed_loader
> return g['real_%s' % caller](*args, **kwargs)
>   File "c:\tools\Python25\Lib\site-packages\django\utils\translation
> \trans_real.
> py", line 209, in activate
> _active[currentThread()] = translation(language)
>   File "c:\tools\Python25\Lib\site-packages\django\utils\translation
> \trans_real.
> py", line 198, in translation
> default_translation = _fetch(settings.LANGUAGE_CODE)
>   File "c:\tools\Python25\Lib\site-packages\django\utils\translation
> \trans_real.
> py", line 181, in _fetch
> app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]),
> appname[p+1:
> ])
>   File "c:\tools\Python25\Lib\site-packages\django\contrib\admin
> \__init__.py", l
> ine 1, in 
> from django.contrib.admin.options import ModelAdmin, HORIZONTAL,
> VERTICAL
>   File "c:\tools\Python25\Lib\site-packages\django\contrib\admin
> \options.py", li
> ne 5, in 
> from django.contrib.contenttypes.models import ContentType
>   File "c:\tools\Python25\Lib\site-packages\django\contrib\contenttypes
> \models.p
> y", line 1, in 
> from django.db import models
>   File "c:\tools\Python25\Lib\site-packages\django\db\models
> \__init__.py", line
> 5, in 
> from django.db.models.query import Q
>   File "c:\tools\Python25\Lib\site-packages\django\db\models
> \query.py", line 7,
> in 
> from django.db.models.fields import DateField
>   File "C:\tools\Python25\lib\site-packages\django\db\models\fields
> \__init__.py"
> , line 666
> class DecimalField(max_digits = 32, decimal_places =
> 0)IntegerField(Field):
>   ^
> SyntaxError: invalid syntax
> 
> The stack trace does not define which line has an incorrect syntax. I
> am having this error even there is nothing in the models.py file.

It says it happened on line 666 of 
C:\tools\Python25\lib\site-packages\django\db\models\fields\__init__.py 
just at the equals sign "max_digits = 32".

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: Two Django visions running at once.

2008-09-17 Thread Norman Harman

KillaBee wrote:
> Is it possible to have two versions of django running at the same time
> on an Ubuntu server(9.0 and 1.0)?

Yes, depending on your definition of "running".

Far too much depends on how you've set things up and what exactly you 
want to accomplish to give advice.  Esp based on the little bit of 
information you have provided.

It is also probably not a Django question but a sysadmin question.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: resolving urls template error

2008-09-18 Thread Norman Harman

Sven Richter wrote:
> when i try to call:
> {% url profile_myiq argument %}

> NoReverseMatch: Reverse for 'youriq.profile_myiq' with arguments '('',)' and 
> keyword arguments '{}' not found.

>   (r'^(?P\w+)/$', 'user', {} 'profile_myiq'),

The error indicates you were providing either empty string, '', or the 
litteral characters '',  (not sure the formating, probably is the former)

Neither of which match the regex for arg "name".  "\w+" matches 1 or 
more word characters.

So, I'm guessing your argument in url tag is wrong.

{% url profile_myiq argument %}


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: Querysets and includes

2008-09-22 Thread Norman Harman

nek4life wrote:
> How would I go about getting a queryset into an include?  Say I have a
> blog and I have a page for the post detail.  On the sidebar I would
> like to have the blog categories dynamically built or have recent
> articles, or recent comments, etc...  What would be the best approach
> to build these "widgets" for use on multiple pages?  Any help would be
> much appreciated.  Thanks.

Custom Template Tags? 
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: Querysets and includes

2008-09-22 Thread Norman Harman

Charles Choiniere wrote:
> On Mon, Sep 22, 2008 at 10:46 AM, Norman Harman <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
> 
> nek4life wrote:
>  > How would I go about getting a queryset into an include?  Say I
> have a
>  > blog and I have a page for the post detail.  On the sidebar I would
>  > like to have the blog categories dynamically built or have recent
>  > articles, or recent comments, etc...  What would be the best approach
>  > to build these "widgets" for use on multiple pages?  Any help
> would be
>  > much appreciated.  Thanks.
> 
> Custom Template Tags?
> 
> http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags
> 
> 
> --
> Norman J. Harman Jr.
> Senior Web Specialist, Austin American-Statesman
> 
> ___
> Get off the sidelines and huddle up with the Statesman all season long
> for complete high school, college and pro coverage in print and online!
> 
> 
> 
> I was looking at that and found the inclusions tags and that looks like 
> what I need, however I'm a little unsure about where to put this 
> function.  Would I put this in the model I want to pull the data from? 
>  I haven't extended the templating system before so I'm a wee bit confused. 

http://docs.djangoproject.com/en/dev/topics/templates/#custom-libraries-and-template-inheritance

http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags

"The app should contain a templatetags directory, at the same level as 
models.py, views.py, etc. If this doesn’t already exist, create it - 
don’t forget the __init__.py file to ensure the directory is treated as 
a Python package.

Your custom tags and filters will live in a module inside the 
templatetags directory. The name of the module file is the name you’ll 
use to load the tags later, so be careful to pick a name that won’t 
clash with custom tags and filters in another app."

Saying all that, depending on what you're actually doing, putting the 
actual "logic" into a method on a model that the template tag calls (as 
opposed to putting the logic in the template tag itself) might make 
sense.  In other instances it might not.

Very general rule:

   If it's doing display/formating type stuff put it in the template tag.

   If it's doing db stuff, calculations based on model fields, proly 
should be in the model.

This is a core of OO & MVC.  each layer/object should do it's thing and 
not get involved in what other layers/objects are doing.


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: function import errors model import in other file

2008-09-22 Thread Norman Harman

Gerard Petersen wrote:
> Hi All,
> 
> I'm trying to import a function. When adding this statement I get a Model 
> import error in a completely different place, not even related. I've added 
> the files from my app directory and their import statements below. 
> 
> Are there any unauthorized imports being done?
> Do I need to specify more exact since it's a deviating filename?
> Do I need to add the deviating filenames (myforms.py, myfunctions.py) to 
> settings.py or _init__.py?
> 
> I'm completely lost. Thanx a lot!
> 
> Regards,
> 
> Gerard.
> 
> 
> ## __init__.py
> empty!
> 
> ## urls.py
> from django.conf.urls.defaults import *
> from django.contrib import admin
> from django.conf import settings
> 
> ## views.py
> from django.shortcuts import render_to_response, get_object_or_404
> from django.conf.urls.defaults import *
> from django.http import Http404, HttpResponseRedirect, HttpResponse
> from django.core.urlresolvers import reverse
> from models import *
> from myforms import *
> from myfunctions import *
> from datetime import datetime
> 
> ## models.py
> from django.db import models
> from django.contrib import admin
> from statemachine import Machine
> import datetime
> 
> ## myforms.py
> from models import *
> from django.forms import *
> 
> ## statemachine.py
> from django.db import models
> from django.utils.functional import curry
> from myfunctions import current_date  << Adding this one
> 
> ## myfunctions.py
> from django.db import models
> from models import MetaData   << Breaks this one
> from datetime import datetime, timedelta
> from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_DOWN
> 
> With this >> ImportError: cannot import name MetaData
> 
> Full trace: http://paste.pocoo.org/show/85970/
> 
> 
> Thanx again!
> 
> 
It looks like you have made a circular import:

   statemachine imports myfunctions which imports models which imports 
statemachine == doh!

Don't do that.


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: strategy for deploying to production server

2008-09-23 Thread Norman Harman

sotirac wrote:
> Just trying to get a feel for what other developers are doing when
> deploying to a production server.  There are some differences between
> my development machine and production server such as the location of
> my media files, the database settings, and if I want to enable caching
> or not.   Right now my option is to comment out some of the code and
> uncomment the other values.  This is time consuming and error proned.
> How do you deal with this issue of working in your development machine
> and then having to deploy the same code into your production server.

Most systems I work on are complex multidev setups, testing setup, 
production (multiple web boxes, db, etc.)

I have found capistrano to be an excellent tool for automating all the 
steps needed to deploy to the various above targets.  It's in Ruby, but 
I was able to use it effectively and I don't know Ruby(At least I don't 
think I do :).  It is not a simple tool though.  Probably overkill for 
people with just a simple hosted server.


I have a proj_base_settings.py that has strangely  enough the base 
settings for project proj

Each dev/test/production environment has a proj_settings.py that imports 
proj_base_settings.py and overrides whatever is required.  This is often 
just setting DEBUG, email addy, and db.  This file is not checked into 
source control.


I prepend proj_ to all the settings files so I can have multiple 
projects in same python path with out conflicts.


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: Querying Users with Permission

2008-09-25 Thread Norman Harman

bobbyc881 wrote:
> I'm generating a list of Users in a specific group, in this case,
> "Artists", for a form:
> 
> artist_group = Group.objects.get(name="Artists")
> artist =
> forms.ModelChoiceField(queryset=User.objects.filter(groups=artist_group),
> required=False)
> 
> I'd like to re-write this to avoid using a Group that could get
> renamed, deleted, or change some other way in the future. I've created
> a custom permission called "in_artist_pulldown" to use. Is there a way
> to query Users that have the permission "in_artist_pulldown."  I can't
> quite seem to figure out how to access that.


User has a many to many relation with Permissions 
http://docs.djangoproject.com/en/dev/topics/db/queries/#many-to-many-relationships

user_permissions is the field name.

So, I think the syntax would be this.

   permission = Permission.objects.get(name="in_artist_pulldown")
   users = permission.users.all()

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Re: actual django stack

2008-09-25 Thread Norman Harman

Frédéric Sidler wrote:
> What it the best Django stack today.
> 
> In django doc, it says that apache with mod_python is the best
> solution in production. But in the same time I see that everyblock use
> nginx (probably in mode fastcgi).
> 
> Did you some of you test different solution and can share some output here.
> 
> Here are the ones I see actually
> 
> Apache mod_python
> Apache in fastcgi mode
> Lighttpd in fastcgi mode
> Nginx in fastcgi mode
> 
> I'm not talking about load balancer, memcached and database here, just
> the application.

"Best" for what?  Best has different meaning for different needs.  If 
you know enough to ask this question you should know enough to answer it 
for your particular situation.

Apache and mod_python is probably the easiest/most common/most tested 
and therefor probably the best to recommend to Djangonista's just 
starting out.

And you forgot wsgi options ;)


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



http://alt.coxnewsweb.com/statesman/img/photos/3699112.jpg

2008-10-17 Thread Norman Harman

is there

Sorry for the screw up
-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
Get off the sidelines and huddle up with the Statesman all season long
for complete high school, college and pro coverage in print and online!

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



Unsubsubscribe

2010-06-06 Thread Jim Norman
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

How do I unsubscribe from this list?

Jim Norman
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkwMVVMACgkQ677kSNWvnhS3EQCeO2OguYmNhKiyywl2HqXnLslF
yUYAn2SxlG+C359KA0quWLNsq0VNn0QA
=DPg7
-END PGP SIGNATURE-

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



Cache middleware causing unit tests to fail

2007-08-16 Thread Norman Harman

Hi,

request.template is None instead of what it should be because the response is 
from the 
cache middleware.

Which is fine.   My question is there a good way to disable the cache 
middleware during 
tests?

"good" being atleast the following. is automatic, isn't based of value of 
DEBUG, doesn't 
require changing django distro.

Is there a special settings file or other file imported during tests only?

thanks,
njharman

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



Re: Cache middleware causing unit tests to fail

2007-08-19 Thread Norman Harman

Eratothene wrote:
> I think you better not disable cache middleware in tests. If tests
> fail, so will be in production. I had similar problem, I thought it
> was something wrong with tests, but really it was problem in the code.
> My site was running well on django built-in server, but not on apache
> mod_python.

My site was working fine.  My unittests was what were in error.

Yeah there are going to be differences between production and devel.  But, 
personally I 
believe unittests should test one thing.  Not many things at once such as 
cache/view/db 
(as an aside I'm sort of sad django doesn't have a mock db for view unittests)

So, I think you should test your cache framework and how your app uses it, but, 
those 
tests should not be part of the view unittests.

I was testing that a specific template was being used to render page.  With 
caching the 
correct behavior is to not use any template, not to render at all, but rather 
to pump 
contents of cache down the wire.

In my test_settings.py file I have:
   # disable cache for testing
   MIDDLEWARE_CLASSES.remove('django.middleware.cache.CacheMiddleware')
   CACHE_BACKEND = "dummy:///"

Then run
   python manage.py --settings=test_settings test
works beautifully.


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



Re: Link that performs an action

2008-04-10 Thread Norman Harman


Taylor wrote:
> Does something exist so that a link on a page performs an action
> rather than just showing a view?
> For example: I have a counter saved to the db, and every time a user
> clicks the link, the counter increases by a certain number and saves.
>   
>
> without even visiting the page that the link
> is on by visiting the URL directly.
They can only visit the page if you provide an url it.  Just don't make 
any url that displays page without your counter

I don't think I understand what you want, since what I think you want is 
super trivial. But...

def my_view(request):
 counter = Counter.objects.get(id=someid)
 counter.count += 1
 counter.save()
 # Or see 
http://www.djangoproject.com/documentation/request_response/ if you want 
to use different value/counter based on what page led them to current view.
 # referer is unreliable
 refer = request.META.get( "HTTP_REFERER", None)
 counter = Counter.objects.get(refer=refer)
 counter.count += 1
 counter.save()
 # do whatever to show view

Which is not a great way of doing it (db hit every page view, fails when 
you start caching results) but those don't matter unless your site is 
real busy.

another option parsing apache/nginx/whatever logs for whenever 
particular url(s) where responded to.

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman

___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: Link that performs an action

2008-04-11 Thread Norman Harman

Taylor wrote:
> Thanks for the replies, but I guess I didn't make myself clear
> enough.  Counter was just as an example, I don't want an actual page
> counter.
>
> I guess part of my question is:  Yes, I can use AJAX-y XMLHttpRequest
> to send info to the server in the background, but has someone done
> this already in django somewhere and posted code that can be plugged
> in?
>
> The idea is to have a view like this:
> def my_view(request,num=0):
>  counter = Counter.objects.get(id=someid)
>  counter.count += num
>  counter.save()
>  # setup view stuff
>
> but without specifying num in the URL or having to use a  in my
> template.
>
> Thanks
>
>   
If num isn't in the URL and it isn't a GET/POST parameter, where is it 
coming from?

For front end of AJAX, use whatever Javascript lib/code you like, Jquery 
is my choice. Django doesn't come with or dictate a particular one.  The 
back end, Django part, of AJAX works exactly like any other view but 
return JSON or XML data instead of HTML.

def my_view(request)
data = simplejson.dumps(Model.objects.filter(somefilter=whatever))
return HttpResponse(data, mimetype="text/javascript")

or
http://www.djangoproject.com/documentation/serialization/

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman

___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: how do I create a zebra table using a template?

2008-04-11 Thread Norman Harman

Kenneth Gonsalves wrote:
> On 11-Apr-08, at 9:36 PM, Kenneth Gonsalves wrote:
>
>   
>> On 11-Apr-08, at 9:28 PM, Chas. Owens wrote:
>>
>> 
>>> {% if forloop.counter % 2 %}
>>>   
>> divisibleby
>> 
>
> http://www.djangoproject.com/documentation/templates/#divisibleby
>
>   
Wouldn't http://www.djangoproject.com/documentation/templates/#cycle be 
a better solution?  I think it was designed exactly for zebra tables.

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman

___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: How to extend django.views.generic.date_based to return more "context variables"?

2008-04-14 Thread Norman Harman

Why don't you use the extra_context parameter to generic views?  Or am I 
misunderstanding what you are trying to do?

def myview(request):
   context = dict()
   context["my_custom_var"] = "wwgd"
   return generic_view(request, extra_context = context, bla=blah,...)

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman

___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: How to extend django.views.generic.date_based to return more "context variables"?

2008-04-14 Thread Norman Harman

fizban wrote:
>
> On 14 Apr, 16:54, "Norman Harman" <[EMAIL PROTECTED]> wrote:
>   
>> Why don't you use the extra_context parameter to generic views?  Or am I
>> misunderstanding what you are trying to do?
>>
>> def myview(request):
>>context = dict()
>>context["my_custom_var"] = "wwgd"
>>return generic_view(request, extra_context = context, bla=blah,...)
>> 
>
> I have just tried setting it up but it is returning a 404 when I try
> to load the page (and it obviously works with date_based.object_detail
> and/or my custom "entry_detail")
>
> This is the view I tried to setup:
>
> def myview(request, year, month, day, queryset, date_field,
> month_format, slug, template_object_name):
>   context = dict()
>   context['year'] = year
>   context['month'] = month
>   context['day'] = day
>
>   return date_based.object_detail(
>   request, year, month, day, queryset, date_field, month_format, 
> slug,
> template_object_name, extra_context=context,
>   )
>
> As far as I understood your suggestion and the docs I found it should
> work, shouldn't it?
>
> The urlconf, beside the from ... import statements is the following:
>
>
> entry_info_dict = {
>   'queryset': Entry.live.all(),
>   'date_field': 'pub_date',
> }
>
> urlpatterns = patterns('django.views.generic.date_based',
>   (r'(?P\d{4})/(?P\d{2})/(?P\d{2})/(?P[\w\d\-]
> +)/$', myview, dict(entry_info_dict, month_format='%m',
> template_object_name='entry')),
> )
>
> (I'm using django.views.generic.date_based there since it's needed by
> the other patterns, I didn't include them since they are relevant --
> however it won't work even if I snip it out)
>
>   

myview should be in the views.py of your app.  The urlpatterns above is 
pointing to some django views file.  You shouldn't edit the django 
source if you can avoid it.

urlpatterns = patterns('',
(r'(?P\d{4})/(?P\d{2})/(?P\d{2})/(?P[\w\d\-]
+)/$', "myapp.views.myview", dict(entry_info_dict, month_format='%m', 
template_object_name='entry')),
)


Not sure if that caused your 404.  They are usually caused by missing 
data (if you used incorrect slug in url), or if regex in urlpatterns is 
wrong.  Turning debug=True in your settings.py should give you more 
information on why there is 404's.

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman

___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: Distributed databases

2008-04-16 Thread Norman Harman

I've never seen anything that would make this "easy" in Django itself.  
You will probably have more luck looking into sql proxies.  Django will 
talk to the proxy, the proxy will figure out what database to actually 
query and return results to Django.  This way Django doesn't have to 
change, doesn't have to even know any thing funky is going on.  Btw, 
Isolated layers like that is a great way to architect a system.

I don't have a sql proxy to recommend, Google does though.

___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: Enterprise applications with Django

2008-04-16 Thread Norman Harman

Hussein B wrote:
> In Java we have a dedicated component model for business logic (EJB)
> and the ability to call remotely other components
> With Java, we can create 3-tier enterprise applications not to mention
> a cluster of servers.
> I didn't play with Django yet but it seems to me that the presentation
> and logic are located on the same server for Django applications.
>
>   

Have you looked at PEAK Python Enterprise Application Kit 
http://peak.telecommunity.com/

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman

___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: Can I print out the context from within a template?

2008-04-18 Thread Norman Harman

Salim Fadhley wrote:
> yml,
> 
> If I want to disable this behavior, is it possible? When a template
> tries to reference an invalid object (e.g. a context variable which
> has not been defined) I'd like to throw an exception. I do not want to
> invent a value.

In my test_settings.py file I put

TEMPLATE_STRING_IF_INVALID = "test_oops_test"

I've subclassed Django's UnitTest.assertTemplateUsed to fail (with 
appropriate message) if it finds that text in the rendered html. And, of 
course, there are unittests that "exercise" all my views and their 
variations.

Not exactly what you are asking for but I find it better to fail 
unittests than throw exception at runtime.

Alternatively or in addition you could set your production settings.py 
to something like,

TEMPLATE_STRING_IF_INVALID = "this is a bug please email 
[EMAIL PROTECTED]"

-- 
Norman J. Harman Jr.
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: At what point does a model get its own app? Wigging as I try to adjust to the Django way.

2008-04-24 Thread Norman Harman

Erik Vorhes wrote:
> There's nothing wrong with parceling out models across different apps.
> And unless you're planning on distributing each app separately, don't
> worry about cross-app dependencies.
> 
> In this case, I'd encourage you to--since you'll probably want to do
> more than just book-related stuff with your people. (The same could be
> said about the books.)
> 
> Another reason to have 2 apps for these models is overall growth of
> models.py. The more code that's there, the harder it becomes to edit.
> (I'm in the process of parceling out a bunch of models myself. Don't
> give yourself that headache!)

If you are distributing apps separately you can use conttenttypes and 
generic relations.

http://www.djangoproject.com/documentation/models/generic_relations/

django-tagging django-voting are some apps that use that.  Find them on 
google code.

-- 
Norman J. Harman Jr.
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: Few things ive been wondering

2008-05-06 Thread Norman Harman

phillc wrote:
  > first:
> 
> How does one develop tests for django web apps?
> im having trouble writing tests.
> i understand there are view tests, but those are so overly complex to
> write.
> i was just wondering how other people approach it, and if anyone can
> point me to some open source application that uses tests properly.
> i would love to give test driven development a try, but right now, i
> feel that my code is too bound to code in my view, which im having
> trouble making unit tests for. (id love to see a django project
> somewhere that was test driven)

TDD is very hard.  I rarely muster the discipline to do pure TDD.  But, 
TDD isn't required to have unittests, which are awesome by themselves.

If you haven't already read 
http://www.djangoproject.com/documentation/testing/

View tests don't have to be complex, the minimal test for a non-form 
view checks quite alot:

urls.py
urlpatterns = patterns("specials.views",
 url(r"^$", "ads", name="ts_ads"))

tests.py
 def test_specials(self):
 url = reverse("ts_ads")
 response = self.client.get(url)
 self.assertTemplateUsed(response, "specials/ads.html")


Basically if I write it I test it.  Don't test that Django works or your 
database works.  They should have their own tests.

For views I mostly don't check they return the expected html(it changes 
too often during development and I think that is better handled with a 
tool such as Selenium).  Instead I check that they use correct template, 
redirect to login page, don't raise exceptions, etc.  I also have 
written a custom UnitTest (extending Django's) that checks for empty 
template vars using TEMPLATE_STRING_IF_INVALID='test_oops_test'.

I do POST to views that have forms and check they work as expected. 
Although, I usually check form validation in separate forms tests.

I check forms with any custom validators or logic.

I check every method I write for models and model managers including 
things like __unicode__ via str(modelinstance).

Also, Every time I find a bug I first write a unittest that fails 
because of that bug.  Then I fix the bug and check unittest then passes.


> fourth:
> 
> i never understood this, why do people do
> 
> somevar = "blah blah %s" % anothervar
> 
> instead of "blah bla" + anothervar
> ?

Since python strings are immutable using + causes a lot of unnecessary 
copying.  It's probably not such a big deal in rarely executed code but 
is a real performance killer in loops.  For consistency and clarity, 
people tend to avoid using + with strings altogether.

For example this is slow/unnecessary:
   s = ""
   for txt in somelist:
 s += txt
   print s

The Pythonic way is to use a list:
   s = list()
   for txt in somelist:
 s.append(txt)
   print "".join(s)

Joining a list of strings is neat because instead of "" you can use ", " 
or "\n", "\t" which are all fairly common and join takes care of not 
having a trailing ", ".

For more see http://www.omahapython.org/IdiomaticPython.html

> fifth:
> 
> in my models, a model object is only aware of the objects above it,
> and not below it.
> in C, i remember i just declared all functions, with no body to it, at
> the top of the file
> then all functions were aware of all functions.
> how do i do this in python?

AFAIK you can't.  In some places with Django you can put names in quotes 
to have the same effect. See 
http://www.djangoproject.com/documentation/model-api/#relationships

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: accessing dictionary elements in opening tag of django template for loop

2008-05-14 Thread Norman Harman

Sorry, I don't know the exact answer but I can point you in right direction.

templates always use dot notation for dictionary access

tag_dict.document.uid

But I don't think that will work inside a "for" tag and also won't work 
cause you want the document.uid to be key not "document".


The workaround I'm aware of is the "with" tag.

http://www.djangoproject.com/documentation/templates/#with

something like this

{% with document.uid as uid %}
   {% for doctag in tag_dict.uid %} {{ doctag.tagid }} {% endfor % }
{% endwith %}

An alternative is to pass in a context var that already has the list you 
want.



-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: where does this caching come?

2008-05-15 Thread Norman Harman

Alex Morega wrote:
> On May 15, 2008, at 02:24 , David Zhou wrote:
>> Are you restarting the server between module changes?
> 
> By default Django does no caching of responses. It's probably what  
> Viktor says: the server (mod_python, mod_wsgi, whatever) won't  
> automatically reload the python code if you change it. The automatic  
> reload behaviour only happens with Django's built-in development server.

Not strictly true.  With mod_python there's a directive to control 
whether apache automatically reloads python code.  You *don't* want to 
set this on for production code(large performance penalty).

 PythonAutoReload On

I'm guessing mod_wsgi and others have something similar.


-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: encrypting form data

2008-05-15 Thread Norman Harman

Mike Chambers wrote:
> I have a commenting app that requires that the item id, and content type 
> id be passed through the form.
> 
> This works fine, but i would like to encrypt that data to make it a 
> little more difficult for people to programatically submit the form.
> 
> Does anyone have any info on how to encrypted form data? I know how to 
> hash it using MD5, and SHA1, etc... but that is only a one way hash. I 
> dont want to have to loop through all of the possible values to compare 
> the hashes as that could get to be expensive.
> 
> Any suggestions?

The standard http://www.djangoproject.com/documentation/csrf/ CSRF 
protection middleware does something like that.

Don't know details but could look there.

If you're gonna 1way hash things such as 'id' and worry about speed then 
store the 1way hashed value in database and do your lookups on that.

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: encrypting form data

2008-05-15 Thread Norman Harman

Richard Dahl wrote:
> Mike,
> I concur with jonknee, the attribute 'hidden' on a form field simply
> tells a browser that is following the standards not to display it.
> The form field and all of the data within it is still sent via http.
> Any script or proxy (i.e. webscarab) or other mechanism such as a
> sniffer can get at the information within any http response or request
> and view that information.  Whether or not the id is sent back as '1'
> or '9ghieus78yurhfyjdn' is irrelevant to solving your problem because
> a script or bot can just as easily return either.  The *accepted*
> solution for this is CAPTCHA.
> -richard

You check that the hash sent back is correct by (re)hashing the id, duh.

Since only you have the secret part it is computationally difficult for 
others to create hashes for arbitrary ids.

One reason to hash id's is that you don't want people / bots whatever 
spidering all your data, this can be security(weak) or load related.

Another is CSRF http://www.djangoproject.com/documentation/csrf/

A reason to not reveal primary keys is to not let competitors know how 
many records you have. 
http://www.guardian.co.uk/world/2006/jul/20/secondworldwar.tvandradio



-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: encrypting form data

2008-05-15 Thread Norman Harman

Gabriel wrote:
> Mike Chambers  gmail.com> writes:
> 
>>
>> I am not concerned if they can send the hash back. I dont want them to 
>> be able to access the underling value that the hash is based on.
>>
>> I am also not concerned about spam, but rather just dont want to expose 
>> raw database ids to the public.
>>
> 
> 
> Hi Mike
> 
> I think you are right to be cautious about not exposing DB IDs publicly. My
> suggestion is to create another column in the table with the IDs and make it a
> unique ID, something like a SHA1 hash of the DB ID + Username +email for
> instance. Then base all requests and DB lookups on this. It won't stop users
> from using a hash they know about, but it will stop them from guessing others.
> You could even index the DB column for performance. Hope that help, if not I
> apologise for not reading your post more carefully!

Creating db column is what I did for storymash.com, for example this url

 http://storymash.com/u/huskerlayd/wolewadu/

"wolewadu" is a unique string used to reference individual chapters in 
urls and other places.  It's not a hash.  It's not related to id. 
Wanted less ugly urls than either ids or hashes provide.  So it's always 
8 alternating constanants/vowels with a bunch of undesirable 
words/substrings disallowed.

We create this once in the save method of Chapter model

if self.hash is None:
self.hash = self._generate_hash()

And queries are:

chapter = Chapter.objects.get(hash="wolewadu")


Definitely make it indexed column though.


The business case is different from what I think Mike wants but similar 
methods can apply.

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: encrypting form data

2008-05-15 Thread Norman Harman

Gabriel wrote:
> Mike Chambers  gmail.com> writes:
> 
>>
>> I am not concerned if they can send the hash back. I dont want them to 
>> be able to access the underling value that the hash is based on.
>>
>> I am also not concerned about spam, but rather just dont want to expose 
>> raw database ids to the public.
>>
> 
> 
> Hi Mike
> 
> I think you are right to be cautious about not exposing DB IDs publicly. My
> suggestion is to create another column in the table with the IDs and make it a
> unique ID, something like a SHA1 hash of the DB ID + Username +email for
> instance. Then base all requests and DB lookups on this. It won't stop users
> from using a hash they know about, but it will stop them from guessing others.
> You could even index the DB column for performance. Hope that help, if not I
> apologise for not reading your post more carefully!

Creating db column is what I did for storymash.com, for example this url

 http://storymash.com/u/huskerlayd/wolewadu/

"wolewadu" is a unique string used to reference individual chapters in 
urls and other places.  It's not a hash.  It's not related to id. 
Wanted less ugly urls than either ids or hashes provide.  So it's always 
8 alternating constanants/vowels with a bunch of undesirable 
words/substrings disallowed.

We create this once in the save method of Chapter model

if self.hash is None:
self.hash = self._generate_hash()

And queries are:

chapter = Chapter.objects.get(hash="wolewadu")


Definitely make it indexed column though.


The business case is different from what I think Mike wants but similar 
methods can apply.

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: where does this caching come?

2008-05-15 Thread Norman Harman

Graham Dumpleton wrote:
> On May 16, 12:21 am, "Norman Harman" <[EMAIL PROTECTED]> wrote:
>> Alex Morega wrote:
>>> On May 15, 2008, at 02:24 , David Zhou wrote:
>>>> Are you restarting the server between module changes?
>>> By default Django does no caching of responses. It's probably what  
>>> Viktor says: the server (mod_python,mod_wsgi, whatever) won't  
>>> automatically reload the python code if you change it. The automatic  
>>> reload behaviour only happens with Django's built-in development server.
>> Not strictly true.  With mod_python there's a directive to control
>> whether apache automatically reloads python code.  You *don't* want to
>> set this on for production code(large performance penalty).
>>
>>  PythonAutoReload On
>>
>> I'm guessingmod_wsgiand others have something similar.
> 
> That option for mod_python does absolutely nothing for Django. This is
> because Django and your application modules for it don't fall into the
> category of modules thats are candidates for reloading.

I didn't believe it so I tested and it seems you're right.

Doh!  That's what I get for misreading docs.

I'm guessing that in "If set to Off, instructs mod_python not to check 
the modification date of the module file." from 
http://www.modpython.org/live/current/doc-html/dir-other-par.html
"module file" referes to a mod_apache module you write using mod python 
and/or the PythonHandler???


Thanks for setting me straight.
-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: business logic and good practices

2008-05-20 Thread Norman Harman

bcurtu wrote:
> Hi,
> 
> The reason you must place your templates out from your app code is
> because if you don't do that, anyone could access to the code via
> browser. Just writing the path of your files, and they have the code.
> It could be a security issue.

That is not the reason, and if you really wanted to you could mix your 
app code and templates, by setting TEMPLATE_DIRS.

None of your django code, templates, settings etc needs to be accessible 
via browser nor should it be.

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: Incrementing by 4 instead of 1?

2008-05-20 Thread Norman Harman

ringemup wrote:
> Hi folks,
> 
> I feel like I must be doing something stupid.  I've got the following
> view:
> 
> def adopt_bunny(request, id):
>   try:
>   bunny = Bunny.objects.get(pk=int(id))
>   except:
>   raise Http404
>   adoptions = bunny.adoption_count
>   adoptions = adoptions + 1
>   bunny.adoption_count = adoptions
>   bunny.save()
>   return single_bunny(request, id, True)
> 
> Every time I make this request (after the first time for that
> particular bunny), it increments by 3 or 4 instead of by 1.
> single_bunny() just calls the object_detail() generic view with some
> extra context.
> 
> How can I track down what's going on?  Or am I doing something
> completely braindead?
> 
> Thanks!

You don't need temp varible.  and there is a short cut for your 
try/except 
http://www.djangoproject.com/documentation/shortcuts/#get-object-or-404 
This would do

def adopt_bunny(request, id):
   bunny = get_object_or_404(Bunny, pk=id)
   bunny.adoption_count += 1
   bunny.save()

Don't know why it would inc by 3 or 4.  Assuming you are running dev 
server...  I'd add a print statement in there

   print "bunny %s: %s" % (bunny.id, bunny.adoption_count)

just to see when/if this code is being called multiple times and the 
value of adoption_count when it is.  Maybe add print to Bunny's save 
method to see where else it is getting modified/saved.

Also I'd probably make a method in the BunnyModel instead of doing this 
in the view.  Maybe overkill for this case (but today's overkill is 
tomorrow's maintenance saving feature)

Bunny(Model):
   ...
   def adopt(self):
   self.adoption_count += 1
   self.save()

Then from your view call it

def adopt_bunny(request, id):
   bunny = get_object_or_404(Bunny, pk=id)
   bunny.adopt()
   return single_bunny(request, id, True)



-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: Try Except Statement not working properly.

2008-05-20 Thread Norman Harman

Greg wrote:
> Since we know what the exception is.  The email address already exist
> in the db (I have unique=True for the email field).  I thought that
> having 'except: pass' would solve that problem.  However, do I need to
> catch a certain exception in order for my loop to continue.  Because
> as of now when the exception happens my loop stops.

You don't *know* that is what the exception is, you assume that.  This 
is one reason it is bad to catch all exceptions.  You don't know what 
you are getting.

The loop, as written, will continue.  There is something else going on.

I would add print statements to determine what is in fact happening.

for row in reader:
  try:
  b = OrderEmail(name=row[0], email=row[1], been_sent="0")
  b.save()
  print "saved", row
  except Exception, msg:
  print msg

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: Try Except Statement not working properly.

2008-05-21 Thread Norman Harman

Greg wrote:

> Norman,
> I added those print statements and ran the script.  The output was
> this over and over again:
> 
> ///
> 
> current transaction is aborted, commands ignored until end of
> transaction block
> 
> //
> 
> Any suggestions?

It sounds like some other exception is, sadly, being masked by the 
transaction abort exception.

Unless you know and like to use debuggers, the answer is almost always 
more print statements :)

I suspect that the file you are reading isn't properly formated csv, or 
the data in row[0] or row[1] aren't what your database expects, or some 
other error like that.

What you need to do is figure out what is actually being sent into 
OrderEmail and why that is causing database to choke and rollback.

   for row in reader:
try:
print row
print row[0], row[1]
b = OrderEmail(name=row[0], email=row[1], been_sent="0")
b.save()
print "saved", row
except Exception, msg:
print msg


I have no idea what OrderEmail is about but this
been_sent="0"
looks suspicious.  Booleans, which been_sent certainly sounds like, in 
Python use True/False not 1/0 and esp not strings "0".  Try
been_sent=False


-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: item "of the day"?

2008-05-22 Thread Norman Harman

[EMAIL PROTECTED] wrote:
> This should be really easy, but I haven't slept in a week and I'm not
> that smart to begin with. I want to get an item of the day.. quote of
> the day, tip of the day, whatever.
> 
> I don't know how many of these items there will be. I am pretty sure I
> want a template tag.
> 
> Can someone point me in the right direction? Thanks.

I don't know if this is the "right" direction but I've had success using 
  memcached to implement of the day items.

If the item is in the cache it gets served.  Otherwise I fetch from 
database and store in cache with expiration of 24 hours.

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: item "of the day"?

2008-05-22 Thread Norman Harman

[EMAIL PROTECTED] wrote:
> 
> 
> On May 22, 12:11 pm, "Norman Harman" <[EMAIL PROTECTED]> wrote:
>> I don't know if this is the "right" direction but I've had success using
>>   memcached to implement of the day items.
>>
>> If the item is in the cache it gets served.  Otherwise I fetch from
>> database and store in cache with expiration of 24 hours.
> 
> Definitely an interesting idea... do you use a template tag for the
> item? The {% cache %} template tag doesn't seem to want to cache my
> template tag.

I've used low-level api 
http://www.djangoproject.com/documentation/cache/#the-low-level-cache-api

And I'm caching context vars, but no reason can't be done in template 
tag.  Probably cleaner that way.


-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: item "of the day"?

2008-05-22 Thread Norman Harman

[EMAIL PROTECTED] wrote:
> I've tried low-level api, and must be missing something:
> 
> class RideNode(template.Node):
> def __init__(self, varname):
> self.varname = varname
> 
> def render(self, context):
> if cache.get('rod'):
>context[self.varname] = cache.get('rod')
> else:
>ride =
> Ride.objects.filter(site=settings.SITE_ID).order_by('?')[:1]
>cache.set('rod', ride, 30)
>context[self.varname] = cache.get('rod')
> return ''

I'm not 100% familiar with Template Tags, but I thought you'd want to do 
the "work" once in init instead of every time in render.

You're not doing it low-level enough :) You're trying to put a QuerySet 
into the cache.  I think you want a single random Ride that would be

   Ride.objects.filter(site=settings.SITE_ID).order_by('?')[0]

Even with a Ride instance instead of a QuerySet you need to pickle it to 
store in cache and unpickle when you pull it out.  (I don't *think* that 
happens automatically)

Instead I'd store the specific values of Ride I want to use.

   cache.set('rod_title', ride_title, 24*60*60)
   cache.set('rod_img_url', ride_img_url, 24*60*60)

The template tags I've created in past tended to create snippets of html 
instead of just setting context vars.  I'd stuff that "rendered" html 
into the cache.


This is code I've used to do things of day/hour in views.  It could be 
adapted to template tags.


def cache_context(keys, ttl, ttw=60):
 """
 Decorator to cache a set of context vars as one unit

 Function decorated should return a dict/RequestContext so that keys 
== func().keys() or None.
 @param keys: keys of context vars, a list
 @param ttl: time to live, in seconds, how long results from 
decorated function are cached
 @param ttw: time to wait, in seconds, time between calls to 
decorated function when it returns None
 """
 def decorate(func):
 def fast(context, func=func, keys=keys, ttl=ttl, ttw=ttw):
 data = cache.get_many(keys)
 if len(data) == len(keys):
 context.update(data)
 else:
 data = func()
 if data is None:
 for k in keys:
 cache.set(k, "", ttw)
 else:
 context.update(data)
 for k in keys:
 cache.set(k, data.get(k, ""), ttl)
 return fast
 return decorate


# cache for day, check every hour
@cache_context(["featured_blog_html",], 3600*24, 3600)
def get_featured_blog_context():
 """
 If blog written within a week. blog_block template renderd to html
 """
 try:
 a_week_ago = datetime.now() - timedelta(days=7)
 entry = Entry.objects.filter(draft=False, 
date__gte=a_week_ago).latest()
 html = render_to_string("blog/entry_block.html", dict(entry=entry))
 logging.info("New featured blog: %s" % entry.title)
     return {"featured_blog_html": html}
 except Entry.DoesNotExist:
 pass


def index(request):
 context = RequestContext(request)
 get_featured_blog_context(context)
 get_featured_foo(context)
 get_featured_bar(context)
 return render_to_response("main/index.html", context)

-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: item "of the day"?

2008-05-23 Thread Norman Harman

[EMAIL PROTECTED] wrote:
> I think I this would be a great plan if I could get caching to work in
> the template tag. Even this returns None:
> 
> def render(self, context):
> cache.set('mykey', 'hello world', 30)
> return cache.get('mykey')

Sounds like you have caching disabled or are using something like 
dummycache.  Are you sure memcached is running?

Reread 
http://www.djangoproject.com/documentation/cache/#setting-up-the-cache


-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
Get out and about this spring with the Statesman! In print and online,
the Statesman has the area's Best Bets and recreation events.
Pick up your copy today or go to statesman.com 24/7.

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



Re: How to Implement "Most Viewed"?

2008-05-25 Thread Norman Harman

blis102 wrote:
> Hello All,
> 
> Im wondering how I could go about implementing a "Most Viewed" feature
> on my site. Lets say I have events, articles, and businesses, how
> could I implement a "Most Viewed Businesses", "Most Viewed Articles",
> "Most Viewed Events", "Most Viewed Content", "Most Viewed Articles
> This Week", etc...? Should I build a model for views and make it a
> foreign key to each model I want to record views for? Should I make a
> middleware? What else could I do?
> 
> Im not really sure what would be best practice in this regard. Im sure
> there are a few different ways to implement this, but what is the
> simplest and most scalable? Any other ideas or suggestions?

Simplest and scalable aren't often achievable in the same sentence.

Unless your site is very low traffic the thing you don't want to do is 
write to the database every view.  That is anti-scalable.

For one project in the past a coworker came up with this:
write log files to a ramdisk, one line per view(fast + simple). A cron 
job slurped the files, did unique views logic, other stuff and updated a 
times_viewed field in the models.

Scaling that to more than one machine adds complexity.  I'd probably 
pursue a different solution when/if traffic warranted it.


-- 
Norman J. Harman Jr.  512 912-5939
Technology Solutions Group, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: best solution for different address formats?

2008-06-11 Thread Norman Harman

[EMAIL PROTECTED] wrote:
> Hello Django-Community,
> 
> currently I'm working on a project where I need to save the user's
> postal address. The problem is that the users come from different
> parts of the world and postal addresses are formatted differently in
> the U.S. or in Austria.
> 
> Does anybody of you already have a suggestion on how to deal with this
> problem?

Almost nobody I've talked to agrees with me, but...

I think the best address solution is to trust your users.  Users know 
best.  Specifically they know best what their address is and how it 
should be formated.  Users are more likely to know about changes to 
their countries addressing scheme.  Etc, etc.

With that in mind the best way to handle varying international addresses 
is with a largish char column backend and multiline text input box on 
frontend.

--
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Template engine

2008-06-13 Thread Norman Harman

Juanjo Conti wrote:
> Hi, I am using Django's template engine to produce rtf files and I
> have noticed something: if the first line of my template is a {%load
> ... %} tag then the result has a withe like at the to of it. This is
> not a problem in html, the common use of the tempalte engine, but is
> fatal in a rtf file.
> 
> I write this because I think that this behaibour should bi fixed, am I right?
> 
> Anyway I have putted the load tag in the second line of my tempalte :)
> 
> Juanjo


Template's white space handling is one of the few things that irks me 
about Django.  I hate having to make confusing formating, jamming stuff 
all on the same line just to get white space correct.

I really wish it had some whitespace handling tools like Cheetah 
http://www.cheetahtemplate.org/docs/users_guide_html/users_guide.html#SECTION00068
 


The spaceless tag helps sometimes, but not for your situation.


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Session lost between two requests from the test client

2008-06-13 Thread Norman Harman

ksachdeva wrote:
> Hi,
> 
> From a testcase I first issue a 'get' request to a view (say view1)
> where I set a request.session['m_key'] = 'myval'. Now I issue a 'post'
> request to a view (say view2). In view2, I tried to obtain
> request.session['m_key'] but I get an error that session does not have
> 'm_key' key.

I've spent a lot of time debugging session problems only to discover I 
had made the bone headed mistake of having this settings combo

CACHE_BACKEND="dummy://"
SESSION_ENGINE="django.contrib.sessions.backends.cache"

...
-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Template engine

2008-06-13 Thread Norman Harman

Russell Keith-Magee wrote:
> If there is a particular whitespace-eating behaviour that you would
> like, you could always implement it yourself in a template tag. If you
> think the template tag could be useful for others, you can share it on
> djangosnippets.org, or open a ticket to have the tag considered for
> inclusion in Django itself.
> 
> If what you're proposing can't be done in a template tag, we're always
> open to suggestions on how to make Django better. Put down your ideas
> in a ticket, and we'll consider it.

What I'm use to is less of particular tag and more of a change to how 
all tags/templates work.  In short, lines in templates that have only 
tags should be "invisible" i.e. they should not be in the output of that 
template.

If after doing tag processing a line(that had 1+ tags to begin with) 
consists of nothing but whitespace then eliminate that line, including 
it's new line.

line numbers for ref:
1: {% if bar %}bar{% endif %}
2: {% for i in list %}
3:   i
4:   {% if False %}{% endif %}
5: {% endfor %}
6: 

which now creates something like this when bar=False, list=[1,2]
1:
2:
3:  1
4:
3:  2
4:
5:
6:

instead outputs this
1:
3:  1
3:  2
6:


But this is a backwards incompatible change, a minor issue, and with 
effort it's possible to work around this issue just not beautifully 
(which contrasts with the rest of Django).

Other stuff is higher priority and the real problem with Django is 
http://superjared.com/entry/real-problem-django/.  I didn't mean to 
sound complainy in previous post, if anyone took it that way.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: unit testing and comparing dictionaries

2008-06-17 Thread Norman Harman

Gene Campbell wrote:
> Hello Djangonauts
> 
> I'm a noob on both Django and Python, so this question might be easy
> for the experts out there.  I am trying to do test first development
> during the development of my model code.  (I have lots of experience
> with test first coding in the Java world, no practical experience in
> the Py world.)
> 
> I want to do something like this
> 
> class ModelTest(TestCase):
> 
> def test_crud_modelone(self):
> mo = ModelOne( name="A name" )
> mo.save()
> 
> saved_mo = mo.objects.get(pk=mo.id)
> 
> assertEqual( vars(mo), vars(saved_mo),"Something not getting saved")
> 
> That assertEqual line fails.  I wrote this
> 
> def compare(self, obj1, obj2, verbose = False):
> other = vars(obj2)
> for d,v in vars(obj1).items():
> if isinstance(other.get(d,None),datetime.date):
> if not other.get(d,None) == v.date():
> return False
> elif not other.get(d,None) == v:
> return False
> 
> return True
> 
> This is probably horrible python, I'm still learning (unlearning
> Java), but it compares correctly for strings and dates so far that
> I've tested.
I've been using python since 1.5, I had to look up what vars() did. 
Probably not idiomatic Python.  (I've always just looked at __dict__ 
directly, which I do rarely).

The assertEqual line (probably) fails because the order of dictionary 
keys is not defined.

 > Some might be asking why I'm testing if my models can be saved, as
 > most of that functionality is tested when Django is tested.  But, I
 > still feel there's a enough that I have to write to warrant a simple
 > sanity test like this.

FWIW I believe testing what you're testing is a waste of time and 
violates unit testing.  Really the db should be mocked, but that is 
fairly hard.  If you didn't write save(), you shouldn't be testing it.


But, if I were testing this I think I'd do something like this
 assertEqual( db_mo, mo,  "local and db versions of %s not 
identical" % mo.__class__)

In general, I trust == (either Python's or the object's author's) more 
than poking into the internals of an object, encapsulation and all that :)


When I compare dictionaries I either convert them to sorted tuples (to 
put keys in proper order)

   expected = dict(var1="dog", var2="cat")
   answer = something_that_return_dict()
   assertEqual( sorted(expected.items()), sorted(answer.items()) )

Or check only certain keys are equal (for instance if the answer dict 
has other stuff in it I don't care about)

   check_these = ["key1", "key3"] # = expected_dict.keys()
   answer = something_that_return_dict()
   for k in check_these:
 self.assertEqual( expected_dict[k], answer[k],
   "expected[%(key)s] != answer[%(key)s]" % {"key":k} )


For Models in which I write a custom save method this is how I usually 
structure it.

   def save(self):
 if self.value is None:
   self.value = self._calc_value()
 super(FooModel, self).save()

   def test_value_on_save(self):
 test_data =( (dict(foo="", bar=""), 42 ),
  (dict(foo="1", bar="3"), 37 ),
  # test more edge cases, etc.
)
 for (expected, data) in test_data
   t = Model(**data)
   t.save()
   self.assertEqual( expected, t.value )

If I had another custom value I'd write another test for it.

Good luck with your continued Python adventures,
-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: redirect with post parameters

2008-06-17 Thread Norman Harman

MarcoX wrote:
> Peter and Daniel, thanks for the reply.
> I must use the POST method because the external site WANT a post
> method.
> parameter2 is a "stupid" info that the external site required.
> I try with your (simple) solution, a hidden html form with a
> javascript redirect...

I had to do something similar for PayPal.  I did it by changing the 
action="" in a confirmation form to point to PayPal.  Instead of form 
POSTing back to me and trying to redirect POST which doesn't work, it 
POSTs directly to PayPal.

The form was constructed to contain all the things PayPal wanted in 
hidden fields.  In PayPal's instance it doesn't matter that user can 
change values(they are checked elsewhere, when PP notifies us of 
payment) but it may in your situation.

Depending on what 3rd party site does/wants another way to do this is to 
use something like urllib2 and POST to 3rdpary in your view code, slurp 
the response and send it back to user.  It will have 3rdparty content 
but come from your server, which is probably gonna cause problems.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: serve static files

2008-06-17 Thread Norman Harman

Molly wrote:
> How would I call the static file in my browser??

By typing in the url to the static file directly in the address bar.

For example if your server is example.com, root of django app is myapp, 
and images are in img dir, and image is named myjp.jpg  the url would be

http:://example.com/myapp/media/img/myjpg.jpg

 From your description it sounds like the css is not being found.  I'd 
look in the HTML source(as seen by browser, with firefox ctrl-u, with IE 
install Firefox) find line(s) that include css.  They probably look 
something like this.

http://yui.yahooapis.com/2.3.1/build/calendar/assets/calendar.css"; />

then see if you access(copy it to address bar, hit return) 
http://yui.yahooapis.com/2.3.1/build/calendar/assets/calendar.css

Either the url(s) in your templates point to wrong place, or the 
urls/document_roots in urlpatterns are wrong, or something else is wrong ;)

btw hard coding a path "C:\dev\incidents\admin_media" in your 
urlpatterns is probably a bad thing to do.  As whoever uses your 
app/where ever you deploy it for production is unlikely to install the 
app in the same place you do on your dev machine.


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: unit testing and comparing dictionaries

2008-06-17 Thread Norman Harman

Gene Campbell wrote:
> Thanks for the insight!  Do you write tests to check for constraints
> that are optional in definitions, for example?
> 
> address4= models.CharField(max_length=45, null=True, blank=True)
> 
> could be written as
> 
> address4= models.CharField(max_length=45)
> 
> Were is the most reasonable place to test this is correct (not regressing)

I'm not sure.  I'm distraught over having validations in two places the 
model and forms that "feed" that model.  And form_from_model or whatever 
it is called is never what I want.   I tend to test the forms as I tend 
to manipulate models through forms and the forms support much richer 
validations than FooFields do.

Blank is an admin thing and I typically don't test those.  Testing 
Nullable field(s) would be data point(s) in creation/save test.

> What about uniqueness, and composite field uniqueness?
> #  unique_together = (("field1", "field2","field3"),)
> 
> I'm thinking it would make sense to try to
> create 2 of an object and save them, and check that it fails

Yep two of the objects whose 3 fields are not unique together.


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Dictionaries, templates and best practices

2008-06-17 Thread Norman Harman

Juan Hernandez wrote:
> it does not return any values.
> 
> I did post.0.title because the dictionary is established like this:
> 
>  >>> test
> {0: {'post': 'My First Post', 'title': 'My First Title'}, 1: {'post': 
> 'My Second Post', 'title': 'My Second Title'}}
> 
> and it goes on and on
> 
> If I could iterate over it, like post.0.title, then post.1.title and so 
> forth, it would be perfect
> 
> Thanks for your help
Don't construct dict like that, make a list instead.
   [ {'post': 'My First Post', 'title': 'My First Title'}, {'post': ... ]


Or, if you don't have control over dict construction, munge it into list.

If order isn't important:
   list_o_dicts = dict_that_should_be_list.values()

If order is important:
   list_o_dicts = [ dict_that_should_be_list[k] for k in 
sorted(dict_that_should_be_list.keys()) ]

Then you can use the template for loop construct normally

{% for dict in list_o_dicts %}
   {{ dict.post }} {{ dict.title }}
{% endfor  %}

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Adding suggest / accept functionality to models

2008-06-17 Thread Norman Harman

Dan wrote:
> There is a functionality which I am interested in and I wonder what is
> the cleanest and most foward compatible way of doing things.
> 
> I want models to sprout a suggest() method which would work like
> save() but keep the data in some structure elsewhere that do not
> modify the original data. Any regular call to that object would work
> as if it wasn't modified. I also want a accept() method that would
> commit the changes (and obviously a reject() method to discard them
> and some way to explore the suggested changes).
> 
> I am not interested in history at all.
> 
> How would you go about implementing those functionalities?

First guess, curious if others think its good idea.

Create model with one2one nullable field "suggestion" and Boolean field 
"is_suggestion".
If suggestion is Null then there is no suggestion.
If suggestion is not Null it is id of suggested data.

The idea is to avoid maintaining two duplicate schemas.


Proly change the default Manager to only show is_suggestion == False rows.


def suggest(self, obj):
 """obj is original obj self is suggestion for""
 self.is_suggestion = True
 self.suggestion = obj
 self.save()

def accept(self):
 "accept this suggestion"
 assert self.is_suggestion
 # need more logic if model has foriegn relationships
 self.suggestion.delete()
 self.suggestion = None
 self.is_suggestion = False

def reject(self):
 assert self.is_suggestion
 # not sure how to delete relation
 # self.suggestion.suggestion = None ???
 self.delete()


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



correct list for newforms admin questions? named urls / replacing admin root page

2008-06-17 Thread Norman Harman

I want to use {% url %} to point into portions of the admin site(and 
change the default url structure).  I hacked this generally 
unfullfilling but working version with old admin.

model = dict(app_label="specials", model_name="adspecial")
urlpatterns += patterns("django.contrib.admin.views.main",
 url(r"^$",  "change_list",
 name="ts_admin_special_list",  kwargs=model),
 url(r"^add/$",  "add_stage",
 name="ts_admin_special_add",   kwargs=model),
 url(r"^(?P\d+)/$",   "change_stage",
 name="ts_admin_special_edit",  kwargs=model),
 ...
)


Not sure how to do this with newforms. I got this to work, but I really 
don't want to make wrappers to get the dynamic urls to work.

url(r"^$", site.root, name="ts_admin", 
kwargs={"url":"specials/adspecial"}),


Actually, I'd really love to learn a cleaner way to do this.  Main goals 
are to have a custom admin "index" page, and not hard code urls.



Thanks,
-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: correct list for newforms admin questions? named urls / replacing admin root page

2008-06-18 Thread Norman Harman

Brian Rosner wrote:
> Hi Norman,
> 
> On Jun 17, 2008, at 3:49 PM, Norman Harman wrote:
> 
>> I want to use {% url %} to point into portions of the admin site(and
>> change the default url structure).  I hacked this generally
>> unfullfilling but working version with old admin.
> 
> 
> This is not yet supported in the newforms-admin branch. See ticket  
> #6470 [1]. At this point your best  bet is to hardcode the URLs.
> 
> [1]:http://code.djangoproject.com/ticket/6470

Actually, I figured out this workaround.  Which I call "not pretty, but 
mostly works".

# tie into django user mgmnt
user = kwargs=dict(app_label="auth", model_name="user")
group = kwargs=dict(app_label="auth", model_name="group")
urlpatterns += patterns("",
 url(r"^auth/user/$", admin.site.root, 
{"url":"auth/user/"},  name="dj_user"),
 url(r"^auth/user/add/$", admin.site.root, 
{"url":"auth/user/add/"},  name="dj_user_add"),
 url(r"^auth/user/(?P[^/]+)/$", 
admin.site.model_page, kwargs=user, name="dj_user_edit"),
 url(r"^auth/user/(?P[^/]+/password)/$", 
admin.site.model_page, kwargs=user, name="dj_user_passwordchange"),
# "catch" other urls we don't care to name
(r"^(auth/.*)$",  admin.site.root),
 )

Has problems with deep linking cause
   self.root_path = re.sub(re.escape(url) + '$', '', request.path)
is only in def root(...) and not in def model_page(...) or constructor 
or something.


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Quick way to find list objects close to the current date?

2008-06-19 Thread Norman Harman

mw wrote:
> Hello,
> 
> 
> I was thinking about ways to list some objects that are close to the
> current date.  I could do this using datetime and just subtract the
> two dates, but this seems like something that has probably been done
> before.  It seems like there would be a more Django way of doing it
> than me doing it manually.

http://www.djangoproject.com/documentation/db-api/#range

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



new forms admin is there an equiv to unique_for_date

2008-06-19 Thread Norman Harman

This is what I'm talking about 
http://www.djangoproject.com/documentation/model-api/#unique-for-date

Searching internets can not find any answer.

Thanks,
-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Thanks!!!!!!!!!!!!!!!!!

2008-06-20 Thread Norman Harman

Django just rocks, thanks.

It has,
   taught me some advanced Python
   made me money on consulting gigs
   allowed storymash.com's owner's vision rapidly come to life
   got me working and actually making progress on a couple personal projects
   helped me land full-time position primarily developing in Python, 
which was pretty hard to find not so long ago.

Lately I've been answering what questions I can on this forum.  Which is 
my preferred way of saying "thanks".  I wish it was easier to contribute.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Automatic Update of template

2008-06-20 Thread Norman Harman

[EMAIL PROTECTED] wrote:
> Hi,
> 
> I am writing a web based chat client in Django framework. When ever I
> receive a message, I get that in a python function which is in the
> same file as my views. Can I directly pass this data to the template
> (by using response_to_render ) to update the template? Could someone
> suggest a way to automatically update messages in the site from python
> code.

are you talking about this? 
http://www.djangoproject.com/documentation/authentication/#messages

or something else?

If the function takes no parameters and returns a string, you can pass 
it in the context and call it like a variable.

{{ myfunction }}

I believe this will call the function each time it is used.  I'd 
probably do something like this instead.

def my_view(request):
   extra = dict()
   extra["message"] = myfunction(args, and, stuff)
   return render_to_response("mytemplate", extra)

see http://www.djangoproject.com/documentation/shortcuts/#render-to-response



-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: custom form with admin look and feel

2008-06-23 Thread Norman Harman

chefsmart wrote:
> I'm using django svn trunk. I have created several custom forms that
> show up in the admin section of the website. However, these forms look
> nothing like the admin forms. I tried extending change_form.html
> template - unsuccessfully.
> 
> Does anyone know what my template should contain to achieve admin look
> and feel.

look in django/contrib/admin/templates

extending admin/base_site.html is what I believe you want.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Where to install additional libraries?

2008-06-23 Thread Norman Harman

Jamie Pittock wrote:
> Thank you Gordon (and Joshua) that's really useful.
> 
> I think I'll use the site-packages folder then.  After doing what you
> said I've noticed I seem to have multiple installs of Python on my
> machine (OSX).
> 
> /usr/lib/python2.5/
> /Library/Python/2.5/
> /opt/local/lib/python2.5/
> /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
> (currently being used)
> 
> This is probably due in part to upgrading to Leopard and it changing
> the location, maybe?
> 
> I presume again it doesn't matter which of these I use aslong as I'm
> consistent?

It does matter, each Python installation is an 'Island'.

Figure out which Python is default.
   # this gives you the version
   python -V
   # this tells you were it is (and around where setup.py install will 
put its files)
   which python

If the default is 
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/bin/python 
but you want to use /usr/local/python2.5/bin/python instead then you 
must make sure you run the correct python when doing installs and when 
running manage.py.

you can use the full path every time
   /usr/local/python2.5/bin/python setup.py install

or you can use an alias (I suggest adding to your .bashrc or similar file)
   alias python=/usr/local/python2.5/bin/python



-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: How best to delete one of multiple records?

2008-06-23 Thread Norman Harman

Kenneth McDonald wrote:
> I have a list of records, and I'd like the user to be able to delete  
> any given record by pressing a button. My current strategy is to have  
> each record in its own form (so that pressing the submit button for  
> that form would delete the record), and have each form contain a  
> hidden field identifying the corresponding record via a unique key so  
> that I know which record to delete. However, this is very crude, and  
> no doubt indicative of the fact that I'm still just starting to learn  
> Django. What would people suggest as better alternatives? Feel free to  
> point me to documentation--I don't mind doing the reading, it's just  
> finding the relevant material that's a problem (there's so much of  
> it :-) ).

I don't think that's bad, all depends on how you want UI to work.

Other options would be putting them in a ChoiceField and using Select 
(dropdown) RadioSelect (radio buttons) or some custom widget.

The choice field options will have only one delete button but require 
user to select which record to delete.  That may or may not be a better 
ui than multiple delete buttons.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Struggling with Django/legacy data

2008-06-23 Thread Norman Harman

skins96 wrote:
> Hi,
> 
> I'm a noob who is struggling with understanding how Django might work
> with legacy data.
> 
> It seems Django's foreign keys rely on having an integer in both the
> parent and child table. However, we get a lot of data where what's
> needed is a join based on characters. For instance, "wht" in the
> parent table would correspond to "wht" in the child table, which then
> has a description field that might have, say, "white" in this
> instance.
> 
> I've looked through tons of documentation, both the Sam's book and the
> DjangoBook, but can't seem to find anything that addresses this. I've
> also tried to look through the archives. Can anyone offer advice?
> 
> I guess to be more to the point, I'm trying to figure out how to
> address it in the model (or if it should even be handled in the
> view).

http://www.djangoproject.com/documentation/model-api/#automatic-primary-key-fields

If you’d like to specify a custom primary key, just specify 
primary_key=True on one of your fields.


http://www.djangoproject.com/documentation/model-api/#relationships

to_field    The field on the related object that the relation is to. By 
default, Django uses the primary key of the related object.
-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Deciding where I am in the template hierarchy

2008-06-24 Thread Norman Harman

3xM wrote:
> Inside a template, is there a way to decide whether it has any parent
> template(s) or it is the root template?
> 
> I've got some templates including each other, but also want to be able
> to view them individually. But i still want the root template to
> extend my base template.
> 
> I'm looking for something like this to put in top of all the
> templates:
> 
> {% if is_root_template %}
>   {% extends "base.html" %}
> {% endif %}

By "root" do you mean the url that arrived at the template is a "/" root 
url.

If so, I would determine this in the view and pass in a template 
varible, 'is_root'.  But I don't think wrapping an extends in a if/endif 
will work.


Or do you mean the template is root as in it doesn't extend any other 
templates.

In that case just skip the if/endif because a template only extends 
another if you tell it to.


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: global variable issue

2008-06-24 Thread Norman Harman

[EMAIL PROTECTED] wrote:
> If I hit Ctrl-R again it puts my name back, and so on. It's like there
> there are two copies of the global that I am accessing. I can't figure
> this out.  Any ideas? Thanks so much!

Rule 1: Don't use globals.
Rule 2: Don't try to store state in a stateless server, use persistent 
storage like a DB.

There *are* two or more copies of the global.  There are as many copies 
as WebFaction runs instances of django (mod_python or whatever)

It works in dev cause manage.py runserver only starts one instance of 
django.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Django inserts an empty string into IntegerField?

2008-06-25 Thread Norman Harman

Huuuze wrote:
> I have defined a zip code field as follows in my Address model:
> 
> zip = models.IntegerField(blank=True, null=True)
> 
> Being a good Djangonaut, I'm using a ModelForm to convert my address
> model into HTML.  Now this where things get dicey.  As you can see in
> the model, zip code can except empty values.  Unfortunately, when I
> attempt to save data entered by a user who has left the zip code field
> blank, I receive a database exception.  Apparently, Django is
> attempting to insert an empty string into my integer-only field.
> 
> From what I can tell, this particular topic has been discussed
> previously:
> 
> http://www.hoboes.com/Mimsy/?ART=595
> 
> Is the solution outlined in the blog post above the long-term solution
> for Django developers or are there plans to have a ModelForm
> understand that I would not want to insert an empty string into an
> integer field?

Are you sure it happens in IntegerFields, that's surprising.  That blog 
is talking about CharFields for which saving "" for None is less surprising.

Instead of mucking with model's save method I'd create my own field, 
NullCharField or NullIntegerField that replaces "" or None with NULL 
according to the null=true parameter.



-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Django inserts an empty string into IntegerField?

2008-06-25 Thread Norman Harman

Huuuze wrote:
> Thanks for getting back to me.  You're correct -- that article is not
> a one-for-one match when compared to my problem, so let me tweak my
> question.
> 
> When I attempt to save (my_form.save()) and I leave the zip code field
> blank, I receive the following exception:
> 
> DataError at /person/new/add/
> invalid input syntax for integer: ""
> 
> When I look at the insert statement, sure enough, an empty string is
> attempting to make its way into my zip code field.
> 
> With that being said, do you expect that behavior?  If not, how can I
> correct the issue?  If you do expect that behavior, how can I go about
> creating a NullIntegerField?  This is new territory for me.

I don't know what ver of Django you're using by my version certainly 
appears that it doesn't perform the way you say it does.  i.e. it looks 
like it does not allow "" for Integer fields.

from '/django/db/models/fields/__init__.py'

class IntegerField(Field):
 empty_strings_allowed = False

Although, It's possible my 3min analysis of what empty_strings_allowed 
does is wrong.  You'd have to look closer at the above file but it looks 
like overriding this

 def get_db_prep_save(self, value):
 "Returns field's value prepared for saving into a database."
 return value

is what your after.  I've not done this before though so "caveat 
programmer".


btw, I really think IntegerField is the wrong column type for a zip 
code. They can be upto 11 chars long and have hyphens.  I'd make it 
CharField or maybe even a USZipCodeField from 
'contrib/localflavor/us/forms.py' There's many others in localflavor if 
your flavor isn't US.


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Unit test problem

2008-06-26 Thread Norman Harman

Malcolm Tredinnick wrote:
> Status code 302 is an HTTP redirect, which is what you would expect to
> see, since your view is always returning a HttpResponseRedirect. The
> test framework doesn't follow redirects.

What about? assertRedirects(response, expected_url, status_code=302, 
target_status_code=200)

http://www.djangoproject.com/documentation/testing/#assertions

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: views.py: Always a simple return?

2008-06-26 Thread Norman Harman

RossGK wrote:
> 
> Stuff

I think you don't want HTTP.

In other words you are wanting (like the Comet folks) HTTP to do things 
it was not designed to do.  In other words you are avoiding its 
strengths and chasing after its weaknesses.

Not sure what your real requirement is but,

Look at the Meta Refresh Tag 
http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm

Which AJAX is an improvement on, which sounds like you are already using 
and I'm not sure why it doesn't work for you.  And stateless requests 
are far more elegant than open TCP connections.  There are reasons the 
HTTP Internet has exploded in a way client server never did.

 From my understanding of Comet it's more or less exactly what you are 
asking for.  http://www.google.com/search?q=django%20comet

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Stability of trunk and 1.0 target: experience, testimonials?

2008-06-27 Thread Norman Harman

I've been using trunk for over 9mo for in production website 
http://storymash.com

During that time, there's been 2-3 times my unittests have failed after 
I've svn updated django.  Each time was a fairly quick fix.  API changes 
aren't hard bugs to track down and fix.  The advantages of all the great 
stuff that has been added to trunk far outweigh the time spent.  In 
fact, I've learned a bit about Django internals tracking down those 
failing unittests.

My current employer, uses .96 or newforms-admin/trunk for several minor 
but still business critical and public facing portions of it's websites 
statesman.com and austin360.com  with *no* problems(well no Django 
problems anyway ;).  The .96 projects started before I arrived or else 
they would probably be trunk as well.


I've been nothing but impressed with the diligence and abilities of 
Django developers and community to maintain multiple stable branches.


Compare Django release discipline and record to other major frameworks. 
  And your PHB's should be scared to use anything but Django.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: Inheriting from auth.models.User

2008-06-30 Thread Norman Harman

Ayaz Ahmed Khan wrote:
> bhunter wrote:
>> This should be a simple question.  I'd like an Employee model.  First
>> name, last name, username, password--basically all the same stuff
>> that's already in django.contrib.auth.models.User.  Maybe I want some
>> other things like salary, too.  So, it makes sense that I should just
>> inherit from this class.
>> [...]
> 
> You don't need to derive a class from the User model.  This is a
> common use-case.  You should be looking at Django Profiles:
> http://www.djangoproject.com/documentation/authentication/#storing-additional-information-about-users

Really? I was sort of hoping with model inheritance and newforms-admin I 
would finally be able to get rid of user profile.  It was a useful hack 
but now that there is a general solution the special case should be 
disfavored, no?

Maybe I'm using it wrong.  I dislike having to user.get_profile.myvar 
select_related doesn't seem to apply to user profiles and in a template 
loop of say blogs the "caching" fails.

{% for blog in blogs %}
blog.author.get_profile.something
{% endfor %}

If there are 10 blogs by the same author then there are 10 hits on 
user_profile to read it each time.


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: django+mod_python, caching or something else?

2008-07-02 Thread Norman Harman

Alex Koshelev wrote:
> Or may be a custom template tag for common stuff.

Or like any code anywhere just extract the common parts to a helper 
function and call that.

-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



Re: testing login problem

2008-07-02 Thread Norman Harman

laspal wrote:
> Hi,
> I have  created initial_data.xml using dumpdata and
> """manage.py loaddata initial_data.xml""" gives me no error.
> but still  I am not able to login using setUp().. and this is
> essential  as all my views functions required login..
> 
> here is my test file:
> 
> import unittest
> 
> from django.test import TestCase
> 
> class IndustryTest(TestCase):
> 
> def setUp(self):
> self.client = Client()
> response =self.client.post('/ibms/login/',
> {'username':'laspal', 'passwords':'abcd'})
> print response
> 
> I am still getting the error."""Your username and password didn't
> match"""
> Please help me out as I have to write lots of test cases for my view
> functions.

Test system creates a new test database from scratch every time it is 
run.  manage.py loaddata has NO effect on test.

I could be wrong but I don't believe test runner automatically loads the 
fixture initial_data.xml

You need to tell it what fixtures to load and you need to put them in 
the correct place.

http://www.djangoproject.com/documentation/testing/#fixture-loading


-- 
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___
You've got fun!  Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

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



  1   2   >