Re: Redirect home page

2009-10-10 Thread jeffschenck

The simplest option is probably to use the redirect generic view
(http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-
generic-simple-redirect-to). You could add something like this to your
urlconf:

(r'^$', 'django.views.generic.simple.redirect_to', {'url': '/en/'}),

jeff

--~--~-~--~~~---~--~~
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: Problem with URL naming, generic templates and custom filtering wrappers

2009-10-10 Thread Scott SA

Hi Karen,

On Oct 10, 5:58 pm, Karen Tracey  wrote:
> On Sat, Oct 10, 2009 at 6:34 PM, Scott SA  wrote:

> > I am trying to use a series of generic views with custom filtering via
> > callbacks as per:


> I cannot figure out how this one differs from the next one, nor can I
> recreate first two errors you are getting (I just get the no reverse match),
> and in making further changes you seem to be moving further away from what
> you want to achieve, so I'm just going to stop here and fix this one.

Sweet, thank you. 8-)

> First, the "P?" should be "?P".  You've got the order of the ?
> and the P reversed.

Finger dyslexia, happens all teh time!

Was, and remains, correct in the urls file. I fabricated the stripped-
down example to try to get to the heart of the matter without
excessive detail.

> Second, since you are specifying this as a bare tuple and not using url(),

I tried using url() and others after reading the 'url' and 'patterns'
source.

> and you want to specify the optional name as 'url-pattern-name', you must
> also include the optional dictionary which comes before the optional name as
> defined here:
>
> http://docs.djangoproject.com/en/dev/topics/http/urls/#patterns

> Given what you have 'url-pattern-name' is being taken to be the optional
> dictionary, not the optional name.  So change it to:
>
>   (r'path/(?P[\w\d-]+)/?$', my_filter_callback, {},
> 'url-pattern-name'),

Hmm, I thought I had done that but maybe something else was also wrong
causing me to follow the wrong path for troubleshooting.

> or use url() (read down further in the doc pointed to), omit the dictionary,
> and specify the name via keyword:
>
>   url(r'path/(?P[\w\d-]+)/?$', my_filter_callback,
> name='url-pattern-name'),

Okay, I know for sure that I tried this, may still have that code
commented out. This is where I received the error that the 'name'
attribute was being passed to 'my_filter_callback', as I recall. I'll
give this another try just to be sure it wasn't a "red herring" that
sucked a few hours out of my day.

After having gone back and adding the empty dictionary in the patterns
(prefix, tuple...) call, I now get resolution and reverse for that
URL. The second part of my prev. statement re. the url call seems the
likely culprit, and a quick double-check on the url() call just proved
it. The problem is another reverse url call later in the page
template, similar name, different regex, etc. 8-(

Thanks for the quick and very informative reply, greatly appreciated.
Sorry for the 'red herring' issue!

Scott

--~--~-~--~~~---~--~~
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: efficiently deleting content based on how old it is

2009-10-10 Thread buttman

I'm the author. Are you sure the comments are broken? I just made one
and it seemed to work.

On Oct 10, 11:55 pm, Kenneth Gonsalves  wrote:
> On Sunday 11 Oct 2009 9:07:38 am buttman wrote:
>
> > you could also do it this way:
>
> >http://pythonblog300246943.blogspot.com/2009/09/cron-jobs-with-django...
> >easy.html
>
> interesting - but the author's commenting module is b0rked, so was unable to
> add a comment (I hope he sees this and sets it right)
> --
> regards
> kghttp://lawgon.livejournal.com
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: efficiently deleting content based on how old it is

2009-10-10 Thread Kenneth Gonsalves

On Sunday 11 Oct 2009 9:07:38 am buttman wrote:
> you could also do it this way:
>
> http://pythonblog300246943.blogspot.com/2009/09/cron-jobs-with-django-made-
>easy.html

interesting - but the author's commenting module is b0rked, so was unable to 
add a comment (I hope he sees this and sets it right)
-- 
regards
kg
http://lawgon.livejournal.com

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



Re: efficiently deleting content based on how old it is

2009-10-10 Thread buttman

you could also do it this way:

http://pythonblog300246943.blogspot.com/2009/09/cron-jobs-with-django-made-easy.html

On Oct 9, 5:56 am, Chris Withers  wrote:
> Streamweaver wrote:
> > You could set this up as a custom manage.py command and run a cron on
> > that.  Gives the advantage of both initiating from outside the app and
> > using Django's DB abstraction layer.
>
> That's prettymuch what I was planning to do :-)
>
> > Then just iterate over the month names more than 6 back from the
> > current position and delete the records.
>
> I'm keen to use "real dates" as Tim suggested. Perhaps just using the
> 1st day in each month as the "month"?
>
> Chris
--~--~-~--~~~---~--~~
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: Problems with custom Auth Backends: 'NoneType' object has no attribute 'DoesNotExist'

2009-10-10 Thread Shawn Milochik

The way to do what you're trying to do is to take advantage of the  
following:

http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

In brief, you'll create another model, which will then be specified in  
your settings.py by AUTH_PROFILE_MODULE. From then on, you will be  
able to use the contrib.auth.model.User  builtin function get_profile 
() to return your custom object.

You will not be subclassing the User model; there's no need, and it  
greatly complicates things to try. I'm currently working on doing this  
myself, because I am adding requirements for the password change.  
Namely, I need the password to expire after 90 days, I need the  
initial password to require a reset after the first successful login,  
and I need to enforce some rules about the complexity and non-reuse of  
the password.

Shawn

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: efficiently deleting content based on how old it is

2009-10-10 Thread Shawn Milochik

Chris,

I know this doesn't answer the hard part of your question, but here's  
a simple way I delete old stuff from a database via an external script  
that's run by cron:

Item.objects.filter(date_updated__lte = datetime.now() - timedelta 
(days = 30)).delete()

If you use timedelta, you can easily identify records that are too  
old. As for your complicated references, assuming you don't have  
cascading deletes happening automatically, you may have to do an  
objects.filter(), get the results, and iterate through those, deleting  
their dependencies before deleting them. That may be several levels  
deep. In any case, make sure you back up your database regularly in  
case of a mistake, and don't forget to add unit testing with robust  
fixtures to develop and test this purge feature.

Shawn



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

2009-10-10 Thread Shawn Milochik


On Oct 8, 2009, at 9:33 AM, grant neale wrote:

>
> Well 1 problem I was thinking about was uploading photos.
> Any suggestion.
>
> Grant

While it's not Django-specific, it's easy to write a Python script  
that monitors an e-mail address and downloads and stores the  
attachments. You could schedule this (maybe with cron) and your script  
could import your Django model and update the database with the info  
on the new files.



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



Distance across a LineString in GeoDjango

2009-10-10 Thread HARRY POTTRER

I have a model which represents a route. I can use the `make_line()`
geoqueryset method to create a LineString like so:

>>> r = Route.objects.get(pk=33)
>>> # a route from Seattle to New York to Miami, a total distance
>>> # of about 3043.8 nautical miles
>>> r

>>> # a collection of the airports used in the route
>>> # turned into a LineString
>>> ls = Airport.objects.filter(routebase__route=r).make_line()
>>> ls


How can I find the total distance of that LineString object, so that
it returns a Distance object that I can then convert to nautical
miles? the .length() method here just returns a float, which is in who-
knows-what units...
--~--~-~--~~~---~--~~
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: Newbie: Trouble getting "import django" to run on Mac OSX 10.5.8

2009-10-10 Thread dbakerweb

I think I figured out my error. I was told to copy the new sub-
directory named "django" to site-packages. I copied the whole
directory (django-1.1) there instead. I made the fix. Now when I
"import django" I just get the prompt back - no error. I assume it is
working.

Thanks for the time you took.

D

On Oct 10, 5:00 pm, Daniel Roseman  wrote:
> On Oct 10, 4:01 pm, dbakerweb  wrote:
>
> > I have gotten to the point where I want to test my install of Django.
> > I run "import django" and get the "No module named django" error. I
> > suspect it is a path issue but I've not been able to understand any
> > googled results for fixing path issues. I am a newbie and not a Unix
> > sysadmin.
>
> > Please help.
>
> Come on, you have to give us something to work with. How is Django
> installed? What is on the pythonpath?
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Redirect home page

2009-10-10 Thread Kurt Neufeld


You could use middleware to do this as I learned last week, but why  
not just make a "view" which is only a function.

urls.py:
...
(r'^$', 'views.DomainRootRedirect' )
...

views.py:
def DomainRootRedirect( request, *args, **kwargs ):
return HttpResponseRedirect( request.get['SCRIPT_NAME'] + "/en/" ) #  
I think SCRIPT_NAME is the param you want


Middleware solution (requires fiddling for your problem):

settings.py:
MIDDLEWARE_CLASSES = (
  ...
 'redirector.ConstructionFilterMiddleware',
  ...
)

redirector/__init__.py:
from django.shortcuts import render_to_response
from django.conf import settings

class ConstructionFilterMiddleware(object):
 """
 This middleware redirects all requests from clients that are
 not in INTERNAL_IPS to the construction.html page
 """

 def process_request(self, request):
 remote_addr = request.META['REMOTE_ADDR']
 is_internal = remote_addr in settings.INTERNAL_IPS

 if not is_internal:
 return render_to_response( 'construction.html' )


On 2009-10-10, at 4:24 PM, Caisys wrote:

>
> Hi,
> I would like visitors to my site homepage www.example.com to be
> redirected to www.example.com/en/ in order to allow for translations
> in the future.
>
> What is the most efficient way?
>
> 1- Use apache mod-rewrite?
> 2- I know i could use the HttpResponseRedirect function in django but
> i felt it might be wasteful to create a view only for this purpose.
> 3- Use a response header?
>
> Thanks
> 

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



Re: Problem with URL naming, generic templates and custom filtering wrappers

2009-10-10 Thread Karen Tracey
On Sat, Oct 10, 2009 at 6:34 PM, Scott SA  wrote:

>
> Hi,
>
> I am trying to use a series of generic views with custom filtering via
> callbacks as per:
>
>
> http://docs.djangoproject.com/en/dev/topics/generic-views/#extending-generic-views
>
> Unfortunately, when I try to name the URL in urls.py, I get various
> errors depending upon how I try to write the pattern call.
>
> I'll write a skeleton of what the code really is:
> ___
>
> in views.py:
> - - - - - - - - - - - - - -
> def my_filter_callback(request, name):
>   ...
>   return list_detail.object_list( request, queryset... )
> ___
>
> in my_template.html:
> - - - - - - - - - - - - - -
> {% for object in obects_list %}
>
> {{ object.name }}
> {% endfor %}
> ___
>
> in urls.py:
> - - - - - - - - - - - - - -
> from views import my_filter_callback
>
> urlpatterns += patterns( '',
>( r'path/(P?[\w\d-]+)/?$', my_filter_callback, 'url-pattern-
> name'),
>   )
>
>
I cannot figure out how this one differs from the next one, nor can I
recreate first two errors you are getting (I just get the no reverse match),
and in making further changes you seem to be moving further away from what
you want to achieve, so I'm just going to stop here and fix this one.

First, the "P?" should be "?P".  You've got the order of the ?
and the P reversed.

Second, since you are specifying this as a bare tuple and not using url(),
and you want to specify the optional name as 'url-pattern-name', you must
also include the optional dictionary which comes before the optional name as
defined here:

http://docs.djangoproject.com/en/dev/topics/http/urls/#patterns

Given what you have 'url-pattern-name' is being taken to be the optional
dictionary, not the optional name.  So change it to:

  (r'path/(?P[\w\d-]+)/?$', my_filter_callback, {},
'url-pattern-name'),

or use url() (read down further in the doc pointed to), omit the dictionary,
and specify the name via keyword:

  url(r'path/(?P[\w\d-]+)/?$', my_filter_callback,
name='url-pattern-name'),

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Newbie: how to get data validation without user interaction?

2009-10-10 Thread Jim DeLaHunt

Yes, Malcolm's “Django Tip: Poor Man's Model Validation” is very
helpful. That should give me enough for this application (which is
very contained and well-behaved).

It's good to know that the term is "model-aware validation", and that
it wasn't somewhere in Django 1.0 that I overlooked.  It's also great
to see forms.model_to_dict(); I didn't know about that.

Thanks again, Karen!
--Jim DeLaHunt

On Oct 10, 3:30 pm, Karen Tracey  wrote:
> On Sat, Oct 10, 2009 at 6:17 PM, Jim DeLaHunt wrote:
>
>
>
> > [snip]
> > 3. Understand if the Django Modelform is the way I ought to be
> > handling this.  Forms are the only Django entity for which I can find
> > documentation about doing validation in accordance with the Model.
> > There's a lot in the Forms documentation about generating HTML and
> > responding to request.POST.  Are there any writeups or patterns of
> > using Forms purely as a formatting and validation mechanism, with no
> > HTML display or HTTP interaction?
>
> > I'm reading through the Modelform documentation right now, but I'd
> > love to know if I'm on the right track.  Thanks in advance for any
> > advice, or pointers to documentation I've overlooked!
>
> Malcolm wrote a blog post you might find helpful for this:
>
> http://www.pointy-stick.com/blog/2008/10/15/django-tip-poor-mans-mode...
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



best way to build a form for m2m-related models (via intermediary table)?

2009-10-10 Thread DaleB

hi,

i am looking for an advice concerning django's forms and formsets.

i am creating a ticket system where the assignees and tickets are
associated via an intermediary table/model.

that's what the models basically looks like:

class Ticket(models.Model):
title = models.CharField('Titel',max_length=160)
assigned_to = models.ManyToManyField
('inventory.User',through='TicketAssignees', blank=True, null=True)

class TicketAssignees(models.Model):
user = models.ForeignKey('inventory.User')
ticket = models.ForeignKey('tracker.Ticket')
status = models.CharField
(max_length=1,choices=RoleChoices,blank=False,null=False)

the intermediary table seemed necessary to me, as i want so send
notifications (via signals) when an assignee is added to or removed
from a ticket.

what is the best way to build a form, that allows me to create a new
ticket?
using a standard modelform the 'assigned_to'-field is rendered as a
multiple choice-widget without the extra fields specified in the
intermediary model (status etc.)
okay, so i could build a custom form and add the missing fields
manually.
but does it make sense to include the fields of both models into the
same form?

i thought about creating an AssigneeForm for the TicketAssignees-Model
and tie it to a TicketForm (where i'd exclude the 'assigned_to'-field)
and glue both forms to new formset.
but as i learned, formsets are basically used to create multiple
copies of the same form.

then inline formsets came to my mind (especially as django's admin
allows to add m2m-related data as InlineAdmin) - but they are, as the
docs state, used for related foreign key data and not for related m2m
data.

what options am i overlooking?
the last thing that comes to my mind is the form wizard - but i am
sure there are simpler solutions ...
--~--~-~--~~~---~--~~
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: Newbie: having trouble with save method

2009-10-10 Thread Karen Tracey
On Sat, Oct 10, 2009 at 6:04 PM, Senthil  wrote:

>
> Hey Guys,
> I am not able to understand this behavior happening in django
>
> My models.py is as follows
>
> from django.db import models
> from django.contrib.auth.models import User
>
>
> class ht_wt(models.Model):
>user = models.ForeignKey(User)
>EntryDate = models.DateField(auto_now = True)
>height = models.IntegerField(verbose_name = 'Users height at that
> given date')
>weight = models.IntegerField(verbose_name = 'Users Weight at that
> given date')
>#userid = models.CharField(max_length = 50,verbose_name =
> 'UserName',blank = False)
>
>def __unicode__(self):
>return 'Table to capture the users height & weight at the
> given
> date'
>

Note this is a rather odd __unicode__ method.  This method is used to get
the string representation of an instance of the model, not the model class
overall.  Usually you'd want to return specific attributes from the model
instance self, so that you can tell which instance you are dealing with.
With what you have here all model instances of this class will appear the
same from their string/unicode representation.


> class food_log(models.Model):
> [snip model that doesn' t have anything to do with the question]
>
> I try query a user from the existing  user table and save that user to
> a new ht_wt model object and save that object and I get an error
> saying that it cannot recognize the users primary key. However, when I
> save a new user and use that in my ht_wt model object, then everything
> works fine as shown below.
>
> >>> from django.contrib.auth.models import User
> >>> from htrack.htapp.models import *
> >>> u = User(username='testuser')
> >>> u
> 
>

You have not actually retrieved a user from the existing user table here.
What you have done is created a new User model instance with username
'testuser'.  This instance has not been saved to the database so it has no
primary key id.

If you want to retrieve an instance from the database you need to use one of
the model methods that actually accesses the database.  For example:

>>> u = User.objects.get(username='testuser')

Assuming that works (there is a User with that username), your subsequent
code will work.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Foreign language in View Model.

2009-10-10 Thread Rizwan

I am trying to extend flatpage view...I have added custom code
here..you can see navigation showing question mark here
http://beta.rmansuri.net/homepage/


from django.contrib.flatpages.models import FlatPage
from django.template import loader, RequestContext
from django.shortcuts import get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect
from django.conf import settings
from django.core.xheaders import populate_xheaders
from django.utils.safestring import mark_safe
import datetime, MySQLdb
DEFAULT_TEMPLATE = 'flatpages/default.html'

def flatpage(request, url):
"""
Flat page view.

Models: `flatpages.flatpages`
Templates: Uses the template defined by the ``template_name``
field,
or `flatpages/default.html` if template_name is not defined.
Context:
flatpage
`flatpages.flatpages` object
"""
if not url.endswith('/') and settings.APPEND_SLASH:
return HttpResponseRedirect("%s/" % request.path)
if not url.startswith('/'):
url = "/" + url
f = get_object_or_404(FlatPage, url__exact=url,
sites__id__exact=settings.SITE_ID)
# If registration is required for accessing this page, and the
user isn't
# logged in, redirect to the login page.
if f.registration_required and not request.user.is_authenticated
():
from django.contrib.auth.views import redirect_to_login
return redirect_to_login(request.path)
if f.template_name:
t = loader.select_template((f.template_name,
DEFAULT_TEMPLATE))
else:
t = loader.get_template(DEFAULT_TEMPLATE)

# To avoid having to always use the "|safe" filter in flatpage
templates,
# mark the title and content as already safe (since they are raw
HTML
# content in the first place).
f.title = mark_safe(f.title)
f.content = mark_safe(f.content)

#custom code start
db = MySQLdb.connect
(user='rmansuri_gq',db='rmansuri_gq',passwd='riz#wan1712',host='localhost')
cursor = db.cursor()
cursor.execute("SELECT * from django_flatpage where id != 2")
details = [row for row in cursor.fetchall()]
db.close()
# custom code ends
c = RequestContext(request, {
'flatpage': f, 'details':details,
})
response = HttpResponse(t.render(c))
populate_xheaders(request, response, FlatPage, f.id)
return response

HTML CODE


http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">

   



{{flatpage.title}}









Gujarati Quran


home
about
contact




[+] |
[-]

 {{flatpage.title}}
 {{flatpage.content}}
 




{% for id,url, title,content in details %}
{{title|safe}}
{% endfor %}



Recent Entries

Recent Entries1 01 Des 
06
Recent Entries2 01 Des 
06
Recent Entries3 01 Des 
06
Recent Entries4 01 Des 
06
Recent Entries5 01 Des 
06





©http://www.rmansuri.net/";
rel="external">rMansuri.net. Valid http://jigsaw.w3.org/
css-validator/check/referer" rel="external">CSS & http://validator.w3.org/check?uri=referer"; rel="external">XHTML






On 10 Oct, 20:40, Joshua Russo  wrote:
> On Sat, Oct 10, 2009 at 9:15 AM, Rizwan  wrote:
>
> > Hello Djangoer,
>
> > I am trying to create website with foreign language in it. I have
> > created model for content type and added one page in it. It saving
> > fine in database. When I have tried to write view model for this page.
> > Its showing me "?" rather then foreign character. I am new born
> > baby in django world. any help or suggestion would be great.
>
> > you can see the this question mark athttp://beta.rmansuri.net/surah/001/
>
> Without the code from your view (and possibly the template) it's
> too difficult to say.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Problem with URL naming, generic templates and custom filtering wrappers

2009-10-10 Thread Scott SA

Hi,

I am trying to use a series of generic views with custom filtering via
callbacks as per:

http://docs.djangoproject.com/en/dev/topics/generic-views/#extending-generic-views

Unfortunately, when I try to name the URL in urls.py, I get various
errors depending upon how I try to write the pattern call.

I'll write a skeleton of what the code really is:
___

in views.py:
- - - - - - - - - - - - - -
def my_filter_callback(request, name):
   ...
   return list_detail.object_list( request, queryset... )
___

in my_template.html:
- - - - - - - - - - - - - -
{% for object in obects_list %}

{{ object.name }}
{% endfor %}
___

in urls.py:
- - - - - - - - - - - - - -
from views import my_filter_callback

urlpatterns += patterns( '',
( r'path/(P?[\w\d-]+)/?$', my_filter_callback, 'url-pattern-
name'),
   )

- - - - - - - - - - - - - -
AttributeErrror:
'str' object has no attribute 'resolve'

/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/django/core/urlresolvers.py in resolve

 211. def resolve(self, path):
 212. tried = []
 213. match = self.regex.search(path)
 214. if match:
 215. new_path = path[match.end():]
 216. for pattern in self.url_patterns:
 217. try:

 218. sub_match = pattern.resolve(new_path)
___

in urls.py:
- - - - - - - - - - - - - -
from views import my_filter_callback

urlpatterns += patterns( '',
( r'path/(P?[\w\d-]+)/?$', my_filter_callback, 'url-pattern-
name'),
   )

- - - - - - - - - - - - - -
ValueError at /path/
dictionary update sequence element #0 has length 1; 2 is required

/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/django/core/urlresolvers.py in resolve
 116. # positional arguments.
 117. kwargs = match.groupdict()
 118. if kwargs:
 119. args = ()
 120. else:
 121. args = match.groups()
 122. # In both cases, pass any extra_kwargs as **kwargs.

 123. kwargs.update(self.default_args)
___

Alternate version of urls.py

urlpatterns += patterns( '',
( r'path/(P?[\w\d-]+)/?$', my_filter_callback ),
   )

# note: after reading the code, I also passed the prefix
"myapp.views",
# then called my callback as "my_filter_callback", trying to get
# the  'url' method of /django/conf/urls/defaults.py to compose
# the callback path as a string.
- - - - - - - - - - - - - -
TemplateSyntaxError at /path/

Caught an exception while rendering: Reverse for 'url-pattern-name'
with arguments '()' and keyword arguments '{'name': u'some-name'}' not
found.
___

So, I followed the source and tried a few different things. For
example, I have tried to call RegexURLPattern adding a 'name'
parameter, but that then gets passed to my callback, which in turn
gets passed to django's generic list architecture. That subsequently
generates an "unexpected attribute" error named "name", instead of it
being used by RegexURLPattern to name the url pattern for reverse.

Am I going to have to sub-class RegexURLPattern and force it to stick
the name 'somewhere' appropriate, because at this point I don't think
things are working as they should and I think I've dug deep enough to
see that I've been making the correct calls.

So, in a word: Help!

Thanks in advance to any and all that can help me decode this mystery.

Scott

PS. My other alternative is to not reverse the URL, but calculate it
m'self, which is less flexible. It may, in the short term be
substantially quicker than some of my other alternatives.

--~--~-~--~~~---~--~~
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: Newbie: how to get data validation without user interaction?

2009-10-10 Thread Karen Tracey
On Sat, Oct 10, 2009 at 6:17 PM, Jim DeLaHunt wrote:

>
> [snip]
> 3. Understand if the Django Modelform is the way I ought to be
> handling this.  Forms are the only Django entity for which I can find
> documentation about doing validation in accordance with the Model.
> There's a lot in the Forms documentation about generating HTML and
> responding to request.POST.  Are there any writeups or patterns of
> using Forms purely as a formatting and validation mechanism, with no
> HTML display or HTTP interaction?
>
> I'm reading through the Modelform documentation right now, but I'd
> love to know if I'm on the right track.  Thanks in advance for any
> advice, or pointers to documentation I've overlooked!
>
>
Malcolm wrote a blog post you might find helpful for this:

http://www.pointy-stick.com/blog/2008/10/15/django-tip-poor-mans-model-validation/

Karen

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



Redirect home page

2009-10-10 Thread Caisys

Hi,
I would like visitors to my site homepage www.example.com to be
redirected to www.example.com/en/ in order to allow for translations
in the future.

What is the most efficient way?

1- Use apache mod-rewrite?
2- I know i could use the HttpResponseRedirect function in django but
i felt it might be wasteful to create a view only for this purpose.
3- Use a response header?

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



Newbie: how to get data validation without user interaction?

2009-10-10 Thread Jim DeLaHunt

Hi, folks:

I appreciate the people who are willing to help out newbies here. In
my journey up Django Mountain, I'm now at the stage where I want to
validate data.  My app is not interactive and has no web component;
I'm just using Django as a database access layer.

My app reads some data out of files, and parse it into a Python
classes of mine. Then I use those classes to populate two Django Model
classes, which are subclasses of models.Model. If I make sure the
incoming data is valid, then I can instantiate the Model classes, and
call their .save() methods, and Django saves to the database
successfully. So that much of the mechanism works.

But in this messy world, not all the data I parse is valid. If some of
the incoming strings are too long for my models.CharField() instances,
then I get the following exception, which stops my script:
_mysql_exceptions.Warning: Data truncated for column 'source' at row 1

What I would like to do is:
 1.  Have a clean way to write those errors to my log, instead of
having the backend stop my script. Is there a pattern I can follow to
catch these exceptions, write a sensible error message, and continue?

 2. Use the Django model to help me validate the data.  At the very
least, I'd like to get at the maxlength parameters of the
models.CharField() instances, and truncate overlong incoming strings
appropriately (and write a message to my log). How can I get at these
model parameters?  An expression like
"MyModel.mystringfield.maxlength" results in a "missing attribute"
error.

3. Understand if the Django Modelform is the way I ought to be
handling this.  Forms are the only Django entity for which I can find
documentation about doing validation in accordance with the Model.
There's a lot in the Forms documentation about generating HTML and
responding to request.POST.  Are there any writeups or patterns of
using Forms purely as a formatting and validation mechanism, with no
HTML display or HTTP interaction?

I'm reading through the Modelform documentation right now, but I'd
love to know if I'm on the right track.  Thanks in advance for any
advice, or pointers to documentation I've overlooked!

--Jim DeLaHunt, Vancouver, Canada  http://jdlh.com/  (Happy
Thanksgiving, you Canucks!)
--~--~-~--~~~---~--~~
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: 'NoneType' object has no attribute 'widget'

2009-10-10 Thread redawn

Hey, can anybody figure out what's going on around here. I stumbled
on
this post since I have a similar issue, 'GeoPt' object has no
attribute 'widget'.
I followed Karen's response and it seems that I have a similar issue
since I
don't explicitly declare 'location' and 'location_geocells' in my
model, because
the get added from 'geomodel.py' . By the way, if I explicitly add
'location' and
'location_geocells' I get a DuplicateAttribute Error.

Here's some pastebin of some of the code, it trips up on the
'rform.is_valid'.
http://pastebin.com/m1cce44a5

And here's 'geomodel.py'
http://code.google.com/p/geomodel/source/browse/trunk/geo/geomodel.py

Red

On Oct 1, 7:54 am, Karen Tracey  wrote:
> On Thu, Oct 1, 2009 at 5:33 AM, dijxtra  wrote:
>
> > On Sep 30, 5:12 pm, Karen Tracey  wrote:
> > > On Wed, Sep 30, 2009 at 10:53 AM, dijxtra  wrote:
>
> > > > I'm getting "'NoneType' object has no attribute 'widget'" exception
> > > > and I just can't figure out where is the problem. Here is my error:
>
> > > > Django Version: 1.1
>
> > > > Traceback:
> > > > [snip]
>
> > > In this form:
>
> > >1. class DiaryEntryForm(ModelForm):
> > >2. importance = models.IntegerField(choices=IMPORTANCE_CHOICES)
> > >3. class Meta:
> > >4. model = DiaryEntry
> > >5. fields = ['text', 'date', 'type', 'importance']
>
> > > 'importance' has been specified as a model field instead of a form field.
> > > It needs to be a form field, since this is a form, not a model.
>
> > Damn. This one was obvious. But, despite of this bugfix, the error
> > still remains.
>
> > This one:http://pastebin.com/pastebin.php?diff=m1867a8ad
> > Gives me this:
> > Django Version: 1.1
>
> > Traceback:
> > [snip]
>
> 234. value = field.widget.value_from_datadict(self.data,> 
> self.files, self.add_prefix(name))
>
> > Exception Value: 'NoneType' object has no attribute 'widget'
>
> OK, looking a bit further, the form lists 'type' in fields but I do not see
> that field in the model?
>
> (If you were only adding 'importance' to the form explicitly in order to try
> to fix this error, best to get rid of it.  Best to go back to the simplest
> version of your code that had problems when posting looking for solutions.
> Posting the original version modified with fixes that don't fix the problem
> just makes it more confusing.)
>
> Karen

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



Newbie: having trouble with save method

2009-10-10 Thread Senthil

Hey Guys,
I am not able to understand this behavior happening in django

My models.py is as follows

from django.db import models
from django.contrib.auth.models import User


class ht_wt(models.Model):
user = models.ForeignKey(User)
EntryDate = models.DateField(auto_now = True)
height = models.IntegerField(verbose_name = 'Users height at that
given date')
weight = models.IntegerField(verbose_name = 'Users Weight at that
given date')
#userid = models.CharField(max_length = 50,verbose_name =
'UserName',blank = False)

def __unicode__(self):
return 'Table to capture the users height & weight at the given
date'
class food_log(models.Model):
user = models.ForeignKey(User)
EntryDate = models.DateField(auto_now = True)
food_name = models.CharField(max_length = 200)
calories = models.IntegerField()
#userid = models.CharField(max_length = 50,verbose_name =
'UserName',blank = False)

def __unicode__(self):
return 'Table to capture the users food log at a given date'

I try query a user from the existing  user table and save that user to
a new ht_wt model object and save that object and I get an error
saying that it cannot recognize the users primary key. However, when I
save a new user and use that in my ht_wt model object, then everything
works fine as shown below.

>>> from django.contrib.auth.models import User
>>> from htrack.htapp.models import *
>>> u = User(username='testuser')
>>> u

>>> h = ht_wt(user = u, height = 75, weight = 60)
>>> h.save()
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/dist-packages/django/db/models/base.py",
line 410, in save
self.save_base(force_insert=force_insert,
force_update=force_update)
  File "/usr/lib/python2.6/dist-packages/django/db/models/base.py",
line 495, in save_base
result = manager._insert(values, return_id=update_pk)
  File "/usr/lib/python2.6/dist-packages/django/db/models/manager.py",
line 177, in _insert
return insert_query(self.model, values, **kwargs)
  File "/usr/lib/python2.6/dist-packages/django/db/models/query.py",
line 1087, in insert_query
return query.execute_sql(return_id)
  File "/usr/lib/python2.6/dist-packages/django/db/models/sql/
subqueries.py", line 320, in execute_sql
cursor = super(InsertQuery, self).execute_sql(None)
  File "/usr/lib/python2.6/dist-packages/django/db/models/sql/
query.py", line 2369, in execute_sql
cursor.execute(sql, params)
  File "/usr/lib/python2.6/dist-packages/django/db/backends/util.py",
line 19, in execute
return self.cursor.execute(sql, params)
  File "/usr/lib/python2.6/dist-packages/django/db/backends/mysql/
base.py", line 89, in execute
raise Database.IntegrityError(tuple(e))
IntegrityError: (1048, "Column 'user_id' cannot be null")
>>> u2 = User(username = 'testuser4')
>>> u2.save()
>>> h.user = u2
>>> h.save()

Can someone explain why this behavior is happening ? I have a hunch
that django knows the users primary key after saving but does not know
it when querying the user. If this is the case,  is there a method to
save new ht_wt and food_log objects for existing users.

Thanks a lot in advance. Django is really cool.

Senthil

--~--~-~--~~~---~--~~
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: Running just core regression tests

2009-10-10 Thread Karen Tracey
On Sat, Oct 10, 2009 at 11:41 AM, Tim Chase
wrote:

>
> Currently, I use
>
> t...@rubbish:~/django/trunk/tests$ python runtests.py
> --settings=settings
>
> to execute the core set of tests.  However, it takes quite a
> while (on the order of hours) on my old box.  Is there a way to
> just run tests on the regressions/ subdirectory or even just a
> particular file within?
>
> How do core devs typically make testing a subset faster?
>
> Hours?  What database are you using?  You show that you are running trunk
level code, so you should have the transaction-based test speedup that went
into 1.1.  However, this speedup only helps for database configurations that
support transactions, so if you are using MySQL with the MyISAM engine tests
will run very slowly.  If that is what is causing the slowness in your case,
switching to using sqlite for the database for testing would help
tremendously.

On my oldest slowest machine (7 year old WinXP box with 384M of memory),
current trunk tests take about 15 minutes to run using sqlite as the
database.  The 1.0.X branch, without the transaction speedups, takes 1.5
hours (even though it has 25% fewer tests).  So the hours time you cite
sounds to me like you must not be running a config that is using the test
speedup that went into 1.1?  Or do you really have a machine so much slower
than my oldest?

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Newbie: Trouble getting "import django" to run on Mac OSX 10.5.8

2009-10-10 Thread dbakerweb

I followed the install instructions in the book entitled: "Python Web
Development with Django". I copied the expanded Directory "Django-1.1"
to /Library/Python/2.5/site-packages. I don't know how to answer the
question about the pythonpath because that is the "howto" info that is
missing. One article on the web says I can add/set to this parameter
in a file called "sys.path" but I can't find such a file on my Mac OSX
system.

D

On Oct 10, 5:00 pm, Daniel Roseman  wrote:
> On Oct 10, 4:01 pm, dbakerweb  wrote:
>
> > I have gotten to the point where I want to test my install of Django.
> > I run "import django" and get the "No module named django" error. I
> > suspect it is a path issue but I've not been able to understand any
> > googled results for fixing path issues. I am a newbie and not a Unix
> > sysadmin.
>
> > Please help.
>
> Come on, you have to give us something to work with. How is Django
> installed? What is on the pythonpath?
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newbie: Trouble getting "import django" to run on Mac OSX 10.5.8

2009-10-10 Thread Daniel Roseman

On Oct 10, 4:01 pm, dbakerweb  wrote:
> I have gotten to the point where I want to test my install of Django.
> I run "import django" and get the "No module named django" error. I
> suspect it is a path issue but I've not been able to understand any
> googled results for fixing path issues. I am a newbie and not a Unix
> sysadmin.
>
> Please help.

Come on, you have to give us something to work with. How is Django
installed? What is on the pythonpath?
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Xampp and django

2009-10-10 Thread Daniel Roseman

On Oct 10, 3:43 pm, djbahati  wrote:
> Hi All,
> Am new to django,
> am developing application but i face a problem in displaying template.
> The browser does not display any template it just display plain text.
> am using django 1.1 and xampp 1.7.1. Any idea?

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



Re: How to create a 3rd-party database driver

2009-10-10 Thread Daniel Rhoden

Thanks guys.  This is much better information than what I had.

On Oct 9, 5:29 pm, Daniel Rhoden  wrote:
> Can you direct me to the documentation for creating my own 3rd-party
> database driver?
>
> I'm wanting to create a sibling to the concept of a SQLite, MySQL, ...
> Driver.  Where's API documentation that says "You must respond to a
> minimum of these function calls to be a back end driver to django".
>
> Said another way, I want to edit the settings.py file and change this
> line:
>
> DATABASE_ENGINE = 'sqlite3'
>
> to something like this:
>
> DATABASE_ENGINE = 'danielsdriver'
>
> Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Foreign language in View Model.

2009-10-10 Thread Joshua Russo
On Sat, Oct 10, 2009 at 9:15 AM, Rizwan  wrote:

>
> Hello Djangoer,
>
> I am trying to create website with foreign language in it. I have
> created model for content type and added one page in it. It saving
> fine in database. When I have tried to write view model for this page.
> Its showing me "?" rather then foreign character. I am new born
> baby in django world. any help or suggestion would be great.
>
> you can see the this question mark at http://beta.rmansuri.net/surah/001/
>

Without the code from your view (and possibly the template) it's
too difficult to say.

--~--~-~--~~~---~--~~
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: Running just core regression tests

2009-10-10 Thread Russell Keith-Magee

On Sat, Oct 10, 2009 at 11:41 PM, Tim Chase
 wrote:
>
> Currently, I use
>
> t...@rubbish:~/django/trunk/tests$ python runtests.py
> --settings=settings
>
> to execute the core set of tests.  However, it takes quite a
> while (on the order of hours) on my old box.  Is there a way to
> just run tests on the regressions/ subdirectory or even just a
> particular file within?
>
> How do core devs typically make testing a subset faster?

There's no way to say "just run the tests in the regression
directory", but you can use the same tricks that ./manage.py test
allows - that is, you can say:

./runtests.py --settings=xxx query aggregation_regress serializers_regress

and that will just run the query, aggregation_regress and
serializers_regress tests. For unit tests, you can go one step deeper
and narrow this down to a single TestCase, or a single test inside a
test case:

./runtests.py --settings=xxx test_client.ClientTest
./runtests.py --settings=xxx test_client.ClientTest.test_get_view

Following on from this, I personally have a couple of scripts where
I've gathered together subsets of tests that I know have a particular
focus - e.g., the tests that are testing core database functions, the
tests for the form library, tests for the admin, etc. These scripts
are effectively just aliases for calls to runtests.py with a list of
relevant test names. That way, I can easily run a subset of the full
test suite with a single script.

If I'm working on a particular feature, I may produce a custom script
for an even more reduced subset - for example, when I was working on
aggregation, I had a script to just run aggregation,
aggregation_regress, expressions, expressions_regress and query.

Of course, I still run the full test suite before I commit anything,
but these subsets are usually good enough during the development of a
particular feature that I know is "just database" or "just forms".

Yours,
Russ Magee %-)

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



Running just core regression tests

2009-10-10 Thread Tim Chase

Currently, I use

t...@rubbish:~/django/trunk/tests$ python runtests.py 
--settings=settings

to execute the core set of tests.  However, it takes quite a 
while (on the order of hours) on my old box.  Is there a way to 
just run tests on the regressions/ subdirectory or even just a 
particular file within?

How do core devs typically make testing a subset faster?

-tkc





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



Re: how to design mobile version of my site based on django?

2009-10-10 Thread Gerard

There's basically two ways. Conditionally have Django serve different 
templates, or even templates with conditions in them. The other is to make 
your site viewable in a phone as well as on a computer screen.

Long term planning .. The 2nd is the better choice but that depends on your 
content.

Might want to look at: http://code.google.com/p/minidetector/

Regards,

Gerard.

hao he wrote:
> I'm developing my site with django,
> 
> mainly, my site works as normal, visited by PC.
> 
> but ,the site will also be visited by mobile device(e.g.iphone)
> 
> who tell me the solution?
> 
> or recommend me some relevant articles?
> 
> thanks .
> 
> > 


-- 
self.url = www.gerardjp.com

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



Newbie: Trouble getting "import django" to run on Mac OSX 10.5.8

2009-10-10 Thread dbakerweb

I have gotten to the point where I want to test my install of Django.
I run "import django" and get the "No module named django" error. I
suspect it is a path issue but I've not been able to understand any
googled results for fixing path issues. I am a newbie and not a Unix
sysadmin.

Please help.

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



Xampp and django

2009-10-10 Thread djbahati

Hi All,
Am new to django,
am developing application but i face a problem in displaying template.
The browser does not display any template it just display plain text.
am using django 1.1 and xampp 1.7.1. Any idea?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to design mobile version of my site based on django?

2009-10-10 Thread hao he

thank you.
you means the greatest difference between PC and phone is the size of
their screen.
ok.
and what I need to do is  to ensure  that the DIV+CSS  is resizable.
but .whether it is easy  for DIV+CSS designed for PC to adapt the
mobile screen?

thank you .


On Oct 10, 3:54 pm, Jani Tiainen  wrote:
> hao he kirjoitti:
>
> > I'm developing my site with django,
>
> > mainly, my site works as normal, visited by PC.
>
> > but ,the site will also be visited by mobile device(e.g.iphone)
>
> > who tell me the solution?
>
> > or recommend me some relevant articles?
>
> This has almost nothing to do with Django.
>
> It's just what to display for smaller display devices and simples way is
> to use simplified versions of huge pages. If your site is "normal",
> there is not much of need to do anything. Standard HTML, CSS and even JS
> works in most mobile devices without problems.
>
> Of course you might want to limit amount of data sent over network since
> mobile speeds aren't that high. So you might want to use some detection
> about "this is mobile device" (maybe there is some magic header that
> reveals it) and forward user to a bit more lightweight page(s) instead
> of using heavy, large screen pages meant for large display computers.
>
> Easiest way is to test your site with mobile and see does it work or not.
>
> --
> Jani Tiainen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: newbie , need some help

2009-10-10 Thread Chris Withers

danin wrote:
>   I am just learning django from last 2 weeks. while learning i get
> confused in validation. Can anyone plese provide me  reference to some
> material so that i can read and underatand it from ther.

http://lmgtfy.com/?q=django+validation

How about getting and reading the Django book while you're at it? ;-)

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: can I do doctest in view function? if I can, how to use fixture data in doctest?

2009-10-10 Thread hao he

the following 2 solution enable  my view function  doctest-able:
--solution 1-it is not convenient to go to
the error point in source.py
--
add the following code to "models.py" of your "views.py"
from common import get_doctest
__test__ = get_doctest('userprofile.views')

##common.get_doctest defination:
def get_doctest(module_name): # you
test_dict={}
module = __import__(module_name,{},{},module_name.split('.')
[-1])
for obj_name,obj in module.__dict__.items():
if '__module__' in dir(obj) and obj.__module__ == module_name:
if obj.__doc__:
test_dict[obj_name] = obj.__doc__
return test_dict

---solution2-you can 'click' and go to the error
point in source.py  (when in
eclipse)--
#modify C:\Python25\Lib\site-packages\django\test\simple.py
#add get_views function
def get_views(app_module):
TEST_MODULE = 'views'
try:
app_path = app_module.__name__.split('.')[:-1]
test_module = __import__('.'.join(app_path + [TEST_MODULE]),
{}, {}, TEST_MODULE)
except ImportError, e:
# Couldn't import tests.py. Was it due to a missing file, or
# due to an import error in a tests.py that actually exists?
import os.path
from imp import find_module
try:
mod = find_module(TEST_MODULE, [os.path.dirname
(app_module.__file__)])
except ImportError:
# 'tests' module doesn't exist. Move on.
test_module = None
else:
# The module exists, so there must be an import error in
the
# test module itself. We don't need the module; so if the
# module was a single file module (i.e., tests.py), close
the file
# handle returned by find_module. Otherwise, the test
module
# is a directory, and there is nothing to close.
if mod[0]:
mod[0].close()
raise
return test_module

#modify the build_suite function as follow:
def build_suite(app_module):
"Create a complete Django test suite for the provided application
module"
suite = unittest.TestSuite()

# Load unit and doctests in the models.py module. If module has
# a suite() method, use it. Otherwise build the test suite
ourselves.
if hasattr(app_module, 'suite'):
suite.addTest(app_module.suite())
else:
suite.addTest(unittest.defaultTestLoader.loadTestsFromModule
(app_module))
try:
suite.addTest(doctest.DocTestSuite(app_module,
 
checker=doctestOutputChecker,
   runner=DocTestRunner))
except ValueError:
# No doc tests in models.py
pass


#added by hehao,enable 'views' doctestable
view_module = get_views(app_module)
if hasattr(view_module, 'suite'):
suite.addTest(view_module.suite())
else:
suite.addTest(unittest.defaultTestLoader.loadTestsFromModule
(view_module))
try:
suite.addTest(doctest.DocTestSuite(view_module,
 
checker=doctestOutputChecker,
   runner=DocTestRunner))
except ValueError:
# No doc tests in models.py
pass



# Check to see if a separate 'tests' module exists parallel to
the
# models module
test_module = get_tests(app_module)
if test_module:
# Load unit and doctests in the tests.py module. If module has
# a suite() method, use it. Otherwise build the test suite
ourselves.
if hasattr(test_module, 'suite'):
suite.addTest(test_module.suite())
else:
suite.addTest
(unittest.defaultTestLoader.loadTestsFromModule(test_module))
try:
suite.addTest(doctest.DocTestSuite(test_module,
 
checker=doctestOutputChecker,
 
runner=DocTestRunner))
except ValueError:
# No doc tests in tests.py
pass

return suite


#modify C:\Python25\Lib\site-packages\django\test\_doctest.py
find the following code:
# Recurse to functions & classes.
if ((inspect.isfunction(val) or inspect.isclass(val))
and
self._from_module(module, val)):
self._find(tests, val, valname, module,
source_lines,
   globs, seen)

update to :
# Recurse to functions & classes & decorator-object
if ((inspect.isfunction(val) or inspect.isclass(val)
or callable(val)  ) and
self._from_module(module, val)):
self._find(tests, val, valname, module,
source_lines,
   globs, seen)


you can write doctest for view
function---
@login_required
def overview(request, template = "userprofile/profile/over

required fields during object instantiation

2009-10-10 Thread Chris Withers

Hi All,

Assuming this model:

class Month(models.Model):
 month = models.DateField(
 db_index=True,
 verbose_name='Month'
 )
 def __unicode__(self):
 return unicode(self.month.strftime('%B %Y'))

Now, I could have sworn this used to throw an error if I did:

m = Month()

...because I haven't supplied a required field. But it no longer seems 
to do so until .save() is called.

Am I imagining things?

This behaviour is suboptimal, here's an example why using the above model:

 >>> Month()
Traceback (most recent call last):
   File "models.py", line 65,
in __unicode__
 return unicode(self.month.strftime('%B %Y'))
AttributeError: 'NoneType' object has no attribute 'strftime'

:-(

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

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



newbie , need some help

2009-10-10 Thread danin

Hi all,
  I am just learning django from last 2 weeks. while learning i get
confused in validation. Can anyone plese provide me  reference to some
material so that i can read and underatand it from ther.

Thanks and regard

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



Problem with cookies and template

2009-10-10 Thread Denis Bahati
Hi all,
Am new to python and django but am facing aproblem with templates and login
the admin page.
1) I cannot login to admin page page because django keeps giving me a
message Look for your browser cofiguration to allow cookies but am sure my
browser allows all cookies.
2) Am using xampp 1.7.1 as webserver, django doesn't display its template.
Any idea for this.

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



Internationalized URLs

2009-10-10 Thread Anderson Santos

Hello, I'm trying to find the best approach to have multiple languages
urls on reusable apps but I can't find a good way to do it and I
couldn't find any useful information around.

I am not sure if the best is just to do something like this:

url(r'^%s/$' % _('mymultipath'),myview,name='myviewname')

or using multiple url files which violates the DRY principal

or if there's a better approach, since I don't know what happens with
the first example when we change the locale on the fly

any opinions?


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



Foreign language in View Model.

2009-10-10 Thread Rizwan

Hello Djangoer,

I am trying to create website with foreign language in it. I have
created model for content type and added one page in it. It saving
fine in database. When I have tried to write view model for this page.
Its showing me "?" rather then foreign character. I am new born
baby in django world. any help or suggestion would be great.

you can see the this question mark at http://beta.rmansuri.net/surah/001/

Thanks,

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



Re: Show first available Image in a loop

2009-10-10 Thread Mike Ramirez
On Saturday 10 October 2009 00:55:02 The Danny Bos wrote:
> Good point.
> Here's the models I'm talking about as they're slightly different than
> your aforementioned solution.
> 
> class Collection(models.Model):
>   title = models.CharField(max_length=50, unique=True, help_text="eg:
> Pokemon, Kiss, Baseball ...")
>   slug = models.SlugField(max_length=50, unique=True)
>   date_added = models.DateField(auto_now=True)
> 
> class CollectionItem(models.Model):
>   collection = models.ForeignKey(Collection)
>   number = models.IntegerField(help_text="Last Added")
>   image = models.ImageField(blank=True, upload_to='temp/')
>   date_added = models.DateField(auto_now=True)
> 
> 
> So 'Collection' would be the 'trading card' set, and 'CollectionItem'
> would be the individual trading card, eg: Pokemon Card #24. We may
> only have images available for a few 'Pokemon' cards, eg: #3, 4, 8, 9.
> So getting a default image that way?
> 
> See what I mean?
> 
> 
> d
> 

you could do something in the template or as a template tag, 

First set a default image field for the collection in the Collection model

This is as a tag, you can define this in your CollectionModel as a method, I 
think either of these are acceptable methods for handling it. The choice is 
yours.

CollectionItem is card in the following examples.

def get_image_or_default(card):
  """ Tag to get a card image or the default for the collection. """
  if os.path.exists(card.image.file):
return '' \
%(card.image.url, card.image.height, card.image.width, card.name)
  else:
return '' \
%(card.collection_set.default_image.url,
  card.collection_set.default_image.height,
  card.collection_set.default_image.width,
  card.name)


Alternatively you can do the same in the template. 

{% if card.image %}  
  set card image
{% else %}
  set default
{% endif %}

if the image doesn't exist the template will return an error about the missing 
file, this test will allow you to set the default or the cards image.

Hope this helps,
 
Mike

-- 
I don't want to be young again, I just don't want to get any older.



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


Re: Model Class Inheritance question

2009-10-10 Thread Jani Tiainen

whiskeyjuvenile kirjoitti:
> I'm making some sort of galactic map with the following classes
> defined in models.py:
> 
> class Star(models.Model):
> name = models.CharField(max_length=200)
> xcoord = models.FloatField()
> ycoord = models.FloatField()
> zcoord = models.FloatField()
> def __unicode__(self):
> return self.name + ' (' + str(self.xcoord) + ', ' + str
> (self.ycoord) + ', ' + str(self.zcoord) + ')'
> 
> class Satellite(models.Model):
> name = models.CharField(max_length=200)
> description = models.TextField(blank=True, null=True)
> system = models.ForeignKey(System, related_name='satellites')
> def __unicode__(self):
> return self.name
> 
> class Planet(Satellite):
> orbital = models.IntegerField()
> 
> class Moon(Satellite):
> suborbital = models.IntegerField()
> orbits = models.ForeignKey(Planet, related_name='moons')
> 
> What should I do so I can refer to an s.planets object containing all
> objects of class Planet with system==s?
> 
> it seems like Star should have added
> def _get_planets(self):
> return self.planets
> def _set_planets(self, planet):
> self.planets.append(planet)
> planets = property(_get_planets, _set_planets)
> 
> and Planet should have something like
> def __init__(self, *args, **kwargs):
> super(Planet, self).__init__(*args, **kwargs)
> self.star.planets.append(self)
> def save(self):
> super(Planet, self).save()
> 
> Does this look accurate?

No. It seems that there is something wrong. There is no relation between 
Star and Satellite, Planet or Moon. Releation is made between System (?) 
and Satellite and Satellite has one to one relation to Planet And Moon 
(comes from inheritance).

To get all Planets in system it should be something like:

Planet.objects.filter(system=s) and that's it. Nothing complicated. But 
to get all Planets from System is a bit more trickier since there 
doesn't exist that reverse relation directly.

So first you need to fetch all Systems that has Satellite that has 
Planet. something like 
System.objects.filter(satellites__planet_set__isnull=False)

A bit tricky. If you don't want to have own table for Satellite, make it 
to abstract and then Planet and Satellite both will be pure concrete 
classes (then of course you can't have single "satellites" but both 
inherited concrete classes do need their own reverse relations.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Show first available Image in a loop

2009-10-10 Thread The Danny Bos


Good point.
Here's the models I'm talking about as they're slightly different than
your aforementioned solution.

class Collection(models.Model):
title = models.CharField(max_length=50, unique=True, help_text="eg:
Pokemon, Kiss, Baseball ...")
slug = models.SlugField(max_length=50, unique=True)
date_added = models.DateField(auto_now=True)

class CollectionItem(models.Model):
collection = models.ForeignKey(Collection)
number = models.IntegerField(help_text="Last Added")
image = models.ImageField(blank=True, upload_to='temp/')
date_added = models.DateField(auto_now=True)


So 'Collection' would be the 'trading card' set, and 'CollectionItem'
would be the individual trading card, eg: Pokemon Card #24. We may
only have images available for a few 'Pokemon' cards, eg: #3, 4, 8, 9.
So getting a default image that way?

See what I mean?


d


On Oct 10, 12:35 pm, Tim Chase  wrote:
> > I'm looping through an array of 'trading card' titles. For instance:
>
> >  - Pokemon
> >  - Kiss
> >  - Baseball
>
> > Instead of showing just the title of the 'trading card', I'd like to
> > display an image of each instead.
> > But not all images are available for every card in a title, for
> > instance 'Pokemon' may only have cards/images for #4, 5, 8, 9 etc.
>
> > How can I get a list of all the titles of 'trading cards' with one
> > image alongside of the first image it finds available.
>
> You don't include code that shows how your view is handing off
> the image-list, but you can define a method on your card to
> return a sample image:
>
>    class Card(Model):
>      # ... stuff ...
>      title = CharField(...)
>      def thumbnail(self):
>        try:
>          return self.image_set[0]
>        except IndexError:
>          return default_image
>    class Image(Model):
>      card = ForeignKey(Card)
>      image = ImageField(...)
>      # ...
>
> which you can then use in your view
>
>    {% for card in cards %}
>      
>       {{ card.title }}
>       
>      
>    {% endfor %}
>
> If you have large quantities of cards, you may want to use
> .select_related() so that the image_set comes back pre-populated.
>   Otherwise, you'll net a lot of extra DB hits you may not want.
>
> -tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to design mobile version of my site based on django?

2009-10-10 Thread Jani Tiainen

hao he kirjoitti:
> I'm developing my site with django,
> 
> mainly, my site works as normal, visited by PC.
> 
> but ,the site will also be visited by mobile device(e.g.iphone)
> 
> who tell me the solution?
> 
> or recommend me some relevant articles?

This has almost nothing to do with Django.

It's just what to display for smaller display devices and simples way is 
to use simplified versions of huge pages. If your site is "normal", 
there is not much of need to do anything. Standard HTML, CSS and even JS 
works in most mobile devices without problems.

Of course you might want to limit amount of data sent over network since 
mobile speeds aren't that high. So you might want to use some detection 
about "this is mobile device" (maybe there is some magic header that 
reveals it) and forward user to a bit more lightweight page(s) instead 
of using heavy, large screen pages meant for large display computers.

Easiest way is to test your site with mobile and see does it work or not.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Simple Form and Model question

2009-10-10 Thread LuisC

Ja!! That is it...
Changed the view function name and it works...

Very nice... thank you to everybody.

Regards

On Oct 10, 2:27 am, Karen Tracey  wrote:
> On Sat, Oct 10, 2009 at 2:04 AM, LuisC  wrote:
>
> > Hi!!!
> > I am having troubles saving my first model using a form:
>
> > My Model:
> > Class Clientes(models.Model):
> >    'Clase para Clientes'
> >    ClienteCodigo = models.IntegerField('Codigo Cliente')
> >    ClienteNombre = models.CharField('Nombre Cliente',max_length=40)
> >    ClienteFechaCreacion = models.DateField('Fecha Actualizacion')
>
> >    def __str__(self):
> >        return self.ClienteNombre
>
> > My Form:
>
> (What you have below isn't a form, it's a view function.)
>
>
>
> > def Clientes(request):
> >    if request.method == 'POST': # If the form has been submitted...
> >        form = ClientesForm(request.POST) # A form bound to the POST
> > data
> >        if form.is_valid(): # All validation rules pass
> >            # Process the data in form.cleaned_data
> >            ClienteCodigo = form.cleaned_data['ClienteCodigo']
> >            ClienteNombre = form.cleaned_data['ClienteNombre']
> >            ClienteFechaCreacion = form.cleaned_data
> > ['ClienteFechaCreacion']
> >            BDbuff = Clientes
> > (ClienteCodigo,ClienteNombre,ClienteFechaCreacion)
> >            BDbuff.save()
> >            return HttpResponseRedirect(reverse
> > ('mysite.ControlHoras.views.index')) # Redirect after POST
> >        else:
> >            return render_to_response('ControlHoras/Clientes.html',
> > {'form': form,}) # Invalid data
> >    else:
> >        form = ClientesForm() # An unbound form
> >        return render_to_response('ControlHoras/Clientes.html',
> > {'form': form,}) # Invalid data
>
> > The forms displays ok, but when submit it I get the following error...
> > Exception Value:  Clientes() takes exactly 1 argument (3 given)
>
> You gave your view function the same name as your model, effectively hiding
> your model.  The code is trying to call Clientes as you have redefined it,
> but the view only takes one argument (request).  You need to use a different
> name for your view function.
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---