Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

getting_started.rst 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. ======================
  2. 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
  8. :doc:`Sandbox site <sandbox>` in case you have trouble with
  9. the below instructions.
  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. $ mkvirtualenv oscar
  16. $ pip install django-oscar
  17. $ django-admin.py startproject frobshop
  18. This will create a folder ``frobshop`` for your project. It is highly
  19. recommended to install Oscar in a virtualenv.
  20. .. attention::
  21. Please ensure that ``pillow``, a fork of the the Python Imaging Library
  22. (PIL), gets installed with JPEG support. Supported formats are printed
  23. when ``pillow`` is first installed.
  24. Instructions_ on how to get JPEG support are highly platform specific,
  25. but guides for ``PIL`` should work for ``pillow`` as well. Generally
  26. speaking, you need to ensure that ``libjpeg-dev`` is installed and found
  27. during installation.
  28. .. _Instructions: http://www.google.com/search?q=install+pil+with+jpeg+support
  29. Settings
  30. --------
  31. Now edit your settings file ``frobshop.frobshop.settings.py`` to specify a
  32. database (we use SQLite for simplicity):
  33. .. code-block:: django
  34. DATABASES = {
  35. 'default': {
  36. 'ENGINE': 'django.db.backends.sqlite3',
  37. 'NAME': 'db.sqlite3',
  38. 'USER': '',
  39. 'PASSWORD': '',
  40. 'HOST': '',
  41. 'PORT': '',
  42. }
  43. }
  44. Then, add ``oscar.apps.basket.middleware.BasketMiddleware`` to
  45. ``MIDDLEWARE_CLASSES``. It is also recommended to use
  46. ``django.middleware.transaction.TransactionMiddleware`` too
  47. Now set ``TEMPLATE_CONTEXT_PROCESSORS`` to:
  48. .. code-block:: django
  49. TEMPLATE_CONTEXT_PROCESSORS = (
  50. "django.contrib.auth.context_processors.auth",
  51. "django.core.context_processors.request",
  52. "django.core.context_processors.debug",
  53. "django.core.context_processors.i18n",
  54. "django.core.context_processors.media",
  55. "django.core.context_processors.static",
  56. "django.contrib.messages.context_processors.messages",
  57. 'oscar.apps.search.context_processors.search_form',
  58. 'oscar.apps.promotions.context_processors.promotions',
  59. 'oscar.apps.checkout.context_processors.checkout',
  60. 'oscar.apps.customer.notifications.context_processors.notifications',
  61. 'oscar.core.context_processors.metadata',
  62. )
  63. Next, modify ``INSTALLED_APPS`` to be a list, add ``South`` and ``compressor``
  64. and append Oscar's core apps:
  65. .. code-block:: django
  66. from oscar import get_core_apps
  67. INSTALLED_APPS = [
  68. 'django.contrib.auth',
  69. 'django.contrib.contenttypes',
  70. 'django.contrib.sessions',
  71. 'django.contrib.sites',
  72. 'django.contrib.messages',
  73. 'django.contrib.flatpages',
  74. ...
  75. 'south',
  76. 'compressor',
  77. ] + get_core_apps()
  78. Note that Oscar requires ``django.contrib.messages`` and
  79. ``django.contrib.flatpages`` which aren't included by default.
  80. Next, add ``django.contrib.flatpages.middleware.FlatpageFallbackMiddleware`` to
  81. your ``MIDDLEWARE_CLASSES`` setting:
  82. .. code-block:: django
  83. MIDDLEWARE_CLASSES = (
  84. ...
  85. 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
  86. )
  87. More info about `django-flatpages installation`_ at the django-project website.
  88. .. _`django-flatpages installation`: https://docs.djangoproject.com/en/dev/ref/contrib/flatpages/#installation
  89. .. tip::
  90. Oscar's default templates use django-compressor_ but it's optional really.
  91. You may decide to use your own templates that don't use compressor. Hence
  92. why it is not one of the 'core apps'.
  93. .. _django-compressor: https://github.com/jezdez/django_compressor
  94. Now set your auth backends to:
  95. .. code-block:: django
  96. AUTHENTICATION_BACKENDS = (
  97. 'oscar.apps.customer.auth_backends.Emailbackend',
  98. 'django.contrib.auth.backends.ModelBackend',
  99. )
  100. to allow customers to sign in using an email address rather than a username.
  101. Set ``MEDIA_ROOT`` and ``MEDIA_URL`` to your environment, and make sure the
  102. path in ``MEDIA_ROOT`` exists. An example from the Sandbox site:
  103. .. code-block:: django
  104. PROJECT_DIR = os.path.dirname(__file__)
  105. location = lambda x: os.path.join(
  106. os.path.dirname(os.path.realpath(__file__)), x)
  107. MEDIA_ROOT = location("public/media")
  108. MEDIA_URL = '/media/'
  109. Verify your ``staticfiles`` settings and ensure that files in ``MEDIA_ROOT``
  110. get served:
  111. * `staticfiles in Django 1.3 and 1.4 <https://docs.djangoproject.com/en/1.3/howto/static-files/#serving-other-directories>`_
  112. * `staticfiles in Django 1.5 <https://docs.djangoproject.com/en/1.5/howto/static-files/#serving-files-uploaded-by-a-user>`_
  113. Modify your ``TEMPLATE_DIRS`` to include the main Oscar template directory:
  114. .. code-block:: django
  115. from oscar import OSCAR_MAIN_TEMPLATE_DIR
  116. TEMPLATE_DIRS = TEMPLATE_DIRS + (OSCAR_MAIN_TEMPLATE_DIR,)
  117. Oscar currently uses Haystack for search so you need to specify:
  118. .. code-block:: django
  119. HAYSTACK_CONNECTIONS = {
  120. 'default': {
  121. 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
  122. },
  123. }
  124. When moving towards production, you'll obviously need to switch to a real search
  125. backend.
  126. The last addition to the settings file is to import all of Oscar's default settings:
  127. .. code-block:: django
  128. from oscar.defaults import *
  129. URLs
  130. ----
  131. Alter your ``frobshop/urls.py`` to include Oscar's URLs:
  132. .. code-block:: django
  133. from django.conf.urls import patterns, include, url
  134. from oscar.app import application
  135. urlpatterns = patterns('',
  136. (r'', include(application.urls))
  137. )
  138. Database
  139. --------
  140. Then create the database and the shop should be browsable:
  141. .. code-block:: bash
  142. $ python manage.py syncdb --noinput
  143. $ python manage.py migrate
  144. $ python manage.py runserver
  145. You should now have a running Oscar install that you can browse.
  146. Creating product classes and fulfillment partners
  147. -------------------------------------------------
  148. Every Oscar deployment needs at least one
  149. :class:`product class <oscar.apps.catalogue.abstract_models.AbstractProductClass>`
  150. and one
  151. :class:`fulfillment partner <oscar.apps.partner.abstract_models.AbstractPartner>`.
  152. These aren't created automatically as they're highly specific to the shop you
  153. want to build.
  154. The quickest way to set them up is to log into the Django admin
  155. interface at http://127.0.0.1:8000/admin/ and create instances of both there.
  156. For a deployment setup, we recommend creating them as `data migration`_.
  157. .. _data migration: http://codeinthehole.com/writing/prefer-data-migrations-to-initial-data/
  158. Defining the order pipeline
  159. ---------------------------
  160. The order management in Oscar relies on the order pipeline that
  161. defines all the statuses an order can have and the possible transitions
  162. for any given status. Statuses in Oscar are not just used for an order
  163. but are handled on the line level as well to be able to handle partial
  164. shipping of an order.
  165. The order status pipeline is different for every shop which means that
  166. changing it is fairly straightforward in Oscar. The pipeline is defined in
  167. your ``settings.py`` file using the ``OSCAR_ORDER_STATUS_PIPELINE`` setting.
  168. You also need to specify the initial status for an order and a line item in
  169. ``OSCAR_INITIAL_ORDER_STATUS`` and ``OSCAR_INITIAL_LINE_STATUS``
  170. respectively.
  171. To give you an idea of what an order pipeline might look like take a look
  172. at the Oscar sandbox settings:
  173. .. code-block:: django
  174. OSCAR_INITIAL_ORDER_STATUS = 'Pending'
  175. OSCAR_INITIAL_LINE_STATUS = 'Pending'
  176. OSCAR_ORDER_STATUS_PIPELINE = {
  177. 'Pending': ('Being processed', 'Cancelled',),
  178. 'Being processed': ('Processed', 'Cancelled',),
  179. 'Cancelled': (),
  180. }
  181. Defining the order status pipeline is simply a dictionary of where each
  182. status is given as a key. Possible transitions into other statuses can be
  183. specified as an iterable of status names. An empty iterable defines an
  184. end point in the pipeline.
  185. With these three settings defined in your project you'll be able to see
  186. the different statuses in the order management dashboard.
  187. Next steps
  188. ==========
  189. The next step is to implement the business logic of your domain on top of
  190. Oscar. The fun part.