How to use the devilry.apps.core.models.Subject 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 / core / testhelpers.py View on Github external
Examples::

        assignmentgroup = create_from_path(
                'ifi:inf1100.spring05.oblig1.student1,student2')
        oblig1 = create_from_path(
                'ifi:inf1100.spring05.oblig1')
    """
    split = path.split(':', 1)
    nodes = split[0].split('.')

    pathsplit = split[1].split('.')

    # Subject
    subjectname = pathsplit[0]
    subject = Subject(short_name=subjectname,
                      long_name=subjectname.capitalize())
    try:
        subject.clean()
        subject.save()
    except:
        subject = Subject.objects.get(short_name=subjectname)
    last = subject

    # Period
    if len(pathsplit) > 1:
        periodname = pathsplit[1]
        period = Period(parentnode=subject, short_name=periodname,
                long_name=periodname.capitalize(), start_time=timezone.now(),
                end_time=timezone.now() + timedelta(10))
        try:
            period.clean()
github devilry / devilry-django / devilry / apps / core / testhelpers.py View on Github external
'ifi:inf1100.spring05.oblig1')
    """
    split = path.split(':', 1)
    nodes = split[0].split('.')

    pathsplit = split[1].split('.')

    # Subject
    subjectname = pathsplit[0]
    subject = Subject(short_name=subjectname,
                      long_name=subjectname.capitalize())
    try:
        subject.clean()
        subject.save()
    except:
        subject = Subject.objects.get(short_name=subjectname)
    last = subject

    # Period
    if len(pathsplit) > 1:
        periodname = pathsplit[1]
        period = Period(parentnode=subject, short_name=periodname,
                long_name=periodname.capitalize(), start_time=timezone.now(),
                end_time=timezone.now() + timedelta(10))
        try:
            period.clean()
            period.save()
        except:
            period = Period.objects.get(parentnode=subject,
                    short_name=periodname)
        last = period
github devilry / devilry-django / src / devilry_subjectadmin / devilry_subjectadmin / rest / allwhereisadmin.py View on Github external
def _subjects_without_periods(self):
        qry = Subject.objects.filter(admins=self.request.user)
        qry = qry.prefetch_related('admins')
        qry = qry.annotate(number_of_periods=Count('periods'))
        qry = qry.filter(number_of_periods=0)
        return qry
github devilry / devilry-django / devilry / devilry_subjectadmin / rest / auth.py View on Github external
def subjectadmin_required(user, subjectid):
    """
    Raise :exc:`devilry_subjectadmin.rest.errors.PermissionDeniedError` unless
    the given ``user`` is admin on all of the given Subjects.

    :param subjectid: ID of Subject to check.
    """
    _admin_required(Subject, user, _('Permission denied'),  subjectid)
github devilry / devilry-django / src / devilry / devilry / apps / superadmin / management / commands / devilry_subjectadminadd.py View on Github external
def get_subject(self, short_name):
        from devilry.apps.core.models import Subject
        try:
            return Subject.objects.get(short_name=short_name)
        except Subject.DoesNotExist, e:
            raise CommandError('Invalid subject-short_name.')
github devilry / devilry-django / devilry / devilry_admin / views / dashboard / overview.py View on Github external
def get_unfiltered_queryset_for_role(self, site):
        """
        Create the queryset, and apply the filters from the filterlist.
        """
        # Return Subjects where the user can be admin on Subject and or admin on a Period within a Subject
        queryset = coremodels.Subject.objects\
            .filter_user_is_admin_for_any_periods_within_subject(self.request.user)\
            .prefetch_active_period_objects()

        # Set unfiltered count on self.
        self.num_total = queryset.count()
        return queryset
github devilry / devilry-django / devilry / devilry_merge_v3database / utils / merger.py View on Github external
def get_subject_by_shortname(self, shortname):
        """
        Get :obj:`devilry.apps.core.models.Subject` by ``shortname`` from current default database.

        Args:
            shortname: Short name of the subject.

        Returns:
            :obj:`devilry.apps.core.models.Subject`: Instance or ``None``.
        """
        try:
            return core_models.Subject.objects.get(short_name=shortname)
        except core_models.Subject.DoesNotExist:
            return None
github devilry / devilry-django / devilry / devilry_superadmin / delete_periods / period_delete.py View on Github external
def __get_subject_queryset(self):
        return Subject.objects\
            .exclude(periods__isnull=True)\
            .all()
github devilry / devilry-django / src / devilry_search / devilry_search / rest / admincontent.py View on Github external
def get_search_queryset(self):
        qry = SearchQuerySet()
        if not self.request.user.is_superuser:
            qry = qry.filter(admin_ids=unicode(self.request.user.id))
        return qry.models(
            Node, Subject, Period, Assignment, AssignmentGroup)