You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

getting_started.rst 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. ============================
  2. Start building your own shop
  3. ============================
  4. For simplicity, let's assume you're building a new e-commerce project from
  5. scratch and have decided to use Oscar. Let's call this shop 'frobshop'
  6. .. tip::
  7. You can always review the set-up of the `Sandbox site`_ in case you have
  8. trouble with the below instructions.
  9. .. _`Sandbox site`: https://github.com/tangentlabs/django-oscar/tree/master/sites/sandbox
  10. Install by hand
  11. ===============
  12. Install Oscar (which will install Django as a dependency), then create the
  13. project:
  14. .. code-block:: bash
  15. pip install django-oscar
  16. django-admin.py startproject frobshop
  17. This will create a folder ``frobshop`` for your project.
  18. Settings
  19. --------
  20. Now edit your settings file ``frobshop.frobshop.settings.py`` to specify a
  21. database (we use SQLite for simplicity):
  22. .. code-block:: django
  23. DATABASES = {
  24. 'default': {
  25. 'ENGINE': 'django.db.backends.sqlite3',
  26. 'NAME': 'db.sqlite3',
  27. 'USER': '',
  28. 'PASSWORD': '',
  29. 'HOST': '',
  30. 'PORT': '',
  31. }
  32. }
  33. Then, add ``oscar.apps.basket.middleware.BasketMiddleware`` to
  34. ``MIDDLEWARE_CLASSES``. It is also recommended to use
  35. ``django.middleware.transaction.TransactionMiddleware`` too
  36. Now set ``TEMPLATE_CONTEXT_PROCESSORS`` to:
  37. .. code-block:: django
  38. TEMPLATE_CONTEXT_PROCESSORS = (
  39. "django.contrib.auth.context_processors.auth",
  40. "django.core.context_processors.request",
  41. "django.core.context_processors.debug",
  42. "django.core.context_processors.i18n",
  43. "django.core.context_processors.media",
  44. "django.core.context_processors.static",
  45. "django.contrib.messages.context_processors.messages",
  46. 'oscar.apps.search.context_processors.search_form',
  47. 'oscar.apps.promotions.context_processors.promotions',
  48. 'oscar.apps.checkout.context_processors.checkout',
  49. 'oscar.apps.customer.notifications.context_processors.notifications',
  50. 'oscar.core.context_processors.metadata',
  51. )
  52. Next, modify ``INSTALLED_APPS`` to be a list, add ``South`` and ``compressor``
  53. and append Oscar's core apps:
  54. .. code-block:: django
  55. from oscar import get_core_apps
  56. INSTALLED_APPS = [
  57. 'django.contrib.auth',
  58. 'django.contrib.contenttypes',
  59. 'django.contrib.sessions',
  60. 'django.contrib.sites',
  61. 'django.contrib.messages',
  62. 'django.contrib.flatpages',
  63. ...
  64. 'south',
  65. 'compressor',
  66. ] + get_core_apps()
  67. Note that Oscar requires ``django.contrib.messages`` and
  68. ``django.contrib.flatpages`` which aren't included by default.
  69. .. tip::
  70. Oscar's default templates use django-compressor_ but it's optional really.
  71. You may decide to use your own templates that don't use compressor. Hence
  72. why it is not one of the 'core apps'.
  73. .. _django-compressor: https://github.com/jezdez/django_compressor
  74. Now set your auth backends to:
  75. .. code-block:: django
  76. AUTHENTICATION_BACKENDS = (
  77. 'oscar.apps.customer.auth_backends.Emailbackend',
  78. 'django.contrib.auth.backends.ModelBackend',
  79. )
  80. to allow customers to sign in using an email address rather than a username.
  81. Modify your ``TEMPLATE_DIRS`` to include the main Oscar template directory:
  82. .. code-block:: django
  83. from oscar import OSCAR_MAIN_TEMPLATE_DIR
  84. TEMPLATE_DIRS = TEMPLATE_DIRS + (OSCAR_MAIN_TEMPLATE_DIR,)
  85. Oscar currently uses Haystack for search so you need to specify:
  86. .. code-block:: django
  87. HAYSTACK_CONNECTIONS = {
  88. 'default': {
  89. 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
  90. },
  91. }
  92. When moving towards production, you'll obviously need to switch to a real search
  93. backend.
  94. The last addition to the settings file is to import all of Oscar's default settings:
  95. .. code-block:: django
  96. from oscar.defaults import *
  97. URLs
  98. ----
  99. Alter your ``frobshop/urls.py`` to include Oscar's URLs:
  100. .. code-block:: django
  101. from django.conf.urls import patterns, include, url
  102. from oscar.app import application
  103. urlpatterns = patterns('',
  104. (r'', include(application.urls))
  105. )
  106. Database
  107. --------
  108. Then create the database and the shop should be browsable:
  109. .. code-block:: bash
  110. python manage.py syncdb --noinput
  111. python manage.py migrate
  112. You should now have a running Oscar install that you can browse.
  113. Defining the order pipeline
  114. ---------------------------
  115. The order management in Oscar relies on the order pipeline that
  116. defines all the statuses an order can have and the possible transitions
  117. for any given status. Statuses in Oscar are not just used for an order
  118. but are handled on the line level as well to be able to handle partial
  119. shipping of an order.
  120. The order status pipeline is different for every shop which means that
  121. changing it is fairly straightforward in Oscar. The pipeline is defined in
  122. your ``settings.py`` file using the ``OSCAR_ORDER_STATUS_PIPELINE`` setting.
  123. You also need to specify the initial status for an order and a line item in
  124. ``OSCAR_INITIAL_ORDER_STATUS`` and ``OSCAR_INITIAL_LINE_STATUS``
  125. respectively.
  126. To give you an idea of what an order pipeline might look like take a look
  127. at the Oscar sandbox settings:
  128. .. code-block:: django
  129. OSCAR_INITIAL_ORDER_STATUS = 'Pending'
  130. OSCAR_INITIAL_LINE_STATUS = 'Pending'
  131. OSCAR_ORDER_STATUS_PIPELINE = {
  132. 'Pending': ('Being processed', 'Cancelled',),
  133. 'Being processed': ('Processed', 'Cancelled',),
  134. 'Cancelled': (),
  135. }
  136. Defining the order status pipeline is simply a dictionary of where each
  137. status is given as a key. Possible transitions into other statuses can be
  138. specified as an iterable of status names. An empty iterable defines an
  139. end point in the pipeline.
  140. With these three settings defined in your project you'll be able to see
  141. the different statuses in the order management dashboard.
  142. Install using Tangent's boilerplate Django project
  143. ==================================================
  144. The easiest way to get started is to use Tangent's `template Django project`_
  145. although it is tailored to an agency structure which may not suit everyone.
  146. .. _`template Django project`: https://github.com/tangentlabs/tangent-django-boilerplate
  147. Set up a virtualenv_, and create a new project using the ``startproject``
  148. management command:
  149. .. code-block:: bash
  150. mkvirtualenv frobshop # using virtualenvwrapper
  151. pip install Django
  152. django-admin.py startproject frobshop \
  153. --template=https://github.com/tangentlabs/tangent-django-boilerplate/zipball/master
  154. .. _virtualenv: http://www.virtualenv.org/en/latest/
  155. This will create a folder ``frobshop`` which is an entire templated project that
  156. follows Tangent's conventions. The structure is::
  157. frobshop/
  158. docs/
  159. www/
  160. conf/
  161. deploy/
  162. public/
  163. static/
  164. templates/
  165. manage.py
  166. settings.py
  167. settings_test.py
  168. urls.py
  169. urls_oscar.py
  170. README.rst
  171. fabconfig.py
  172. fabfile.py
  173. deploy-to-test.sh
  174. deploy-to-stage.sh
  175. deploy-to-prod.sh
  176. Replace a few files with Oscar-specific versions (the templated project can be
  177. used for non-Oscar projects too):
  178. .. code-block:: bash
  179. mv frobshop/www/urls{_oscar,}.py
  180. mv frobshop/www/deploy/requirements{_oscar,}.txt
  181. mv frobshop/www/conf/default{_oscar,}.py
  182. Install dependencies:
  183. .. code-block:: bash
  184. cd frobshop/www
  185. pip install -r deploy/requirements.txt
  186. Create database:
  187. .. code-block:: bash
  188. python manage.py syncdb --noinput
  189. python manage.py migrate
  190. And that should be it.
  191. Next steps
  192. ==========
  193. The next step is to implement the business logic of your domain on top of
  194. Oscar. The fun part.