feature/fix_generate_pass
Andrey 8 years ago
parent 57a5f35e73
commit 83e5e3ad0e
  1. 12
      access/models/other.py
  2. 45
      access/views.py

@ -3,7 +3,7 @@ from django.db import models
from courses.models import Course, Vertex
from maps.models import CourseRoute
from django.db.models import Q
class Invite(models.Model):
owner = models.OneToOneField(to=settings.AUTH_USER_MODEL, null=True)
@ -50,6 +50,16 @@ class Progress(models.Model):
self.course.title,
)
def add_vertex(self, vertex):
self.progress_list.add(vertex)
parent = vertex.vertex_set.first() if vertex.vertex_set.all().exists() else None
if parent:
children_ids = self.progress_list.values_list('id', flat=True)
_flt = ~Q(id__in=children_ids)
parent.children.filter(_flt)
def get_template(self):
return self.template if self.template else self.course.route

@ -187,51 +187,12 @@ class UpdateProgress(APIView):
if vertex.content_type.model == 'task':
return res_403
try:
next_vertex = vertex.get_next(['task', 'tutorial'])
except ValueError:
next_vertex = None
try:
progress = Progress.objects.get(user=request.user, course=vertex.course, active_obj=vertex)
progress.active_obj = next_vertex
if not next_vertex:
progress.success = True
if next_vertex.content_type.model == 'task':
"""
создание тредов для приёма домашки
"""
teacher_thread = Thread.objects.get(
key="""user_%s""" % vertex.course.get_teacher().id,
)
user_thread = Thread.objects.get(
key="""user_%s""" % request.user.id,
)
support_thread = Thread.objects.get(
key="suports",
)
child_thread = Thread.objects.create(
key="""user_%s__vertex_%s""" % (request.user.id, vertex.id,),
text="""Домашняя работа по курсу %s и теме %s для студента %s""" %
(vertex.course.title, vertex.vertex_set.all()[0].title, request.user.get_full_name()),
)
child_thread.subscribers.add(request.user)
child_thread.parent.add(teacher_thread)
child_thread.parent.add(support_thread)
child_thread.parent.add(user_thread)
progress.save()
return Response({'id': progress.active_obj.id, 'type': progress.active_obj.content_type.model}, status=200)
progress.add_vertex(vertex)
return Response(status=204)
except Progress.DoesNotExist:
pass
return Response({'id': next_vertex.id, 'type': next_vertex.content_type.model}, status=200)
return res_403
class UserGuardView(APIView):

Loading…
Cancel
Save