β—ˆ LoginRequired for the view πŸ’ˆ Django 1.8 - django

I have been using
the braces LoginRequired Mixin in the past, Now it does not seem to work. No errors just you can see the view without Logging in.
Is this the same library?
It seems that a lot of things have changed in django since the last time I have used it. thanks. ξƒΏ

You can use official django login_required method.
from django.contrib.auth.decorators import login_required
class SomeClassView(View):
#classmethod
def as_view(cls, **initkwargs):
view = super(SomeClassView, cls).as_view(**initkwargs)
return login_required(view)
Documentation: https://docs.djangoproject.com/en/1.8/topics/auth/default/#the-login-required-decorator

Yes, this is the same library. The ReadTheDocs link that you posted links directly to the brack3t/django-braces page linked in your question.
Regarding versioning, here is the statement from the Readme.md file:
Our policy going forward is that django-braces officially supports the current version of Django and one version each direction (e.g. 1.6.x is current, so 1.5.x, 1.6.x, and 1.7.x are all supported). There won't be any restraints on using other versions of Django, though, but it will be a "buyer beware" situation.
According to the repo's releases page, v1.8 is current, so it should support Django 1.7.x, 1.8.x, and 1.9.x under the current release.

Related

django rest_framework permission error

I'm using dry-rest-permission package to write authentication for django webService. When I write permission method as same as the package docs I encounter internal server error and this :'bool' object is not callable
And this is my method:
#staticmethod
#authenticated_users
def has_create_permission(request):
return True
I guess you're using incompatible version of dry-rest-permission with your current django framework. In #authenticated_users decorator request.user.is_authenticated() is called but in newer version of django is_authenticated has changed to a bool attribute from a function returning bool.
You could refer to their last commits that correct usage of is_authenticated.
As it seems they doesn't release that commit yet you have to apply referred path manually to get rid of the error.
Per that page: "Using User.is_authenticated() and User.is_anonymous() as methods rather than properties is no longer supported."
Hope this can help you:
https://github.com/chibisov/drf-extensions/issues/200

Cannot import serializers.ListSerializer

When trying to use ListSerializer, according to this doc, I get an error:
Cannot find reference 'ListSerializer' in 'serializers.py'
Here is my import statement:
from rest_framework import serializers
What am I doing wrong?
Make sure you are using Django REST Framework 3. The ListSerializer was added in DRF 3 and did not exist in earlier version.
You can check this using pip freeze, and you should see a line similar to...
djangorestframework==3.0
...in the the output. If you are using an earlier version, you can upgrade to get the new ListSerializer, as well as many other features that were recently introduced.

Django 1.7 tutorial: Use generic views

I need to use Jython instead of Python, I found that jython2.7b2 works with DJango 1.7. So, I am stuck using the beta version. I am trying to follow the current Django tutorial and I have ran into a problem. I am not sure if I am using generic views properly. When I try to change the urls.py (polls) file. I see that pydev complains that views.IndexView, views.DetailView, and ResultsView don't exist. Am I doing something wrong? Or did they change the way generics work in version 1.7?
My System:
Windows 7
jython2.7b2
Django-1.7c3
postgresql-9.3.5-1-windows-x64
postgresql-9.3-1102.jdbc41.jar
Here is the url for the tutorial, go to the section "Use generic views: Less code is better"
Django tutorial part 04
Once you have changed your urls.py, you need to define the new views.
This is covered in the next section of the tutorials, Amend views.

Migrating a django app from 1.3.1 to 1.5

We are considering migrating our dated django 1.3.1 app to the latest version (1.5.4).
I don't like migrations.
Are any specific problems to be thought of? Any show stoppers you may think of?
Of course I will study release notes and all this.
Will it be a real head ache or is it doable?
We have migrated our app from 1.4 to 1.5, we didn't fetch any issue which is blocker. We had needed to done couple of changes related to adminmedia, json library uses and url syntaxing in our html templates. They were some normal issues only.
But yes as you said its always better to check release notes before upgrading to latest version.
Hope this will help you.
Here are the few things you need to take care of:
Project directory structure has been changed.
Include ALLOWED_HOSTS in settings.py.
django.utils.simplejson is deprecated. import simplejson can be used instead.
Session data will not be saved, when the response code is 500.
django.forms.ModelMultipleChoiceField now returns an empty QuerySet as the empty value instead of an empty list.
Uploaded files are no longer created as executable by default. If you need them to be executable change FILE_UPLOAD_PERMISSIONS to your needs.
{% load adminmedia %} template tag can no longer be used.
If you’re using django.contrib.redirects, make sure INSTALLED_APPS contains django.contrib.sites.

django-debug-toolbar with django-cms and Django 1.3

I keep hitting an error when trying to use django-debug-toolbar and django-cms together.
"MpttMeta has no attribute 'class'"
I have a feeling it's something to do with the Mptt app bundled with Django CMS, but I'm not sure, and I've seen this on a few projects but I'm surprised I can't find a direct hit for the error message in Google so I thought I'd post here.
I've tried using latest released version of debug toolbar, also the develop branch, and also dcramer's fork, but it's making no difference. I'm on Django 1.3 and Django CMS 2.1.3.
Any ideas?
Thanks!
The problem is that django-debug-toolbar expects the MpttMeta class needs to be a 'new style' class, which is a fairly straightforward patch (line 33 in django-cms/publisher/mptt_support.py). Change:
class MpttMeta:
to
class MpttMeta(object):
In Django-CMS 2.1.3, they still have their own monkey-patched mptt bundled with Django-CMS. In the next release of Django-CMS will no longer bundle its own mptt and will instead rely on the independently developed package.
It could be any problem related to Django 1.3.
Django CMS 2.1.3 supports only 1.2.X branch: http://docs.django-cms.org/en/2.1.3/getting_started/installation.html#requirements
Jonas Obrist, Django CMS dev says "Maybe a minor version of
2.1 will add official 1.3 support"
Or you can put this in yours .... urls.py for example. Not in settings.py because project will not start.
from publisher.mptt_support import MpttMeta
if not hasattr(MpttMeta, '__class__'):
MpttMeta.__class__ = type
Caught AttributeError while rendering: class MpttMeta has no attribute '__class__'
I believe this had to do with the way the MPTTMeta class is loaded into the metaclass (MPTTModelBase) making it not have a class attribute.
A monkeypatch fix is to wrap the offending statement in django-debug-toolbar like so:
try:
text = "method %s on %s object" % (receiver.__name__, receiver.im_self.__class__.__name__)
except:
text = "method %s on %s object" % (receiver.__name__, type(receiver.im_self).__name__)
This changes the output slightly to become
method finish_mptt_class on classobj object
Clearly not a permanent fix, but it gets you the debug-toolbar + django-cms working.