Added content page method
This commit is contained in:
parent
b12253fb6b
commit
6a1fea76b6
27
apps/main/migrations/0050_contentpage.py
Normal file
27
apps/main/migrations/0050_contentpage.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# Generated by Django 2.2.7 on 2020-01-22 12:41
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0049_remove_navigationbarpermission_section'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ContentPage',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created', models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Date created')),
|
||||
('modified', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||
('content', models.TextField(verbose_name='content')),
|
||||
('slug', models.SlugField(max_length=255, null=True, unique=True, verbose_name='slug')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
27
apps/main/migrations/0051_auto_20200122_1256.py
Normal file
27
apps/main/migrations/0051_auto_20200122_1256.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# Generated by Django 2.2.7 on 2020-01-22 12:56
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0050_contentpage'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='contentpage',
|
||||
options={'verbose_name': 'content page', 'verbose_name_plural': 'content page'},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='contentpage',
|
||||
name='name',
|
||||
field=models.CharField(default='', max_length=255, verbose_name='name'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='contentpage',
|
||||
name='content',
|
||||
field=models.TextField(default='', verbose_name='content'),
|
||||
),
|
||||
]
|
||||
|
|
@ -20,8 +20,10 @@ from review.models import Review
|
|||
from tag.models import Tag
|
||||
from utils.exceptions import UnprocessableEntityError
|
||||
from utils.methods import dictfetchall
|
||||
from utils.models import (ProjectBaseMixin, TJSONField, URLImageMixin,
|
||||
TranslatedFieldsMixin, PlatformMixin)
|
||||
from utils.models import (
|
||||
ProjectBaseMixin, TJSONField, URLImageMixin,
|
||||
TranslatedFieldsMixin, PlatformMixin,
|
||||
)
|
||||
|
||||
|
||||
class Currency(TranslatedFieldsMixin, models.Model):
|
||||
|
|
@ -156,10 +158,10 @@ class SiteFeature(ProjectBaseMixin):
|
|||
published = models.BooleanField(default=False, verbose_name=_('Published'))
|
||||
main = models.BooleanField(default=False,
|
||||
help_text='shows on main page',
|
||||
verbose_name=_('Main'),)
|
||||
verbose_name=_('Main'), )
|
||||
backoffice = models.BooleanField(default=False,
|
||||
help_text='shows on backoffice page',
|
||||
verbose_name=_('backoffice'),)
|
||||
verbose_name=_('backoffice'), )
|
||||
nested = models.ManyToManyField('self', blank=True, symmetrical=False)
|
||||
old_id = models.IntegerField(null=True, blank=True)
|
||||
|
||||
|
|
@ -402,6 +404,24 @@ class Footer(ProjectBaseMixin):
|
|||
links = models.ManyToManyField(FooterLink, verbose_name=_('links'), related_name='link_footer')
|
||||
|
||||
|
||||
class ContentPageQuerySet(models.QuerySet):
|
||||
"""QuerySet for model ContentPage."""
|
||||
|
||||
|
||||
class ContentPage(ProjectBaseMixin):
|
||||
name = models.CharField(_('name'), max_length=255, default='')
|
||||
content = models.TextField(_('content'), default='')
|
||||
slug = models.SlugField(max_length=255, unique=True, null=True,
|
||||
verbose_name=_('slug'))
|
||||
|
||||
objects = ContentPageQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
verbose_name = _('content page')
|
||||
verbose_name_plural = _('content page')
|
||||
|
||||
|
||||
class PanelQuerySet(models.QuerySet):
|
||||
"""Panels QuerySet."""
|
||||
|
||||
|
|
@ -458,7 +478,7 @@ class Panel(ProjectBaseMixin):
|
|||
}
|
||||
with connections['default'].cursor() as cursor:
|
||||
count = self._raw_count(raw)
|
||||
start = page*page_size
|
||||
start = page * page_size
|
||||
cursor.execute(*self.set_limits(start, page_size))
|
||||
data["count"] = count
|
||||
data["next"] = self.get_next_page(count, page, page_size)
|
||||
|
|
@ -468,7 +488,7 @@ class Panel(ProjectBaseMixin):
|
|||
return data
|
||||
|
||||
def get_next_page(self, count, page, page_size):
|
||||
max_page = count/page_size-1
|
||||
max_page = count / page_size - 1
|
||||
if not 0 <= page <= max_page:
|
||||
raise exceptions.NotFound('Invalid page.')
|
||||
if max_page > page:
|
||||
|
|
|
|||
|
|
@ -345,3 +345,21 @@ class NavigationBarPermissionBaseSerializer(serializers.ModelSerializer):
|
|||
'sections',
|
||||
'permission_mode_display',
|
||||
]
|
||||
|
||||
|
||||
class ContentPageSerializer(serializers.ModelSerializer):
|
||||
"""Content page serializer"""
|
||||
|
||||
name = serializers.CharField()
|
||||
content = serializers.CharField()
|
||||
slug = serializers.CharField()
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
model = models.ContentPage
|
||||
fields = [
|
||||
'id',
|
||||
'name',
|
||||
'content',
|
||||
'slug'
|
||||
]
|
||||
|
|
|
|||
|
|
@ -9,4 +9,5 @@ common_urlpatterns = [
|
|||
path('awards/<int:pk>/', AwardRetrieveView.as_view(), name='awards_retrieve'),
|
||||
path('carousel/', CarouselListView.as_view(), name='carousel-list'),
|
||||
path('determine-location/', DetermineLocation.as_view(), name='determine-location'),
|
||||
path('content-pages/', ContentPage.as_view(), name='content-pages')
|
||||
]
|
||||
|
|
|
|||
|
|
@ -95,3 +95,11 @@ class DetermineLocation(generics.GenericAPIView):
|
|||
'country_code': country_code,
|
||||
})
|
||||
raise Http404
|
||||
|
||||
|
||||
class ContentPage(generics.ListCreateAPIView):
|
||||
"""Method to get content pages"""
|
||||
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
serializer_class = serializers.ContentPageSerializer
|
||||
queryset = models.ContentPage.objects.all()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user