New version of django-permissionsx
Hi, I would be absolutely grateful if you could please check it out and give me some feedback. What I'm interested in particular is how it works with different Django/Python/apps configurations and if the syntax/API is easy to follow. I would be even more happy if you found it useful in your projects ;) Docs: https://github.com/thinkingpotato/django-permissionsx PyPi: https://pypi.python.org/pypi/django-permissionsx/ Cheers, Robert -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d3e5abdd-7dd7-497f-b950-da1747e6e79f%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: New version of django-permissionsx
A short update: I just pushed a new package with some bug fixes and new functionality. Docs were also updated. On Friday, October 4, 2013 5:33:41 AM UTC+2, thinkin...@gmail.com wrote: > > Hi, > > I would be absolutely grateful if you could please check it out and give > me some feedback. What I'm interested in particular is how it works with > different Django/Python/apps configurations and if the syntax/API is easy > to follow. I would be even more happy if you found it useful in your > projects ;) > > Docs: > https://github.com/thinkingpotato/django-permissionsx > > PyPi: > https://pypi.python.org/pypi/django-permissionsx/ > > Cheers, > Robert > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/082ea6e9-e484-44b0-b2a3-7aacfde1b93f%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Accessing attributes of the current view in Django middleware?
Hey, Try along these lines: def process_view(self, request, view_func, view_args, view_kwargs): view = get_class(view_func.__module__, view_func.__name__) view.my_attribute While `get_class()`: from django.utils import importlib def get_class(module_name, cls_name): try: module = importlib.import_module(module_name) except ImportError: raise ImportError('Invalid class path: {}'.format(module_name)) try: cls = getattr(module, cls_name) except AttributeError: raise ImportError('Invalid class name: {}'.format(cls_name)) else: return cls Robert On Friday, December 27, 2013 8:39:49 PM UTC, alk wrote: > > I'm trying to access an attribute of the current view instance in the > middleware layer. > > For example, given a class-based view like this: > > # views.pyclass MyView(View): > my_attribute = 'something' > > I'd love to be able to get a handle on my_attribute in the middleware by > doing something like this: > > # middleware.pydef process_view(self, request, view_func, view_args, > view_kwargs): > my_attribute = request.view.my_attribute > > Of course, this does not work because Django doesn't expose the view > instance through the request object. > > Is there any way to get this accomplished? > > Many thanks! > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0238bf6b-5c16-4eeb-9122-cb068accb913%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Accessing attributes of the current view in Django middleware?
On Saturday, December 28, 2013 6:44:16 PM UTC, alk wrote: > > > On Saturday, December 28, 2013 8:19:22 AM UTC-5, thinkin...@gmail.comwrote: >> >> Hey, >> >> Try along these lines: >> >> def process_view(self, request, view_func, view_args, view_kwargs): >> view = get_class(view_func.__module__, view_func.__name__) >> view.my_attribute >> > > Heh, yeah, this seems to be the only way. I was kind of headed in this > direction but I'm fairly new to Django/python, and to programming in > general. Is this safe/efficient? I guess this just involves importing the > view class once per request -- doesn't seem like a big deal but would love > some feedback. > > Thanks again! > Is it safe: well, as far as I can tell there is no reason it should not be. In terms of efficiency, it's always a little bit an overhead to every request, no matter you need it or not. Have a look at this code: https://github.com/thinkingpotato/django-permissionsx/blob/v0.0.6/permissionsx/middleware.py There's some caching done etc. And it's been tested in production. I had to retreat from that solution for a few reasons (one of them was making the permissions available for other apps or frameworks), but I've spent several hours looking for a better approach with not much success. Good luck, R. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/315d88d7-a3dc-4d72-8135-720ae8046bc5%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: referencing models before syncdb
Check if that is not something you're looking for: https://docs.djangoproject.com/en/1.5/ref/signals/#post-syncdb On Wednesday, December 25, 2013 7:18:45 PM UTC, vinaya...@iiitd.ac.in wrote: > > I have an actions.py file which defines custom actions for the admin page > for one of my models. It uses an intermediary page (like the default delete > action) and hence has a corresponding form which is also declared in the > same file. > > For some reason, I had drop by database (development) and now when I try > to run syncdb, it gives me the following error: > > > Traceback (most recent call last): > File "/home/vinayak/pyCharm/helpers/pycharm/django_manage.py", line 23, > in > run_module(manage_file, None, '__main__', True) > File "/usr/lib/python2.7/runpy.py", line 176, in run_module > fname, loader, pkg_name) > File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code > mod_name, mod_fname, mod_loader, pkg_name) > File "/usr/lib/python2.7/runpy.py", line 72, in _run_code > exec code in run_globals > File "/home/vinayak/zenatix/customuser/manage.py", line 10, in > execute_from_command_line(sys.argv) > File > "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", > line 399, in execute_from_command_line > utility.execute() > File > "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", > line 392, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File > "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", > line 242, in run_from_argv > self.execute(*args, **options.__dict__) > File > "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", > line 284, in execute > self.validate() > File > "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", > line 310, in validate > num_errors = get_validation_errors(s, app) > File > "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", > > line 34, in get_validation_errors > for (app_name, error) in get_app_errors().items(): > File > "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line > 196, in get_app_errors > self._populate() > File > "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line > 75, in _populate > self.load_app(app_name, True) > File > "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line > 99, in load_app > models = import_module('%s.models' % app_name) > File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", > line 40, in import_module > __import__(name) > File "/usr/local/lib/python2.7/dist-packages/debug_toolbar/models.py", > line 63, in > patch_root_urlconf() > File "/usr/local/lib/python2.7/dist-packages/debug_toolbar/models.py", > line 51, in patch_root_urlconf > reverse('djdt:render_panel') > File > "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line > 480, in reverse > app_list = resolver.app_dict[ns] > File > "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line > 310, in app_dict > self._populate() > File > "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line > 262, in _populate > for pattern in reversed(self.url_patterns): > File > "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line > 346, in url_patterns > patterns = getattr(self.urlconf_module, "urlpatterns", > self.urlconf_module) > File > "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line > 341, in urlconf_module > self._urlconf_module = import_module(self.urlconf_name) > File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", > line 40, in import_module > __import__(name) > File "/home/vinayak/zenatix/customuser/customuser/urls.py", line 6, in > > admin.autodiscover() > File > "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", > line 29, in autodiscover > import_module('%s.admin' % app) > File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", > line 40, in import_module > __import__(name) > File "/home/vinayak/zenatix/customuser/iiitd/admin.py", line 3, in > > from actions import grant_read_permission > File "/home/vinayak/zenatix/customuser/iiitd/actions.py", line 13, in > > class SelectUserForm(forms.Form): > File "/home/vinayak/zenatix/customuser/iiitd/actions.py", line 16, in > SelectUserForm > clientObj = ClientInfo.objects.all()[:1].get() > File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", > line 301, in get > num = len(clone) > File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", > line 77, in __len__ > self._fetch_all() > File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", > line 854