This file is indexed.

/usr/share/doc/python-django-feincms-doc/html/integration.html is in python-django-feincms-doc 1.7.4-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Integrating 3rd party apps into your site &mdash; FeinCMS 1.7.4 documentation</title>
    
    <link rel="stylesheet" href="_static/nature.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '1.7.4',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="FeinCMS 1.7.4 documentation" href="index.html" />
    <link rel="next" title="Media library" href="medialibrary.html" />
    <link rel="prev" title="Administration interfaces" href="admin.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="medialibrary.html" title="Media library"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="admin.html" title="Administration interfaces"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">FeinCMS 1.7.4 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="integrating-3rd-party-apps-into-your-site">
<span id="integration"></span><h1>Integrating 3rd party apps into your site<a class="headerlink" href="#integrating-3rd-party-apps-into-your-site" title="Permalink to this headline"></a></h1>
<p>With FeinCMS come a set of standard views which you might want to check
out before starting to write your own. Included is a standard view for
pages, and a set of generic view drop-in replacements which know about
the CMS.</p>
<div class="section" id="default-page-handler">
<h2>Default page handler<a class="headerlink" href="#default-page-handler" title="Permalink to this headline"></a></h2>
<p>The default CMS handler view is <tt class="docutils literal"><span class="pre">feincms.views.cbv.handler</span></tt>. You can
add the following as last line in your <tt class="docutils literal"><span class="pre">urls.py</span></tt> to make a catch-all
for any pages which were not matched before:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">feincms.views.cbv.views</span> <span class="kn">import</span> <span class="n">Handler</span>
<span class="n">handler</span> <span class="o">=</span> <span class="n">Handler</span><span class="o">.</span><span class="n">as_view</span><span class="p">()</span>

<span class="n">urlpatterns</span> <span class="o">+=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^$&#39;</span><span class="p">,</span> <span class="n">handler</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;feincms_home&#39;</span><span class="p">),</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^(.*)/$&#39;</span><span class="p">,</span> <span class="n">handler</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;feincms_handler&#39;</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Note that this default handler can also take a keyword parameter <tt class="docutils literal"><span class="pre">path</span></tt>
to specify which url to render. You can use that functionality to
implement a default page by adding another entry to your <tt class="docutils literal"><span class="pre">urls.py</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre>from feincms.views.cbv.views import Handler
handler = Handler.as_view()

...
    url(r&#39;^$&#39;, handler, {&#39;path&#39;: &#39;/rootpage&#39;},
        name=&#39;feincms_home&#39;)
...
</pre></div>
</div>
<p>Please note that it&#8217;s easier to include <tt class="docutils literal"><span class="pre">feincms.urls</span></tt> at the bottom
of your own URL patterns like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># ...</span>

<span class="n">urlpatterns</span> <span class="o">+=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;&#39;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s">&#39;feincms.urls&#39;</span><span class="p">)),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>The URLconf entry names <tt class="docutils literal"><span class="pre">feincms_home</span></tt> and <tt class="docutils literal"><span class="pre">feincms_handler</span></tt> must
both exist somewhere in your project. The standard <tt class="docutils literal"><span class="pre">feincms.urls</span></tt>
contains definitions for both. If you want to provide your own view,
it&#8217;s your responsability to create correct URLconf entries.</p>
</div>
<div class="section" id="generic-and-custom-views">
<h2>Generic and custom views<a class="headerlink" href="#generic-and-custom-views" title="Permalink to this headline"></a></h2>
<p>If you use FeinCMS to manage your site, chances are that you still want
to use generic and/or custom views for certain parts. You probably still need a
<tt class="docutils literal"><span class="pre">feincms_page</span></tt> object inside your template to generate the navigation and
render regions not managed by the generic views. The best way to ensure
the presence of a <tt class="docutils literal"><span class="pre">feincms_page</span></tt> instance in the template context is
to add <tt class="docutils literal"><span class="pre">feincms.context_processors.add_page_if_missing</span></tt> to your
<tt class="docutils literal"><span class="pre">TEMPLATE_CONTEXT_PROCESSORS</span></tt> setting.</p>
</div>
<div class="section" id="integrating-3rd-party-apps">
<span id="integration-applicationcontent"></span><h2>Integrating 3rd party apps<a class="headerlink" href="#integrating-3rd-party-apps" title="Permalink to this headline"></a></h2>
<p>Third party apps such as django-registration can be integrated in the CMS
too. <a class="reference internal" href="contenttypes.html#feincms.content.application.models.ApplicationContent" title="feincms.content.application.models.ApplicationContent"><tt class="xref py py-class docutils literal"><span class="pre">ApplicationContent</span></tt></a> lets you
delegate a subset of your page tree to a third party application. The only
thing you need is specifying a URLconf file which is used to determine which
pages exist below the integration point.</p>
<div class="section" id="adapting-the-3rd-party-application-for-feincms">
<h3>Adapting the 3rd party application for FeinCMS<a class="headerlink" href="#adapting-the-3rd-party-application-for-feincms" title="Permalink to this headline"></a></h3>
<p>The integration mechanism is very flexible. It allows the website
administrator to add the application in multiple places or move the
integration point around at will. Obviously, this flexibility puts
several constraints on the application developer. It is therefore
probable, that you cannot just drop in a 3rd party application and
expect it to work. Modifications of <tt class="docutils literal"><span class="pre">urls.py</span></tt> and the templates
will be required.</p>
<p>The following examples all assume that we want to integrate a news
application into FeinCMS. The
<a class="reference internal" href="contenttypes.html#feincms.content.application.models.ApplicationContent" title="feincms.content.application.models.ApplicationContent"><tt class="xref py py-class docutils literal"><span class="pre">ApplicationContent</span></tt></a> will
be added to the page at <tt class="docutils literal"><span class="pre">/news/</span></tt>, but that&#8217;s not too important really,
because the 3rd party app&#8217;s assumption about where it will be integrated
can be too easily violated.</p>
<p>An example <tt class="docutils literal"><span class="pre">urls.py</span></tt> follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">patterns</span><span class="p">,</span> <span class="n">include</span><span class="p">,</span> <span class="n">url</span>
<span class="kn">from</span> <span class="nn">django.views.generic.detail</span> <span class="kn">import</span> <span class="n">DetailView</span>
<span class="kn">from</span> <span class="nn">django.views.generic.list</span> <span class="kn">import</span> <span class="n">ListView</span>
<span class="kn">from</span> <span class="nn">news.models</span> <span class="kn">import</span> <span class="n">Entry</span>


<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^$&#39;</span><span class="p">,</span> <span class="n">ListView</span><span class="o">.</span><span class="n">as_view</span><span class="p">(</span>
        <span class="n">queryset</span><span class="o">=</span><span class="n">Entry</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">(),</span>
        <span class="p">),</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;entry_list&#39;</span><span class="p">),</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^(?P&lt;slug&gt;[^/]+)/$&#39;</span><span class="p">,</span> <span class="n">DetailView</span><span class="o">.</span><span class="n">as_view</span><span class="p">(</span>
        <span class="n">queryset</span><span class="o">=</span><span class="n">Entry</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">(),</span>
        <span class="p">),</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;entry_detail&#39;</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Please note that you should not add the <tt class="docutils literal"><span class="pre">news/</span></tt> prefix here. You should
<em>not</em> reference this <tt class="docutils literal"><span class="pre">urls.py</span></tt> file anywhere in a <tt class="docutils literal"><span class="pre">include</span></tt> statement.</p>
</div>
<div class="section" id="registering-the-3rd-party-application-with-feincms-applicationcontent">
<h3>Registering the 3rd party application with FeinCMS&#8217; <tt class="docutils literal"><span class="pre">ApplicationContent</span></tt><a class="headerlink" href="#registering-the-3rd-party-application-with-feincms-applicationcontent" title="Permalink to this headline"></a></h3>
<p>It&#8217;s as simple as that:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">feincms.content.application.models</span> <span class="kn">import</span> <span class="n">ApplicationContent</span>
<span class="kn">from</span> <span class="nn">feincms.module.page.models</span> <span class="kn">import</span> <span class="n">Page</span>

<span class="n">Page</span><span class="o">.</span><span class="n">create_content_type</span><span class="p">(</span><span class="n">ApplicationContent</span><span class="p">,</span> <span class="n">APPLICATIONS</span><span class="o">=</span><span class="p">(</span>
    <span class="p">(</span><span class="s">&#39;news.urls&#39;</span><span class="p">,</span> <span class="s">&#39;News application&#39;</span><span class="p">),</span>
    <span class="p">))</span>
</pre></div>
</div>
</div>
<div class="section" id="writing-the-models">
<h3>Writing the models<a class="headerlink" href="#writing-the-models" title="Permalink to this headline"></a></h3>
<p>Because the URLconf entries <tt class="docutils literal"><span class="pre">entry_list</span></tt> and <tt class="docutils literal"><span class="pre">entry_detail</span></tt> aren&#8217;t
reachable through standard means (remember, they aren&#8217;t <tt class="docutils literal"><span class="pre">include</span></tt>d
anywhere) it&#8217;s not possible to use standard <tt class="docutils literal"><span class="pre">reverse</span></tt> calls to
determine the absolute URL of a news entry. FeinCMS provides its own
<tt class="docutils literal"><span class="pre">app_reverse</span></tt> function (see <a class="reference internal" href="#integration-reversing-urls"><em>More on reversing URLs</em></a> for
details) and <tt class="docutils literal"><span class="pre">permalink</span></tt> decorator mimicking the interface of
Django&#8217;s standard functionality:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
<span class="kn">from</span> <span class="nn">feincms.content.application</span> <span class="kn">import</span> <span class="n">models</span> <span class="k">as</span> <span class="n">app_models</span>

<span class="k">class</span> <span class="nc">Entry</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
   <span class="n">title</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
   <span class="n">slug</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">SlugField</span><span class="p">()</span>
   <span class="n">description</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">TextField</span><span class="p">(</span><span class="n">blank</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

   <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
       <span class="n">ordering</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;-id&#39;</span><span class="p">]</span>

   <span class="k">def</span> <span class="nf">__unicode__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
       <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">title</span>

   <span class="nd">@app_models.permalink</span>
   <span class="k">def</span> <span class="nf">get_absolute_url</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
       <span class="k">return</span> <span class="p">(</span><span class="s">&#39;entry_detail&#39;</span><span class="p">,</span> <span class="s">&#39;news.urls&#39;</span><span class="p">,</span> <span class="p">(),</span> <span class="p">{</span>
           <span class="s">&#39;slug&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">slug</span><span class="p">,</span>
           <span class="p">})</span>
</pre></div>
</div>
<p>The only difference is that you do not only have to specify the view name
(<tt class="docutils literal"><span class="pre">entry_detail</span></tt>) but also the URLconf file (<tt class="docutils literal"><span class="pre">news.urls</span></tt>) for this
specific <tt class="docutils literal"><span class="pre">permalink</span></tt> decorator. The URLconf string must correspond to the
specification used in the <tt class="docutils literal"><span class="pre">APPLICATIONS</span></tt> list in the <tt class="docutils literal"><span class="pre">create_content_type</span></tt>
call.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Previous FeinCMS versions only provided a monkey patched <tt class="docutils literal"><span class="pre">reverse</span></tt>
method with a slightly different syntax for reversing URLs. This
behavior is still available and as of now (FeinCMS 1.5) still active
by default. It is recommended to start using the new way right now
and add <tt class="docutils literal"><span class="pre">FEINCMS_REVERSE_MONKEY_PATCH</span> <span class="pre">=</span> <span class="pre">False</span></tt> to your settings file.</p>
</div>
</div>
<div class="section" id="returning-content-from-views">
<h3>Returning content from views<a class="headerlink" href="#returning-content-from-views" title="Permalink to this headline"></a></h3>
<p>Three different types of return values can be handled by the application
content code:</p>
<ul class="simple">
<li>Unicode data (e.g. the return value of <tt class="docutils literal"><span class="pre">render_to_string</span></tt>)</li>
<li><tt class="docutils literal"><span class="pre">HttpResponse</span></tt> instances</li>
<li>A tuple consisting of two elements: A template instance, template name or list
and a context <tt class="docutils literal"><span class="pre">dict</span></tt>. More on this later under
<a class="reference internal" href="#integration-applicationcontent-inheritance20"><em>Letting the application content use the full power of Django&#8217;s template inheritance</em></a></li>
</ul>
<p>Unicode data is inserted verbatim into the output. <tt class="docutils literal"><span class="pre">HttpResponse</span></tt> instances
are returned directly to the client under the following circumstances:</p>
<ul class="simple">
<li>The HTTP status code differs from <tt class="docutils literal"><span class="pre">200</span> <span class="pre">OK</span></tt> (Please note that 404 errors may
be ignored if more than one content type with a <tt class="docutils literal"><span class="pre">process</span></tt> method exists on
the current CMS page.)</li>
<li>The resource was requested by <tt class="docutils literal"><span class="pre">XmlHttpRequest</span></tt> (that is, <tt class="docutils literal"><span class="pre">request.is_ajax</span></tt>
returns <tt class="docutils literal"><span class="pre">True</span></tt>)</li>
<li>The response was explicitly marked as <tt class="docutils literal"><span class="pre">standalone</span></tt> by the
<tt class="xref py py-func docutils literal"><span class="pre">feincms.views.decorators.standalone()</span></tt> view decorator</li>
<li>The mimetype of the response was not <tt class="docutils literal"><span class="pre">text/plain</span></tt> or <tt class="docutils literal"><span class="pre">text/html</span></tt></li>
</ul>
<p>Otherwise, the content of the response is unpacked and inserted into the
CMS output as unicode data as if the view returned the content directly, not
wrapped into a <tt class="docutils literal"><span class="pre">HttpResponse</span></tt> instance.</p>
<p>If you want to customize this behavior, provide your own subclass of
<tt class="docutils literal"><span class="pre">ApplicationContent</span></tt> with an overridden <tt class="docutils literal"><span class="pre">send_directly</span></tt> method. The
described behavior is only a sane default and might not fit everyone&#8217;s
use case.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The string or response returned should not contain <tt class="docutils literal"><span class="pre">&lt;html&gt;</span></tt> or <tt class="docutils literal"><span class="pre">&lt;body&gt;</span></tt>
tags because this would invalidate the HTML code returned by FeinCMS.</p>
</div>
</div>
<div class="section" id="letting-the-application-content-use-the-full-power-of-django-s-template-inheritance">
<span id="integration-applicationcontent-inheritance20"></span><h3>Letting the application content use the full power of Django&#8217;s template inheritance<a class="headerlink" href="#letting-the-application-content-use-the-full-power-of-django-s-template-inheritance" title="Permalink to this headline"></a></h3>
<p>If returning a simple unicode string is not enough and you&#8217;d like to modify
different blocks in the base template, you have to ensure two things:</p>
<ul class="simple">
<li>Use the class-based page handler. This is already the default if you include
<tt class="docutils literal"><span class="pre">feincms.urls</span></tt> or <tt class="docutils literal"><span class="pre">feincms.views.cbv.urls</span></tt>.</li>
<li>Make sure your application views use the third return value type described
above: A tuple consisting of a template and a context <tt class="docutils literal"><span class="pre">dict</span></tt>.</li>
</ul>
<p>The news application views would then look as follows. Please note the absence
of any template rendering calls:</p>
<p><tt class="docutils literal"><span class="pre">views.py</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">get_object_or_404</span>
<span class="kn">from</span> <span class="nn">news.models</span> <span class="kn">import</span> <span class="n">Entry</span>

<span class="k">def</span> <span class="nf">entry_list</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="c"># Pagination should probably be added here</span>
    <span class="k">return</span> <span class="s">&#39;news/entry_list.html&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;object_list&#39;</span><span class="p">:</span> <span class="n">Entry</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">()}</span>

<span class="k">def</span> <span class="nf">entry_detail</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">slug</span><span class="p">):</span>
    <span class="k">return</span> <span class="s">&#39;news/entry_detail&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;object&#39;</span><span class="p">:</span> <span class="n">get_object_or_404</span><span class="p">(</span><span class="n">Entry</span><span class="p">,</span> <span class="n">slug</span><span class="o">=</span><span class="n">slug</span><span class="p">)}</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">urls.py</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.conf.urls.defaults</span> <span class="kn">import</span> <span class="n">patterns</span><span class="p">,</span> <span class="n">include</span><span class="p">,</span> <span class="n">url</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;news.views&#39;</span><span class="p">,</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^$&#39;</span><span class="p">,</span> <span class="s">&#39;entry_list&#39;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;entry_list&#39;</span><span class="p">),</span>
    <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^(?P&lt;slug&gt;[^/]+)/$&#39;</span><span class="p">,</span> <span class="s">&#39;entry_detail&#39;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;entry_detail&#39;</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>The two templates referenced, <tt class="docutils literal"><span class="pre">news/entry_list.html</span></tt> and
<tt class="docutils literal"><span class="pre">news/entry_detail.html</span></tt>, should now extend a base template. The recommended
notation is as follows:</p>
<div class="highlight-python"><div class="highlight"><pre>{% extends feincms_page.template.path|default:&quot;base.html&quot; %}

{% block ... %}
{# more content snipped #}
</pre></div>
</div>
<p>This ensures that the the selected CMS template is still used when rendering
content.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Older versions of FeinCMS only offered fragments for a similar purpose. They
are still suported, but it&#8217;s recommended you switch over to this style instead.</p>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">If you add two application content blocks on the same page and both use this
mechanism, the later &#8216;wins&#8217;.</p>
</div>
</div>
<div class="section" id="more-on-reversing-urls">
<span id="integration-reversing-urls"></span><h3>More on reversing URLs<a class="headerlink" href="#more-on-reversing-urls" title="Permalink to this headline"></a></h3>
<p>Application content-aware URL reversing is available both for Python and
Django template code.</p>
<p>The function works almost like Django&#8217;s own <tt class="docutils literal"><span class="pre">reverse()</span></tt> method except
that it resolves URLs from application contents. The second argument,
<tt class="docutils literal"><span class="pre">urlconf</span></tt>, has to correspond to the URLconf parameter passed in the
<tt class="docutils literal"><span class="pre">APPLICATIONS</span></tt> list to <tt class="docutils literal"><span class="pre">Page.create_content_type</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">feincms.content.application.models</span> <span class="kn">import</span> <span class="n">app_reverse</span>
<span class="n">app_reverse</span><span class="p">(</span><span class="s">&#39;mymodel-detail&#39;</span><span class="p">,</span> <span class="s">&#39;myapp.urls&#39;</span><span class="p">,</span> <span class="n">args</span><span class="o">=...</span><span class="p">)</span>
</pre></div>
</div>
<p>or:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">app_reverse</span><span class="p">(</span><span class="s">&#39;mymodel-detail&#39;</span><span class="p">,</span> <span class="s">&#39;myapp.urls&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=...</span><span class="p">)</span>
</pre></div>
</div>
<p>The template tag has to be loaded from the <tt class="docutils literal"><span class="pre">applicationcontent_tags</span></tt>
template tag library first:</p>
<div class="highlight-python"><div class="highlight"><pre>{% load applicationcontent_tags %}
{% app_reverse &quot;mymodel_detail&quot; &quot;myapp.urls&quot; arg1 arg2 %}
</pre></div>
</div>
<p>or:</p>
<div class="highlight-python"><div class="highlight"><pre>{% load applicationcontent_tags %}
{% app_reverse &quot;mymodel_detail&quot; &quot;myapp.urls&quot; name1=value1 name2=value2 %}
</pre></div>
</div>
<p>Storing the URL in a context variable is supported too:</p>
<div class="highlight-python"><div class="highlight"><pre>{% load applicationcontent_tags %}
{% app_reverse &quot;mymodel_detail&quot; &quot;myapp.urls&quot; arg1 arg2 as url %}
</pre></div>
</div>
</div>
<div class="section" id="additional-customization-possibilities">
<h3>Additional customization possibilities<a class="headerlink" href="#additional-customization-possibilities" title="Permalink to this headline"></a></h3>
<p>The <tt class="docutils literal"><span class="pre">ApplicationContent</span></tt> offers additional customization possibilites for those who
need them. All of these must be specified in the <tt class="docutils literal"><span class="pre">APPLICATIONS</span></tt> argument to
<tt class="docutils literal"><span class="pre">create_content_type</span></tt>.</p>
<ul>
<li><p class="first"><tt class="docutils literal"><span class="pre">urls</span></tt>: Making it easier to swap the URLconf file:</p>
<p>You might want to use logical names instead of URLconf paths when you create
your content types, so that the <tt class="docutils literal"><span class="pre">ApplicationContent</span></tt> apps aren&#8217;t tied to
a particular <tt class="docutils literal"><span class="pre">urls.py</span></tt> file. This is useful if you want to override a few
URLs from a 3rd party application, f.e. replace <tt class="docutils literal"><span class="pre">registration.urls</span></tt> with
<tt class="docutils literal"><span class="pre">yourapp.registration_urls</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre>Page.create_content_type(ApplicationContent, APPLICATIONS=(
  (&#39;registration&#39;, &#39;Account creation and management&#39;, {
      &#39;urls&#39;: &#39;yourapp.registration_urls&#39;,
      }),
  )
</pre></div>
</div>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">admin_fields</span></tt>: Adding more fields to the application content interface:</p>
<p>Some application contents might require additional configuration parameters
which should be modifyable by the website administrator. <tt class="docutils literal"><span class="pre">admin_fields</span></tt> to
the rescue!</p>
<div class="highlight-python"><div class="highlight"><pre>def registration_admin_fields(form, *args, **kwargs):
  return {
      &#39;exclusive_subpages&#39;: forms.BooleanField(
          label=_(&#39;Exclusive subpages&#39;),
          required=False,
          initial=form.instance.parameters.get(&#39;exclusive_subpages&#39;, True),
          help_text=_(&#39;Exclude everything other than the application\&#39;s content when rendering subpages.&#39;),
          ),
      }

Page.create_content_type(ApplicationContent, APPLICATIONS=(
  (&#39;registration&#39;, &#39;Account creation and management&#39;, {
      &#39;urls&#39;: &#39;yourapp.registration_urls&#39;,
      &#39;admin_fields&#39;: registration_admin_fields,
      }),
  )
</pre></div>
</div>
<p>The form fields will only be visible after saving the <tt class="docutils literal"><span class="pre">ApplicationContent</span></tt>
for the first time. They are stored inside a JSON-encoded field. The values
are added to the template context indirectly when rendering the main template
by adding them to <tt class="docutils literal"><span class="pre">request._feincms_extra_context</span></tt>.</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">path_mapper</span></tt>: Customize URL processing by altering the perceived path of the page:</p>
<p>The applicaton content uses the remainder of the URL to resolve the view inside
the 3rd party application by default. This works fine most of the time, sometimes
you want to alter the perceived path without modifying the URLconf file itself.</p>
<p>If provided, the <tt class="docutils literal"><span class="pre">path_mapper</span></tt> receives the three arguments, <tt class="docutils literal"><span class="pre">request.path</span></tt>,
the URL of the current page and all application parameters, and must return
a tuple consisting of the path to resolve inside the application content and
the path the current page is supposed to have.</p>
<p>This <tt class="docutils literal"><span class="pre">path_mapper</span></tt> function can be used to do things like rewrite the path so
you can pretend that an app is anchored deeper than it actually is (e.g.
/path/to/page is treated as &#8220;/&lt;slug&gt;/&#8221; using a parameter value rather
than &#8220;/&#8221; by the embedded app)</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">view_wrapper</span></tt>: Decorate every view inside the application content:</p>
<p>If the customization possibilites above aren&#8217;t sufficient, <tt class="docutils literal"><span class="pre">view_wrapper</span></tt>
can be used to decorate each and every view inside the application content
with your own function. The function specified with <tt class="docutils literal"><span class="pre">view_wrapper</span></tt> receives
an additional parameters besides the view itself and any arguments or
keyword arguments the URLconf contains, <tt class="docutils literal"><span class="pre">appcontent_parameters</span></tt> containing
the application content configuration.</p>
</li>
</ul>
</div>
<div class="section" id="letting-3rd-party-apps-define-navigation-entries">
<span id="page-ext-navigation"></span><h3>Letting 3rd party apps define navigation entries<a class="headerlink" href="#letting-3rd-party-apps-define-navigation-entries" title="Permalink to this headline"></a></h3>
<p>Short answer: You need the <tt class="docutils literal"><span class="pre">feincms.module.page.extensions.navigation</span></tt>
extension module. Activate it like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">Page</span><span class="o">.</span><span class="n">register_extensions</span><span class="p">(</span><span class="s">&#39;feincms.module.page.extensions.navigation&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Please note however, that this call needs to come after all
<tt class="docutils literal"><span class="pre">NavigationExtension</span></tt> subclasses have been processed, because otherwise they
will not be available for selection in the page administration! (Yes, this is
lame and yes, this is going to change as soon as we find a
better solution. In the meantime, stick your subclass definition before
the register_extensions call.)</p>
<p>Because the use cases for extended navigations are so different, FeinCMS
does not go to great lengths trying to cover them all. What it does though
is to let you execute code to filter, replace or add navigation entries when
generating a list of navigation entries.</p>
<p>If you have a blog and you want to display the blog categories as subnavigation
entries, you could do it as follows:</p>
<ol class="arabic simple">
<li>Create a navigation extension for the blog categories</li>
<li>Assign this navigation extension to the CMS page where you want these navigation entries to appear</li>
</ol>
<p>You don&#8217;t need to do anything else as long as you use the built-in
<tt class="docutils literal"><span class="pre">feincms_nav</span></tt> template tag &#8211; it knows how to handle extended navigations.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">feincms.module.page.extensions.navigation</span> <span class="kn">import</span> <span class="n">NavigationExtension</span><span class="p">,</span> <span class="n">PagePretender</span>

<span class="k">class</span> <span class="nc">BlogCategoriesNavigationExtension</span><span class="p">(</span><span class="n">NavigationExtension</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">_</span><span class="p">(</span><span class="s">&#39;blog categories&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">children</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">page</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">category</span> <span class="ow">in</span> <span class="n">Category</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">():</span>
            <span class="k">yield</span> <span class="n">PagePretender</span><span class="p">(</span>
                <span class="n">title</span><span class="o">=</span><span class="n">category</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                <span class="n">url</span><span class="o">=</span><span class="n">category</span><span class="o">.</span><span class="n">get_absolute_url</span><span class="p">(),</span>
                <span class="p">)</span>

<span class="k">class</span> <span class="nc">PassthroughExtension</span><span class="p">(</span><span class="n">NavigationExtension</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="s">&#39;passthrough extension&#39;</span>

    <span class="k">def</span> <span class="nf">children</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">page</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">page</span><span class="o">.</span><span class="n">children</span><span class="o">.</span><span class="n">in_navigation</span><span class="p">():</span>
            <span class="k">yield</span> <span class="n">p</span>

<span class="n">Page</span><span class="o">.</span><span class="n">register_extensions</span><span class="p">(</span><span class="s">&#39;feincms.module.page.extensions.navigation&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that the objects returned should at least try to mimic a real page so
navigation template tags as <tt class="docutils literal"><span class="pre">siblings_along_path_to</span></tt> and friends continue
to work, ie. at least the following attributes should exist:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">title</span>     <span class="o">=</span> <span class="s">&#39;(whatever)&#39;</span>
<span class="n">url</span>       <span class="o">=</span> <span class="s">&#39;(whatever)&#39;</span>

<span class="c"># Attributes that MPTT assumes to exist</span>
<span class="n">parent_id</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">id</span>
<span class="n">tree_id</span>   <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">tree_id</span>
<span class="n">level</span>     <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">level</span><span class="o">+</span><span class="mi">1</span>
<span class="n">lft</span>       <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">lft</span>
<span class="n">rght</span>      <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">rght</span>
</pre></div>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Integrating 3rd party apps into your site</a><ul>
<li><a class="reference internal" href="#default-page-handler">Default page handler</a></li>
<li><a class="reference internal" href="#generic-and-custom-views">Generic and custom views</a></li>
<li><a class="reference internal" href="#integrating-3rd-party-apps">Integrating 3rd party apps</a><ul>
<li><a class="reference internal" href="#adapting-the-3rd-party-application-for-feincms">Adapting the 3rd party application for FeinCMS</a></li>
<li><a class="reference internal" href="#registering-the-3rd-party-application-with-feincms-applicationcontent">Registering the 3rd party application with FeinCMS&#8217; <tt class="docutils literal"><span class="pre">ApplicationContent</span></tt></a></li>
<li><a class="reference internal" href="#writing-the-models">Writing the models</a></li>
<li><a class="reference internal" href="#returning-content-from-views">Returning content from views</a></li>
<li><a class="reference internal" href="#letting-the-application-content-use-the-full-power-of-django-s-template-inheritance">Letting the application content use the full power of Django&#8217;s template inheritance</a></li>
<li><a class="reference internal" href="#more-on-reversing-urls">More on reversing URLs</a></li>
<li><a class="reference internal" href="#additional-customization-possibilities">Additional customization possibilities</a></li>
<li><a class="reference internal" href="#letting-3rd-party-apps-define-navigation-entries">Letting 3rd party apps define navigation entries</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="admin.html"
                        title="previous chapter">Administration interfaces</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="medialibrary.html"
                        title="next chapter">Media library</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/integration.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="medialibrary.html" title="Media library"
             >next</a> |</li>
        <li class="right" >
          <a href="admin.html" title="Administration interfaces"
             >previous</a> |</li>
        <li><a href="index.html">FeinCMS 1.7.4 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2009-2010, Feinheit GmbH and contributors.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.1.
    </div>
  </body>
</html>