Merge branch 'master' into diego
This commit is contained in:
@@ -85,7 +85,7 @@ TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [os.path.join(BASE_DIR, '../templates'),],
|
||||
# 'APP_DIRS': True,
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
@@ -93,12 +93,6 @@ TEMPLATES = [
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
'loaders': [
|
||||
(
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
[os.path.join(BASE_DIR, '../templates')],
|
||||
),
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
@@ -159,7 +153,7 @@ USE_TZ = True
|
||||
# https://docs.djangoproject.com/en/2.2/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = 'static'
|
||||
|
||||
TAXONOMY_FILE = 'shop-taxonomy.es-ES.txt'
|
||||
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ urlpatterns = [
|
||||
path('api/v1/my_company/', company_views.my_company, name='my-company'),
|
||||
path('api/v1/companies/sample/', company_views.random_company_sample , name='company-sample'),
|
||||
path('api/v1/purchase_email/', product_views.purchase_email, name='purchase-email'),
|
||||
path('api/v1/products/all_categories/', product_views.all_categories, name='all-categories'),
|
||||
path('api/v1/stats/me/', stat_views.track_user, name='user-tracker'),
|
||||
path('api/v1/autocomplete/category-tag/', product_views.CategoryTagAutocomplete.as_view(), name='category-autocomplete'),
|
||||
path('api/v1/', include(router.urls)),
|
||||
|
||||
@@ -18,6 +18,7 @@ from stats.models import StatsLog
|
||||
from companies.models import Company
|
||||
from companies.serializers import CompanySerializer
|
||||
from utils.tag_filters import CompanyTagFilter
|
||||
from rest_framework import filters
|
||||
from back_latienda.permissions import IsCreator, IsSiteAdmin
|
||||
|
||||
from utils import woocommerce
|
||||
@@ -28,6 +29,9 @@ class CompanyViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = CompanySerializer
|
||||
permission_classes = [IsAuthenticatedOrReadOnly, IsCreator]
|
||||
filterset_class = CompanyTagFilter
|
||||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = ['company_name__unaccent__icontains', 'short_name__unaccent__icontains']
|
||||
|
||||
|
||||
def perform_create(self, serializer):
|
||||
serializer.save(creator=self.request.user)
|
||||
|
||||
@@ -13,7 +13,7 @@ from rest_framework import status
|
||||
|
||||
from companies.factories import CompanyFactory
|
||||
from products.factories import ProductFactory, ActiveProductFactory
|
||||
from products.models import Product
|
||||
from products.models import Product, CategoryTag
|
||||
|
||||
from core.factories import CustomUserFactory
|
||||
from core.utils import get_tokens_for_user
|
||||
@@ -1258,3 +1258,37 @@ class PurchaseEmailTest(APITestCase):
|
||||
payload = response.json()
|
||||
self.assertTrue( 'email' in payload['error'])
|
||||
|
||||
|
||||
class AllCategoriesTest(APITestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""Tests setup
|
||||
"""
|
||||
self.endpoint = '/api/v1/products/all_categories/'
|
||||
# self.factory = ProductFactory
|
||||
self.model = CategoryTag
|
||||
# create user
|
||||
self.email = f"user@mail.com"
|
||||
self.password = ''.join(random.choices(string.ascii_uppercase, k = 10))
|
||||
self.user = CustomUserFactory(email=self.email, is_active=True)
|
||||
self.user.set_password(self.password)
|
||||
self.user.save()
|
||||
|
||||
def test_get_all_categories(self):
|
||||
# create instances
|
||||
instances = [
|
||||
self.model.objects.create(name='A'),
|
||||
self.model.objects.create(name='B'),
|
||||
self.model.objects.create(name='C'),
|
||||
self.model.objects.create(name='D'),
|
||||
self.model.objects.create(name='E'),
|
||||
]
|
||||
|
||||
response = self.client.get(self.endpoint)
|
||||
|
||||
# assertions
|
||||
self.assertEquals(response.status_code, 200)
|
||||
|
||||
payload = response.json()
|
||||
|
||||
self.assertEquals(len(instances), len(payload))
|
||||
|
||||
@@ -307,7 +307,7 @@ def purchase_email(request):
|
||||
email.send()
|
||||
logging.info(f"Email sent to {company}")
|
||||
# send confirmation email to user
|
||||
user_message = render_to_string('purchase_contact_confirmation.html', {
|
||||
user_message = render_to_string('purchase_contact_confirmation_v2.html', {
|
||||
'company': company,
|
||||
'product': product,
|
||||
'company_message': company_message,
|
||||
@@ -333,3 +333,13 @@ def purchase_email(request):
|
||||
|
||||
# response
|
||||
return Response()
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@permission_classes([AllowAny,])
|
||||
def all_categories(request):
|
||||
all_categories = []
|
||||
for instance in CategoryTag.objects.all():
|
||||
all_categories.append(instance.label)
|
||||
return Response(data=all_categories)
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user