How to use the devilry.simplified.FieldSpec function in devilry

To help you get started, we’ve selected a few devilry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github devilry / devilry-django / devilry / apps / extjshelpers / tests.py View on Github external
score = models.IntegerField()
    introtext = models.TextField()
    text = models.TextField()


@simplified_modelapi
class SimplifiedUser(object):
    #@classmethod
    #def read_authorize(cls, user, obj):
        #return True

    class Meta:
        model = User
        resultfields = FieldSpec('id', 'first', 'last', 'email', 'score',
                                 textfields=['introtext', 'text'])
        searchfields = FieldSpec('first', 'last')
        methods = []


@restful_modelapi
class RestUser(ModelRestfulView):
    class Meta:
        simplified = SimplifiedUser
        belongs_to = 'RestUser'
        has_many = 'RestUser'

    # Override to avoid having to add the rest as an url
    @classmethod
    def get_rest_url(cls, *args, **kwargs):
        return '/restuser'
github devilry / devilry-django / src / devilry / devilry / apps / gradeeditors / simplified / examiner.py View on Github external
from django.db.models import Q

from devilry.apps.core.models import Assignment
from devilry.simplified import (SimplifiedModelApi, simplified_modelapi,
                                FieldSpec, PermissionDenied, FilterSpecs,
                                FilterSpec)
from ..models import Config, FeedbackDraft


@simplified_modelapi
class SimplifiedConfig(SimplifiedModelApi):
    class Meta:
        model = Config
        resultfields = FieldSpec('gradeeditorid', 'assignment', 'config')
        searchfields = FieldSpec()
        methods = ('read',)

    @classmethod
    def read_authorize(cls, user, obj):
        if not Assignment.published_where_is_examiner(user).filter(id=obj.assignment_id).exists():
            raise PermissionDenied()


@simplified_modelapi
class SimplifiedFeedbackDraft(SimplifiedModelApi):
    class Meta:
        model = FeedbackDraft
        resultfields = FieldSpec('id', 'delivery', 'saved_by', 'save_timestamp', 'draft', 'published', 'staticfeedback')
        searchfields = FieldSpec()
        filters = FilterSpecs(FilterSpec('delivery'))
        methods = ('create', 'read', 'search')
github devilry / devilry-django / src / devilry / apps / administrator / simplified / simplifiedperiodapplicationkeyvalue.py View on Github external
from devilry.simplified import (simplified_modelapi,
                                PermissionDenied, FieldSpec,
                                FilterSpecs, FilterSpec)
from devilry.apps.core import models
from devilry.coreutils.simplified.metabases import SimplifiedAbstractApplicationKeyValueMixin

from cansavebase import CanSaveBase


@simplified_modelapi
class SimplifiedPeriodApplicationKeyValue(CanSaveBase):
    """ Simplified wrapper for :class:`devilry.apps.core.models.RelatedStudentKeyValue`. """
    class Meta(SimplifiedAbstractApplicationKeyValueMixin):
        model = models.PeriodApplicationKeyValue
        methods = ['create', 'read', 'update', 'delete', 'search']
        resultfields = FieldSpec('period') + SimplifiedAbstractApplicationKeyValueMixin.resultfields
        editablefields = ('period',) + SimplifiedAbstractApplicationKeyValueMixin.editablefields
        filters = FilterSpecs(FilterSpec('period', supported_comp=('exact',)),
                              FilterSpec('period__start_time'),
                              FilterSpec('period__end_time'),
                              FilterSpec('period__parentnode', supported_comp=('exact',)),
                              FilterSpec('period__parentnode__parentnode', supported_comp=('exact',))
                             ) + SimplifiedAbstractApplicationKeyValueMixin.filters

    @classmethod
    def create_searchqryset(cls, user):
        """ Returns all related users of this type where given ``user`` is admin or superadmin.

        :param user: A django user object.
        :rtype: a django queryset
        """
        return cls._meta.model.where_is_admin_or_superadmin(user)
github devilry / devilry-django / src / devilry / apps / administrator / simplified / simplifiedassignmentgroup.py View on Github external
from helpers import _convert_list_of_usernames_to_userobjects
from cansavebase import CanSaveBase


@simplified_modelapi
class SimplifiedAssignmentGroup(CanSaveBase):
    """ Simplified wrapper for
    :class:`devilry.apps.core.models.AssignmentGroup`. """
    class Meta(SimplifiedAssignmentGroupMetaMixin):
        """ Defines what methods an Administrator can use on an AssignmentGroup object using the Simplified API """
        editablefields = ('id', 'name', 'is_open', 'parentnode')
        fake_editablefields = ('fake_examiners', 'fake_candidates', 'fake_tags')
        methods = ['create', 'read', 'update', 'delete', 'search']
        resultfields = \
                FieldSpec(users=['candidates__student__username', 'candidates__identifier', 'examiners__user__username'],
                          students_full_name=['candidates__student__devilryuserprofile__full_name'],
                          tags=['tags__tag']) + \
                SimplifiedAssignmentGroupMetaMixin.resultfields
        searchfields = FieldSpec('tags__tag',
                                 'candidates__student__username',
                                 'examiners__user__username',
                                 'candidates__student__devilryuserprofile__full_name') + SimplifiedAssignmentGroupMetaMixin.searchfields
        filters = SimplifiedAssignmentGroupMetaMixin.filters + \
                FilterSpecs(FilterSpec('candidates__student__username', type_converter=stringOrNoneConverter),
                            FilterSpec('examiners__user__username', type_converter=stringOrNoneConverter),
                            FilterSpec('tags__tag', type_converter=stringOrNoneConverter))


    @classmethod
    def create_searchqryset(cls, user):
        """ Returns all Deadline-objects where given ``user`` is admin or superadmin.
github devilry / devilry-django / src / devilry / devilry / coreutils / simplified / metabases / candidate.py View on Github external
from devilry.apps.core import models
from devilry.simplified import FieldSpec, FilterSpec, FilterSpecs, ForeignFilterSpec


class SimplifiedCandidateMetaMixin(object):
    """ Defines the django model to be used, resultfields returned by
    search and which fields can be used to search for a Candidate object
    using the Simplified API """
    model = models.Candidate
    resultfields = FieldSpec('id',
                             'assignment_group')
    searchfields = FieldSpec()
    filters = FilterSpecs(FilterSpec('id'),
                          FilterSpec('assignment_group'),
                          FilterSpec('assignment_group__parentnode'), # Assignment
                          FilterSpec('assignment_group__parentnode__parentnode'), # Period
                          FilterSpec('assignment_group__parentnode__parentnode__parentnode') # Subject
                         )
github devilry / devilry-django / devilry / coreutils / simplified / metabases / staticfeedback.py View on Github external
from devilry.apps.core import models
from devilry.simplified import FieldSpec, FilterSpec, FilterSpecs, ForeignFilterSpec



class SimplifiedStaticFeedbackMetaMixin(object):
    """ Defines the django model to be used, resultfields returned by
    search and which fields can be used to search for a StaticFeedback object
    using the Simplified API """
    model = models.StaticFeedback
    resultfields = FieldSpec('id',
                             'grade',
                             'is_passing_grade',
                             'saved_by',
                             'save_timestamp',
                             'delivery',
                             'rendered_view',
                             candidates=['delivery__deadline__assignment_group__candidates__identifier'],
                             period=['delivery__deadline__assignment_group__parentnode__parentnode__id',
                                     'delivery__deadline__assignment_group__parentnode__parentnode__short_name',
                                     'delivery__deadline__assignment_group__parentnode__parentnode__long_name'],
                             subject=['delivery__deadline__assignment_group__parentnode__parentnode__parentnode__id',
                                      'delivery__deadline__assignment_group__parentnode__parentnode__parentnode__short_name',
                                      'delivery__deadline__assignment_group__parentnode__parentnode__parentnode__long_name'],
                             assignment=['delivery__deadline__assignment_group__parentnode__id',
                                         'delivery__deadline__assignment_group__parentnode__short_name',
                                         'delivery__deadline__assignment_group__parentnode__long_name'],
github devilry / devilry-django / devilry / coreutils / simplified / metabases / delivery.py View on Github external
from devilry.apps.core import models
from devilry.simplified import FieldSpec, FilterSpec, FilterSpecs, ForeignFilterSpec



class SimplifiedDeliveryMetaMixin(object):
    """ Defines the django model to be used, resultfields returned by
    search and which fields can be used to search for a Delivery object
    using the Simplified API """
    model = models.Delivery
    editablefields = ('deadline', 'successful')
    resultfields = FieldSpec('id',
                             'number',
                             'time_of_delivery',
                             'deadline',
                             'successful',
                             'delivery_type', 'alias_delivery',
                             delivered_by=['delivered_by__identifier'],
                             candidates=['deadline__assignment_group__candidates__identifier'],
                             deadline=['deadline__deadline'],
                             assignment_group=['deadline__assignment_group',
                                               'deadline__assignment_group__name'],
                             assignment_group_users=['deadline__assignment_group__examiners__username',
                                                     'deadline__assignment_group__candidates__identifier'],
                             assignment=['deadline__assignment_group__parentnode',
                                         'deadline__assignment_group__parentnode__short_name',
                                         'deadline__assignment_group__parentnode__long_name'],
                             period=['deadline__assignment_group__parentnode__parentnode',
github devilry / devilry-django / devilry / apps / administrator / simplified.py View on Github external
@simplified_modelapi
class SimplifiedRelatedExaminer(RelatedUsersBase):
    """ Simplified wrapper for :class:`devilry.apps.core.models.RelatedExaminer`. """
    class Meta(RelatedUsersMetaBase):
        """ Defines what methods an Administrator can use on a RelatedExaminer object using the Simplified API """
        model = models.RelatedExaminer

@simplified_modelapi
class SimplifiedRelatedStudent(RelatedUsersBase):
    """ Simplified wrapper for :class:`devilry.apps.core.models.RelatedStudent`. """
    class Meta(RelatedUsersMetaBase):
        """ Defines what methods an Administrator can use on a RelatedStudent object using the Simplified API """
        model = models.RelatedStudent
        resultfields = RelatedUsersMetaBase.resultfields + FieldSpec('candidate_id')
        searchfields = RelatedUsersMetaBase.searchfields + FieldSpec('candidate_id')
        editablefields = RelatedUsersMetaBase.editablefields + ('candidate_id',)
        filters = RelatedUsersMetaBase.filters + FilterSpecs(FilterSpec('candidate_id'))


@simplified_modelapi
class SimplifiedRelatedStudentKeyValue(SimplifiedModelApi):
    """ Simplified wrapper for :class:`devilry.apps.core.models.RelatedStudentKeyValue`. """
    class Meta:
        model = models.RelatedStudentKeyValue
        methods = ['create', 'read', 'update', 'delete', 'search']
        resultfields = FieldSpec('id', 'application', 'key', 'value', 'relatedstudent', 'student_can_read')
        searchfields = FieldSpec('application', 'key', 'value', 'relatedstudent__user__username')
        editablefields = ('application', 'key', 'value', 'relatedstudent', 'student_can_read')
        filters = FilterSpecs(FilterSpec('id', supported_comp=('exact',)),
                              FilterSpec('student_can_read', supported_comp=('exact',), type_converter=boolConverter),
                              FilterSpec('application', supported_comp=('exact',)),
github devilry / devilry-django / devilry / apps / administrator / simplified / simplifiedassignmentgroup.py View on Github external
from helpers import _convert_list_of_usernames_to_userobjects
from cansavebase import CanSaveBase


@simplified_modelapi
class SimplifiedAssignmentGroup(CanSaveBase):
    """ Simplified wrapper for
    :class:`devilry.apps.core.models.AssignmentGroup`. """
    class Meta(SimplifiedAssignmentGroupMetaMixin):
        """ Defines what methods an Administrator can use on an AssignmentGroup object using the Simplified API """
        editablefields = ('id', 'name', 'is_open', 'parentnode')
        fake_editablefields = ('fake_examiners', 'fake_candidates', 'fake_tags')
        methods = ['create', 'read', 'update', 'delete', 'search']
        resultfields = \
                FieldSpec(users=['candidates__student__username', 'examiners__user__username'],
                          students_full_name=['candidates__student__devilryuserprofile__full_name'],
                          tags=['tags__tag']) + \
                SimplifiedAssignmentGroupMetaMixin.resultfields
        searchfields = FieldSpec('tags__tag',
                                 'candidates__student__username',
                                 'examiners__user__username',
                                 'candidates__student__devilryuserprofile__full_name') + SimplifiedAssignmentGroupMetaMixin.searchfields
        filters = SimplifiedAssignmentGroupMetaMixin.filters + \
                FilterSpecs(FilterSpec('candidates__student__username', type_converter=stringOrNoneConverter),
                            FilterSpec('examiners__user__username', type_converter=stringOrNoneConverter),
                            FilterSpec('tags__tag', type_converter=stringOrNoneConverter))


    @classmethod
    def create_searchqryset(cls, user):
        """ Returns all Deadline-objects where given ``user`` is admin or superadmin.
github devilry / devilry-django / devilry / coreutils / simplified / metabases / period.py View on Github external
class SimplifiedPeriodMetaMixin(object):
    """ Defines the django model to be used, resultfields returned by
    search and which fields can be used to search for a Period object
    using the Simplified API """
    model = models.Period
    resultfields = FieldSpec('id',
                             'parentnode',
                             'short_name',
                             'long_name',
                             'start_time',
                             'end_time',
                             subject=['parentnode__short_name',
                                      'parentnode__long_name'])
    searchfields = FieldSpec('short_name',
                             'long_name',
                             'parentnode__short_name',
                             'parentnode__long_name')
    filters = FilterSpecs(FilterSpec('parentnode'),
                          FilterSpec('short_name'),
                          FilterSpec('long_name'),
                          FilterSpec('start_time'),
                          FilterSpec('end_time'),
                          ForeignFilterSpec('parentnode',  # Subject
                                            FilterSpec('parentnode'),
                                            FilterSpec('short_name'),
                                            FilterSpec('long_name')))