Пример #1
0
def get_entry_node(node, user):
    return {
        'type':
        node.type,
        'nID':
        node.id,
        'jID':
        node.journal.id,
        'entry':
        EntrySerializer(node.entry, context={
            'user': user
        }).data if node.entry else None,
    } if node else None
Пример #2
0
    def GDPR(self, request, pk):
        """Get a zip file of all the userdata.

        Arguments:
        request -- request data
        pk -- user ID to download the files from

        Returns
        On failure:
            unauthorized -- when the user is not logged in
            forbidden -- when its not a superuser nor their own data
        On success:
            success -- a zip file of all the userdata with all their files
        """
        if int(pk) == 0:
            pk = request.user.id

        user = User.objects.get(pk=pk)

        # Check the right permissions to get this users data, either be the user of the data or be an admin.
        if not (request.user.is_superuser or request.user.id == pk):
            return response.forbidden(
                'You are not allowed to view this user\'s data.')

        profile = UserSerializer(user).data
        journals = Journal.objects.filter(user=pk)
        journal_dict = {}
        for journal in journals:
            # Select the nodes of this journal but only the ones with entries.
            entry_ids = Node.objects.filter(journal=journal).exclude(
                entry__isnull=True).values_list('entry', flat=True)
            entries = Entry.objects.filter(id__in=entry_ids)
            # Serialize all entries and put them into the entries dictionary with the assignment name key.
            journal_dict.update({
                journal.assignment.name:
                EntrySerializer(entries,
                                context={
                                    'user': request.user,
                                    'comments': True
                                },
                                many=True).data
            })

        archive_path, archive_name = file_handling.compress_all_user_data(
            user, {
                'profile': profile,
                'journals': journal_dict
            })

        return response.file(archive_path, archive_name)
Пример #3
0
    def create(self, request):
        """Set a new grade for an entry.

        Arguments:
        request -- request data
            entry_id -- entry ID
            grade -- grade
            published -- published state

        Returns:
        On failure:
            unauthorized -- when the user is not logged in
            key_error -- missing keys
            not_found -- could not find the entry, author or assignment

        On success:
            success -- with the assignment data
        """
        entry_id, grade, published = utils.required_typed_params(
            request.data, (int, 'entry_id'), (float, 'grade'),
            (bool, 'published'))

        entry = Entry.objects.get(pk=entry_id)
        journal = entry.node.journal
        assignment = journal.assignment

        request.user.check_permission('can_grade', assignment)

        if published:
            request.user.check_permission('can_publish_grades', assignment)

        if grade is not None and grade < 0:
            return response.bad_request(
                'Grade must be greater than or equal to zero.')

        grade = factory.make_grade(entry, request.user.pk, grade, published)

        if published:
            Comment.objects.filter(entry=entry).update(published=True)

        # TODO: Is the lti flag ever used? Else move replace_result to celery
        return response.created({
            'entry':
            EntrySerializer(entry, context={
                'user': request.user
            }).data,
            'lti':
            lti_grade.replace_result(journal)
        })
Пример #4
0
def get_deadline(node, user):
    """Convert entrydeadline to a dictionary."""
    return {
        'description':
        node.preset.description,
        'type':
        node.type,
        'nID':
        node.id,
        'jID':
        node.journal.id,
        'deadline':
        node.preset.deadline,
        'template':
        TemplateSerializer(node.preset.forced_template).data,
        'entry':
        EntrySerializer(node.entry, context={
            'user': user
        }).data if node.entry else None,
    } if node else None