How to properly use django-cms apphooks - django

Below is my django cms apphook, its showing the app on the drop down but it doesn't hook the application to a page.
The project is in django 2.1.11, python3.7.1, and django cms 3.6.0
I have tried to change the apphook file to cms_apps.py and cms_app.py. I have also tried this tutorial.
I would be happy if someone can share a working manual for this procedure.
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
#apphook_pool.register # register the application
class PeoplemanagerApphook(CMSApp):
app_name = "peoplemanager"
name = "People Application"
def get_urls(self, page=None, language=None, **kwargs):
return ["peoplemanager.urls"]
The page loads, however it does not display the contents of the model

Related

Apply common custom authentication functionality to multiple Flask projects

I've created a class which authenticates users based on our company's user server. I'd like to apply it to any of our Flask apps which use Flask-Login rather than repeating the code in each project. I'm not sure what the right pattern for this is, or how to implement it.
I thought of a few options:
Python module - simply authentication, the module would do the login then return something (maybe credentials or token).
Flask 'app' - authenticates, includes a login and logout screen, and somehow gets linked in with #login_manager.user_loader. The issue I see is that the user loaded could have any application's User schema.
What is a good pattern for implementing this common authentication for multiple projects?
Extract the common functions of setting up a Flask-Login manger and the custom login views/functions you need to a simple Flask extension package. Install this package with pip in the environment of each project and use it when creating that project's Flask app.
company_auth/company_auth.py
from flask import Blueprint, redirect, url_for, render_template
from flask_login import LoginManager
from flask_wtf import Form
bp = Blueprint('auth', __name__)
class LoginForm(Form):
# define your login form
#bp.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForm()
if form.validate_on_submit():
# do custom login stuff
return redirect(url_for('index'))
return render_template('auth/login.html', form=form)
def init_app(app, user_model):
# have to pass in the user model since it's different between apps
login_manager = LoginManager()
login_manager.login_view = 'auth.login'
#login_manager.user_loader
def company_user_loader(id):
user = user_model.query.get(id)
# do custom user loading stuff
return user
app.register_blueprint(bp, url_prefix='/auth')
company_auth/setup.py
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(
name='company_auth',
version='1.0',
py_modules=['company_auth'],
url='http://davidism.com/',
license='BSD',
author='davidism',
author_email='davidism#gmail.com',
description='Flask extension for company auth',
requires=['flask']
)
Create a distribution of the package to install in other projects.
$ python setup.py sdist
For each project, install the package, import and run the init_app function, and provide the auth templates. (Your extension could include default templates too, but this answer would get gigantic if I go down that path. See Flask-Security for an example of default templates.)
$ project_env/bin/activate
$ pip install /path/to/company_auth/dist/company_auth-1.0.tar.gz
Create the auth templates:
project/
templates/
auth/
login.html
app.py
Set up the app with the custom auth:
import company_auth
company_auth.init_app()

Change header 'Django administration' text on nginx

I followed this question's answers to change my django admin panel title header.
I tried this:
There is an easy way to set admin site header - assign it to current
admin instance in urls.py like this
admin.site.site_header = 'My admin'
But it just works when I'm running the page via Python manage.py runserver
My question is how can I change the admin title header when I'm running the site via gunicorn and nginx
writing this code at the bottom of urls.py somehow worked:
admin.site.site_header = 'My admin'
If you already have an admin.py file started wherein you have registered your particular models, you can simply adjust these values there.
your_app/admin.py
# Simple admin setup
from django.contrib import admin
from .models import MyModel
# Register model
admin.site.register(MyModel)
# Tweak admin site settings like title, header, 'View Site' URL, etc
admin.site.site_title = 'My App Admin'
admin.site.site_header = 'My App Admin'
You can find all the attributes here.
follow the below steps to customize the site header and site title text of django admin login page :
1.)First import admin module in settings.py file like as below :
from django.contrib import admin
2.)In bottom of settings.py file add these lines:
admin.site.site_header = 'MY_SITE_HEADER'
admin.site.site_title = 'MY_SITE_TITLE'
The above method works in latest version of django i.e.1.11.3 till date.
You can make changes to parts of the admin by providing a template in an admin subdir of your templates directory to override what is provided by admin.
In this case, you'd want to provide a base_site.html template. You can see what the default one looks like here: https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/base_site.html

Django Registration with Django cms

I have integrated django-registration with django-cms. I have multilingual django-cms for my site with two languages English and french. I am facing issue in url-mapping. as django-cms has multiple language, so it attached language code after domain name. While in django-registration it consider such url as 404.
Below is flow, I putted registration button on click of that I have explicitly set to http://localhost:8000/accounts/register/ and it display registration page properly, but after successful completion of registration, it redirects to http://localhost:8000/en/accounts/register/complete/ , where language code is attached with url and django-registration says page not found. If I manually remove language code from url, it works fine.
Can anybody help me ?
url.py for project.
urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls'), name="home"),
url(r'^news/', include('multilingual_news.urls')),
url(r'^search/', include('haystack.urls')),
url(r'^member/',include('openerp_member.urls')),
(r'^accounts/',include('registration.backends.default.urls')),
)
You need to add an AppHook for Django-Registration. So what I did was:
create a new app called "cmsauth"
create the according cms_apps.py:
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _
class RegistrationApphook(CMSApp):
name = _("RegistrationApphook")
urls = ["registration.backends.hmac.urls"]
apphook_pool.register(RegistrationApphook)
create a CMS Page like "Accounts"
link the AppHook RegistrationApphook (you might need to restart server for it to become available)
Now you should be able to reach the URLs.

enable a model on Django Admin on Dreamhost

Hi I've created a new app (Paginas) but I cannot see inside the admin page. I've added 'paginas' to INSTALLED_APP. My admin.py is
# coding=utf-8
from django.contrib import admin
from .models import Pagina
class PaginaAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("titulo",)}
list_display = ('titulo' , 'contenido')
class Media:
js = ('/layout/grappelli/tinymce/jscripts/tiny_mce/tiny_mce.js','/layout/grappelli/tinymce_setup/tinymce_setup.js')
admin.site.register(Pagina,PaginaAdmin)
I am using passenger_wsgi.py file, I've touched tmp/restart.txt file, I've killed python process
I don't know what else can I do
The project you can see it on github https://github.com/totechess/paralisis_cerebral
What kind of error do you get when you go to your site yoursite.com/admin/
Did you add admin to INSTALLED_APPS? Note the S
....
'django.contrib.admin',
....
Perhaps your urls.py are not updated properly? What is the error?

Django admin: Can't add app to admin

I have installed Django on my host (I use their install version 1.1.1), all is working fine.
I have created some apps and they are registered in my settings.py (I can verify this works when i visit the site, the app shows up).
In the folder of this app i have created admin.py with the following content:
from progmaticnet.page.models import Page, PageContent
from django.contrib import admin
class PageContentInline( admin.StackedInline ):
model = PageContent
extra = 1
max_num = 1
class PageAdmin( admin.ModelAdmin ):
inlines = [ PageContentInline ]
class Media:
#js = ('/site_media/js/tinymce/jscripts/tiny_mce/tiny_mce.js', '/site_media/js/tinymce/textarea.js')
admin.site.register( Page, PageAdmin )
But my app doesn't show up in the admin... It is said in the documentation that you'll need to restart the server, although i can't do that (runs on apache), i have a dispatch.fcgi with this content:
#!/usr/bin/python
import sys, os
project_sys="/home/progmati/public_html"
#add a custom python path
sys.path.insert(0, project_sys)
# set the DJANGO_SETTINGS_MODULE environment variable
os.environ['DJANGO_SETTINGS_MODULE'] = 'progmaticnet.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded")
I have killed the process and started it anew but with no avail...
Does anybody know what to do about it?
Thanks
Why is the js declaration commented out in your Media class? That looks like it'll be an invalid class definition as a result (class definitions can't be entirely empty). Try uncommenting it, or adding pass below the commented out line, like this:
class Media:
#js = ('/site_media/js/tinymce/jscripts/tiny_mce/tiny_mce.js', '/site_media/js/tinymce/textarea.js')
pass