コード例 #1
0
ファイル: classes.py プロジェクト: rafaelnunes/goo-course
    def get(self, class_id):
    	cls = Class.get_by_id(int(class_id))
    	if not cls:
    		self.abort(404)

        upload_to = blobstore.create_upload_url('/addmaterial')
        return self.render('app/class_detail.html', cls=cls, upload_to=upload_to)
コード例 #2
0
ファイル: api.py プロジェクト: flavio342/nave_mae_backend
    def post(self):

        form = RegisterForm()

        if form.validate_on_submit():

            photo = upload_file(request.files['photo'])

            obj = Class(name=form.name.data, photo=photo)

            institution_obj = get_institution_by_id(form.institution_id.data)
            if institution_obj:

                institution_obj.classes.append(obj)

                db.session.add(obj)
                db.session.add(institution_obj)
                db.session.commit()

                return {'success': True}

            else:

                return {
                    'success': False,
                    "errors": {
                        "institution_id": ["Instituição não existe"]
                    }
                }

        else:

            return {'success': False, "errors": form.errors}
コード例 #3
0
ファイル: classes.py プロジェクト: rafaelnunes/goo-course
    def post(self):
        upload_files = self.get_uploads('mfile')
        title = self.request.get('mtitle')
        class_id = self.request.get('class_id')

        cls = Class.get_by_id(int(class_id))

        for afile in upload_files:
            cls.add_material(title, afile.key())

        return redirect('/class/' + str(cls.key.id()) + '#support-tab')
コード例 #4
0
    def upload_video(self):
        upload_files = self.get_uploads('video_upload')
        title = self.request.get('video_title')
        class_id = self.request.get('class_id')
        import pdb;pdb.set_trace()

        cls = Class.get_by_id(int(class_id))

        print 'Video Uploaded - ' + str(upload_files)

        return redirect('/class/' + str(cls.key.id()) + '#video-tab')
コード例 #5
0
ファイル: classes.py プロジェクト: rafaelnunes/goo-course
    def by_subject(self, subject_id):
    	subject = Subject.get_by_id(int(subject_id))

        if not subject:
            return self.abort(404)

    	alerts = []

    	if self.request.method == 'POST':
    		title = self.request.get('title')
    		desc = self.request.get('desc')

    		if not title:
    			alerts.append('Title field is required!')
    		else:
	    		clazz = Class(title=title, description=desc, subject=subject.key)
    			clazz.put()
    			return self.render('app/class_detail.html', cls=clazz)

    	classes = subject.get_classes()
    	return self.render('app/classes.html', classes=classes, alerts=alerts, subject=subject)
コード例 #6
0
ファイル: classes.py プロジェクト: rafaelnunes/goo-course
    def add_resource(self):
    	cls = Class.get_by_id(int(self.request.get('class_id')))

    	if not cls:
    		self.abort(404)

    	title = self.request.get('rtitle')
    	url = self.request.get('rurl')

    	cls.add_resource(title, url)

        deferred.defer(notify_followers_new_content, cls.subject, _queue='notify')

    	return redirect('/class/' + str(cls.key.id()) + '#additional-tab')
コード例 #7
0
    def generate(self) -> Schedule:
        classes = []

        for C in self.schedule_param.courses:
            assigned_instructors = self._get_assigned_Instructors_for(
                C, )

            for sec_i in range(C.num_of_sections):
                instructor, timeslot, room = self._get_unique_Instr_Timeslot_Room(
                    assigned_instructors, C, classes, )

                section = Section(C, sec_i+1)
                classes.append(Class(section, instructor, room, timeslot))

        return Schedule(classes)
コード例 #8
0
ファイル: classes.py プロジェクト: rafaelnunes/goo-course
    def delete(self, class_id):
    	cls = Class.get_by_id(int(class_id))
    	if cls:
    		cls.key.delete()

    	return redirect_to('classes_by_subject', subject_id=cls.subject.id())
コード例 #9
0
    def _contract_remove_users_view(self, contract_id, dry_run = False):
        contract = Contract.objects.get(id=contract_id)
        contract_archive_group = u'Espaço Aberto %s' % (contract.name,)

        if not Group.objects.filter(name=contract_archive_group).exists():
            contract_archive_group = Group(name=contract_archive_group)
            contract_archive_group.save()
        else:
            contract_archive_group = Group.objects.get(name=contract_archive_group)

        groups_add = [Group.objects.get(name="Espaço Aberto"),
                      Group.objects.get(name="students"), contract_archive_group]

        errors = {
            'num_errors' : 0,
            'email_with_error' : [],
        }
        stats = {
            "users_to_add" : 0,
        }
        users_to_remove = TimtecUser.objects\
            .exclude(is_superuser=True, is_staff=True)\
            .exclude(groups=Group.objects.get(name="Espaço Aberto"))

        stats["users_to_add"] = len(users_to_remove)

        if errors['num_errors'] == 0:
            groups_remove = contract.groups \
                .exclude(Q(name="Avante") | Q(name="Entremeios")) \
                .values_list('id', flat=True)
            contract_classes = contract.classes.exclude(name__contains="ARQUIVO_")
            archive_classes = {}
            for c in contract_classes:
                archive_class_name = "%s%s@%s" % \
                                     (
                                         CONTRACT_ARCHIVE_CLASS_PREFIX,
                                         c.course.name,
                                         contract.name
                                     )
                if not Class.objects \
                    .filter(name=archive_class_name,
                            course=c.course,
                            contract__id=contract_id).exists():
                    archive_class = Class(name=archive_class_name,
                                          course=c.course,)
                    archive_class.save()
                    archive_class.contract.add(contract_id,)
                else:
                    archive_class = Class.objects.get(name=archive_class_name,
                                                         course=c.course,
                                                         contract__id=contract_id)
                archive_classes[c.name + c.course.name] = archive_class

            from django.db import transaction
            with transaction.atomic():
                for u in users_to_remove:
                    for g in groups_remove:
                        if not dry_run:
                            u.groups.remove(g)

                    for g in groups_add:
                        if not dry_run:
                            u.groups.add(g)

                    for c in u.classes.all().exclude(name__contains="ARQUIVO_"):
                        if c.contract.first() and \
                            c.contract.first().id == contract.id:
                            if not dry_run:
                                c.remove_students(u)
                                archive_classes[c.name + c.course.name] \
                                    .add_students(u)

            return (stats, errors)
        else:
            return errors
コード例 #10
0
ファイル: views.py プロジェクト: hacklabr/paralapraca
def contract_remove_users_view(request):
    CONTRACT_ARCHIVE_CLASS_PREFIX = "ARQUIVO_"
    contract_id = request.data.get('contract', None)
    if not contract_id:
        return Response({"error" : "Contrato não informado"},
                        status=status.HTTP_400_BAD_REQUEST)

    users = request.data.get('users', None)
    if users:
        users = users.split('\n')
    else:
        return Response({"error" : "Erro ao receber lista de usuários"},
                        status=status.HTTP_400_BAD_REQUEST)

    contract = Contract.objects.get(id=contract_id)
    contract_archive_group = u'Espaço Aberto %s' % (contract.name,)
    if not Group.objects.filter(name=contract_archive_group).exists():
        contract_archive_group = Group(name=contract_archive_group)
        contract_archive_group.save()
    else:
        contract_archive_group = Group.objects.get(name=contract_archive_group)

    groups_add = [Group.objects.get(name="Espaço Aberto"),
                  Group.objects.get(name="students"), contract_archive_group]

    errors = {
        'num_errors' : 0,
        'email_with_error' : [],
    }
    users_to_remove = []
    for u in users:
        if TimtecUser.objects.filter(email=u).exists():
            user = TimtecUser.objects.get(email=u)
            users_to_remove.append(user)
        else:
            errors['num_errors']+=1
            errors['email_with_error'].append(u)

    if errors['num_errors'] == 0:
        groups_remove = contract.groups.values_list('id', flat=True)
        contract_classes = contract.classes.exclude(name__contains="ARQUIVO_")
        archive_classes = {}
        for c in contract_classes:
            archive_class_name = "%s%s@%s" % \
                                 (
                                     CONTRACT_ARCHIVE_CLASS_PREFIX,
                                     c.course.name,
                                     contract.name
                                 )
            if not Class.objects \
                .filter(name=archive_class_name,
                        course=c.course,
                        contract__id=contract_id).exists():
                archive_class = Class(name=archive_class_name,
                                      course=c.course,)
                archive_class.save()
                archive_class.contract.add(contract_id,)
            else:
                archive_class = Class.objects.get(name=archive_class_name,
                                                     course=c.course,
                                                     contract__id=contract_id)
            archive_classes[c.name + c.course.name] = archive_class

        from django.db import transaction
        with transaction.atomic():
            for u in users_to_remove:
                for g in groups_remove:
                    u.groups.remove(g)

                for g in groups_add:
                    u.groups.add(g)

                for c in u.classes.all().exclude(name__contains="ARQUIVO_"):
                    if c.contract.first().id == contract.id:
                        c.remove_students(u)
                        archive_classes[c.name + c.course.name].add_students(u)

        return Response({}, status=status.HTTP_200_OK)
    else:
        return Response(errors, status=status.HTTP_400_BAD_REQUEST)