ewoudenberg | 1 Nov 03:26 2009
Picon

Django crash when accessing User instance containing ManyToMany field only through request.user


Hi,

I'm adding row level permissions to the admin using this guideline:
http://www.djangosnippets.org/snippets/1054/. Everything works fine
when I add a simple ForeignKey to the User object and use that to
identify records 'owned' by the user. e.g.:

  from django.contrib.auth.models import User
  User.add_to_class('venue', models.ForeignKey(Venue))

However, when I add a ManyToManyField, so that a user can effectively
be many owners, e.g.:

  from django.contrib.auth.models import User
  User.add_to_class('venues', models.ManyToManyField(Venue))

I get this Django crash:

Exception Value:
Cannot resolve keyword 'user' into field. Choices are:  <shows all
fields of the Venue object>

Exception Location:	C:\Python25\lib\site-packages\django-trunk\django
\db\models\sql\query.py in setup_joins, line 1737

Here is the offending line:

        print request.user.venues.all()

(Continue reading)

Jeff | 1 Nov 04:59 2009
Picon

Bad Marshal Data error


Hi,

I'm getting the following error when I run "python manage.py", "python
manage.py runserver", or "python manage.py shell" in my project's
directory:

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "/usr/lib/python2.6/site-packages/django/core/management/
__init__.py", line 360, in execute_manager
    setup_environ(settings_mod)
  File "/usr/lib/python2.6/site-packages/django/core/management/
__init__.py", line 343, in setup_environ
    project_module = import_module(project_name)
  File "/usr/lib/python2.6/site-packages/django/utils/importlib.py",
line 35, in import_module
    __import__(name)
ValueError: bad marshal data

I tried to take out the project name from import statements in my
applications using "find . -type f | xargs grep -l 'oslaurier.' |
xargs sed -i -e 's/oslaurier.//g'" right before the error above
started occuring. After it stared happened I performed a hard reset
with git to a version that ran previously with no problems. Now I get
the error above. I also switched over to another branch that I hadn't
touched in a month and that gives me the error above as well.

I'd be very thankful for any help you can provide.
(Continue reading)

nostradamnit | 1 Nov 10:20 2009
Picon

Re: Django crash when accessing User instance containing ManyToMany field only through request.user


Hi,

I'm not sure what's causing your error, but it appears that using
User.add_to_class is not the recommended approach for extending the
user model.

James Bennet explains it very well here -
http://groups.google.com/group/django-users/browse_thread/thread/a35d94ce1a7893b0/9e45e7bfc58cfa05?lnk=gst&q=add_to_class#9e45e7bfc58cfa05

Basically, create a UserProfile class and associate it to your user
via the User.profile property. There are many resources online, just
search for 'django user.profile'

I use and prefer this approach
http://www.codekoala.com/blog/2009/quick-django-tip-user-profiles/

Good luck,
Sam

On Nov 1, 3:26 am, ewoudenberg <eric.woudenb... <at> gmail.com> wrote:
> Hi,
>
> I'm adding row level permissions to the admin using this
guideline:http://www.djangosnippets.org/snippets/1054/. Everything works fine
> when I add a simple ForeignKey to the User object and use that to
> identify records 'owned' by the user. e.g.:
>
>   from django.contrib.auth.models import User
>   User.add_to_class('venue', models.ForeignKey(Venue))
(Continue reading)

Daniele Procida | 1 Nov 11:48 2009
Picon

Unrelated Inline admin objects


Every example discussing inline admin objects invovles (naturally)
models that are related to one another, for example, a books model
placed inline on an authors model admin:

<http://docs.djangoproject.com/en/dev/ref/contrib/admin/
#inlinemodeladmin-objects>

But what if there were no relation? How does the admin know which inline
items belong to it? 

Daniele

--~--~---------~--~----~------------~-------~--~----~
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 <at> googlegroups.com
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Angel Talavera | 1 Nov 12:14 2009
Picon

Paginate huge file

How can I create a view to paginate thru a huge table?


--~--~---------~--~----~------------~-------~--~----~
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 <at> googlegroups.com
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Karen Tracey | 1 Nov 12:55 2009
Picon

Re: Unrelated Inline admin objects

On Sun, Nov 1, 2009 at 6:48 AM, Daniele Procida <daniele <at> apple-juice.co.uk> wrote:


Every example discussing inline admin objects invovles (naturally)
models that are related to one another, for example, a books model
placed inline on an authors model admin:

<http://docs.djangoproject.com/en/dev/ref/contrib/admin/
#inlinemodeladmin-objects
>

But what if there were no relation? How does the admin know which inline
items belong to it?


You can't list an unrelated model inline with another.  I believe you'll get an error about no ForeignKey pointing to the parent model existing in the one you are trying to inline.

Karen

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

Karen Tracey | 1 Nov 12:52 2009
Picon

Re: Bad Marshal Data error

Try deleting all your .pyc files and it might go away.

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

Karen Tracey | 1 Nov 12:59 2009
Picon

Re: Paginate huge file

On Sun, Nov 1, 2009 at 7:14 AM, Angel Talavera <aftalaveraforty <at> gmail.com> wrote:

How can I create a view to paginate thru a huge table?



You could use a generic view (http://docs.djangoproject.com/en/dev/ref/generic-views/) -- these allow you to specify how many items per page. If you want to write your own view, use a Paginator (http://docs.djangoproject.com/en/dev/topics/pagination/) directly.

Karen
 

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

Daniele Procida | 1 Nov 13:14 2009
Picon

Re: Unrelated Inline admin objects


On Sun, Nov 1, 2009, Karen Tracey <kmtracey <at> gmail.com> wrote:

>> But what if there were no relation? How does the admin know which inline
>> items belong to it?
>>
>>
>You can't list an unrelated model inline with another.  I believe you'll get
>an error about no ForeignKey pointing to the parent model existing in the
>one you are trying to inline.

Thanks. 

I was then going to ask: suppose you have two ForeignKeys pointing to
the parent model? But I've just found the fk_name option for inlines,
which controls it.

Daniele

--~--~---------~--~----~------------~-------~--~----~
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 <at> googlegroups.com
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

birkin | 1 Nov 13:21 2009
Picon

file-download question


I expect the following views.py file-download code to work, but am
getting an error, and would like feedback.

The function:

def item( request, item_id ):
  from django.http import HttpResponse, HttpResponseNotFound
  ## valid-item check
  if not item_id == '123':
    return HttpResponseNotFound( '404 / Not Found' )
  ## access
  path = '%s/cats.jpg' % ( settings_app.FOLDER_PATH )
  f = open( path, mode='rb' )
  ## delivery
  response = HttpResponse( f )
  return response
  # end def item()

The error:

mod_wsgi (pid=1196): Exception occurred processing WSGI script '/Users/
birkin/Documents/Brown_Library/djangoProjects/testbed/apache/
django.wsgi'.
Traceback (most recent call last):
  File "/Developer_3rd/django_src/django/core/handlers/wsgi.py", line
243, in __call__
    response = middleware_method(request, response)
  File "/Developer_3rd/django_src/django/middleware/cache.py", line
93, in process_response
    cache.set(cache_key, response, timeout)
  File "/Developer_3rd/django_src/django/core/cache/backends/
locmem.py", line 80, in set
    self._set(key, pickle.dumps(value), timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/copy_reg.py", line 70, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle file objects

Background info -- what surprises me so with this is that similar code
in another project's views.py works fine:

def itemStatus( request, pid, SSL=None ):
  from django.http import HttpResponse, HttpResponseForbidden
  from studio_app.models import Identity, Item
  if not 'REMOTE_ADDR' in request.META:
    return HttpResponseForbidden( '403 / forbidden' )
  if not request.META['REMOTE_ADDR'] in
studio_app_settings.FEDORA_METS_INGESTER_LEGIT_IPS:
    ## authentication
    authentication_result = utility_code.authenticateViaHttpBasic
(request)
    if type(authentication_result) == Identity:
      pass   # if authentication is successful, an identity-instance
will be returned
    else:
      auth_required_response =
utility_code.makeHttpBasicAuthRequiredResponse()   # if authentication
fails, the string 'not_legit' is returned, and an 'authorization-
required' response will be returned
      return auth_required_response
  ## access
  item = Item.objects.get( fedora_id=pid )
  path = '%s%s' %
( studio_app_settings.STUDIO_APP_FILE_UPLOAD_LOCATION,
item.original_file )
  f = open( path, mode='rb' )
  ## delivery
  response = HttpResponse( f )
  response['Content-Disposition'] = 'attachment; filename=%s' %
item.name
  return response
  # end def itemStatus()

In the working code there are some differences. I have an Item model
that contains a FileField field which uploads to a specified
FileSystemStorage location. But I don't think the differences are
relevant, because I've examined the response.__dict__ for the working
code and non-working code -- before and after the updated content-
disposition -- and it looks like what is being handled by 'return
response' in both code-blocks is the same.

Thanks in advance.

-Birkin
--~--~---------~--~----~------------~-------~--~----~
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 <at> googlegroups.com
To unsubscribe from this group, send email to django-users+unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Gmane