Re: Filtering a blank date field

2007-03-02 Thread Phil Powell

Well, to answer my own question, it turned out that the Q object was
the key to this.  It allows me to use a more complex OR statement,
rather than the usual AND.  So I've ended up with:

class ActiveManager(models.Manager):
  def get_query_set(self):
objects = super(ActiveManager, self).get_query_set()
objects = objects.filter(Q(active_from__isnull = True) |
Q(active_from__lte = datetime.datetime.today()))
objects = objects.filter(Q(active_to__isnull = True) |
Q(active_to__gte = datetime.datetime.today()))
return objects

On 02/03/07, Phil Powell <[EMAIL PROTECTED]> wrote:
> I'm writing a custom Manager to only return objects which fall within
> dates set for Active From and Active To fields.  It currently looks
> like this:
>
> class ActiveManager(models.Manager):
>   def get_query_set(self):
> objects = super(ActiveManager, self).get_query_set()
> objects = objects.exclude(active_from__lt = datetime.datetime.today())
> objects = objects.exclude(active_to__gt = datetime.datetime.today())
> return objects
>
> Here's the gotchya though: if either of those dates aren't set, I want
> the object to still be returned.  i.e. if Active From isn't set, then
> it's date should be treated as the beginning of time.
>
> An easy fix would be for me to make these required fields, but I'd
> quite like them to be optional.  Is there any way I can do this
> without writing a custom query?
>
> -Phil
>

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



Filtering a blank date field

2007-03-02 Thread Phil Powell

I'm writing a custom Manager to only return objects which fall within
dates set for Active From and Active To fields.  It currently looks
like this:

class ActiveManager(models.Manager):
  def get_query_set(self):
objects = super(ActiveManager, self).get_query_set()
objects = objects.exclude(active_from__lt = datetime.datetime.today())
objects = objects.exclude(active_to__gt = datetime.datetime.today())
return objects

Here's the gotchya though: if either of those dates aren't set, I want
the object to still be returned.  i.e. if Active From isn't set, then
it's date should be treated as the beginning of time.

An easy fix would be for me to make these required fields, but I'd
quite like them to be optional.  Is there any way I can do this
without writing a custom query?

-Phil

--~--~-~--~~~---~--~~
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: newforms SelectDateWidget

2007-02-27 Thread Phil Powell

Thanks Mike - that did the trick.  I thought there would be a simple
solution - should have RTFM more thoroughly...

On 27/02/07, Mike <[EMAIL PROTECTED]> wrote:
>
> The range function has an optional 'step' argument.
>
> Howzabout:
>
> SelectDateWidget(years=range(2006,1900,-1))
>
> > But is there an easy way I can make the years display in reverse -
> > i.e. descending rather than ascending?
>
>
> >
>

--~--~-~--~~~---~--~~
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: Upcoming Django release, and the future

2007-02-27 Thread Phil Powell

On 26/02/07, James Bennett <[EMAIL PROTECTED]> wrote:
> If there's a bug that's been annoying the heck out of you and you want
> it fixed before the release, this would be the time to speak up about
> it. We have a fairly high concentration of Django developers all in
> one place with nothing to do but code, so hopefully we'll be able to
> hit a lot of stuff and get a release out very quickly (we'd like to
> release 0.96 in the next day or two).

My vote would be for a design decision to be made on 1541 and other
tickets related to mail.

-Phil

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



newforms SelectDateWidget

2007-02-27 Thread Phil Powell

Just a quick query about the SelectDateWidget:

The widget accepts an optional 'years' parameter for displaying a
range of years, like this:

SelectDateWidget(years = range(1900, 2006))

But is there an easy way I can make the years display in reverse -
i.e. descending rather than ascending?

-Phil

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



Using choices with newforms.form_for_model

2007-02-20 Thread Phil Powell

Hi,

I have this:

  class SomeModel(models.Model):
some_choice = models.CharField(maxlength=255, choices=CHOICES_DICT)

And I'm generating a form for HTML display using this:

  SomeForm = newforms.models.form_for_model(SomeModel)
  form = SomeForm()

But my some_choices field just shows up as a standard TextInput
widget.  I've tried overriding the widget using a custom callback,
like this:

  def obj_callback(f, **kwargs):
if f.name == "some_choice":
  kwargs['widget'] = newforms.Select()
return f.formfield(**kwargs)

  SomeForm = newforms.models.form_for_model(SomeModel,
formfield_callback = obj_callback)
  form = SomeForm()

But as you would expect, this displays a Select widget, but it has no
options.  I've got a temporary workaround which does this:

  kwargs['widget'] = newforms.Select(choices=CHOICES_DICT)

...but it's not very DRY, and I'd really like to do away with the
callback function completely, instead defining the data model where it
belongs: in the model.  My expectation was that the formfield would
recognise the choices=CHOICES in my model and generate a widget
accordingly, but it doesn't.

Am I missing something here?  Or is this worth a patch submission?
Seems like I'm having to do a lot of hacking to get my forms
displaying nicely, particularly when it comes to designating widgets
for fields in a model.

Any enlightenment much appreciated.

-Phil

--~--~-~--~~~---~--~~
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: Newforms MultiValueField

2007-02-07 Thread Phil Powell
Thanks for the pointers.  I soon came to realise that I did indeed need to
subclass the MultValue classes, and currently have something like this:

class PostcodeField(forms.MultiValueField):
  def compress(self, data_list):
return ''.join(data_list)

class PostcodeWidget(forms.MultiWidget):
  def __init__(self, attrs=None):
widgets = (forms.TextInput(attrs=attrs), forms.TextInput(attrs=attrs))
super(PostcodeWidget, self).__init__(widgets, attrs)
  def decompress(self, value):
if value:
  return value.split('__')
return ['', '']
  def format_output(self, rendered_widgets):
return u''.join(rendered_widgets)

Then in the form class:

  postcode = PostcodeField(
fields = (
  forms.CharField(max_length = 4),
  forms.CharField(max_length = 4)
),
widget = PostcodeWidget
  )

Far from perfect yet, but I understand a lot more about how this code
functions.

-Phil

On 06/02/07, canen <[EMAIL PROTECTED]> wrote:
>
>
> Phil,
>
> Thought an example might help.
>
> class VacationBudgetField(MultiValueField):
> def __init__(self, required=True, label=None, widget=None,
> initial=None, f_type=(), currency=(), amount=None):
> fields = (ChoiceField(choices=f_type),
> ChoiceField(choices=currency), IntegerField())
> widget = widget or BudgetWidget(f_type=f_type,
> currency=currency, amount=amount)
> super(VacationBudgetField, self).__init__(fields, required,
> widget, label, initial)
>
> def compress(self, data_list):
> if data_list:
> return " ".join(str(i) for i in data_list)
> return None
>
> ## Where BuggetWidget is
> class BudgetWidget(MultiWidget):
> def __init__(self, attrs=None, f_type=(), currency=(),
> amount=None):
> widgets = (Select(attrs=attrs, choices=f_type),
> Select(attrs=attrs, choices=currency), TextInput())
> super(BudgetWidget, self).__init__(widgets, attrs)
>
> def decompress(self, value):
> if value:
> return value.split(' ', 2)
> return ['', '', '']
>
> ## Used it like so...
> budget = VacationBudgetField(f_type=[('a', 'a'), ('b', 'b')],
> currency=[('d', 'd'), ('e', 'e')])
>
> Hope that helps.
>
> On Feb 6, 4:51 pm, "canen" <[EMAIL PROTECTED]> wrote:
> > Phil,
> >
> > I think you must subclass it and define the compress method. See the
> > comments herehttp://code.djangoproject.com/browser/django/trunk/
> > django/newforms/fields.py#L412.  You will also need a MultiWidget to
> > go with the field.
> >
> > On Feb 6, 10:04 am, "Phil Powell" <[EMAIL PROTECTED]> wrote:
> >
> > > Hi,
> >
> > > Can anyone provide any pointers on how I use MultiValueField?  Can I
> > > use it straight out of the box, or do I have to subclass to create a
> > > new field and a new MultiValueWidget?
> >
> > > I thought that this code would just work:
> >
> > > postcode = forms.MultiValueField(fields=(forms.CharField
> (max_length=4),
> > > forms.CharField(max_length=4)))
> >
> > > But all I ever get rendered in my template (using {{ form.postcode }})
> > > is a single text input.
> >
> > > Any advice would be much appreciated.
> >
> > > -Phil
>
>
> >
>

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



Newforms MultiValueField

2007-02-06 Thread Phil Powell

Hi,

Can anyone provide any pointers on how I use MultiValueField?  Can I
use it straight out of the box, or do I have to subclass to create a
new field and a new MultiValueWidget?

I thought that this code would just work:

postcode = forms.MultiValueField(fields=(forms.CharField(max_length=4),
forms.CharField(max_length=4)))

But all I ever get rendered in my template (using {{ form.postcode }})
is a single text input.

Any advice would be much appreciated.

-Phil

--~--~-~--~~~---~--~~
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: Cent OS Deployment

2007-01-29 Thread Phil Powell

I've currently got a large-scale app in development on CentOS (but to
be deployed on Red Hat), but it's running on Python 2.3.  Aside from
your Python install, there are also a few pre-requisites you might
need to install alongside Django, such as MySQL-Python.

Don't know if it's any help, but here's a quick log from when I last
did the install (after source installs of Apache and MySQL):

su
cd /usr/lib/python2.3/site-packages/
svn co http://code.djangoproject.com/svn/django/trunk/ django_src
ln -s `pwd`/django_src/django /usr/lib/python2.3/site-packages/django
cp django_src/django/bin/django-admin.py /usr/bin/
yum install mod_python
cp /usr/lib/httpd/modules/mod_python.so /opt/apache/modules/
yum install python-devel
exit
wget http://downloads.sourceforge.net/mysql-python/MySQL-python-1.2.1_p2.tar.gz
gzip -d MySQL-python-1.2.1_p2.tar.gz
tar xvf MySQL-python-1.2.1_p2.tar
cd MySQL-python-1.2.1_p2
python setup.py build
su
python setup.py install
cd /opt/apache
[Insert:
LoadModule python_module  modules/mod_python.so
]
bin/apachectl restart
exit
[Copy textile.py to home dir]
su
cp textile.py /usr/lib/python2.3/site-packages/

On 27/01/07, Noah Gift <[EMAIL PROTECTED]> wrote:
> Anyone have any good tips on Cent OS deployments?  I would like to use
> python 2.5, but it is a little tricky with Cent...
>
>
> Thanks,
>
>
> Noah Gift
>
>  >
>

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



"cannot import" error when doing an import of an app's models

2007-01-26 Thread Phil Powell

This is a very odd one:

I have a number of apps installed, and I'm updating models.py in one
of them to import the models of another, like this:

from mysite.myapp1.models import MyModel

Nothing unusual about that, huh?  Except now if I run manage.py
validate, I get errors like this:

mysite.myapp2: cannot import name MyModel
mysite.myapp3: cannot import name MyModel
mysite.myapp4: cannot import name AnotherModel

I remove that import line, and all is fine.  I've checked that all
apps are installed in settings.py, although changing the order of
those installed apps gives me slightly different apps complaining
about different models.

Very weird.  Has anyone experienced anything similar?

-Phil

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



Generic form appearing on multiple pages

2007-01-17 Thread Phil Powell


Hi - got a bit of a tricky one, which I can't quite come up with a
sensible design pattern for:

I have a contact form, which appears on a number of different pages
across a site.  To keep it generic and cut down on duplication of
code, my thinking was that I should create a templatetag to display it
wherever it is needed.  It uses a Manipulator to inject the form into
the template's context, and looks something like this:

def generic_form(context):
 manipulator = Contact.AddManipulator()
 errors = new_data = {}
 return {
   'form': forms.FormWrapper(manipulator, new_data, errors),
 }

register = template.Library()
register.inclusion_tag('tag_templates/generic_form.html',
takes_context=True)(generic_form)

That all works fine, but here's the killer: I want the form to POST to
the current URL, whch could potentially be any URL on the site, and
handle all of the validation / error handling in-situ.  i.e. I want
the user to be able to submit the form on the page they are looking
at, and have that same page returned with the form updated with either
success or validation errors.  My initial thinking was that a
dedicated view would be the way to go, which would redirect back to
the refering URL - but that creates all sorts of nightmares with
context and request variables!

Ultimately, this will use XMLHttpRequest to POST and refersh just the
form portion of the page, but I need a graceful non-JavaScript
solution too.  My thinking is that it's just not going to be possible,
but just interested to know if anyone has ever done anything similar?

-Phil

--~--~-~--~~~---~--~~
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: Re: Singleton model instance

2006-12-07 Thread Phil Powell

Thanks for the input guys.  I'm kind of approaching this from a client
perspective, so was fishing around for the simplest use case from an
inexperienced admin user's point of view.

The suggestions of using a Page and "chunk" schema makes perfect
sense, and a quick Google threw up a good example[1].

However, I was kind of missing a trick, as Django's admin provides
exactly what I need in the form of user permissions - all I need to do
is set up a single intance for a given page model, with the fields
defined.  Then it's just a matter of changing permissions to only
allow client users to edit that instance.

Thanks for your help guys - all food for thought.

-Phil

[1] http://www.carthage.edu/webdev/?p=15

On 05/12/06, Jeff Forcier <[EMAIL PROTECTED]> wrote:
>
> As James and Fredrik have implied, I believe the proper solution here
> is to abstract things enough so that you *can* map the concept to a
> relational database; in this case, assuming that every 'Page' has an
> identifier, a 'Title' and, perhaps, multiple 'Sections' (each with an
> identifier and text), you make a Page model with (unique) Name and
> Title attributes, and then a Section or PageSection or etc, model, with
> Name and Text fields and a ForeignKey to Page.
>
> Then your homepage is a Page whose Name is "homepage" and whose Title
> is the page title, then with a few Sections: one named "introduction"
> with the intro text, one named "footer" with footer text, etc.
>
> Finally, you'd probably want to make a templatetag that operates on
> these models, so you can do something like {% printsection 
>  %} where  is the current Page object, and  name> is the name of the section you wish to print.
>
> So your homepage would looke something like this:
>
> 
> 
> {{ mypage.title }}
> 
> 
> {{ mypage.title }}
> {% printsection mypage "introduction" %}
>
> stuff goes here
>
> {% printsection mypage "footer" %}
> 
> 
>
> I'm sure you can come up with more specific and/or efficient variants
> on this theme, but basically this is going down the road that leads to
> content management systems, which have solved this basic problem for
> some time now :)
>
> Regards,
> Jeff
>
> Phil Powell wrote:
> >
> > Perhaps I've not explained myself properly.  Here's an example:
> >
> > I have a "Homepage" which has fields such as "Page Title",
> > "Introduction Text", "Footer Text" etc.  I want to be able to edit
> > these fields just like I'd edit a standard model instance, but because
> > there is only one instance of my "Homepage" I never want more than one
> > instance of it to exist.
> >
> > -Phil
>
>
> >
>

--~--~-~--~~~---~--~~
 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: Re: Singleton model instance

2006-12-04 Thread Phil Powell

On 04/12/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> I'm not sure I get how a singleton would solve the "pages generated from
> multiple chunks" problem.
>
> why not just use a model that holds (pagename, chunkname, chunk data)
> triplets, and use a view that brings up all the chunks for a given page ?

Perhaps I've not explained myself properly.  Here's an example:

I have a "Homepage" which has fields such as "Page Title",
"Introduction Text", "Footer Text" etc.  I want to be able to edit
these fields just like I'd edit a standard model instance, but because
there is only one instance of my "Homepage" I never want more than one
instance of it to exist.

-Phil

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



Singleton model instance

2006-12-04 Thread Phil Powell

Hi all,

Apologies if this has been asked on the list before, but a search
didn't throw up anything relevant.

I want to have a series of pages, with certain areas of content which
are editable.  I don't want to use flatpages, as I'd like the editable
content to be broken down into chunks, rather than one big lump of
content.

Is there a way to easily set a model to have one singleton instance?
I've thought about adding some pre-save code to check and only allow
for one instance, but wondered if there was a more graceful way to do
this?

-Phil

--~--~-~--~~~---~--~~
 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: Using a session variable in templates

2006-08-02 Thread Phil Powell

That sounds like just the thing I need - to hook into every request
and inject into the context dictionary.  Will give it a try.  Thanks
Chris!

On 01/08/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Context processors might work:
> http://www.djangoproject.com/documentation/templates_python/
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Using a session variable in templates

2006-08-01 Thread Phil Powell

Hi all,

I'm trying to implement something I'd imagine is quite simple, but
have come a bit unstuck when it comes to finding a graceful way to so
it.

What I want to do is sotre a random number (easy enough) in the users
session, then retrieve it in my base template (this is for the purpose
of selecting one of a number of different style sheets).  I've looked
at using middleware, but that would require me to set the variable in
each of my views?  I want to have this available for *every* template,
including flatpages.

Is there a simple way to do this?

-Phil

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



Batch record processing

2006-07-26 Thread Phil Powell

Hi all,

I've got a Django app with a whole stack of data which I want to be
able to update on a semi-regular basis.  It's currently in Excel
format, which is then easily converted to CSV and imported into a
pre-defined MySQL table, with a relevant Django model defined around
it.

It all works pretty swiftly and efficiently - particularly considering
there are around 12,000 rows of data!

However, there is an image asset which relates to each row, and I want
a way to find a way to easily use the Django API to assign the
relevant image to the associated record, using a filename which
references a unique identifier.

I've got the bare-bones of a python script which will iterate over
each record and search a directory for a file with the relevant name,
but I'm having difficulty seeing how I can assign that image to the
relevant Django object.  Assigning it using the standard ImageField
gives me problems: even though the image is referenced, it gets saved
in the DB with it's full filesystem path.

Anyone have any pointers on how I might be able to implement this
gracefully?  Or am I just being too hacky with the API? ;)

-Phil

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



Re: Caching in Django admin

2006-07-20 Thread Phil Powell

That's excellent - strange I came across the problem right at the same
time you were fixing it ;)

-P

On 20/07/06, Jacob Kaplan-Moss <[EMAIL PROTECTED]> wrote:
>
> On Jul 20, 2006, at 4:45 AM, Phil Powell wrote:
> > It seems odd that this doesn't seem to have popped up as a common
> > issue, if it is indeed something related to site-wide caching - it's
> > definitely a bit of a show-stopper when it comes to having a client
> > using an admin interface which doesn't function in a rationale way (to
> > thier eyes at least).
>
> Actually, it does come up fairly often, so I fixed in [3395]. I added
> a FAQ entry about it: http://www.djangoproject.com/documentation/faq/
> #how-can-i-prevent-the-cache-middleware-from-caching-the-admin-site.
>
> Jacob
>
> >
>

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



Re: Caching in Django admin

2006-07-20 Thread Phil Powell

Thanks for the feedback guys - good to know that I'm not alone in
seeing this behaviour.

It seems odd that this doesn't seem to have popped up as a common
issue, if it is indeed something related to site-wide caching - it's
definitely a bit of a show-stopper when it comes to having a client
using an admin interface which doesn't function in a rationale way (to
thier eyes at least).

Your idea, Axel, of caching individual views has two stumbling blocks for me:

1) Am I right in thinking that decorators were only introduced in Python 2.4?
2) This would mean overriding the admin views for every application
I'm running, and makes me groan at the thought of keeping things
up-to-date.

Rock: blowing away the cache files, although would work, doesn't sound
like a very graceful way to deal with this problem.

I'd be interested to know the thoughts of any of the core developers on this?

-Phil

On 20/07/06, Axel Steiner <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> > It looks like the right way to deal with this is to implement per page
> > caching, but that doesn't look too simple to me. I hope that someone
> > will prove me wrong by posting some simple instructions for implemeting
> > per page caching. Alternatively please post a mechanism for disabling
> > global caching for selected pages (even though I doubt that that is
> > possible without creating some custom middleware.)
>
> caching individual views is also simple. When your cache is already setup,
> just add a decorator for each view, which should be cached.
>
> from django.views.decorators.cache import cache_page
>
> @cache_page(900)
> def myview(request):
>...
>
> The argument for cache_page is the cache timeout in seconds.
>
> Bye,
> Axel
>
> >
>

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



Caching in Django admin

2006-07-19 Thread Phil Powell

Hi,

Perhaps I'm missing something simple, but ever since I enabled caching
middleware in my apps, I've noticed that it's causing lots of strange
behaviour in my admin: updates taking a while to show up, new objects
not showing up, messages taking a while to filter through.

I'm assuming it's something to do with caching, since I don't see the
same behaviour in a dev environment with caching switched off.

I've not updated the admin templates for a while, but after a quick
snoop around the code, doesn't seem to be anything which would have
been changed which might have an effect on this.

Is there a simple way to disable caching for admin?  Or should it
happen automatically?

Thanks,

-Phil

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



Re: Checking whether a Foreignkey object has been assigned to anything

2006-07-12 Thread Phil Powell

Jorge - that is exactly what I was after - thanks very much!  I don't
have too many categories, and don't expect there to be more than 100
or so - so the convenience outweighs the overhead.

This way, I'm even able to add filters before doing the iteration.

-Phil

On 12/07/06, Jorge Gajon <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> If there are not a lot of categories (i.e. a thousand or more), you
> could iterate over all categories and filter only those that have a
> photo_set of 1 or more. For example in a view you could do:
>
> categories = [c for c in Category.objects.all() if c.photo_set.count()]
>
> You could say that it is not very optimal because you are fetching all
> the categories. But I personally wouldn't worry about it if there are
> not many categories.
>
> Cheers,
> Jorge
>
> On 7/12/06, Phil Powell <[EMAIL PROTECTED]> wrote:
> >
> > Hi - I've got a bit of a conundrum.
> >
> > I have two models, Category and Photo which look something like this:
> >
> > class Category(models.Model):
> >   title = models.CharField(maxlength=80)
> >   slug = models.SlugField(prepopulate_from=("title",))
> >
> > class Photo(models.Model):
> >   catalogue_number = models.IntegerField(maxlength=80)
> >   slug = models.SlugField(prepopulate_from=("catalogue_number",))
> >   category = models.ForeignKey(Category,blank=True)
> >
> > There is a one-to-many relationship defined so that a Photo can be
> > assigned a Category.
> >
> > Now, what I want to be able to do is get a list of Categories, but
> > ONLY those Categories which have been assigned to one or more Photos.
> >
> > I can think of plenty of ugly ways to work around this, but wondered
> > whether anyone had a graceful solution?
> >
> > -Phil
> >
> > >
> >
>
> >
>

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



Re: FileBrowser Test Version

2006-07-12 Thread Phil Powell

Still having trouble with those thumbnails Patrick:

Seems that whenever I click on the thumbnail link, or the "delete"
link, a blank filebrowser index page is returned to me.  The URL seems
to be formed properly in the form:

/admin/filebrowser/makethumb/my_file.jpg

Seems to be rendering the response, but with no context returned.  Any ideas?

-Phil

On 12/07/06, patrickk <[EMAIL PROTECTED]> wrote:
>
> makethumb works for me - although the makethumb-image is not
> displayed correctly (I´ve already changed that).
>
> change line 170 of filebrowser/views.py from
> path_to_file = '/media/img/filebrowser_Thumb.gif'
> to
> path_to_file = '/media/img/filebrowser/filebrowser_Thumb.gif'
>
> note: our hosting-provider has setup trac for us. so, hopefully we'll
> have an SVN address soon.
>
> patrick
>
> Am 12.07.2006 um 14:01 schrieb Phil Powell:
>
> >
> > Thanks for the update Patrick.  I've got this part working, but having
> > trouble with makethumb on existing files on the server - not had time
> > to delve too deeply yet to see what the problem is though.
> >
> > -Phil
> >
> > On 11/07/06, va:patrick.kranzlmueller <[EMAIL PROTECTED]>
> > wrote:
> >>
> >> a new version of the filebrowser is available for download.
> >>
> >> CHANGES:
> >> 001: You may define an initial directory for each FileBrowseField by
> >> adding a path to the help_text: Like "FileBrowser: /images/blog/" or
> >> "FileBrowser: /documents/pdf/".
> >> 002: Sorting algorithm also works with Python 2.3 now (thanks
> >> Archatas)
> >> 003: Additional slashes are only used for folders now
> >>
> >> I still need to look at the breadcrumbs.
> >>
> >> thanks for your feedback,
> >> patrick
> >>
> >>
> >> Am 11.07.2006 um 12:39 schrieb Archatas:
> >>
> >>>
> >>> Very nice, but there are some gotchas/bugs:
> >>>
> >>> 1. to make it work on Python 2.3, you need to change
> >>> line 198 in views.py
> >>> file_list.sort(cmp, lambda x: x[int(o)])
> >>> to
> >>> file_list.sort(lambda x, y: cmp(x[int(o)], y[int(o)]))
> >>> (sort method takes only the comparisson function as a parameter in
> >>> Python 2.3)
> >>>
> >>> 2. The links in the admin breadcrubs are not relative as in the
> >>> original admin, therefore I need to change all templates if I
> >>> have my
> >>> django project in some directory instead of in the root of the
> >>> domain.
> >>>
> >>> 3. If I upload an image to the root of uploads, the thumbnail isn't
> >>> showed, because of additional slash in the path that is added
> >>> next to
> >>> the dir_name which doesn't exist. I think, you should also check
> >>> whether dir_name is set at all, and only then add that slash at the
> >>> end.
> >>>
> >>> 4. It works in Firefox, but it seems a little bit strange and may
> >>> not
> >>> work in other browsers, because all the uploaded images are being
> >>> accessed with additional slash at the end of the URL.
> >>>
> >>> That were my notices. But on the whole, great work!
> >>>
> >>> Aidas Bendoraitis [aka Archatas]
> >>>
> >>> patrickk wrote:
> >>>> today we´ve finished the test version of our django filebrowser.
> >>>>
> >>>> some screenshots are here:
> >>>> http://www.vonautomatisch.at/django/filebrowser/
> >>>>
> >>>> you can download the filebrowser here:
> >>>> http://www.vonautomatisch.at/django/filebrowser/FileBrowser.zip
> >>>>
> >>>> installation shouldn´t take more than 5-10 minutes.
> >>>> requirements: we are using PIL to create the thumbnails.
> >>>>
> >>>> this version is for testing (although we´re already using it). I
> >>>> hope
> >>>> that some of you will find the time to install the filebrowser.
> >>>> feedback is more than welcome.
> >>>>
> >>>> thanks,
> >>>> patrick
> >>>
> >>>
> >>>>
> >>
> >>
> >>>
> >>
> >
> > >
>
>
>
>
>
>
>
> >
>

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



Re: FileBrowser Test Version

2006-07-12 Thread Phil Powell

Thanks for the update Patrick.  I've got this part working, but having
trouble with makethumb on existing files on the server - not had time
to delve too deeply yet to see what the problem is though.

-Phil

On 11/07/06, va:patrick.kranzlmueller <[EMAIL PROTECTED]> wrote:
>
> a new version of the filebrowser is available for download.
>
> CHANGES:
> 001: You may define an initial directory for each FileBrowseField by
> adding a path to the help_text: Like "FileBrowser: /images/blog/" or
> "FileBrowser: /documents/pdf/".
> 002: Sorting algorithm also works with Python 2.3 now (thanks Archatas)
> 003: Additional slashes are only used for folders now
>
> I still need to look at the breadcrumbs.
>
> thanks for your feedback,
> patrick
>
>
> Am 11.07.2006 um 12:39 schrieb Archatas:
>
> >
> > Very nice, but there are some gotchas/bugs:
> >
> > 1. to make it work on Python 2.3, you need to change
> > line 198 in views.py
> > file_list.sort(cmp, lambda x: x[int(o)])
> > to
> > file_list.sort(lambda x, y: cmp(x[int(o)], y[int(o)]))
> > (sort method takes only the comparisson function as a parameter in
> > Python 2.3)
> >
> > 2. The links in the admin breadcrubs are not relative as in the
> > original admin, therefore I need to change all templates if I have my
> > django project in some directory instead of in the root of the domain.
> >
> > 3. If I upload an image to the root of uploads, the thumbnail isn't
> > showed, because of additional slash in the path that is added next to
> > the dir_name which doesn't exist. I think, you should also check
> > whether dir_name is set at all, and only then add that slash at the
> > end.
> >
> > 4. It works in Firefox, but it seems a little bit strange and may not
> > work in other browsers, because all the uploaded images are being
> > accessed with additional slash at the end of the URL.
> >
> > That were my notices. But on the whole, great work!
> >
> > Aidas Bendoraitis [aka Archatas]
> >
> > patrickk wrote:
> >> today we´ve finished the test version of our django filebrowser.
> >>
> >> some screenshots are here:
> >> http://www.vonautomatisch.at/django/filebrowser/
> >>
> >> you can download the filebrowser here:
> >> http://www.vonautomatisch.at/django/filebrowser/FileBrowser.zip
> >>
> >> installation shouldn´t take more than 5-10 minutes.
> >> requirements: we are using PIL to create the thumbnails.
> >>
> >> this version is for testing (although we´re already using it). I hope
> >> that some of you will find the time to install the filebrowser.
> >> feedback is more than welcome.
> >>
> >> thanks,
> >> patrick
> >
> >
> > >
>
>
> >
>

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



Re: FileBrowser Test Version

2006-07-11 Thread Phil Powell

This is fantastic stuff!  I'll be taking a look at testing it out and
possibly implementing for a current project (thousands of image files
to manage).

Any plans for a SVN address?

-Phil

On 08/07/06, patrickk <[EMAIL PROTECTED]> wrote:
>
> today we´ve finished the test version of our django filebrowser.
>
> some screenshots are here:
> http://www.vonautomatisch.at/django/filebrowser/
>
> you can download the filebrowser here:
> http://www.vonautomatisch.at/django/filebrowser/FileBrowser.zip
>
> installation shouldn´t take more than 5-10 minutes.
> requirements: we are using PIL to create the thumbnails.
>
> this version is for testing (although we´re already using it). I hope
> that some of you will find the time to install the filebrowser.
> feedback is more than welcome.
>
> thanks,
> patrick
>
>
>
> >
>

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



Re: Triple Store / RDF

2006-06-22 Thread Phil Powell

On 22/06/06, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> I guess mine was more of a combination. I wrote an interface that was
> similar to the querying interface in Django at the time (0.90 / 0.91
> style). Give it keyword args of what to select and triples describing
> the filtering conditions. So I could write things like
>
> get_object(values = ['?x', '?y'],
>where = ['?x has ?y', '?y is red'])

I found myself using Rubys hash objects and string literals to quite
good effect for building quite complex queries, so for example (excuse
the bad code):

Resource.find(:all, :user => {:first_name => 'John', :surname => 'Doe'})

And then you could go one better with:

Resource.find(:all, :article => {
  :user => {:first_name => 'John', :surname => 'Doe'},
  :subject => 'rdf'
})

I wonder how that would look in Python...?

> In my infinite spare time, perhaps...

Hmmm, spare time? What an interesting concept ;)

-Phil

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



Re: Triple Store / RDF

2006-06-22 Thread Phil Powell

Thanks Malcolm.  I'm curious more than anything, since RDF etc gets
talked about a lot, but implementations rarely seem to make it into
the real-world.

I referenced the exact same resource to pull together a basic
triple-store library in Rails a while back, and it was fairly painless
(although a tad hacky) - perhaps I'll sit down to try the same with
Python and Django sometime.  I certainly found the code I had working
to be VERY powerful.

Just out of curiosity, did you use a SPARQL-style syntax to build
queries, then convert it into standard SQL?  Or did you do what I did,
and have an object-based API translate to SQL without a middle-man?

-Phil

On 19/06/06, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>
> On Mon, 2006-06-19 at 12:35 +0100, Phil Powell wrote:
> > Hi all,
> >
> > Just out of pure curiosity: has anyone had any experience / know of
> > any work around using RDF / triple stores with Django?
>
> This was the "toy project" I used to get familiar with Django in about
> October last year (aah.. the memories). I made up a model and some
> auxilliary methods based around [1] and a simple web page so that I
> could run queries. It was a "learning Django" exercise, rather than
> aimed at doing anything useful, so I didn't take it very far or try to
> optimise it much. Might be fun to revisit with the latest Django changes
> (the original code would not run any more), because some of the more
> RDF-like interfaces could be put into the model managers and the like,
> making it a bit more seamless.
>
> [1] http://www.picdiary.com/triplequerying/
>
> There wasn't really anything specially hard about this. The model was as
> simple as it gets and trying out possibilities for the API was the
> interesting part.
>
> Regards,
> Malcolm
>
>
>
> >
>

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



Re: manipulating images

2006-06-20 Thread Phil Powell

It might be worth you taking a look at the work done on Thumbnails in
DjangoUtils:

http://djangoutils.python-hosting.com/wiki/Thumbnails

Although not a solid chunk of code (there are a few issues with
namespaces, and it uses some Python 2.4 specific stuff), but with a
bit of hacking I got automatic thumbnail generation working recently,
using template filters.

-Phil

On 20/06/06, Sasha <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> I'd like to create a thumbnail for an image after it has been uploaded.
> I have seen two possible approaches descibed here - subclassing
> ImageField and overriding the save() method of the model. Although the
> former seems more elegant, the latter seems like less work and I'm
> inclined to try it first.
>
> However I'm not clear about how I can manipulate an ImageField (or any
> field for that matter) inside the models' save() method. Can anyone
> help?
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Existing database into django models?

2006-06-19 Thread Phil Powell

This ought to do the job:

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

-Phil

On 19/06/06, Mike Crowe <[EMAIL PROTECTED]> wrote:
>
> Hi folks,
>
> I'm just starting looking at a django backend for a system we need to
> redo.  The existing db is MSSQL (yes, I know it's not quite supported
> yet).  We need a system which supports most of the adodb classes.  We
> will start with supported DB's, and hopefully the additional ones will
> be ready when we are.
>
> However, here's my question:  The existing DB is very well laid out.
> Is there a way to convert that DB Schema into django models?  Doesn't
> have to be purely automatic, but any tool which would help this
> migration would be appreciated.
>
> TIA
> Mike
>
>
> >
>

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



Triple Store / RDF

2006-06-19 Thread Phil Powell

Hi all,

Just out of pure curiosity: has anyone had any experience / know of
any work around using RDF / triple stores with Django?

-Phil

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



Re: Processing Image on Save

2006-06-16 Thread Phil Powell

On 16/06/06, mwtb <[EMAIL PROTECTED]> wrote:
> Okay, I haven't looked at that, so at least it's a new options, thanks.
> My Python ability gets a bit stretched when reading some of the code in
> that area, but I guess that's a good thing.

I've just been playing around with creating new field types, and it
can be a little daunting at first as there's little documentation on
the subject (perhaps I should write up my findings).  Like you say
though, it's good to dive in and get familiar with the code, and once
you figure it out, custom field types are actually quite simple.

-P

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



Re: Settings Model

2006-06-16 Thread Phil Powell

As far as I know, there's no way to restrict the number of instances
of a particular model.  You could hack the admin templates to hide
"Add" buttons if an instance of a particular model already exists.  Or
override the save method in the model so that it doesn't save if an
instance already exists (which would be a bit confusing for an admin
user, and probably a bad idea)

-Phil

On 16/06/06, bradford <[EMAIL PROTECTED]> wrote:
>
> I need a model called settings that has some application settings the
> user can edit in the admin.  How should I set this model up so that one
> and only one settings record always exists for the lifetime of the
> application.
>
> Also, please let me know if this approach is incorrect.
>
>
> >
>

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



Re: Comment URLs hardcoded?

2006-05-24 Thread Phil Powell

And in addition, for anyone who's interested, if you change the
default path from /comments/ for your commenting, you'll need this
patch:

http://code.djangoproject.com/ticket/1997

It will rectify an issue with posted forms redirecting to the wrong location.

-Phil

On 24/05/06, Phil Powell <[EMAIL PROTECTED]> wrote:
> Well, I found a simple solution to my own problem, so for the archives:
>
> If you place files form.html and freeform.html in a directory called
> comments/ within your templates/ directory, they will override the
> default templates!
>
> Nice and simple, and obvious when I thought about it a little - this
> is what I'm finding great about Django: conventions allow you to make
> assumptions which just work!
>
> -Phil
>
> On 24/05/06, Phil Powell <[EMAIL PROTECTED]> wrote:
> > I just wanted to pose this question before raising a ticket, or
> > starting to work on a patch, just incase someone's got a workaround.
> >
> > I'm implementing contrib.comments, and everything works fine in a
> > basic dev setup.  However, I'm running into a problem when trying to
> > deploy on a more complex setup running through Apache.
> >
> > Ive got an app running under a URL of the format:
> > http://www.somedomain.com/site/appname/.  I want to run comments
> > through a URL like: http://www.somedomain.com/site/comments/, but it
> > appears to me that the "action" attribute in the comment forms is
> > hardcoded to /comments/
> >
> > I could do some really hacky URL manipulation, but I'd rather not -
> > would seem to me that a more sensible solution would be to provide an
> > overide for the standard path to comments.
> >
> > Anyone else run into the same problem?  Found a graceful fix?
> >
> > Thanks,
> >
> > -Phil
> >
>

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



Re: Comment URLs hardcoded?

2006-05-24 Thread Phil Powell

Well, I found a simple solution to my own problem, so for the archives:

If you place files form.html and freeform.html in a directory called
comments/ within your templates/ directory, they will override the
default templates!

Nice and simple, and obvious when I thought about it a little - this
is what I'm finding great about Django: conventions allow you to make
assumptions which just work!

-Phil

On 24/05/06, Phil Powell <[EMAIL PROTECTED]> wrote:
> I just wanted to pose this question before raising a ticket, or
> starting to work on a patch, just incase someone's got a workaround.
>
> I'm implementing contrib.comments, and everything works fine in a
> basic dev setup.  However, I'm running into a problem when trying to
> deploy on a more complex setup running through Apache.
>
> Ive got an app running under a URL of the format:
> http://www.somedomain.com/site/appname/.  I want to run comments
> through a URL like: http://www.somedomain.com/site/comments/, but it
> appears to me that the "action" attribute in the comment forms is
> hardcoded to /comments/
>
> I could do some really hacky URL manipulation, but I'd rather not -
> would seem to me that a more sensible solution would be to provide an
> overide for the standard path to comments.
>
> Anyone else run into the same problem?  Found a graceful fix?
>
> Thanks,
>
> -Phil
>

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



Comment URLs hardcoded?

2006-05-24 Thread Phil Powell

I just wanted to pose this question before raising a ticket, or
starting to work on a patch, just incase someone's got a workaround.

I'm implementing contrib.comments, and everything works fine in a
basic dev setup.  However, I'm running into a problem when trying to
deploy on a more complex setup running through Apache.

Ive got an app running under a URL of the format:
http://www.somedomain.com/site/appname/.  I want to run comments
through a URL like: http://www.somedomain.com/site/comments/, but it
appears to me that the "action" attribute in the comment forms is
hardcoded to /comments/

I could do some really hacky URL manipulation, but I'd rather not -
would seem to me that a more sensible solution would be to provide an
overide for the standard path to comments.

Anyone else run into the same problem?  Found a graceful fix?

Thanks,

-Phil

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



Re: How fix the "feature" of not serving static files?

2006-05-24 Thread Phil Powell

There's one very good reason why Django (and any other framework / CMS
worth it's salt) deliberately avoids serving static files, and that
reason is "performance".

Your content serving mechanism should be about retrieving and
manipulating content data, and performance can be haevily impacted if
a system is asked to serve up static content aswell.  Even systems
which hold media files in a database tend to have a caching layer
which serves synchronised media files.

The core principle is: serve dynamic content from one place, serve
static media files from another.  At the simplest level, this can be
two web servers running on a single machine.  At the extreme level, it
can mean having media server clusters.

So in that respect, this is not a "bug" unique to Django - it's an
accepted practice which I think you'll find MSN using.

I can't quite grasp the problem you're having here (perhaps I'm
ovelooking something).  Why can you not just use absolute URLs?  Why
not just use /media/css/my.css?  Or if you're in need of a way to set
a global path, add a new setting to your settings.py file which you
can then import and use in your templates?

Seems to me (and like I say: maybe I'm missing something) that you're
going a very long way round to solve a simple problem.

On 24/05/06, Wilson Miner <[EMAIL PROTECTED]> wrote:
>
> Is there a particular reason you can't just use the full media url in
> your templates? ie. "http://media.coolsite.com/files/css/shadow.css;
> instead of "../css/shadow.css"?
>
> On 5/23/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >
> > I'm building a CMS for my internal use... I own a web development &
> > desing company... we have experience in ASP.NET but I'm looking for
> > something more "ligth" and come to django... For people with deadlines:
> > that are we!
> >
> > Despite the fact I see how django is productive in a lot of areas, I
> > get bloked in how somethings are done..
> >
> > For example, the "feature" of not serve static files. The worst? I
> > don't can relly in the available workarounds to this "feature" (yeah I
> > put "feature" for be sarcasting... I understand the reason, the why,
> > but be patiente: I have a deadline too and this experiment is taking
> > more than expected!!)
> >
> > I have the fallback of the serve static documentation... but this is
> > not working for me (0.95 + dev web server + win 2003)
> >
> > And anyway this is not good for real work. So:
> >
> > I have two desirable ideas:
> >
> > 1- Use a tag and inject the MEDIA_URL here: (I don't like the
> > suggestion to mess with the template system... to much code)
> >
> > {% BaseUrl %}/css/sample.css
> >
> > I put a templetetag/jhonWebInjector.py dir under my project, then under
> > my core app, then under my specific app.
> >
> > I do this:
> >
> > "Etiquetas estandar de jhonWeb."
> >
> > from django.template import Node, NodeList, Template, Context,
> > resolve_variable
> > from django.template import TemplateSyntaxError, VariableDoesNotExist,
> > BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END
> > from django.template import get_library, Library,
> > InvalidTemplateLibrary
> > from django.conf import settings
> > import sys
> >
> > register = template.Library()
> >
> > class BaseUrl(template.Node):
> > def __init__(self):
> > pass
> >
> > def render(self, context):
> > context['BaseUrl'] = 'uno'
> > return ''
> >
> > def do_get_BaseUrl(parser, token):
> > """
> > {% BaseUrl %}
> > """
> > return 'uno'
> >
> > register.tag('BaseUrl', do_get_BaseUrl)
> >
> > and in the template:
> >
> > {% load "jhonWebInjector" %}
> > {{ BaseUrl }}
> >
> > But say:
> >
> > '"jhonWebInjector"' is not a valid tag library: Could not load template
> > library from django.templatetags."jhonWebInjector", No module named
> > "jhonWebInjector"
> >
> > However... this is a HACK. I don't like to say to my designers: Look
> > dude, I chose a development framework, and have this beautifull
> > template thing that break the use of any web desing editor like
> > dreamweaver or topstylebecause is necesary put this little hack, so you
> > not can see in realtime what is happening with your ... errr... desing
> >
> > 2- However, I'm thinking in the lines of the dotnetnuke people: This
> > tool have a "install template" thing that convert a .html template in a
> > .ascx module and put the rigth paths to the images and css and
> > javascript.
> >
> > So, my ideas is do this way:
> >
> > The way is done under a local environment, like topstyle:
> >
> > 
> >
> > And do some magic to the response (where, how? a middleware?) to look
> > for paths with a regex, and auto-magically turn it in:
> >
> >  > href="http://media.coolsite.com/files/css/shadow.css; />
> >
> > The 1) is a nice hack by now but I like to know if is possible do in
> > the fly the 2)
> >
> > I think this is the way if is expected that normal web designers build
> > the front-end of the system...
> 

Re: How to write a module level method rather than a instance method

2006-05-22 Thread Phil Powell

On 22/05/06, Carlos Yoder <[EMAIL PROTECTED]> wrote:
>
> Guys, let's try to cut down on cynicism, please? We all have our day
> jobs, responsibilities, families and so on and so forth, and this is a
> motivation-driven, heartfelt project.

Hear hear.  Malcolm is putting a lot of effort into getting
documentation in order and I'm sure he'd appreciate our help by
providing a simple link to *where* mistakes our out-dated documents
reside, rather than posting cynical RTFM-like Google replies.

It's about contribution and just a little respect.

-Phil

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



Re: Django and static files URLs

2006-05-17 Thread Phil Powell

Surely you don't need to have the entire absolute URL - an sbsolute
URL can be defined by just ensuring a preceeding forward slash appears
in your paths - for example:



should change to:



This will cause the resource to be referenced from the root of your domain.

Alternatively, you can use a BASE tag in the head of your HTML to set
a a full or partial base path to preceed all relative resources.

Hope that helps.

-Phil

On 17/05/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> My templates refer to CSS and images with absolute URL. I
> cannot serve them with relative URLs, like I used to do in PHP
> with:
> 
> (or can I? If so please let me know).
>
> This is fine until the moment I put my work on production
> server, where I need to update all static URLs (from
> http://localhost:8080/media/... to
> http://www.mystuff.com/media/...).
>
> I came across a few posts dealing about static files and URLs,
> usually ending up with some kind of request for a 'website
> root URL' tag in templates.
>
> Does such a thing exist in Django (without creating custom tag)?
> Are there any works in progress?
> More generally, what are the best practices for not having to
> substitute all media URLs in my templates (without serving the
> same files for dev and prod) ?
>
> Thanks.
>
> Accédez au courrier électronique de La Poste : www.laposte.net ;
> 3615 LAPOSTENET (0,34 €/mn) ; tél : 08 92 68 13 50 (0,34€/mn)
>
>
>
>
> >
>

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



Re: Dreamhost - does anyone know a better webhosting?

2006-05-16 Thread Phil Powell

I have been hosted with these guys: http://www.bytemark.co.uk/ for
quite some time.  I started out with them when they were a young
startup, and I can highly recommend them if you're looking for "full
control" solution.

They are a UK-based company, and they provide a very reliable "Virtual
machine" solution starting at just £15 per month.  You get full root
access and can install any flavour of Linux you want.  They also have
a very useful "server farm" if ever you have the need for some serious
bit-crunching!

I'm currently hosting a couple of Django-based sites and have seen
very good performance.  If by chance you use them, do me a favour and
tell them you were recommended by ppowell - they have a very
open-source friendly "thank you" scheme going (and are general
open-source advocates all round).

-Phil

On 16/05/06, PythonistL <[EMAIL PROTECTED]> wrote:
>
> I have been using Dreanhost for share webhosting service for a few
> months already but I found out it is very unreliable. If there is a
> higher traffic my site goes down. From the beginnig I was happy - no
> problem  - but now when more users come to my site - problems repeat
> all over and over again.
> Does anyone know a better webhosting?
> Or is it a problem of Django that brings very load on  a server??
>
> Thank you
> L.
>
>
> >
>

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



Re: ManyToManyField reverse lookup not working

2006-05-16 Thread Phil Powell

It may not be exactly related to the problem you're having, but worth checking:

I was having some difficulty checking the right syntax for use when
referencing many-to-many fields recently, and noticed that the syntax
has changed from what is currently documented.  You can find a chart
documenting the old vs. new syntax here:

http://code.djangoproject.com/wiki/RemovingTheMagic

Hope that might at least lead you in the right direction for solving
your problem.

-Phil

On 16/05/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Hello Gunnar,
>
> I am sorry, that was kind of a copy error -- in my model names
> maxlength is correctly set and it validates without errors.
> I still have no clue why no reverse lookup methods are added.
>
> derelm
>
>
> >
>

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



Re: Problems with setup of Django with Apache and mod_python

2006-05-12 Thread Phil Powell
Hi Gunnar,I had a few issues when setting up my first Django project through mod_python, the main tricky bit being the setup of the correct PythonPath variable.  However, seems you've got that right.The only other thing I can think of is that Apache doesn't have permission to access your Django project directory?
-PhilOn 12/05/06, Gunnar Wegner <[EMAIL PROTECTED]> wrote:
Dear group,sorry for starting another thread on this issue. I am both new to Python andDjango. -I have been trying for two days now to transfer a little sample project fromthe development server to Apache (
2.0.54) with mod_python (3.2.8) on OpenSuSE10.0; following exactly(?) the documentation given (and looking through therelated posts in the archieves - to no avail).My httpd.conf contains a section like this:
SetHandler python-programPythonHandler django.core.handlers.modpythonPythonPath "['/home/gunnar/EigeneDateien/Linux/Django'] + sys.path
"SetEnv DJANGO_SETTINGS_MODULE gunnarsseite.settingsPythonDebug OnMy project's files live in the 'gunnarsseite' subdirectory of the 'Django' dirabove. (Playing around with my models after running python 
manage.py shelldoes work. Playing around when running the python shell directly doesn't.)Whenever I try to load my project in the browser, I get this error:Mod_python error: "PythonHandler django.core.handlers.modpython
"Traceback (most recent call last):  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, inHandlerDispatchresult = object(req)  File "/usr/lib/python2.4/site-packages/django/core/handlers/modpython.py",
line 157, in handlerreturn ModPythonHandler()(req)  File "/usr/lib/python2.4/site-packages/django/core/handlers/modpython.py",line 116, in __call__from django.conf import settings
  File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 68,in ?settings = Settings(settings_module)  File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 30, in
__init__raise EnvironmentError, "Could not import settings '%s' (is it onsys.path?): %s" % (self.SETTINGS_MODULE, e)EnvironmentError: Could not import settings 'gunnarsseite.settings' (is it on
sys.path?): No module named gunnarsseite.settingsReloading at times also gives me this error:Mod_python error: "PythonHandler django.core.handlers.modpython"Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, inHandlerDispatchresult = object(req)  File "/usr/lib/python2.4/site-packages/django/core/handlers/modpython.py",
line 157, in handlerreturn ModPythonHandler()(req)  File "/usr/lib/python2.4/site-packages/django/core/handlers/modpython.py",line 116, in __call__from django.conf import settings
  File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 11,in ?from django.conf import global_settingsImportError: cannot import name global_settingsWhat am I missing here? Any help would be appreciated. Greetings from
Frankfurt,Gunnar :)P.S.: Let me add that I am fascinated by the ease of learning Django!

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


Re: Comment options not appearing in admin

2006-05-11 Thread Phil Powell
Sure, I understand that complete automation isn't practical, but a kind of generic "allow comments" utility within the admin might prove useful.For now though, your suggestion of a hand-rolled solution sounds like the way I need to go.  Thanks for the advice.
-PhilOn 11/05/06, Waylan Limberg <[EMAIL PROTECTED]> wrote:
On 5/11/06, Phil Powell <[EMAIL PROTECTED]> wrote:> Thanks for the clarification - always useful while the documentation is in a> state of flux.>
> I've now got the front-end comments working as expected, and I'm mightily> impressed with the ease of integration.>> I guess my early query was erring towards a (false) expectation that the> admin would provide me with advanced options for my custom models - I'd
> anticipated that there would be advanced options added to each edit page, to> allow me to administer things like comment activation on individual objects.>  On reflection, that would require updates to every model I expect.  A case
> of me expecting a little too much from the system ;)>> Does anybody know of any plans / efforts towards that kind of mechanism> though?  Would be very useful.>Well, the comments app would have to be installed and your templates
would need to include the the proper tags, perhaps wrapped in an iftag. Then, with an 'allow_comments' field in your model, you couldturn comments on or off from the admin. Even if there was a practicalway to automate the model related stuff, you would still need to tell
the template where and how to display the comments so completeautomation is not really practical.> -Phil>>> On 10/05/06, Wilson Miner < [EMAIL PROTECTED]
> wrote:> >> > With comments installed you can use the comments template tags to> > attach a comment thread to any object in the template.> >> > For example, for a hypothetical blog post, the template code to get
> > the list of free comments for the object might look like this:> >> > {% load comments %}> > {% get_free_comment_list for blog.posts object.id as comment_list %}
> >> > There's also a templage tag for spitting out the form for posting a> > comment to that object:> >> > {% free_comment_form for blog.posts 
object.id %}> >> > You can find out more about how the comment tags work in the> > templatetags library in django.contrib.comments:> >> 
http://code.djangoproject.com/browser/django/trunk/django/contrib/comments/templatetags/comments.py> >> > On 5/10/06, Phil Powell <[EMAIL PROTECTED]> wrote:
> > > HI all,> > >> > > I'm a relative newbie to django, but so far I'm mightily impressed> > > (particularly with the speed of development).> > >> > > I've just run into my first serious problem when trying to get comments
> > > functioning though.  Here's what I've done:> > >> > > added 'django.contrib.comments' to my INSTALLED_APPS> > > run 'python manage.py install comments'> > > run 'python 
manage.py syncb'> > >> > > When I'm looking in admin, I can see the new 'Comments' and 'Free> comments'> > > sections, and there are advanced options for flatpages, but I can't see
> > > anything which allows me to administer comments for my models.  Am I> missing> > > something completely obvious?  Or have I missed out a step?> > >> > > Thanks in advance.
> > >> > > -Phil> > >> > >  >> > >> >> >> >> >>>>  >>--Waylan Limberg
[EMAIL PROTECTED]

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


Re: Comment options not appearing in admin

2006-05-11 Thread Phil Powell
Thanks for the clarification - always useful while the documentation is in a state of flux.I've now got the front-end comments working as expected, and I'm mightily impressed with the ease of integration.I guess my early query was erring towards a (false) expectation that the admin would provide me with advanced options for my custom models - I'd anticipated that there would be advanced options added to each edit page, to allow me to administer things like comment activation on individual objects.  On reflection, that would require updates to every model I expect.  A case of me expecting a little too much from the system ;)
Does anybody know of any plans / efforts towards that kind of mechanism though?  Would be very useful.-PhilOn 10/05/06, Wilson Miner <
[EMAIL PROTECTED]> wrote:With comments installed you can use the comments template tags to
attach a comment thread to any object in the template.For example, for a hypothetical blog post, the template code to getthe list of free comments for the object might look like this:{% load comments %}
{% get_free_comment_list for blog.posts object.id as comment_list %}There's also a templage tag for spitting out the form for posting acomment to that object:{% free_comment_form for 
blog.posts object.id %}You can find out more about how the comment tags work in thetemplatetags library in django.contrib.comments:
http://code.djangoproject.com/browser/django/trunk/django/contrib/comments/templatetags/comments.pyOn 5/10/06, Phil Powell <[EMAIL PROTECTED]> wrote:> HI all,
>> I'm a relative newbie to django, but so far I'm mightily impressed> (particularly with the speed of development).>> I've just run into my first serious problem when trying to get comments
> functioning though.  Here's what I've done:>> added 'django.contrib.comments' to my INSTALLED_APPS> run 'python manage.py install comments'> run 'python manage.py syncb'>> When I'm looking in admin, I can see the new 'Comments' and 'Free comments'
> sections, and there are advanced options for flatpages, but I can't see> anything which allows me to administer comments for my models.  Am I missing> something completely obvious?  Or have I missed out a step?
>> Thanks in advance.>> -Phil>>  >>

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


Comment options not appearing in admin

2006-05-10 Thread Phil Powell
HI all,I'm a relative newbie to django, but so far I'm mightily impressed (particularly with the speed of development).I've just run into my first serious problem when trying to get comments functioning though.  Here's what I've done:
added 'django.contrib.comments' to my INSTALLED_APPSrun 'python manage.py install comments'run 'python manage.py syncb'When I'm looking in admin, I can see the new 'Comments' and 'Free comments' sections, and there are advanced options for flatpages, but I can't see anything which allows me to administer comments for my models.  Am I missing something completely obvious?  Or have I missed out a step?
Thanks in advance.-Phil

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