unicode decode errors in loggging on server

2012-10-05 Thread Bram de Jong
Hello all,


My login setup on my server does not enable console logging, only
to-file logging (see at the end of this message for the logger setup).
However, just now I got a unicode decode error in my logging:


  File "/home/xyz/site/xyz/views.py", line 520, in xx_yy_zz
logger.error(u"Successfully decoded data but data is not json: %s"
% decoded)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb5 in position
1: ordinal not in range(128)

I'm a bit puzzled by this as I'm logging only to files, which should
be written as UTF-8...
If anyone has a clue, let me know!

greetings,

 - bram


My logging setup:

LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': '%(asctime)s %(levelname)-7s %(process)d
%(thread)d %(name)-20s ## %(message)s'
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'default': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': abs_path(os.path.join('logs', 'default.log')),
'maxBytes': 1024 * 1024 * 5, # 5 MB
'backupCount': 50,
'formatter': 'standard'
},
'db_handler': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': abs_path(os.path.join('logs', 'django_db.log')),
'maxBytes': 1024*1024*5, # 5 MB
'backupCount': 50,
'formatter': 'standard',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'standard'
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'Site.custom_admin_logging.CustomAdminEmailHandler',
'formatter': 'standard',
}
},
'loggers': {
'': {
'handlers': ['default', 'mail_admins'],
'level': 'DEBUG',
'propagate': True
},
'django.request': {
'handlers': ['default', 'mail_admins'],
'level': 'WARNING',
'propagate': True,
},
'django.db.backends': {
'handlers': ['db_handler', 'mail_admins'],
'level': 'DEBUG',
'propagate': False,
},
}
}



-- 
http://www.samplesumo.com
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

office: +32 (0) 9 335 59 25
mobile: +32 (0) 484 154 730

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



Re: custom db field as filter in admin

2012-06-22 Thread Bram de Jong
On Fri, Jun 22, 2012 at 12:27 PM, Melvyn Sopacua  wrote:
> On 22-6-2012 12:09, Bram de Jong wrote:
>
>> However, when I turn this field into a filter in the admin, instead of
>> seeing the filter-versions as my string (i.e. "1.0.5rc3") I see it as
>> the underlying database type (i.e.1301)
>
> I suspected there is another code path that doesn't call to_python
> properly, but let's rule out it's not the same as my issue:
> Is this field a foreign key for the model that's being displayed?

It isn't.

Where should I be digging to figure out the code path being called?

Additionally clicking the filter will make things crash because I'm
getting a string which is "1301" if I do.

Just to rule out simple stupidity on my part, here's the model field
and form field I'm using.

http://dpaste.com/762328/

 - Bram

-- 
http://www.samplesumo.com
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

office: +32 (0) 9 335 59 25
mobile: +32 (0) 484 154 730

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



custom db field as filter in admin

2012-06-22 Thread Bram de Jong
Hello all,


I have a custom DB field: a version string like "1.0.5rc3" which is
actually stored as an int in the db.
After fidling around a bit I managed to make the field so that
everything you would think should work works. It looks like a version
string everywhere, I can input it as a version string everywhere.

However, when I turn this field into a filter in the admin, instead of
seeing the filter-versions as my string (i.e. "1.0.5rc3") I see it as
the underlying database type (i.e.1301)

I implemented __unicode__ and __str__ on my object, but no luck either!


 - bram

-- 
http://www.samplesumo.com
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

office: +32 (0) 9 335 59 25
mobile: +32 (0) 484 154 730

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



Re: list_display showing latest creation date of set?

2012-06-14 Thread Bram de Jong
please ignore this email!

 - bram

On Thu, Jun 14, 2012 at 1:07 PM, Bram de Jong  wrote:
> Hi all,
>
> I have:
>
> class A(models.Model)
>    created =
>
> --
> http://www.samplesumo.com
> http://www.freesound.org
> http://www.smartelectronix.com
> http://www.musicdsp.org
>
> office: +32 (0) 9 335 59 25
> mobile: +32 (0) 484 154 730



-- 
http://www.samplesumo.com
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

office: +32 (0) 9 335 59 25
mobile: +32 (0) 484 154 730

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



list_display showing latest creation date of set?

2012-06-14 Thread Bram de Jong
Hi all,

I have:

class A(models.Model)
   created =

-- 
http://www.samplesumo.com
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

office: +32 (0) 9 335 59 25
mobile: +32 (0) 484 154 730

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



field-null or not-null filter?

2012-06-14 Thread Bram de Jong
Hey guys,


I was wondering if there is a way of making a field null vs not-null filter
without coding it yourself?

I tried:

list_filter = (('field_which_is_foreign_key', BooleanFieldListFilter),)

In the end I wrote this little one:

class MyFieldFilter(SimpleListFilter):
title = _(' field_which_is_foreign_key ')
parameter_name = ' field_which_is_foreign_key _n'

def lookups(self, request, model_admin):
return (
('T', _('Null')),
('F', _('Not Null')),
)

def queryset(self, request, queryset):
if self.value() == 'T':
return queryset.filter( field_which_is_foreign_key=None)
if self.value() == 'F':
return queryset.exclude( field_which_is_foreign_key =None)


But that's not very generic, I might need this for more fields!
Any way to do it with a bool filter?


 - bram

-- 
http://www.samplesumo.com
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

office: +32 (0) 9 335 59 25
mobile: +32 (0) 484 154 730

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



Re: (fundamental) problem with password reset in 1.x: URL's become too long

2011-11-17 Thread Bram de Jong
On Wed, Nov 16, 2011 at 2:39 PM, Andre Terra  wrote:
> Since url shorteners have already been suggested, how about the possibility
> of writing a shorter url pattern in urls.py. Would something like
> http://www.freesound.org/r/1-123-a12345678ed12345d123/ be good enough for
> you?

Sure, we could do that...

> On Tue, Nov 15, 2011 at 2:34 PM, Tom Evans  wrote:
>> In text emails, if the URL is
>> presented on a single line, by itself, surrounded by angle brackets,
>> all email clients should be able to handle it (apart from the broken
>> ones of course!)

The angle bracket thing is new to me: how exactly does this help? You
do mean regular < and > right?

So



Should be better than

http://www.google.com

?


 - Bram

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



Re: (fundamental) problem with password reset in 1.x: URL's become too long

2011-11-15 Thread Bram de Jong
Hmm,

We have 2 milion users and this isn;t really a good solution for us...

Does anyone else have an alternative password-reset app which doesn't
use as many characters as the default one?

 - bram

On Mon, Nov 14, 2011 at 4:57 PM, creecode  wrote:
> Hello Bram,
>
> It's been awhile since I've had this problem.  I don't think it is possible
> to totally solve the issue but it can be reduced.  The problem is not Django
> but rather how email is handled from point to point.  What I do is always
> put urls on a line by themselves and I put two empty lines above and below.
> That way is very much easier to see a url wrapping problem.  I also put a
> note in the email about the url wrapping problem and if the link doesn't'
> work ask the user to make sure the whole url is in the address field.  In
> addition I add that they may need to manually copy and paste.  I also have a
> template email ready to go when a support question of this nature comes in
> that I can shoot off reiterating what the problem might be and a possible
> solution.
>
> If you go this route let us know how it works for you.
>
> Toodle-lo...
> creecode
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/JF1FmBDYIFoJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
http://www.samplesumo.com
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

office: +32 (0) 9 335 59 25
mobile: +32 (0) 484 154 730

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



(fundamental) problem with password reset in 1.x: URL's become too long

2011-11-14 Thread Bram de Jong
Hello all,


on freesound.org we are using the built-in password reset view to send
users password reset emails... and there is a bit of a fundamental
problem with the password reset emails, or more in detail the password
reset URLS: they are way too long.

In our app we get URLs like this:

http://www.freesound.org/home/resetpassword/confirm/1-123-a12345678ed12345d123/

OK, we could cut back the URL by removing our own path
"home/resetpassword/confirm", but I'm sure other people have the same
problems.

Once every 10s of times this gives us problems because -I suppose-
some email apps cut off the URL, or add newlines into it (perhaps the
dashes!).


We were actually having the same type of problems with (our own)
activation links. Cutting them back to only a fewer (random)
characters solved all the problems there.


cheers,


 - Bram

-- 
http://www.samplesumo.com
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

office: +32 (0) 9 335 59 25
mobile: +32 (0) 484 154 730

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



crashes on long queries

2011-10-04 Thread Bram de Jong
Hello all,


On Freesound.org we run a stack of nginx / django via flup /
supervisorcontrol (for keeping the workers up) + postgres on another
machine

We have noticed that if we run long queries (for example deleting an
object with many, many cascades) everything crashes. More
specifically, our workers die and we seem to be getting "connection
reset by peer" on both the DB and webserver side. I say "we seem"
because we aren't 100% sure yet the two are related - but the
suspicion is sneaky!

We know long queries are bad, but... sometimes there is no way to not
do them and we would prefer not to have to restart the webserver if
they happen =)))

Has anyone else seen this happen?


 - bram


-- 
http://www.samplesumo.com
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

office: +32 (0) 9 335 59 25
mobile: +32 (0) 484 154 730

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



Re: ann: freesound and django

2011-09-16 Thread Bram de Jong
> http://www.assembla.com/code/freesound

My appologies: https://www.assembla.com/code/freesound/git/nodes


 - bram

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



ann: freesound and django

2011-09-16 Thread Bram de Jong
hello everyone,

just a small message to say that htp://www.freesound.org now runs on django
:)

all the code is gpl and can be found here:

http://www.assembla.com/code/freesound

For those interested, our stack is: nginx, postgres, solr, ...

bram

-- 
http://www.samplesumo.com
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

office: +32 (0) 9 335 59 25
mobile: +32 (0) 484 154 730

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



testing: running something after the fixtures have been loaded

2011-02-08 Thread Bram de Jong
Hi,


we want to write some testing code, but our site uses Solr for
indexing. The test cases we are running are testing -among other
things- the searching.

problem is: we need to run some additional code to index the stuf the
fixtures just inserted into the DB.

as far as I read it the django unit tests run setUp before the
fixtures are loaded...
is that correct?


 - bram

-- 
http://www.samplesumo.com
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

office: +32 (0) 9 335 59 25
mobile: +32 (0) 484 154 730

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



keeping counts of verbs (downloads, comments, ...)

2008-09-17 Thread Bram de Jong
hello all,


I have objects in the db which are being commented/favorited/downloaded
many, many times.
I'd like to keep counts of those verbs, in various time spans (#downloads
today, this month, all time).

Having done this for another site, I have found that this isn't the easiest
thing in the world when you have heavy traffic:
I had some rather large sql queries running once in a while which do the
counting and store in various tables, but updating almost all rows (each
object gets new counts) each time is a pretty bad idea (especially in
postgres), so I ended up running vacuum analyze every time after the
updates. Right now I'm thinking of creating some separate code for it and
actually store the results in memcached instead of the database.

Can anyone give any advice on how to do this, in particular (or not!) with
django?

thanks a lot for any hints!

 - Bram

-- 
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

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



request: auth_user User model, not enough characters in email

2008-08-28 Thread Bram de Jong
hello all,

it's obviously a very small hack in the django source code, but it would be
nice if the email-field would have a few more characters.
I have a few pesky users who actually use my site and have a vry long
email address.

 - bram

-- 
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

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



user defined ordering + admin?

2008-08-20 Thread Bram de Jong

Hello All,


Has anyone done any work on letting the user define a custom sort
order for objects in "nfa"?
I.e. for example extending a base-class that has a single "order"
integer field and up() and down() functions.
Once that is done, I guess it would be relatively easy to override the
"nfa" list-views for objects derived from this class.

Of course I'm betting someone has already done the work for me :)
Hence this email!
Anyone?


 - Bram

-- 
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

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



per object permissions, caching and templates?

2008-07-25 Thread Bram de Jong

hello all,


For freesound.org I really need per-object permissions and caching.
I would also love to use the {% cache %} template tag as much as
possible because it's so easy and transparent!
Now, say for example I have a sound, and a user can either edit it or
not, or vote for it or not.

can edit > has_change_permission (per object, not per app)
can vote > probably is_authenticated

In general the usage of the per-object permissions in the templates
(and now that I think of, in the views as well :D) is a bit unclear to
me.

How can use these two variables in my pages together with {% cache %}?

{% cache 500 sound_page user.is_authenticated  %}

I see little difference between using per-app permissions in templates
and using per-object permissions, so having some way to do it would be
awesome.


 - bram

-- 
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org

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

2008-07-25 Thread Bram de Jong

Hello,

On Fri, Jul 25, 2008 at 4:55 PM, Hanne Moa <[EMAIL PROTECTED]> wrote:
>
> AFAIK is_authenticated doesn't enter into it at all.


I think I might not have explained very well...

Newforms-admin ( i.e. "admin" now :) ) has per-object permissions.
These are more programmatic than per-row permissions (i.e. one is
permissions, per row on the database level, the other is a set of
if/else flow control statements in python).

The question was:

* are there any easy access methods for these per-object permissions
in the templates, and -if so- can they be used in conjunction with the
cache template tag.
* aditionally, how does one use the per-object permissions, as defined
in the AdminClasses, in general?


In a perfect world it would be possible to do something like (this is
just an example!):

{% cache  someobject.id user.is_authenticated
user.has_edit_permissions|someobject %}
  {% if user.is_authenticated%}... show comment box... {% endif %}
  {% if user.has_edit_permissions|object_shown %}... show "edit this
object" link... {% endif %}
{% endcache %}

This would mean 4 cached views would be created per displayed object.


Of course one can do all of this in the view, but as far as I know,
you would have to immediately switch to the low-level cache API in
order to do what I just described - nor would you be able to use
generic views out of the box.

cheerio,


 - Bram

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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-admin weird error ( 'str' object has no attribute '_default_manager' )

2008-07-25 Thread Bram de Jong

On Fri, Jul 18, 2008 at 5:45 PM, Karen Tracey <[EMAIL PROTECTED]> wrote:
>
> Determining which part of the fieldsets definition generates the error would
> be helpful.  You might be able to determine it by looking at the local vars
> in the debug page.  Alternatively you could experiment with removing pieces
> of it to see which field is causing the error.  Basic fieldsets validation
> works (I'm sure it's got tests and I have models that use it and still work
> on current newforms-admin), so it's something specific to your model.  If
> you could strip your models down to a reasonably simple testcase that
> displays the error it would be helpful.

Sorry for not replying this earlier.
Splitting my admin settings into admin.py modules, and updating to the
latest trunk fixed this problem.


 - Bram

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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-admin weird error ( 'str' object has no attribute '_default_manager' )

2008-07-18 Thread Bram de Jong

Hello all,

just updated to latest newforms-admin (r7947) and


This is the admin for one of my (rather large) models:

class Sound(SocialModel): # SocialModel is a model that defines some
GenericRelation
user = models.ForeignKey(User)
# snip
license = models.ForeignKey(License)
geotag = models.ForeignKey(GeoTag, null=True, blank=True, default=None)
#snip
sources = models.ManyToManyField('self', symmetrical=False,
related_name='remixes', blank=True)
pack = models.ForeignKey('Pack', null=True, blank=True, default=None)
#snip
type = models.CharField(db_index=True, max_length=4,
choices=SOUND_TYPE_CHOICES)
#

class SoundAdmin(admin.ModelAdmin):
raw_id_fields = ('user', 'pack', 'sources', 'geotag')
list_display = ('id', 'user', 'original_filename', 'license')
list_filter = ('processing_state', 'moderation_state', 'license')
fieldsets = (
 (None, {'fields': ('user', 'created', 'modified')}),
 ('Filenames', {'fields': ('original_path', 'base_filename_slug')}),
 ('User defined fields', {'fields': ('description', 'license',
'geotag', 'original_filename', 'sources', 'pack')}),
 ('File properties', {'fields': ('md5', 'type', 'duration',
'bitrate', 'bitdepth', 'samplerate', 'filesize', 'channels')}),
 ('Moderation', {'fields': ('moderation_state',
'moderation_date', 'moderation_bad_description')}),
 ('Processing', {'fields': ('processing_state',
'processing_date', 'processing_log')}),
 )
admin.site.register(Sound, SoundAdmin)


And this is the error I get when validating:

Traceback:
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  85. response = callback(request, *callback_args,
**callback_kwargs)
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/auth/decorators.py"
in __call__
  66. if self.test_func(request.user):
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/auth/middleware.py"
in __get__
  5. request._cached_user = get_user(request)
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/auth/__init__.py"
in get_user
  80. user_id = request.session[SESSION_KEY]
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/sessions/backends/base.py"
in __getitem__
  33. return self._session[key]
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/sessions/backends/base.py"
in _get_session
  147. self._session_cache = self.load()
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/sessions/backends/db.py"
in load
  20. expire_date__gt=datetime.datetime.now()
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/manager.py"
in get
  82. return self.get_query_set().get(*args, **kwargs)
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/query.py"
in get
  296. clone = self.filter(*args, **kwargs)
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/query.py"
in filter
  479. return self._filter_or_exclude(False, *args, **kwargs)
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/query.py"
in _filter_or_exclude
  497. clone.query.add_q(Q(*args, **kwargs))
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/sql/query.py"
in add_q
  1159. can_reuse=used_aliases)
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/sql/query.py"
in add_filter
  1037. alias, True, allow_many, can_reuse=can_reuse)
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/sql/query.py"
in setup_joins
  1197. field, model, direct, m2m = opts.get_field_by_name(name)
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/options.py"
in get_field_by_name
  274. cache = self.init_name_map()
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/options.py"
in init_name_map
  300. for f, model in self.get_all_related_m2m_objects_with_model():
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/options.py"
in get_all_related_m2m_objects_with_model
  377. cache = self._fill_related_many_to_many_cache()
File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/

Re: Custom ID field with random string

2008-03-31 Thread Bram de Jong

why not use slugs then?

http://www.example.com/projects/username/my-cool-project/

sounds a lot nice than

http://www.example.com/projects/0sdf0s463sdg0/

 - bram

On Mon, Mar 31, 2008 at 11:21 AM, Julien <[EMAIL PROTECTED]> wrote:
>
>  One reason is because I believe string allows to store bigger amounts
>  of data, since IDs wouldn't be counted in base 10. E.g. YouTube videos
>  which are identified by random generated strings.
>  Another reason is because I want to keep things a bit more transparent
>  to the users. Instead of having a url like www.example.com/projects/3/,
>  I'd have something like  www.example.com/projects/iuyf876ertg/
>  I don't really want the user to know that his project is number 3...
>
>
>
>  On Mar 31, 8:11 pm, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote:
>  > On 31-Mar-08, at 2:30 PM, Julien wrote:
>  >
>  > > I just thought I'd try to make it clearer what I'm after. Instead of
>  > > having numbers as ID for my objects, I'd like to have random strings
>  > > (e.g. "sadfwetbtyvt32452" or "fd70982876adhfd"...). Those strings have
>  > > to be unique across the table.
>  > > Is that easily achievable? Am I on the right track with the code
>  > > above?
>  >
>  > why? what do you hope to achieve by doing this?
>  >
>  > --
>  >
>  > regards
>  > kghttp://lawgon.livejournal.comhttp://nrcfosshelpline.in/code/
>
>
> >
>



-- 
http://freesound.iua.upf.edu
http://www.smartelectronix.com
http://www.musicdsp.org

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



newbie: object from maniputor versus set_foo.add( )

2006-06-13 Thread Bram de Jong - MTG

hi,

More newbie questions. I have something similar to:

class BlogPost:
[...]

class Comment:
[...]
blog_post = models.ForeignKey(BlogPost)


Now, when POSTing a comment, I have to set the 'blog' of the comment to 
the right blog item.


Right now I do:

def post_comment(request, blog_id):
[snip]

blog_post = BlogPost.objects.get(id__exact=blog_id) # from URL

# If data was POSTed, we're trying to create a new Comment.
 new_data = request.POST.copy()

 # load up the blog id
 new_data['blog_post'] = blog_id

 # Check for errors.
 errors = manipulator.get_validation_errors(new_data)

 if not errors:
 # No errors. This means we can save the data!
 manipulator.do_html2python(new_data)
 new_comment = manipulator.save(new_data)

[snip]

But this seems a bit dodgy as there is a blog.comment_set.add(..) 
function. I.e. how can I nicely tell the object that "blog_post" is it's 
parent? How do I join what the manipulator does and the way add( ) works 
without calling save twice?

I could do:

new_comment = manipulator.save(new_data)
new_comment.blog_post = blog_post
new_commet.save()

Which looks nicer, but saves twice.



  - bram

-- 
MTG   - http://www.mtg.upf.edu/
The Freesound Project - http://freesound.iua.upf.edu
Smartelectronix   - http://www.smartelectronix.com
Musicdsp  - http://www.musicdsp.org
Office Telephone  - +34 935 422 101

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



hello & question (sorting related cmodels)

2006-06-13 Thread Bram de Jong - MTG

Hello everyone,



A (long) question:

I have two models, linked by a single key. LinkClass ("search engines", 
...) and Link ("http://www.google.com";, "http://www.yahoo.com";)

Now, in Python I can do:

for link_class in LinkClass.objects.all():
 print link_class.name
 for link in link_class.link_set.all().order_by("name"):
 print "\t", link

In the templates I do:

{% for link_class in object_list %}
 {{ link_class.name }}
 
 {% for link in link_class.objects.all %}
 {{ link.name }}
 {% endfor %}
 
{% endfor %}

But I can't "order by" in the link_class.objects.all (or I missed some 
functionality)!

Now there's a few solutions I see, none of which I like:

1. use the dictsort or something equal in the templating language: I 
don't like this as it doesn't use the underlying DB for the sorting, 
thus is slow (afaic...).

2. add a function:

 def ordered_links(self):
 return self.link_set.all().order_by("name")

to the link class. I don't like this, because if I add another link type 
( say class VerySpecialLinks ) which has the LinkClass as foreign key, 
this function will not work for this special type of link and I'll have 
to write another function in LinkClass.

3. write a view and fill a dict with the info I want, pass the dict then 
print via the template. This seems ridiculous as would be writing the 
same twice (once in python, once in the templating).


Is there a nice AND simple solution for this?


  - bram

-- 
MTG   - http://www.mtg.upf.edu/
The Freesound Project - http://freesound.iua.upf.edu
Smartelectronix   - http://www.smartelectronix.com
Musicdsp  - http://www.musicdsp.org
Office Telephone  - +34 935 422 101

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



new here and where/how/what to cache...

2006-02-01 Thread Bram de Jong - MTG


Hi,


(new here, hello all)


My latest website ( http://freesound.iua.upf.edu ) is becoming more 
popular then it was ever meant to be, so I'm looking at rewriting it in 
django and rethinking the model space from the bottom up...



Now, I have some questions about caching. Here goes:

1. how does one cache websites (with django) that have personalized 
views for the users? I.e. there's lot's of thing like


if(user has voted for this item)
   display "hello  you voted /10 for this item"
else
   display voting dropdown

Obviously this is a simple example. How does one handle this in the 
caching? If I have X pages with voting boxes and Y users, I don't want 
to be caching X x Y files...



2. does django automatically invalidate caches when objects, displayed 
in the cached page, are changed? I.e. say a person votes and you want to 
display the page with his new vote on it. This means I should invalidate 
the cached page. Does django help me with this in any way, or should it 
be done by the coder.



Thanks a lot for any possible answers!



 - bram

--
MTG   - http://www.iua.upf.es/mtg
The Freesound Project - http://freesound.iua.upf.edu
Smartelectronix   - http://www.smartelectronix.com
Musicdsp  - http://www.musicdsp.org
Office Telephone  - +34 935 422 101