Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
set_django_settings_module(opt)
from django.contrib.auth.models import User
from devilry.apps.core.models import Period
def exit_help():
p.print_help()
raise SystemExit()
if len(args) != 2:
exit_help()
setup_logging(opt)
subject_short_name, period_short_name = args
period = Period.objects.get(short_name=period_short_name,
parentnode__short_name=subject_short_name)
users = User.objects.filter(
candidate__assignment_group__parentnode__parentnode=period).distinct()
for user in users:
print "%s;%s;%s" % (
subject_short_name.upper(),
user.username,
period.student_passes_period(user))
def _get_instance(self, id):
try:
qry = Period.objects.select_related('parentnode')
period = qry.get(id=id)
except Period.DoesNotExist:
raise ErrorResponse(statuscodes.HTTP_404_NOT_FOUND,
{'detail': 'The period with ID {id} does not exist'.format(id=id)})
self._permissioncheck(period)
statusQry = period.qualifiedforexams_status.all()
if statusQry.count() == 0:
raise ErrorResponse(statuscodes.HTTP_404_NOT_FOUND,
{'detail': 'The period has no statuses'})
statusQry = statusQry.select_related(
'period', 'user', 'user__devilryuserprofile')
grouper = GroupsGroupedByRelatedStudentAndAssignment(period)
out = self._serialize_period(period)
out.update({
def build_menu(self):
super(Menu, self).build_menu()
period = self.request.cradmin_role
self.add_role_menuitem_object()
self.add_allperiods_breadcrumb_item()
self.add_singleperiods_breadcrumb_item(period=period, active=True)
def does_not_exist_view(request):
raise Http404()
class CrAdminInstance(devilry_crinstance.BaseCrInstanceStudent):
id = 'devilry_student_period'
menuclass = Menu
roleclass = Period
rolefrontpage_appname = 'overview'
apps = [
('overview', overview.App),
]
def get_rolequeryset(self):
return Period.objects\
.filter_user_is_relatedstudent(user=self.request.user)\
.select_related('parentnode')
def get_titletext_for_role(self, role):
"""
Get a short title briefly describing the given ``role``.
Remember that the role is a Period.
"""
context['groups_waiting_for_deliveries'] = list(
AssignmentGroup.objects\
.filter_student_has_access(self.request.user)\
.filter_is_active()\
.filter_waiting_for_deliveries()\
.select_related(
'last_deadline',
'parentnode', # Assignment
'parentnode__parentnode', # Period
'parentnode__parentnode__parentnode', # Subject
)\
.order_by('last_deadline__deadline')
)
active_periods = Period.objects\
.filter_active()\
.filter_is_candidate_or_relatedstudent(self.request.user)\
.order_by('-start_time', 'parentnode__long_name', 'long_name')
# active_periods = Period.objects\
# .filter_active()\
# .filter_is_candidate_or_relatedstudent(self.request.user)\
# .extra(
# select={
# 'lastest_feedback_string': """
# SELECT
# core_assignment.short_name
# || ","
# || core_assignment.grading_system_plugin_id
# || ","
# || core_staticfeedback.is_passing_grade
def get_rolequeryset(self):
return Period.objects.filter_user_is_admin(user=self.request.user)\
.order_by('-start_time')
def periodadmin_required(user, periodid):
"""
Raise :exc:`devilry_subjectadmin.rest.errors.PermissionDeniedError` unless
the given ``user`` is admin on all of the given Periods.
:param periodid: ID of Periods to check.
"""
_admin_required(Period, user, _('Permission denied'), periodid)
def get_url(self):
return reverse_cradmin_url(
instanceid='devilry_admin_periodadmin',
appname='overview',
roleid=self.period.id,
viewname=crapp.INDEXVIEW_NAME
)
def get_extra_css_classes_list(self):
return ['devilry-admin-period-overview-perioditemframe']
class Overview(listbuilderview.FilterListMixin, listbuilderview.View):
template_name = 'devilry_admin/subject/overview_for_period_admins.html'
model = Period
frame_renderer_class = PeriodItemFrame
value_renderer_class = devilry_listbuilder.period.AdminItemValue
def add_filterlist_items(self, filterlist):
filterlist.append(listfilter.django.single.textinput.Search(
slug='search',
modelfields=[
'long_name',
'short_name',
],
label_is_screenreader_only=True
))
def get_filterlist_url(self, filters_string):
return self.request.cradmin_app.reverse_appurl(
'filter',
def get_context_data(self, *args, **kwargs):
context = super(SemesterOverview, self).get_context_data(*args, **kwargs)
period = Period.objects.get(id=self.kwargs['pk'])
context['period'] = period
context['qualifiesforexams'] = None
try:
status = Status.get_current_status(period)
except Status.DoesNotExist:
pass
else:
if status.status == Status.READY:
try:
qualifies = status.students.get(relatedstudent__user=self.request.user)
context['qualifiesforexams'] = qualifies.qualifies
except QualifiesForFinalExam.DoesNotExist:
pass
return context
class Period(DocType):
"""
Class to represent a Period from :class:`devilry.apps.core.models.period.Period`
"""
class Meta:
index = 'basenodes'
class PeriodRegistryItem(AbstractBaseNodeRegistryItem):
"""
A RegistryItem class of :class:`core.models.period.Period` that defines the properties of a :class:`.Period` as DocType.
Is added to the :file:`.elasticsearch_registry.registry` singleton.
"""
modelclass = coremodels.Period
doctype_class = Period
def get_search_text(self, modelobject):
period = modelobject
search_text = \
u'{long_name} {short_name} ' \
u'{subject_long_name} {subject_short_name} ' \
u'{parentnode_long_name} {parentnode_short_name}'.format(
long_name=period.long_name,
short_name=period.short_name,
subject_long_name=period.subject.long_name,
subject_short_name=period.subject.short_name,
parentnode_long_name=period.subject.parentnode.long_name,
parentnode_short_name=period.subject.parentnode.short_name)
return search_text
if random:
self.random_generate(
subject_name=subject_name,
period_name=period_name,
assignment_name=assignment_name,
num_students=num_students)
else:
subject = coremodels.Subject(
long_name=subject_name,
short_name='stat_subject'
)
subject.save()
period_start_time = timezone.now() - timezone.timedelta(days=50)
period_end_time = timezone.now() + timezone.timedelta(days=50)
period = coremodels.Period(
long_name=period_name,
short_name='stat_period',
start_time=period_start_time,
end_time=period_end_time,
parentnode=subject
)
period.save()
assignment_publishing_time = period_start_time + timezone.timedelta(days=3)
assignment = coremodels.Assignment(
long_name=assignment_name,
short_name='stat_assignment',
publishing_time=assignment_publishing_time,
first_deadline=assignment_publishing_time + timezone.timedelta(days=7),
points_to_grade_mapper=coremodels.Assignment.POINTS_TO_GRADE_MAPPER_RAW_POINTS,
max_points=50,