Browse Source

Improve docs on how to customise an app

- Made instructions on using a custom template more expliciy.  Should be
  better for new users.
- Fixes a few typos and mistakes in the code examples.

This commit is squash of pull request #640.
master
Krystian Cybulski 13 years ago
parent
commit
7b2a4cadf7

+ 28
- 3
docs/source/howto/how_to_customise_an_app.rst View File

@@ -77,8 +77,20 @@ The ``models.py`` file should import all models from the oscar app being overrid
77 77
     # myproject/promotions/models.py
78 78
     from oscar.apps.promotions.models import *
79 79
 
80
-Now replace ``oscar.apps.promotions`` with ``myproject.promotions`` in the ``INSTALLED_APPS``
81
-setting in your settings file.
80
+Now replace ``oscar.apps.promotions`` with ``myproject.promotions``  in the
81
+``INSTALLED_APPS`` setting in your settings file. To do it, you will need to let
82
+Oscar know that you're replacing the corresponding core app with yours.  You can
83
+do that by supplying an extra argument to ``get_core_apps`` function::
84
+
85
+    # myproject/settings.py
86
+
87
+    from oscar import get_core_apps
88
+    # ...
89
+    INSTALLED_APPS = [
90
+    ] + get_core_apps(['myproject.promotions'])
91
+
92
+The ``get_core_apps`` function will replace ``oscar.apps.promotions`` with
93
+``myproject.promotions``.
82 94
 
83 95
 Now create a new homepage view class in ``myproject.promotions.views`` - you can subclass
84 96
 Oscar's view if you like::
@@ -91,11 +103,22 @@ Oscar's view if you like::
91 103
 In this example, we set a new template location but it's possible to customise the view
92 104
 in any imaginable way.
93 105
 
106
+Now create the alternative template ``new-homeview.html``.  This could either be
107
+in a project-level ``templates`` folder that is added to your ``TEMPLATE_DIRS``
108
+settings, or a app-level ``templates`` folder within your 'promotions' app.  For
109
+now, put something simple in there, such as::
110
+
111
+    <html>
112
+        <body>
113
+            <p>You have successfully overridden the homepage template.</p>
114
+        </body>
115
+    </html>
116
+
94 117
 Next, create a new ``app.py`` for your local promotions app which maps your new ``HomeView``
95 118
 class to the homepage URL::
96 119
 
97 120
     # myproject/promotions/app.py
98
-    from oscar.apps.promotions import PromotionsApplication as CorePromotionsApplication
121
+    from oscar.apps.promotions.app import PromotionsApplication as CorePromotionsApplication
99 122
 
100 123
     from myproject.promotions.views import HomeView
101 124
 
@@ -114,6 +137,8 @@ Finally, hook up the new view to the homepage URL::
114 137
     class BaseApplication(Shop):
115 138
         promotions_app = promotions_app
116 139
 
140
+    application = BaseApplication()
141
+
117 142
 Quite long-winded, but once this step is done, you have lots of freedom to customise
118 143
 the app in question.
119 144
 

+ 1
- 1
docs/source/howto/how_to_override_a_core_class.rst View File

@@ -2,7 +2,7 @@
2 2
 How to override a core class
3 3
 ============================
4 4
 
5
-Much of Oscar's functionality is implemented using classes, when when a module
5
+Much of Oscar's functionality is implemented using classes, when a module
6 6
 function might seem a better choice.  This is to allow functionality to be
7 7
 customised.  Oscar uses a dynamic class loading mechanism that can be used to
8 8
 override Oscar's core classes and use custom versions.

Loading…
Cancel
Save