Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

getting_started.rst 6.8KB

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