Creating Applications
dwatkinsweb edited this page May 14, 2014
·
1 revision
In amp-cms applications are the primary way of restricting access which views a pagelet is able to access. Pagelets point to an application and can only access views defined in the associated urlconf.
- Add your application to settings.AMPCMS_APPLICATIONS
settings.py
AMPCMS_APPLICATIONS = [ 'myapp' ]
- Create your views and urls as normal. Each application will point to a urlconf so set up different urlconf's for each restriction set.
views.py
class View1(AmpCmsView): .... class View2(AmpCmsView): .... class View3(AmpCmsView): .... class View4(AmpCmsView): ....
urls1.py
from django.conf.urls import patterns, url import views urlpatterns = patterns('', url('^view1/?$', view=views.View1.as_view(), name='view1'), url('^view3/?$', view=views.View3.as_view(), name='view3'))
urls2.py
from django.conf.urls import patterns, url import views urlpatterns = patterns('', url('^view2/?$', view=views.View2.as_view(), name='view2'), url('^view4/?$', view=views.View4.as_view(), name='view4'))
- Add an ampcms_app.py file to define your ampcms applications. This needs to be in the root level of the of the package you added in settings.AMPCMS_APPLICATIONS
ampcms_app.py
from ampcms.lib.application.mapper import AmpCmsApplication, application_mapper application1 = AmpCmsApplication('myapp.urls1', 'myapp1') application_mapper.register('myapp1', application1) application2 = AmpCmsApplication('myapp.urls2', 'myapp2') application_mapper.register('myapp2', application2)
- You end up with a file structure similar to this
myapp |- ampcms_app.py |- urls1.py |- urls2.py |- views.py
- You can now set any pagelets to point to either of those applications. The pagelet will only be able to access urls within the urlconf registered with application the pagelet is pointing to.
-
application1
and any pagelets set to use it will only be able to access/view1
and/view3
. -
application2
and any pagelets set to use it will only be able to access/view2
and/view4
.