Commit b1b40e55 authored by Eduardo Nunes's avatar Eduardo Nunes
Browse files

Merge branch 'develop' of git.hacklab.com.br:hackmooc/django-courses into develop

parents 0dc09acb f943f463
......@@ -28,7 +28,12 @@ def get_upload_path(instance, filename):
class File(models.Model):
# title = models.CharField(_('Title'), max_length=255)
title = models.CharField(
_('Title'),
max_length=255,
blank=True,
null=True
)
file = models.FileField(
upload_to=get_upload_path,
)
......@@ -37,3 +42,6 @@ class File(models.Model):
related_name='files',
verbose_name=_('Files'),
)
class Meta:
ordering = ['-pk']
......@@ -11,7 +11,7 @@ class CourseMaterialViewSet(viewsets.ModelViewSet):
serializer_class = CourseMaterialSerializer
permission_classes = (IsAuthenticated,)
lookup_field = 'course'
filter_fields = ('course__id',)
filter_fields = ('course__id', 'course__slug')
def pre_save(self, obj):
# Get Question vote usign kwarg as questionId
......@@ -20,8 +20,13 @@ class CourseMaterialViewSet(viewsets.ModelViewSet):
self.kwargs['course'] = obj.course
return super(CourseMaterialViewSet, self).pre_save(obj)
def perform_update(self, serializer):
instance = CourseMaterial.objects.get(id=self.request.data['id'])
instance.text = self.request.data['text']
instance.save()
class CourseMaterialFileViewSet(mixins.DestroyModelMixin, viewsets.GenericViewSet):
class CourseMaterialFileViewSet(viewsets.ModelViewSet):
model = CourseMaterialFile
queryset = CourseMaterialFile.objects.all()
serializer_class = FilesSerializer
......
# Generated by Django 2.2.20 on 2021-04-16 20:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('courses', '0023_auto_20210412_1852'),
]
operations = [
migrations.AddField(
model_name='coursematerial',
name='text_en',
field=models.TextField(null=True, verbose_name='Question'),
),
migrations.AddField(
model_name='coursematerial',
name='text_es',
field=models.TextField(null=True, verbose_name='Question'),
),
migrations.AddField(
model_name='coursematerial',
name='text_pt_br',
field=models.TextField(null=True, verbose_name='Question'),
),
migrations.AddField(
model_name='file',
name='title',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Title'),
),
migrations.AddField(
model_name='file',
name='title_en',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Title'),
),
migrations.AddField(
model_name='file',
name='title_es',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Title'),
),
migrations.AddField(
model_name='file',
name='title_pt_br',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Title'),
),
]
# Generated by Django 2.2.20 on 2021-04-21 04:06
import courses.course_material.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('courses', '0024_auto_20210416_1715'),
]
operations = [
migrations.AddField(
model_name='file',
name='file_en',
field=models.FileField(null=True, upload_to=courses.course_material.models.get_upload_path),
),
migrations.AddField(
model_name='file',
name='file_es',
field=models.FileField(null=True, upload_to=courses.course_material.models.get_upload_path),
),
migrations.AddField(
model_name='file',
name='file_pt_br',
field=models.FileField(null=True, upload_to=courses.course_material.models.get_upload_path),
),
]
# Generated by Django 2.2.20 on 2021-05-04 18:04
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('courses', '0025_auto_20210421_0106'),
]
operations = [
migrations.AlterModelOptions(
name='file',
options={'ordering': ['-pk']},
),
]
......@@ -766,7 +766,7 @@ class ProfessorMessage(models.Model):
)
def __str__(self):
return self.professor.name + " - " + self.subject + " - " + str(self.date)
return self.subject + " - " + str(self.date)
def send(self):
# bcc = list with all destinataries
......
from modeltranslation.translator import register, TranslationOptions
from .models import Course, Lesson, Unit, ProfessorMessage
from .course_material.models import CourseMaterial, File
@register(Course)
......@@ -19,6 +20,17 @@ class LessonTranslationOptions(TranslationOptions):
class UnitTranslationOptions(TranslationOptions):
fields = ('title', 'video', 'side_notes', 'chat_room')
@register(ProfessorMessage)
class ProfessorMessageTranslationOptions(TranslationOptions):
fields = ('subject','message')
\ No newline at end of file
fields = ('subject','message')
@register(CourseMaterial)
class CourseMaterialTranslationOptions(TranslationOptions):
fields = ('text',)
@register(File)
class FileTranslationOptions(TranslationOptions):
fields = ('title', 'file')
......@@ -68,7 +68,9 @@ class CourseViewSet(viewsets.ModelViewSet):
# Q(is_public=True, ) | Q(groups__in=self.request.user.groups.all(), status='published')
# )
#)
query = Q(status='published')
from django.utils.translation import get_language
current_language = get_language()
query = Q(status='published', lang__contains=[current_language])
if (CourseProfessor.objects.filter(user=self.request.user, role='coordinator').exists()):
query.add(Q(
......@@ -142,7 +144,8 @@ class ProfessorMessageViewSet(viewsets.ModelViewSet):
queryset = ProfessorMessage.objects.all()
filter_fields = ('course', 'classrooms')
serializer_class = ProfessorMessageSerializer
permission_classes = (IsAssistantOrCoordinatorOrAdminOrRecipient,)
# permission_classes = (IsAssistantOrCoordinatorOrAdminOrRecipient)
permission_classes = (IsAdminOrReadOnly, )
def perform_create(self, serializer):
classes = serializer.context['request'].data.get('classes', None)
......@@ -172,17 +175,18 @@ class ProfessorMessageViewSet(viewsets.ModelViewSet):
def get_queryset(self):
queryset = super().get_queryset()
all_messages = self.request.query_params.get('all_messages', None)
if all_messages:
queryset = queryset.order_by('-id').distinct()
# all_messages = self.request.query_params.get('all_messages', None)
# if all_messages:
# queryset = queryset.order_by('-id').distinct()
else:
query = Q(
Q(users=self.request.user)
| Q(groups__in=self.request.user.groups.all())
| Q(professor=self.request.user)
)
queryset = queryset.filter(query).order_by('-id').distinct()
# else:
# query = Q(
# Q(users=self.request.user)
# | Q(groups__in=self.request.user.groups.all())
# | Q(professor=self.request.user)
# )
# queryset = queryset.filter(query).order_by('-id').distinct()
queryset = queryset.order_by('-id').distinct()
classroom = self.request.query_params.get('classroom', None)
if classroom:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment