We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Long serv response
Every page responses with timeout of ~3s.
Sometimes category and product pages return 502 error.

Checked this pages: Main, Category, Product



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `shopelectro/models.py`
Content:
```
1 import random
2 import string
3 import typing
4 from uuid import uuid4
5 
6 from django.conf import settings
7 from django.db import models
8 from django.urls import reverse
9 from django.utils.translation import ugettext_lazy as _
10 
11 from catalog import models as catalog_models
12 from ecommerce import models as ecommerce_models
13 from pages import models as pages_models
14 
15 
16 def randomize_slug(slug: str) -> str:
17     slug_hash = ''.join(
18         random.choices(string.ascii_lowercase, k=settings.SLUG_HASH_SIZE)
19     )
20     return f'{slug}_{slug_hash}'
21 
22 
23 class SECategoryQuerySet(catalog_models.CategoryQuerySet):
24     def get_categories_tree_with_pictures(self) -> 'SECategoryQuerySet':
25         categories_with_pictures = (
26             self
27             .filter(products__page__images__isnull=False)
28             .distinct()
29         )
30 
31         return categories_with_pictures.get_ancestors(include_self=True)
32 
33 
34 class SECategoryManager(
35     catalog_models.CategoryManager.from_queryset(SECategoryQuerySet)
36 ):
37     pass
38 
39 
40 class Category(catalog_models.AbstractCategory, pages_models.SyncPageMixin):
41 
42     objects = SECategoryManager()
43     # pages.models.Page.objects_ field. It has the same problem.
44     objects_ = SECategoryManager()
45     uuid = models.UUIDField(default=uuid4, editable=False)
46 
47     @classmethod
48     def get_default_parent(cls):
49         return pages_models.CustomPage.objects.filter(slug='catalog').first()
50 
51     @property
52     def image(self):
53         products = self.products.all()
54         return products[0].image if products else None
55 
56     def get_absolute_url(self):
57         return reverse('category', args=(self.page.slug,))
58 
59 
60 class Product(catalog_models.AbstractProduct, pages_models.SyncPageMixin):
61 
62     # That's why we are needed to explicitly add objects manager here
63     # because of Django special managers behaviour.
64     # Se se#480 for details.
65     objects = catalog_models.ProductManager()
66 
67     category = models.ForeignKey(
68         Category,
69         on_delete=models.CASCADE,
70         null=True,
71         related_name='products',
72         verbose_name=_('category'),
73     )
74 
75     tags = models.ManyToManyField(
76         'Tag',
77         related_name='products',
78         blank=True,
79         verbose_name=_('tags'),
80     )
81 
82     vendor_code = models.SmallIntegerField(verbose_name=_('vendor_code'))
83     uuid = models.UUIDField(default=uuid4, editable=False)
84     purchase_price = models.FloatField(
85         default=0, verbose_name=_('purchase_price'))
86     wholesale_small = models.FloatField(
87         default=0, verbose_name=_('wholesale_small'))
88     wholesale_medium = models.FloatField(
89         default=0, verbose_name=_('wholesale_medium'))
90     wholesale_large = models.FloatField(
91         default=0, verbose_name=_('wholesale_large'))
92 
93     def get_absolute_url(self):
94         return reverse('product', args=(self.vendor_code,))
95 
96     @property
97     def average_rate(self):
98         """Return rounded to first decimal averaged rating."""
99         rating = self.product_feedbacks.aggregate(
100             avg=models.Avg('rating')).get('avg', 0)
101         return round(rating, 1)
102 
103     @property
104     def feedback_count(self):
105         return self.product_feedbacks.count()
106 
107     @property
108     def feedback(self):
109         return self.product_feedbacks.all().order_by('-date')
110 
111     def get_params(self):
112         return Tag.objects.filter_by_products([self]).get_group_tags_pairs()
113 
114     def get_brand_name(self) -> str:
115         brand: typing.Optional['Tag'] = Tag.objects.get_brands([self]).get(self)
116         return brand.name if brand else ''
117 
118 
119 class ProductFeedback(models.Model):
120     product = models.ForeignKey(
121         Product, on_delete=models.CASCADE, null=True,
122         related_name='product_feedbacks'
123     )
124 
125     date = models.DateTimeField(
126         auto_now=True, db_index=True, verbose_name=_('date'))
127     name = models.CharField(
128         max_length=255, db_index=True, verbose_name=_('name'))
129     rating = models.PositiveSmallIntegerField(
130         default=1, db_index=True, verbose_name=_('rating'))
131     dignities = models.TextField(
132         default='', blank=True, verbose_name=_('dignities'))
133     limitations = models.TextField(
134         default='', blank=True, verbose_name=_('limitations'))
135     general = models.TextField(
136         default='', blank=True, verbose_name=_('limitations'))
137 
138 
139 def _default_payment():
140     """Default payment option is first element of first tuple in options."""
141     assert settings.PAYMENT_OPTIONS[0][0], 'No payment options!'
142     return settings.PAYMENT_OPTIONS[0][0]
143 
144 
145 class Order(ecommerce_models.Order):
146     address = models.TextField(blank=True, default='')
147     payment_type = models.CharField(
148         max_length=255,
149         choices=settings.PAYMENT_OPTIONS,
150         default=_default_payment()
151     )
152     comment = models.TextField(blank=True, default='')
153     # total price - total purchase price
154     revenue = models.FloatField(default=0, verbose_name=_('revenue'))
155 
156     @property
157     def payment_type_name(self):
158         """Return name for an order's payment option."""
159         return next(
160             name for option, name in settings.PAYMENT_OPTIONS
161             if self.payment_type == option
162         )
163 
164     def set_positions(self, cart):
165         """
166         Save cart's state into Order instance.
167 
168         @todo #589:60m Create Cart model.
169          See details here: https://github.com/fidals/shopelectro/pull/590#discussion_r222544672
170         """
171         self.revenue = cart.total_revenue()
172         self.save()
173         for id_, position in cart:
174             self.positions.create(
175                 order=self,
176                 product_id=id_,
177                 vendor_code=position['vendor_code'],
178                 name=position['name'],
179                 price=position['price'],
180                 quantity=position['quantity'],
181             )
182         return self
183 
184 
185 class CategoryPage(pages_models.ModelPage):
186     """Create proxy model for Admin."""
187 
188     class Meta(pages_models.ModelPage.Meta):  # Ignore PycodestyleBear (E303)
189         proxy = True
190 
191     # noinspection PyTypeChecker
192     objects = pages_models.ModelPage.create_model_page_managers(Category)
193 
194 
195 class ProductPage(pages_models.ModelPage):
196     """Create proxy model for Admin."""
197 
198     class Meta(pages_models.ModelPage.Meta):  # Ignore PycodestyleBear (E303)
199         proxy = True
200 
201     # noinspection PyTypeChecker
202     objects = (
203         pages_models.ModelPage
204         .create_model_page_managers(Product)
205     )
206 
207 
208 class TagGroup(catalog_models.TagGroup):
209     pass
210 
211 
212 class TagQuerySet(catalog_models.TagQuerySet):
213     pass
214 
215 
216 class Tag(catalog_models.Tag):
217     group = models.ForeignKey(
218         TagGroup, on_delete=models.CASCADE, null=True, related_name='tags',
219     )
220 
221 
222 class ExcludedModelTPageQuerySet(pages_models.PageQuerySet):
223     def exclude_type(self):
224         return self.exclude(type=pages_models.Page.MODEL_TYPE)
225 
226 # @todo #rf169:30m Fix model.Manager bad inheritance
227 #  Now we have this problem:
228 #  ```
229 #  In [2]: type(ExcludedModelTPage.objects.all())
230 #  Out[2]: mptt.querysets.TreeQuerySet
231 #  ```
232 #  But should be `pages.models.PageQuerySet`.
233 #  Or just rm all excluded staff
234 #  in favor on direct excluded filter using.
235 class ExcludedModelTPageManager(
236     models.Manager.from_queryset(ExcludedModelTPageQuerySet)
237 ):
238 
239     def get_queryset(self):
240         return super().get_queryset().exclude(type=pages_models.Page.MODEL_TYPE)
241 
242 
243 class ExcludedModelTPage(pages_models.Page):
244 
245     class Meta(pages_models.Page.Meta):  # Ignore PycodestyleBear (E303)
246         proxy = True
247 
248     objects = ExcludedModelTPageManager()
249     # pages.models.Page.objects_ field. It has the same problem.
250     objects_ = ExcludedModelTPageManager()
251
```

Path: `etc/gunicorn.py`
Content:
```
1 import multiprocessing
2 import os
3 
4 default_workers = multiprocessing.cpu_count() * 2 + 1
5 workers = os.environ.get('WEB_CONCURRENCY', default_workers)
6 worker_class = 'sync'
7 max_requests = 300
8 max_requests_jitter = 300
9 errorlog = '-'
10
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/etc/gunicorn.py b/etc/gunicorn.py
--- a/etc/gunicorn.py
+++ b/etc/gunicorn.py
@@ -6,4 +6,5 @@
 worker_class = 'sync'
 max_requests = 300
 max_requests_jitter = 300
+timeout = 120
 errorlog = '-'
diff --git a/shopelectro/models.py b/shopelectro/models.py
--- a/shopelectro/models.py
+++ b/shopelectro/models.py
@@ -223,6 +223,7 @@
     def exclude_type(self):
         return self.exclude(type=pages_models.Page.MODEL_TYPE)
 
+
 # @todo #rf169:30m Fix model.Manager bad inheritance
 #  Now we have this problem:
 #  ```

{"golden_diff": "diff --git a/etc/gunicorn.py b/etc/gunicorn.py\n--- a/etc/gunicorn.py\n+++ b/etc/gunicorn.py\n@@ -6,4 +6,5 @@\n worker_class = 'sync'\n max_requests = 300\n max_requests_jitter = 300\n+timeout = 120\n errorlog = '-'\ndiff --git a/shopelectro/models.py b/shopelectro/models.py\n--- a/shopelectro/models.py\n+++ b/shopelectro/models.py\n@@ -223,6 +223,7 @@\n     def exclude_type(self):\n         return self.exclude(type=pages_models.Page.MODEL_TYPE)\n \n+\n # @todo #rf169:30m Fix model.Manager bad inheritance\n #  Now we have this problem:\n #  ```\n", "issue": "Long serv response\nEvery page responses with timeout of ~3s.\r\nSometimes category and product pages return 502 error.\r\n\r\nChecked this pages: Main, Category, Product\r\n\r\n\n", "before_files": [{"content": "import random\nimport string\nimport typing\nfrom uuid import uuid4\n\nfrom django.conf import settings\nfrom django.db import models\nfrom django.urls import reverse\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom catalog import models as catalog_models\nfrom ecommerce import models as ecommerce_models\nfrom pages import models as pages_models\n\n\ndef randomize_slug(slug: str) -> str:\n    slug_hash = ''.join(\n        random.choices(string.ascii_lowercase, k=settings.SLUG_HASH_SIZE)\n    )\n    return f'{slug}_{slug_hash}'\n\n\nclass SECategoryQuerySet(catalog_models.CategoryQuerySet):\n    def get_categories_tree_with_pictures(self) -> 'SECategoryQuerySet':\n        categories_with_pictures = (\n            self\n            .filter(products__page__images__isnull=False)\n            .distinct()\n        )\n\n        return categories_with_pictures.get_ancestors(include_self=True)\n\n\nclass SECategoryManager(\n    catalog_models.CategoryManager.from_queryset(SECategoryQuerySet)\n):\n    pass\n\n\nclass Category(catalog_models.AbstractCategory, pages_models.SyncPageMixin):\n\n    objects = SECategoryManager()\n    # pages.models.Page.objects_ field. It has the same problem.\n    objects_ = SECategoryManager()\n    uuid = models.UUIDField(default=uuid4, editable=False)\n\n    @classmethod\n    def get_default_parent(cls):\n        return pages_models.CustomPage.objects.filter(slug='catalog').first()\n\n    @property\n    def image(self):\n        products = self.products.all()\n        return products[0].image if products else None\n\n    def get_absolute_url(self):\n        return reverse('category', args=(self.page.slug,))\n\n\nclass Product(catalog_models.AbstractProduct, pages_models.SyncPageMixin):\n\n    # That's why we are needed to explicitly add objects manager here\n    # because of Django special managers behaviour.\n    # Se se#480 for details.\n    objects = catalog_models.ProductManager()\n\n    category = models.ForeignKey(\n        Category,\n        on_delete=models.CASCADE,\n        null=True,\n        related_name='products',\n        verbose_name=_('category'),\n    )\n\n    tags = models.ManyToManyField(\n        'Tag',\n        related_name='products',\n        blank=True,\n        verbose_name=_('tags'),\n    )\n\n    vendor_code = models.SmallIntegerField(verbose_name=_('vendor_code'))\n    uuid = models.UUIDField(default=uuid4, editable=False)\n    purchase_price = models.FloatField(\n        default=0, verbose_name=_('purchase_price'))\n    wholesale_small = models.FloatField(\n        default=0, verbose_name=_('wholesale_small'))\n    wholesale_medium = models.FloatField(\n        default=0, verbose_name=_('wholesale_medium'))\n    wholesale_large = models.FloatField(\n        default=0, verbose_name=_('wholesale_large'))\n\n    def get_absolute_url(self):\n        return reverse('product', args=(self.vendor_code,))\n\n    @property\n    def average_rate(self):\n        \"\"\"Return rounded to first decimal averaged rating.\"\"\"\n        rating = self.product_feedbacks.aggregate(\n            avg=models.Avg('rating')).get('avg', 0)\n        return round(rating, 1)\n\n    @property\n    def feedback_count(self):\n        return self.product_feedbacks.count()\n\n    @property\n    def feedback(self):\n        return self.product_feedbacks.all().order_by('-date')\n\n    def get_params(self):\n        return Tag.objects.filter_by_products([self]).get_group_tags_pairs()\n\n    def get_brand_name(self) -> str:\n        brand: typing.Optional['Tag'] = Tag.objects.get_brands([self]).get(self)\n        return brand.name if brand else ''\n\n\nclass ProductFeedback(models.Model):\n    product = models.ForeignKey(\n        Product, on_delete=models.CASCADE, null=True,\n        related_name='product_feedbacks'\n    )\n\n    date = models.DateTimeField(\n        auto_now=True, db_index=True, verbose_name=_('date'))\n    name = models.CharField(\n        max_length=255, db_index=True, verbose_name=_('name'))\n    rating = models.PositiveSmallIntegerField(\n        default=1, db_index=True, verbose_name=_('rating'))\n    dignities = models.TextField(\n        default='', blank=True, verbose_name=_('dignities'))\n    limitations = models.TextField(\n        default='', blank=True, verbose_name=_('limitations'))\n    general = models.TextField(\n        default='', blank=True, verbose_name=_('limitations'))\n\n\ndef _default_payment():\n    \"\"\"Default payment option is first element of first tuple in options.\"\"\"\n    assert settings.PAYMENT_OPTIONS[0][0], 'No payment options!'\n    return settings.PAYMENT_OPTIONS[0][0]\n\n\nclass Order(ecommerce_models.Order):\n    address = models.TextField(blank=True, default='')\n    payment_type = models.CharField(\n        max_length=255,\n        choices=settings.PAYMENT_OPTIONS,\n        default=_default_payment()\n    )\n    comment = models.TextField(blank=True, default='')\n    # total price - total purchase price\n    revenue = models.FloatField(default=0, verbose_name=_('revenue'))\n\n    @property\n    def payment_type_name(self):\n        \"\"\"Return name for an order's payment option.\"\"\"\n        return next(\n            name for option, name in settings.PAYMENT_OPTIONS\n            if self.payment_type == option\n        )\n\n    def set_positions(self, cart):\n        \"\"\"\n        Save cart's state into Order instance.\n\n        @todo #589:60m Create Cart model.\n         See details here: https://github.com/fidals/shopelectro/pull/590#discussion_r222544672\n        \"\"\"\n        self.revenue = cart.total_revenue()\n        self.save()\n        for id_, position in cart:\n            self.positions.create(\n                order=self,\n                product_id=id_,\n                vendor_code=position['vendor_code'],\n                name=position['name'],\n                price=position['price'],\n                quantity=position['quantity'],\n            )\n        return self\n\n\nclass CategoryPage(pages_models.ModelPage):\n    \"\"\"Create proxy model for Admin.\"\"\"\n\n    class Meta(pages_models.ModelPage.Meta):  # Ignore PycodestyleBear (E303)\n        proxy = True\n\n    # noinspection PyTypeChecker\n    objects = pages_models.ModelPage.create_model_page_managers(Category)\n\n\nclass ProductPage(pages_models.ModelPage):\n    \"\"\"Create proxy model for Admin.\"\"\"\n\n    class Meta(pages_models.ModelPage.Meta):  # Ignore PycodestyleBear (E303)\n        proxy = True\n\n    # noinspection PyTypeChecker\n    objects = (\n        pages_models.ModelPage\n        .create_model_page_managers(Product)\n    )\n\n\nclass TagGroup(catalog_models.TagGroup):\n    pass\n\n\nclass TagQuerySet(catalog_models.TagQuerySet):\n    pass\n\n\nclass Tag(catalog_models.Tag):\n    group = models.ForeignKey(\n        TagGroup, on_delete=models.CASCADE, null=True, related_name='tags',\n    )\n\n\nclass ExcludedModelTPageQuerySet(pages_models.PageQuerySet):\n    def exclude_type(self):\n        return self.exclude(type=pages_models.Page.MODEL_TYPE)\n\n# @todo #rf169:30m Fix model.Manager bad inheritance\n#  Now we have this problem:\n#  ```\n#  In [2]: type(ExcludedModelTPage.objects.all())\n#  Out[2]: mptt.querysets.TreeQuerySet\n#  ```\n#  But should be `pages.models.PageQuerySet`.\n#  Or just rm all excluded staff\n#  in favor on direct excluded filter using.\nclass ExcludedModelTPageManager(\n    models.Manager.from_queryset(ExcludedModelTPageQuerySet)\n):\n\n    def get_queryset(self):\n        return super().get_queryset().exclude(type=pages_models.Page.MODEL_TYPE)\n\n\nclass ExcludedModelTPage(pages_models.Page):\n\n    class Meta(pages_models.Page.Meta):  # Ignore PycodestyleBear (E303)\n        proxy = True\n\n    objects = ExcludedModelTPageManager()\n    # pages.models.Page.objects_ field. It has the same problem.\n    objects_ = ExcludedModelTPageManager()\n", "path": "shopelectro/models.py"}, {"content": "import multiprocessing\nimport os\n\ndefault_workers = multiprocessing.cpu_count() * 2 + 1\nworkers = os.environ.get('WEB_CONCURRENCY', default_workers)\nworker_class = 'sync'\nmax_requests = 300\nmax_requests_jitter = 300\nerrorlog = '-'\n", "path": "etc/gunicorn.py"}], "after_files": [{"content": "import random\nimport string\nimport typing\nfrom uuid import uuid4\n\nfrom django.conf import settings\nfrom django.db import models\nfrom django.urls import reverse\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom catalog import models as catalog_models\nfrom ecommerce import models as ecommerce_models\nfrom pages import models as pages_models\n\n\ndef randomize_slug(slug: str) -> str:\n    slug_hash = ''.join(\n        random.choices(string.ascii_lowercase, k=settings.SLUG_HASH_SIZE)\n    )\n    return f'{slug}_{slug_hash}'\n\n\nclass SECategoryQuerySet(catalog_models.CategoryQuerySet):\n    def get_categories_tree_with_pictures(self) -> 'SECategoryQuerySet':\n        categories_with_pictures = (\n            self\n            .filter(products__page__images__isnull=False)\n            .distinct()\n        )\n\n        return categories_with_pictures.get_ancestors(include_self=True)\n\n\nclass SECategoryManager(\n    catalog_models.CategoryManager.from_queryset(SECategoryQuerySet)\n):\n    pass\n\n\nclass Category(catalog_models.AbstractCategory, pages_models.SyncPageMixin):\n\n    objects = SECategoryManager()\n    # pages.models.Page.objects_ field. It has the same problem.\n    objects_ = SECategoryManager()\n    uuid = models.UUIDField(default=uuid4, editable=False)\n\n    @classmethod\n    def get_default_parent(cls):\n        return pages_models.CustomPage.objects.filter(slug='catalog').first()\n\n    @property\n    def image(self):\n        products = self.products.all()\n        return products[0].image if products else None\n\n    def get_absolute_url(self):\n        return reverse('category', args=(self.page.slug,))\n\n\nclass Product(catalog_models.AbstractProduct, pages_models.SyncPageMixin):\n\n    # That's why we are needed to explicitly add objects manager here\n    # because of Django special managers behaviour.\n    # Se se#480 for details.\n    objects = catalog_models.ProductManager()\n\n    category = models.ForeignKey(\n        Category,\n        on_delete=models.CASCADE,\n        null=True,\n        related_name='products',\n        verbose_name=_('category'),\n    )\n\n    tags = models.ManyToManyField(\n        'Tag',\n        related_name='products',\n        blank=True,\n        verbose_name=_('tags'),\n    )\n\n    vendor_code = models.SmallIntegerField(verbose_name=_('vendor_code'))\n    uuid = models.UUIDField(default=uuid4, editable=False)\n    purchase_price = models.FloatField(\n        default=0, verbose_name=_('purchase_price'))\n    wholesale_small = models.FloatField(\n        default=0, verbose_name=_('wholesale_small'))\n    wholesale_medium = models.FloatField(\n        default=0, verbose_name=_('wholesale_medium'))\n    wholesale_large = models.FloatField(\n        default=0, verbose_name=_('wholesale_large'))\n\n    def get_absolute_url(self):\n        return reverse('product', args=(self.vendor_code,))\n\n    @property\n    def average_rate(self):\n        \"\"\"Return rounded to first decimal averaged rating.\"\"\"\n        rating = self.product_feedbacks.aggregate(\n            avg=models.Avg('rating')).get('avg', 0)\n        return round(rating, 1)\n\n    @property\n    def feedback_count(self):\n        return self.product_feedbacks.count()\n\n    @property\n    def feedback(self):\n        return self.product_feedbacks.all().order_by('-date')\n\n    def get_params(self):\n        return Tag.objects.filter_by_products([self]).get_group_tags_pairs()\n\n    def get_brand_name(self) -> str:\n        brand: typing.Optional['Tag'] = Tag.objects.get_brands([self]).get(self)\n        return brand.name if brand else ''\n\n\nclass ProductFeedback(models.Model):\n    product = models.ForeignKey(\n        Product, on_delete=models.CASCADE, null=True,\n        related_name='product_feedbacks'\n    )\n\n    date = models.DateTimeField(\n        auto_now=True, db_index=True, verbose_name=_('date'))\n    name = models.CharField(\n        max_length=255, db_index=True, verbose_name=_('name'))\n    rating = models.PositiveSmallIntegerField(\n        default=1, db_index=True, verbose_name=_('rating'))\n    dignities = models.TextField(\n        default='', blank=True, verbose_name=_('dignities'))\n    limitations = models.TextField(\n        default='', blank=True, verbose_name=_('limitations'))\n    general = models.TextField(\n        default='', blank=True, verbose_name=_('limitations'))\n\n\ndef _default_payment():\n    \"\"\"Default payment option is first element of first tuple in options.\"\"\"\n    assert settings.PAYMENT_OPTIONS[0][0], 'No payment options!'\n    return settings.PAYMENT_OPTIONS[0][0]\n\n\nclass Order(ecommerce_models.Order):\n    address = models.TextField(blank=True, default='')\n    payment_type = models.CharField(\n        max_length=255,\n        choices=settings.PAYMENT_OPTIONS,\n        default=_default_payment()\n    )\n    comment = models.TextField(blank=True, default='')\n    # total price - total purchase price\n    revenue = models.FloatField(default=0, verbose_name=_('revenue'))\n\n    @property\n    def payment_type_name(self):\n        \"\"\"Return name for an order's payment option.\"\"\"\n        return next(\n            name for option, name in settings.PAYMENT_OPTIONS\n            if self.payment_type == option\n        )\n\n    def set_positions(self, cart):\n        \"\"\"\n        Save cart's state into Order instance.\n\n        @todo #589:60m Create Cart model.\n         See details here: https://github.com/fidals/shopelectro/pull/590#discussion_r222544672\n        \"\"\"\n        self.revenue = cart.total_revenue()\n        self.save()\n        for id_, position in cart:\n            self.positions.create(\n                order=self,\n                product_id=id_,\n                vendor_code=position['vendor_code'],\n                name=position['name'],\n                price=position['price'],\n                quantity=position['quantity'],\n            )\n        return self\n\n\nclass CategoryPage(pages_models.ModelPage):\n    \"\"\"Create proxy model for Admin.\"\"\"\n\n    class Meta(pages_models.ModelPage.Meta):  # Ignore PycodestyleBear (E303)\n        proxy = True\n\n    # noinspection PyTypeChecker\n    objects = pages_models.ModelPage.create_model_page_managers(Category)\n\n\nclass ProductPage(pages_models.ModelPage):\n    \"\"\"Create proxy model for Admin.\"\"\"\n\n    class Meta(pages_models.ModelPage.Meta):  # Ignore PycodestyleBear (E303)\n        proxy = True\n\n    # noinspection PyTypeChecker\n    objects = (\n        pages_models.ModelPage\n        .create_model_page_managers(Product)\n    )\n\n\nclass TagGroup(catalog_models.TagGroup):\n    pass\n\n\nclass TagQuerySet(catalog_models.TagQuerySet):\n    pass\n\n\nclass Tag(catalog_models.Tag):\n    group = models.ForeignKey(\n        TagGroup, on_delete=models.CASCADE, null=True, related_name='tags',\n    )\n\n\nclass ExcludedModelTPageQuerySet(pages_models.PageQuerySet):\n    def exclude_type(self):\n        return self.exclude(type=pages_models.Page.MODEL_TYPE)\n\n\n# @todo #rf169:30m Fix model.Manager bad inheritance\n#  Now we have this problem:\n#  ```\n#  In [2]: type(ExcludedModelTPage.objects.all())\n#  Out[2]: mptt.querysets.TreeQuerySet\n#  ```\n#  But should be `pages.models.PageQuerySet`.\n#  Or just rm all excluded staff\n#  in favor on direct excluded filter using.\nclass ExcludedModelTPageManager(\n    models.Manager.from_queryset(ExcludedModelTPageQuerySet)\n):\n\n    def get_queryset(self):\n        return super().get_queryset().exclude(type=pages_models.Page.MODEL_TYPE)\n\n\nclass ExcludedModelTPage(pages_models.Page):\n\n    class Meta(pages_models.Page.Meta):  # Ignore PycodestyleBear (E303)\n        proxy = True\n\n    objects = ExcludedModelTPageManager()\n    # pages.models.Page.objects_ field. It has the same problem.\n    objects_ = ExcludedModelTPageManager()\n", "path": "shopelectro/models.py"}, {"content": "import multiprocessing\nimport os\n\ndefault_workers = multiprocessing.cpu_count() * 2 + 1\nworkers = os.environ.get('WEB_CONCURRENCY', default_workers)\nworker_class = 'sync'\nmax_requests = 300\nmax_requests_jitter = 300\ntimeout = 120\nerrorlog = '-'\n", "path": "etc/gunicorn.py"}]}