|
|
@@ -14,21 +14,19 @@ doesn't stop there. Almost every aspect of it can be altered.
|
|
14
|
14
|
:doc:`Various techniques </internals/design-decisions>` are employed to achieve
|
|
15
|
15
|
that level of adaptability.
|
|
16
|
16
|
|
|
17
|
|
-To extend the behavior of a Oscar core app, you will at least need to create an
|
|
|
17
|
+To extend the behavior of an Oscar core app, you will at least need to create an
|
|
18
|
18
|
app with the same label. Depending on what should be adapted, different steps
|
|
19
|
19
|
are necessary beyond that. The steps are detailed below; this overview might
|
|
20
|
20
|
help you to figure out what needs to be done.
|
|
21
|
21
|
|
|
22
|
|
-================================== ==================== ==================================== ========================
|
|
23
|
|
-Goals vs. necessary steps Override model class Override view class (or change URLs) Override any other class
|
|
24
|
|
-================================== ==================== ==================================== ========================
|
|
25
|
|
-Python module with same label Necessary Necessary Necessary
|
|
26
|
|
-Custom root and local ``app.py`` Not necessary Necessary Not necessary
|
|
27
|
|
-Add as Django app Necessary Not necessary Necessary
|
|
28
|
|
-================================== ==================== ==================================== ========================
|
|
|
22
|
+================================ ============================= ================= =================
|
|
|
23
|
+Goals vs. necessary steps Python module with same label Add as Django app Custom ``app.py``
|
|
|
24
|
+================================ ============================= ================= =================
|
|
|
25
|
+Override a model class Necessary Necessary Not necessary
|
|
|
26
|
+Override any other class or view Necessary Necessary Not necessary
|
|
|
27
|
+Change app URLs or add views Necessary Necessary Necessary
|
|
|
28
|
+================================ ============================= ================= =================
|
|
29
|
29
|
|
|
30
|
|
-If more complex changes are desired, it is usually easiest to do all of the
|
|
31
|
|
-steps.
|
|
32
|
30
|
Please also refer to the following how-tos for further instructions and examples.
|
|
33
|
31
|
|
|
34
|
32
|
* :doc:`/howto/how_to_customise_models`
|
|
|
@@ -47,16 +45,13 @@ E.g., to create a local version of ``oscar.apps.order``, do the following::
|
|
47
|
45
|
$ touch yourproject/order/__init__.py
|
|
48
|
46
|
|
|
49
|
47
|
|
|
50
|
|
-Custom root and local ``app.py``
|
|
51
|
|
-================================
|
|
52
|
|
-
|
|
53
|
|
-Root ``app.py``
|
|
54
|
|
----------------
|
|
|
48
|
+Custom ``app.py``
|
|
|
49
|
+=================
|
|
55
|
50
|
|
|
56
|
51
|
Oscar's views and URLs use a tree of 'app' instances, each of which subclass
|
|
57
|
52
|
:class:`oscar.core.application.Application` and provide ``urls`` property.
|
|
58
|
|
-Oscar has a root app instance in ``oscar/app.py`` which can be imported into
|
|
59
|
|
-your ``urls.py``::
|
|
|
53
|
+Oscar has a root app instance in ``oscar/app.py`` which should already be
|
|
|
54
|
+wired up in your ``urls.py``::
|
|
60
|
55
|
|
|
61
|
56
|
# urls.py
|
|
62
|
57
|
from oscar.app import application
|
|
|
@@ -66,9 +61,12 @@ your ``urls.py``::
|
|
66
|
61
|
(r'', include(application.urls)),
|
|
67
|
62
|
)
|
|
68
|
63
|
|
|
69
|
|
-To get control over the mapping between URLs and views, you need to use a local
|
|
70
|
|
-``application`` instance, that (usually) subclasses Oscar's. Hence, create
|
|
71
|
|
-``yourproject/app.py`` with contents::
|
|
|
64
|
+Modifying root app
|
|
|
65
|
+------------------
|
|
|
66
|
+
|
|
|
67
|
+If you want to change URLs or views of the root application above, you need to
|
|
|
68
|
+replace it with your own ``application`` instance, that (usually) subclasses
|
|
|
69
|
+Oscar's. Hence, create ``yourproject/app.py`` with contents::
|
|
72
|
70
|
|
|
73
|
71
|
# yourproject/app.py
|
|
74
|
72
|
from oscar.app import Shop
|
|
|
@@ -89,34 +87,33 @@ Now hook this up in your ``urls.py`` instead::
|
|
89
|
87
|
(r'', include(application.urls)),
|
|
90
|
88
|
)
|
|
91
|
89
|
|
|
92
|
|
-This step only needs to be done once. All customisation will only entail
|
|
93
|
|
-overriding parts of the newly added ``BaseApplication``.
|
|
|
90
|
+Modifying sub-apps
|
|
|
91
|
+------------------
|
|
94
|
92
|
|
|
95
|
|
-Local ``app.py``
|
|
96
|
|
-----------------
|
|
|
93
|
+Sub-apps such as the ``catalogue`` app are loaded dynamically, just as most
|
|
|
94
|
+other classes in Oscar::
|
|
97
|
95
|
|
|
98
|
|
-If you want to modify a view or change a URL, you need to create an ``app.py``
|
|
99
|
|
-for your local app. It will usually inherit from Oscar's version::
|
|
|
96
|
+ # oscar/app.py
|
|
|
97
|
+ class Shop(Application):
|
|
|
98
|
+ name = None
|
|
100
|
99
|
|
|
101
|
|
- # yourproject/order/app.py
|
|
|
100
|
+ catalogue_app = get_class('catalogue.app', 'application')
|
|
|
101
|
+ customer_app = get_class('customer.app', 'application')
|
|
|
102
|
+ ...
|
|
|
103
|
+
|
|
|
104
|
+That means you can leave the root app unchanged, and just need to create another
|
|
|
105
|
+``application`` instance. It will usually inherit from Oscar's version::
|
|
|
106
|
+
|
|
|
107
|
+ # yourproject/promotions/app.py
|
|
102
|
108
|
|
|
103
|
109
|
from oscar.apps.promotions.app import PromotionsApplication as CorePromotionsApplication
|
|
|
110
|
+ from .views import MyExtraView
|
|
104
|
111
|
|
|
105
|
112
|
class PromotionsApplication(CorePromotionsApplication):
|
|
106
|
|
- pass
|
|
|
113
|
+ extra_view = MyExtraView
|
|
107
|
114
|
|
|
108
|
115
|
application = PromotionsApplication()
|
|
109
|
116
|
|
|
110
|
|
-and hook it up in your root ``app.py``::
|
|
111
|
|
-
|
|
112
|
|
- # yourproject/app.py
|
|
113
|
|
- from oscar.app import Shop
|
|
114
|
|
-
|
|
115
|
|
- from yourproject.promotions.app import application as promotions_app
|
|
116
|
|
-
|
|
117
|
|
- class BaseApplication(Shop):
|
|
118
|
|
- promotions_app = promotions_app
|
|
119
|
|
-
|
|
120
|
117
|
|
|
121
|
118
|
Add as Django app
|
|
122
|
119
|
=================
|