Re: Stuck trying integrate jinja2 - need compatibility extensions

2009-12-09 Thread Michael Elsdörfer
Todd,

I recommend that you have a look at Coffin:

http://github.com/dcramer/coffin

It comes with a {% url %} that should work out of the box.

The snippets you linked are not tags, but functions, that is, you
would do something like:

{{ url('my_view') }}

You  need the pass the functions in those snippets into the context,
or add them as globals (not sure how to do with with chouwa). However,
it seems like chouwa has it's own url() global:

http://bitbucket.org/trevor/chouwa/changeset/857d017f8c47/

So the template syntax above might just work

Michael

--

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




Re: RSS Aggregator

2010-05-13 Thread Michael Elsdörfer
I'm working on a Universal Feed Parser-based library to create 
aggregators. The idea is that the process of parsing a feed and syncing 
it's items with a database can be customized by various addins:


http://github.com/miracle2k/feedplatform

It mostly works already, though it lacks the polishing for a release. 
You'll probably find yourself spending some time with the source code if 
you decide to try it.


Michael

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



Re: Modifing User.__unicode__

2008-01-08 Thread Michael Elsdörfer

I'd probably put it in my models file.

Michael

Thomas Guettler schrieb:
> Hi,
> 
> our customer wants to display the username as 'username: firstname
> lastname'
> 
> The easiest way would be to overwrite User.__unicode__. But where 
> should you put code like this? Up to now I put it in our middleware.
> 
> Any comments, or better solutions?
> 
> # middleware.py import new from django.contrib.auth.models import
> User
> 
> def user_unicode(self): return '%s: %s %s' % (self.username,
> self.first_name, self.last_name) 
> User.__unicode__=new.instancemethod(user_unicode, None, User)
> 
> > 

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



Re: How can I parse and process the contents of an URL?

2008-01-28 Thread Michael Elsdörfer

 > but the page seems to load forever and I'm stuck!

I'm pretty sure I ran into this before, and IIRC it's because Django's 
runserver, which I assume you are using, can only handle one request at 
a time - try a different test url.

Michael

MariusB schrieb:
> I'm trying to take a link as an argument, open it, read it's content 
> and then display the first 50 characters from it. First of all, I've
> tried to put the code in the views.py, but I didn't make it. Now I
> made a middleware component with this code:
> 
> import urllib2 from django.shortcuts import render_to_response
> 
> TEST_URL = 'http://127.0.0.1:8000/openurl/'
> 
> class Char50(object): def process_view(self, request, view_func,
> view_args, view_kwargs): query = request.POST.get('q', '') c =
> urllib2.urlopen(TEST_URL) contents = c.read( ) conturl =
> contents[0:50] return render_to_response("test.html", { "query":
> query, "results": conturl })
> 
> but the page seems to load forever and I'm stuck! I've read the 
> chapters from the djangobook, searched on the Internet, but I still 
> haven't found a solution.
> 
> Please help me! > 

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



Re: How to know if an object is being created in the save() method?

2008-01-30 Thread Michael Elsdörfer

 >> There is 'post_save' signal with 'created' parameter. But,
 >> unfortunately, this feature is undocumented...
 >
 > It's something related with "dispatcher" class? Please let me know if
 > there is more about signals than the code below. I simply just use
 > this;

If you use post_save instead of pre_save, your signal handler is passed 
a 'created' flag.

Michael

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



Re: How to know if an object is being created in the save() method?

2008-01-30 Thread Michael Elsdörfer

 > def save(self): if self.pk: ...=> being created else: ...=> being
 > updated
 >
 > I vaguely remember seeing a parameter for the save method which would
 >  do that, but I can't find it. Any thoughts?

That's the correct way to do it, unless you want to use signals:

http://www.martin-geber.com/weblog/2007/10/29/django-signals-vs-custom-save-method/

Michael

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



Re: Trying to dynamically generate labels in newforms

2008-01-30 Thread Michael Elsdörfer

 > There's no other way to set it?

Just set the labels *before* calling super().

Michael

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



Re: Any way to know if a value has changed before saving?

2008-01-31 Thread Michael Elsdörfer

 > I'd like to override the save() method and within it I'd like to test
 >  if a value has changed, that is, if that value as stored in the
 > object (in memory) is different from what is actually stored in
 > database.

Another approach is using __getattr__ to monitor changes. It saves you a 
query, but it also makes it more likely that the actual database value 
might have changed in the meantime.

Michael

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



Re: User permissions

2008-01-31 Thread Michael Elsdörfer

 > gallery application, and I have several uses who can post their
 > galleries to this application. Is there a way to create permission on
 >  a per-user basis.

There apparently was some work on a per-object permissions branch in the 
past, but it looks pretty dead:

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

Michael

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



Re: RSS escaping, {{ autoescape }} and |safe

2008-02-02 Thread Michael Elsdörfer

 > I'm sure  I'm not the only person who has come across
 > this problem

I ran into this yesterday:

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

Might be related?

Michael

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



Re: query.filter(some_foreignKey_field__exact=None)

2008-02-07 Thread Michael Elsdörfer

 > subtasks = tasks.exclude(part_of__exact='None')
 > returns the correct subset, with the "top" tasks omitted. Why?

'None' is a string, so if anything, you'd have to use: part_of__exact=None

However, what you're looking for is probably:

subtasks = Task.objects.filter(part_of__isnull=True)

Michael

[EMAIL PROTECTED] schrieb:
> Why does hitting TAB (nervous emacs autoindent twitch) complete a
> post being edited???  Anyhow, here's the full question This could be
> elementary...  In a model:
> 
> class Task(models.Model): ... part_of = models.ForeignKey('Task',
> null=True, blank=True, related_name='subtasks') ...
> 
> I am trying to do a query (after having a number of tasks and
> subtasks entered:
> 
> tasks = Task.objects.all() toptasks =
> tasks.filter(part_of__exact='None')
> 
> to find tasks that are "not part of another",  e.g.  they are not 
> "subtasks".   This always returns an empty set However:
> 
> subtasks = tasks.exclude(part_of__exact='None')
> 
> returns the correct subset, with the "top" tasks omitted. Why?
> 
> On Feb 7, 12:06 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> 
> wrote:
>> This could be elementary...  In a model:
>> 
>> class Task(models.Model):t
> > 

--~--~-~--~~~---~--~~
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: Creating password protected RSS feeds

2008-02-11 Thread Michael Elsdörfer

 > How can I create passwords protected feeds with Django? I guess I
 > will have to go beyond the contrib.feeds framework, but if some one
 > has any recipes/links to how to do this, it would be most helpful!

Use your own custom view to render the feed, and just wrap HTTP auth 
around it. There are some snippets around implementing it, for example:

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

Michael

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



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

2008-04-23 Thread Michael Elsdörfer

On Apr 23, 10:29 pm, Jay <[EMAIL PROTECTED]> wrote:
> In the django docs I see that you can easily make a foreign key by
> referencing the model:
>
>   manufacturer = models.ForeignKey('production.Manufacturer')
>
> ...but it feels like maybe stepping outside the "django way."

You can also just import the model itself from the other app and use
it directly. This works just fine as long as you don't need cross
references, i.e. app A importing app B importing app A.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django and Services

2008-05-01 Thread Michael Elsdörfer

> So I guess I'm just curious to hear how other members of the
> community have solved this.  Are people slipping business logic into
> the model classes for the most part?

If what I need to write doesn't really fit in any of the common
"places" (models, managers, views, middleware etc.), then I would say
you are free to put it wherever you want to. I don't think there would
be anything wrong with using, say, ./project/app/services/facebook.py.
Or just ./project/services/facebook.py if it's not specific to an
application.

I know some people are creating separate apps (within their project)
for that sort of thing. I guess that makes most sense if you can map
sub-parts of what you implement to Django pieces. Say your Facebook
functionality wants provide it's own set of template tags. Or a
callback view for the API. Or if there is a chance it *might* need
it's own model at some point.

For a Facebook client that possibly doesn't even depend on your
project,   you might even want to consider a separate reusable
package.

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



Re: ModelForms

2008-06-17 Thread Michael Elsdörfer

> form.category.queryset =
> Category.objects.filter(blog__exact=request.user.author_set.all()
> [0].blog) print form.category.queryset

I am somewhat surprised that this would work at all. The field objects
should be accessible via

FormClass.base_fields['fieldname']

or

form_instance.fields['fieldname']

so you should be able to say for example:

form_instance.fields['fieldname'].queryset = myqueryset

There is also:

form_instance.fields['fieldname'].choices
form_instance.fields['fieldname'].widget.choices

AFAIK, at some point in the past there were issues with choices not
being updated when the queryset was changed, but that should have been
fixed a long time ago.

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



NodeList.render() and SafeString

2007-11-29 Thread Michael Elsdörfer

I just updated to an auto-escaping enabled trunk, and I'm trying to
adjust some template tags. One of them stores a nodelist and renders
it at some point.

Now, NodeList.render() returns escaped data, but does not mark it as
safe (it's a unicode instance). Is this just an oversight, or as
designed? If the latter, can anyone explain why?

Michael

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



Re: NodeList.render() and SafeString

2007-11-30 Thread Michael Elsdörfer

> It's an oversight; I hadn't thought of that case. You're right, marking
> render() output as safe should be the right thing to do. If you'd care
> to open a ticket so this doesn't get lost, I'll fix it tomorrow or
> during the sprint on the weekend.

Thanks Malcolm:

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

Michael

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



Dynamically adding methods to Widget instance

2007-12-01 Thread Michael Elsdörfer

I just spent the last 5 hours debugging this, what a nightmare ;)

I recently updated from around rev. ~5600 to the latest trunk. Before 
the update, I was doing this:

# wrap render method
MyFormClass.base_fields['fieldname'].widget.render = 
new.instancemethod()
...
myform = MyFormClass()
...
myform.fields['fieldname'].widget.choices = [...]

That worked fine then (in retrospect, I am not sure why). After the 
update, the last assignment to choices stopped having any effect.

What happens is: constructing MyFormClass() does a deepcopy() on 
base_fields. When that process reaches a widget, the __deepcopy__ 
implementation of Django's Widget class is called, which basically falls 
back to a normal shadow copy. As a result, the dynamically created 
render wrapper still refers to the *old* Widget instance of the form 
class - in other words:

MyFormClass.base_fields['fieldname'].widget.render.im_self = \
myform.fields['fieldname'].widget.render.im_self

but:

MyFormClass.base_fields['fieldname'].widget != \
myform.fields['fieldname'].widget

Now as I said, I'm not sure why it worked before and what broke it (a 
real deepcopy() fails with "instancemethod expected at least 2 
arguments, got 0" - apparently this is a known Python problem).

Does anyone have an idea how to work around this, or do I have to use a 
completely different approach to put my custom render() method to use?

Thanks,

Michael

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



Re: Is it possible to create a related model from within another save() method?

2007-12-15 Thread Michael Elsdörfer

 > class Description(ChangeImplementor, models.Model):

I might have a flaw in my logic, but if you were to switch the bases, 
inherit from models.Model first, and implemented a save() in 
ChangeImplementor, models.Model.save() should be called first, create 
the row, and by the time ChangeImplementor.save() is executed, you 
should have access to the primary key.

Maybe worth a try.

Michael

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



Re: Is it possible to create a related model from within another save() method?

2007-12-16 Thread Michael Elsdörfer

Andrew schrieb:
 > That's a good thought, but unfortunately that's not the way multiple
 > inheritance works... only the first method in the chain gets called.

Ah, your right. Although you can still call models.Model.save() in your 
ChangeImplementor.save() yourself, or even do something like:

class Description(ChangeImplementor, models.Model): pass

class ChangeImplementor(object):
 def save(self):
s = super(ChangeImplementor, self)
if hasattr('save', s):
s.save()

Although it probably starts to get a bit hackish...

Michael

Andrew schrieb:
> That's a good thought, but unfortunately that's not the way multiple 
> inheritance works... only the first method in the chain gets called.
> 
> On Dec 15, 6:54 am, Michael Elsdörfer <[EMAIL PROTECTED]>
> wrote:
>>> class Description(ChangeImplementor, models.Model):
>> 
>> I might have a flaw in my logic, but if you were to switch the
>> bases, inherit from models.Model first, and implemented a save() in
>>  ChangeImplementor, models.Model.save() should be called first,
>> create the row, and by the time ChangeImplementor.save() is
>> executed, you should have access to the primary key.
>> 
>> Maybe worth a try.
>> 
>> Michael
> > 


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



Re: Templates, filesystem, caching?

2007-12-17 Thread Michael Elsdörfer

Rob Hudson schrieb:
> If I understand correctly, these cache the templates after they have 
> been rendered.  What I'm curious about is if there is a way to cache 
> templates before they are rendered so you can provide different 
> contexts to them.  It seems like there would still be some gains 
> involved -- a filesystem read, parsing the template into nodes, etc.

I've been wondernig the same thing. If I do {% include "item.html" %} 
for 200 items, will item.html be re-read each time? Glancing at the 
code, it appears so.

Michael

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



Re: Templates, filesystem, caching?

2007-12-18 Thread Michael Elsdörfer

James Bennett schrieb:
> Manually call get_template() or select_template(), and stuff the
> resulting Template object into a module-global variable somewhere.
> Then just re-use it, calling render() with different contexts, each
> time you need it.

Is there anything speaking against building that behaviour directly into 
Django?

Michael

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