One-to-many relations

2007-07-05 Thread mrstone

Hi all

I have a problem I have been struggeling with for a while.

I have two models:

InfoProxy and Permission

A InfoProxy can have several Permissions

class Permission(models.Model):
 info_proxy = models.ForeignKey(InfoProxy,
related_name='permissions')
 permission_type = models.CharField(maxlength=1,
choices=PERMISSION_CHOICES)
 usergroup =   models.ForeignKey(UserGroup)

class InfoProxy(models.Model, UrlItem):
"""
   A proxy pointing to a (Info)Item
"""
info_type = models.ForeignKey(ContentType,
related_name='infoproxies')
info_id = models.PositiveIntegerField()
info_item = generic.GenericForeignKey(ct_field="info_type",
fk_field="info_id")

render_type = models.ForeignKey(ContentType,
related_name='render_infoproxies', blank=True, null=True)
render_id = models.PositiveIntegerField(blank=True, null=True)
render_item = generic.GenericForeignKey(ct_field="render_type",
fk_field="render_id")

created = models.DateTimeField('date created')
modified = models.DateTimeField('date modified')
owner = models.ForeignKey(User)

language_code = models.CharField(maxlength=20)
rank = models.IntegerField( blank=True, null=True)
grade = models.IntegerField( blank=True, null=True)
objects = InfoProxyManager()

I want to query for all object a user has permission to read depending
on groups (code below)
This code works without any problems on developer server. On
mod_python however I (sometimes) get the below error.
If I hit refresh in the browser, it usually works.

I have tried several things like:
All imports are with full paths
Classes put in site-packages
(Maybe something is wrong when loading classes)
I have checked so at least one permission exist on every InfoProxy

Anyone have had a similar problem?
Any hint that can help me try other options?

Any help is very much appreciated.
Sten


--
Error trace
--
  File "/usr/local/lib/python2.4/site-packages/django/core/handlers/
base.py", line 77, in get_response
response = callback(request, *callback_args, **callback_kwargs)

  File "/usr/local/lib/python2.4/site-packages/jellyspot/server/apps/
locations/proxy/views.py", line 264, in flashes
result_list = ResultList(request, query)

  File "/usr/local/lib/python2.4/site-packages/jellyspot/server/apps/
common/results.py", line 36, in __init__
self.get_results(request)

  File "/usr/local/lib/python2.4/site-packages/jellyspot/server/apps/
common/results.py", line 84, in get_results
raise IncorrectLookupParameters(str(e))

IncorrectLookupParameters: Cannot resolve keyword 'permissions' into
field. Choices are: id, info_type, info_id, render_type, render_id,
created, modified, owner, indexer, language_code, rank, grade


query code

try:
if user and user.is_authenticated():

query = """select uub.usergroup_id  from users_buddy
as ub
left join users_usergroup_buddies as uub on
uub.buddy_id = ub.id  where ub.buddy_id = %s
""" % (user.id)

cursor = connection.cursor()
cursor.execute(query)

group_idents = [item[0] for item in cursor.fetchall()]
group_idents.append(USERGROUP_MEMBERS.id)
else:
group_idents = []

group_idents.append(USERGROUP_EVERYONE.id)


if user and user.is_authenticated():
 qs = self.all().filter( Q(owner__exact=user.id) |
 
Q(permissions__usergroup__in=group_idents)).distinct()
else:
 qs =
self.all().filter(permissions__usergroup__in=group_idents).distinct()

return qs
except Exception, e:
print e
return self.get_empty_query_set()


--~--~-~--~~~---~--~~
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: Simple python question

2007-04-11 Thread mrstone


> What I'm doing is to load a model from a template.
> I have in a template something like this:
> {% block menu %}
> {% block rss %}
>
> I want to load "menu" and "rss", but I think that is too much work for
> now, I have no idea how to implement it and I probably won't do it.
> Thank you very much for your help.


Have you looked at template tags?
Check this tutorial: 
http://www.djangoproject.com/documentation/templates_python/
-Sten


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



Problems with GenericForeignKey and ForeignKey

2007-03-18 Thread mrstone

I have sticky bug I can  not figure out how to solve.

On the dev server it works fine, but moving to mod_python...

I'm running a query and it throws an exception, but if I reload the
page it works fine.

the model has this structure:

class InfoProxy(models.Model):
info_type = models.ForeignKey(ContentType,
related_name='infoproxies')
info_id = models.PositiveIntegerField()
info_item = models.GenericForeignKey(ct_field="info_type",
fk_field="info_id")
created = models.DateTimeField('date created')
modified = models.DateTimeField('date modified')
owner = models.ForeignKey(User)

class Permission(models.Model):
 info_proxy = models.ForeignKey(InfoProxy,
related_name='permissions')
 permission_type = models.CharField(maxlength=1,
choices=PERMISSION_CHOICES)
 usergroup =   models.ForeignKey(UserGroup)

 def __str__(self):
 try:
 return 'Item:%s  Proxy:%s  %s  %s' %
(str(self.info_proxy.getItem().id), str(self.info_proxy.id),
   self.permission_type, str(self.usergroup_id))
 except:
 return 'Item:MISSING Proxy:%s  %s  %s' %
(str(self.info_proxy.id), self.permission_type,
   str(self.usergroup_id))


The problem occurs when running a query like:

self.all().filter(permissions__usergroup__in=group_idents).distinct()

When running admin and listing 'permissions' I notice that MISSING
proxy is displayed, but when pressing refresh it works like it should.

My guess is that there is something wrong in loading the classes/
models.
Could it be related to http://code.djangoproject.com/ticket/2438

Any hints in debugging this or how to move forward is welcome

regards
Sten


--~--~-~--~~~---~--~~
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: Multiple profiles

2007-02-06 Thread mrstone

The current framework only allow for one "profile class" per site.

If you want you can  let this class return different profiles
depending on the user.

class mysiteprofile(models.Model)
   user = models.ForeignKey(User, unique=True,
related_name='user_profile')
   ...
   ...

   def get_for_user(self):
 if self.user is something:
   return profile_one
 else:
   return profile_two

@login_required
def myview(request):
profile = request.user.get_profile().get_for_user()

On Feb 5, 5:01 pm, "voltron" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Accoridng to the Django book, one could extend the basic user model by
> adding a profile class, this class is then set in the settings module
> thus:
>
> AUTH_PROFILE_MODULE = "myapp.mysiteprofile"
>
> How do I set multiple profiles? I would like to have different types
> of users, diffrentiating via different profiles.
>
> 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?hl=en
-~--~~~~--~~--~--~---



Cookies on mobile phones NOT to expire at browser close

2007-01-23 Thread mrstone

I have been trying to use persistent sessions (cookies) on a mobile
phone and never got it to work.
When I change settings.SESSION_EXPIRE_AT_BROWSER_CLOSE = False cookies
stops to work on the phone.

After digging down I noticed that it's setting max_age that brakes it
on the phone.

When setting expire to desired and max_age=None in process_response
(SessionMiddleware?) it works.

I have submitted a ticket (http://code.djangoproject.com/ticket/3298)
on the issue.  Is there anyone else having the same problem or does
anyone have it working and in that case on what phone.

I have tried on Nokia 6680, N80 and 6280. None is working.


Regards
Sten


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

2007-01-15 Thread mrstone


Im having trouble to get 'funky' characters to work with newform posts.

I have read the posts on the subject, and Im not sure if I run into a
bug...


class Guide(models.Model):
   about = models.CharField(maxlength=1500)


class EditForm(forms.Form):
   about =
forms.CharField(widget=forms.Textarea(attrs={'rows':'15',
'cols':'40'}),max_length=1500, required=False)


In my view:

if edit_form.is_valid():
   clean_data = edit_form.clean_data
   guide.about = clean_data['about']
   guide.save()

When posting 'A word about ÅÄÖ'  mysql gives: Warning: Data
truncated for column 'about' at row 1
 return self.cursor.execute(sql, params)  and stores everything up to
the funky chars.

If I change to "raw" input  (guide.about = request.POST['about'] ) it
actually get stored in db but guide.save() throws UnicodeDecodeError:
'ascii' codec can't decode byte 0xc3 in position 90: ordinal not in
range(128)

Please, any help would be valuable

Regards
Sten


--~--~-~--~~~---~--~~
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: Weird apache problem

2007-01-06 Thread mrstone


A wild guess is that there is something wrong with the data in your
database...
...are you using the same database from the dev server?


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



Cookies on mobile phones

2006-12-30 Thread mrstone


I have a problem using cookies lasting longer than a session.

When setting SESSION_EXPIRE_AT_BROWSER_CLOSE to True everything works
fine but setting to False NO cookie is set.

Hints in any direction is welcome:-)


Cheers
Sten


--~--~-~--~~~---~--~~
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: (Admin) user logged in in model field

2006-11-06 Thread mrstone

Hi

I think you will find your answers here:
http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser

regards
Sten


--~--~-~--~~~---~--~~
 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: UTF8 character set problem

2006-10-27 Thread mrstone

How did you exported the data between linux and xp?
Have you checked that the db table in mysql is set to utf8?

cheers
:-S


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



Relation query stops working when moving to Linux (from Mac)

2006-10-13 Thread mrstone

I'm getting a strange error that I have not been able to sort out.

When moving my project to the production server the below query stops
working. (It works fine on Mac)

I noticed that using CamelCase in fieldnames is an issue when moving
code, but that doesn't seem to be the problem here.

Any other hints that could point me in any direction?


Thanks
Sten


qs = InfoProxy.objects.filter(info_locations__country_code =
where.country_code)

the related model:

class InfoLocation(models.Model):
info_proxy = models.ForeignKey(InfoProxy,
db_column="info_proxy_id", related_name='info_locations')
country_code = models.CharField(maxlength=2, db_index=True)


.
The trace:

  File
"/usr/local/lib/python2.4/site-packages/django/db/models/query.py",
line 171, in iterator
select, sql, params = self._get_sql_clause()

  File
"/usr/local/lib/python2.4/site-packages/django/db/models/query.py",
line 444, in _get_sql_clause
joins2, where2, params2 = self._filters.get_sql(opts)

  File
"/usr/local/lib/python2.4/site-packages/django/db/models/query.py",
line 574, in get_sql
joins2, where2, params2 = val.get_sql(opts)

  File
"/usr/local/lib/python2.4/site-packages/django/db/models/query.py",
line 622, in get_sql
return parse_lookup(self.kwargs.items(), opts)

  File
"/usr/local/lib/python2.4/site-packages/django/db/models/query.py",
line 730, in parse_lookup
joins2, where2, params2 = lookup_inner(path, lookup_type, value,
opts, opts.db_table, None)

  File
"/usr/local/lib/python2.4/site-packages/django/db/models/query.py",
line 831, in lookup_inner
raise TypeError, "Cannot resolve keyword '%s' into field" % name

TypeError: Cannot resolve keyword 'info_locations' into field


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

2006-10-04 Thread mrstone

Hi Beau

No, I'm afraid not.

I did not have time to look into it further so it's still an open thing
for me.


Regards
Sten


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



Relevance

2006-09-15 Thread mrstone

Hi

I'm fiddling around with MySQL fulltext search and run into a problem.

Using the below code works:

match_expr = "MATCH(name) AGAINST (%s IN BOOLEAN MODE)"
qs =
Place.objects.all().filter(name__search=query).extra(select={'relevance':
match_expr}, params=[query])


But when calling qs.count() I get:
TypeError at /
not all arguments converted during string formatting

Is this a bug or am I using the extra in a wrong way?

Cheers
Sten


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



Session get_decoded

2006-09-06 Thread mrstone

  File
"/usr/local/lib/python2.4/site-packages/django/contrib/sessions/middleware.py",
line 57, in _get_session
self._session_cache = s.get_decoded()

  File
"/usr/local/lib/python2.4/site-packages/django/contrib/sessions/models.py",
line 61, in get_decoded
encoded_data = base64.decodestring(self.session_data)

  File "/usr/local/lib/python2.4/base64.py", line 319, in decodestring
return binascii.a2b_base64(s)

TypeError: a2b_base64() argument 1 must be string or read-only
character buffer, not array.array



I get the following error when trying to move my project to another
server. I have pinned it down to the Mysql installation. Anyone seen
this and can hint in any direction?

Regards
Sten


--~--~-~--~~~---~--~~
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: Disable autoreload to allow single thread debugging

2006-08-15 Thread mrstone

If you running Eclipse with PyDev you can create a file
'debugServer.py' with the following content:


import os
os.environ['DJANGO_SETTINGS_MODULE']='mysite.settings'
from django.core import management
management.runserver(addr='0.0.0.0', port='8080', use_reloader=False)


Then set up Eclipse to run/debug with that file and you can set
breakpoint etc right thru the hole process

Regards
Sten


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