Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
'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
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
def get_model(self):
return models.Subject
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)
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.')
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
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
def __get_subject_queryset(self):
return Subject.objects\
.exclude(periods__isnull=True)\
.all()
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)