diff --git a/apps/course/models.py b/apps/course/models.py index 72cfad97..d4966b3c 100644 --- a/apps/course/models.py +++ b/apps/course/models.py @@ -1,4 +1,5 @@ import arrow +from random import shuffle from uuid import uuid4 from django.db import models from django.core.exceptions import ValidationError @@ -98,7 +99,7 @@ class Course(BaseModel, DeactivatedMixin): class Meta: verbose_name = 'Курс' verbose_name_plural = 'Курсы' - ordering = ['-created_at'] + ordering = ['-is_featured', ] def __str__(self): return str(self.id) + ' ' + self.title @@ -149,6 +150,24 @@ class Course(BaseModel, DeactivatedMixin): def count_videos_in_lessons(self): return Video.objects.filter(lesson__in=self.lessons.all()).count() + @classmethod + def shuffle(cls, qs, order_is_featured = True): + if order_is_featured: + featured = [] + other = [] + for c in list(qs): + if c.is_featured: + featured.append(c) + else: + other.append(c) + shuffle(featured) + shuffle(other) + return featured + other + else: + all = list(qs) + shuffle(all) + return all + class Category(models.Model): title = models.CharField('Название категории', max_length=100) diff --git a/apps/course/views.py b/apps/course/views.py index 3ecd6bd0..857a57d0 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -241,7 +241,6 @@ class CoursesView(ListView): def get(self, request, *args, **kwargs): self.object_list = self.get_queryset() - allow_empty = self.get_allow_empty() if request.is_ajax(): context = self.get_context_data() template_name = self.get_template_names() @@ -283,6 +282,7 @@ class CoursesView(ListView): context = super().get_context_data() filtered = CourseFilter(self.request.GET) context.update(filtered.data) + context['course_items'] = Course.shuffle(context.get('course_items')) return context def get_template_names(self): diff --git a/project/views.py b/project/views.py index c8400f14..57435b56 100644 --- a/project/views.py +++ b/project/views.py @@ -74,7 +74,7 @@ class IndexView(TemplateView): 'online': online, 'online_coming_soon': online_coming_soon, 'school_schedule': school_schedule, - 'course_items': Course.objects.filter(status=Course.PUBLISHED)[:6], + 'course_items': Course.shuffle(Course.objects.filter(status=Course.PUBLISHED)[:6]), 'is_purchased': school_payment_exists, 'min_school_price': SchoolSchedule.objects.aggregate(Min('month_price'))['month_price__min'], 'school_schedules': SchoolSchedule.objects.all(), diff --git a/web/src/components/CourseRedactor.vue b/web/src/components/CourseRedactor.vue index 28e10243..b3703785 100644 --- a/web/src/components/CourseRedactor.vue +++ b/web/src/components/CourseRedactor.vue @@ -992,28 +992,28 @@ }); } - // let user = api.getCurrentUser(this.accessToken); - // promises.push(user); - // - // user.then((response) => { - // if (response.data) { - // this.me = response.data; - // - // if(this.me.role == ROLE_ADMIN) { - // api.getUsers({role: [ROLE_AUTHOR,ROLE_ADMIN], page_size: 1000}, this.accessToken) - // .then((usersResponse) => { - // if (usersResponse.data) { - // this.users = usersResponse.data.results.map((user) => { - // return { - // title: `${user.first_name} ${user.last_name}`, - // value: user.id - // } - // }); - // } - // }); - // } - // } - // }); + let user = api.getCurrentUser(this.accessToken); + promises.push(user); + + user.then((response) => { + if (response.data) { + this.me = response.data; + + /* if(this.me.role == ROLE_ADMIN) { + api.getUser(this.me.id, {role: [ROLE_AUTHOR, ROLE_ADMIN], page_size: 1000}, this.accessToken) + .then((usersResponse) => { + if (usersResponse.data) { + this.users = usersResponse.data.results.map((user) => { + return { + title: `${user.first_name} ${user.last_name}`, + value: user.id + } + }); + } + }); + } */ + } + }); // if (this.courseId) { // this.loadCourse().then(()=>{this.updateViewSection(window.location, 'load')}).catch(()=>{