Django add admin settings not related to user view of site - django

I want to add some settings to the Django admin interface. In particular I want to have fields set up to allow the administrator to enter POP3 mail settings.
Eg
[ ] Enable mail checking (checkbox)
[______] Mail server
[______] User name
[______] Password
etc
These fields will always exist and are not dependent on anything a front end user would enter.
Documentation seems to only talk about ModelAdmin, which I don't think is what I want.

This sounds like something would go in settings and you want to edit this from the admin. dbsettings is a django project that allows you to do this.
Since settings.py is just plain Python code, you can create your own custom settings and manipulate them from the admin. There are some guidelines if you do want to create custom settings.

Related

How do make a Page in Django CMS require login?

I notice there is a login_required parameter to the Page objects, but there doesn't seem to be any way via the admin to actually set it, and even when I set it via the shell, it doesn't seem to do anything.
How does one create a page with Django CMS that requires the user to be logged in to see it?
Thanks.
To use permissions, you have to enable them in your settings. CMS_PERMISSION = True You can then set per-page-permissions in the toolbar: Page->View restrictions. See Documentation

How to sign in with the Google+ API using Django?

How might I go about adding a Google+ API sign-in to my Django website?
First you must create OAuth credentials for Google+.
Go to the Google Developer Console
Create a new project.
Go to "APIs and authentication" -> "Authorization screen" and give your product a name. Click "Save".
Go to "APIs and authentication" -> "Credentials". Under "OAuth", click "Create New Client ID". Add "http://localhost:8000/soc/complete/google-oauth2/" should be listed as a callback URL. This will only work for testing, make sure to put in your actual domain when in production.
Now let's add python-social-auth to your Django app.
Install python-social-auth with pip
Set the appropriate Django settings:
Add 'social.apps.django_app.default' to INSTALLED_APPS:
Add the SOCIAL_AUTH_GOOGLE_OAUTH2_KEY and SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET settings with the client key and secret you created earlier. The client key is the "Client ID" listed in the "Credentials" screen in the Google developer console, the one which ends in ".apps.googleusercontent.com". Only take the part before the dot. The secret is listed as "Client secret".
Make sure you have the AUTHENTICATION_BACKENDS setting explicitly defined, and that it contains 'social.backends.google.GoogleOAuth2'. An example would be:
AUTHENTICATION_BACKENDS = (
'social.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend')
Define the SOCIAL_AUTH_PIPELINE setting as detailed in the python-social-auth documentation. What every setting does is listed in that page.
If you have something to do with the information you get from Google+, I recommend defining a function:
def save_profile(backend, user, response, *args, **kwargs):
if backend.name == "google-oauth2":
# do something
where user is a django.contrib.auth.models.User object, and response is a dictionary. Then add that function to the SOCIAL_AUTH_PIPELINE using the full module path, after create_user.
If you don't want to do anything with that information you can leave the default pipeline as-is.
Finally, you'll want to add the python-social-auth urls to your site's urlpatterns:
from django.conf.urls import include
url("^soc/", include("social.apps.django_app.urls", namespace="social"))
And that should do it! It's time for testing. First, ./manage.py makemigrations for the required migrations of python-social-auth, and then ./manage.py migrate, as explained here. Then, you can run the development server, and go to http://localhost:8000/soc/login/google-oauth2/?next=/ .
Hopefully I did not skip explaining any step and it will work. Feel free to ask more questions and read the docs. Also, here is a working example that you should check out.
#rhaps0dy's answer is correct, but python-social-auth is now deprecated and migrated as social-auth-app-django. So this is what I made different from #rhaps0dy guidelines.
Instead of python-social-auth, I installed social-auth-app-django,
'social.apps.django_app.default' becomes 'social_django'
'social.backends.google.GoogleOAuth2' is now 'social_core.backends.google.GoogleOAuth2'
url("^soc/", include("social.apps.django_app.urls", namespace="social")) becomes url("^soc/", include("social_django.urls", namespace="social"))

how can i check that a admin user is logged into django website or not into NGINX

I want to see that admin user is logged in or not into nginx.conf file .
I need this for my specific requirement.
My Try :
I tried to fetch COOKIES into nginx.conf file.
but when admin is logged out so cookies are changed so i am not able figure out that if a admin is logged in or not.
As far as I know this is not possible.
Django uses encrypted cookies by default and stores all data in the session table in the DB (also encrypted). You could check if the user has a cookie set in nginx but you won't be able to verify if that cookie value actually means "Admin" or "random other cookie value".
Also unless you're using custom nginx modules to check the contents of the cookie you run the risk of someone managing to trick nginx into thinking the user is an admin when that is not the case.
I'm not sure what the use case is here but you could try doing something with the django middleware or looking for third party plugins instead of using nginx.
If you want to limit file access to a specific file, e.g. admin-only images/javascript/data files or such you could try the HttpAccessKeyModule for Nginx and just generate a custom 'url' for your admin to access them.
You can also try looking into: http://nginx.org/en/docs/http/ngx_http_auth_request_module.html and see about delegating the check to some part of Django which just returns Yes or No to nginx.
There might be another nginx plugin somewhere which you can add/enable for an admin user from within django. But this requires you to think the other way around. With django telling nginx the user is an admin. Instead of nginx finding it out itself.
Hope this helps you in some way.

User management app for Django's auth

I am working on a small Django site where every user who leaves a comment on the site gets an email with a password (email is the user name) to change the comment later on.
The site should also support functions for users to retrieve or reset passwords. For this simple task I wanted to use the Django auth capabilities.
Is there a Django app which provides a simple package of user management (to reset or change a user's password) which I could incorporate in my site?
Would packages like Pinax or Drupal help for this simple task? They seem to be the overkill.
If you are looking for an advanced profile-/account-module you could take a look at django-userena
Some other options are listed in the profiles-grid on Django Packages.
Reset and change password are both included in the standard contrib.auth views.
I would have a look at django-user-accounts

Where is Django's admin read-only permission for models?

I've read at How can I MODIFY django to create "view" permission? that Django 1.2 cames with a read-only permission for admin models. Where I set this option? It's not found as a permission in the auth app.
Thanks
You need to follow the steps outlined in the linked answer. The 1.2 feature mentioned in the article concerns adding the editable=False option to a model's field which renders the field non-editable in the admin interface for all users.
If you really are missing this functionality i suggest opening a ticket on the django support site to have this fix added to django however remember that the django admin site is for ADMINS. It is not designed to be used as A CRUD interface for all users, just an administrative interface for diving into the data and editing it in place. It's only over time that people have been adding more and more User friendly enhancements to it.