How to use the devilry.apps.core.models.Period 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 / adminscripts / devilry-export-periodstatus.py View on Github external
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))
github devilry / devilry-django / devilry / devilry_qualifiesforexam / rest / status.py View on Github external
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({
github devilry / devilry-django / devilry / devilry_student / views / period / crinstance_period.py View on Github external
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.
        """
github devilry / devilry-django / devilry / devilry_student / views / frontpage.py View on Github external
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
github devilry / devilry-django / devilry / devilry_admin / views / period / crinstance_period.py View on Github external
def get_rolequeryset(self):
        return Period.objects.filter_user_is_admin(user=self.request.user)\
            .order_by('-start_time')
github devilry / devilry-django / devilry / devilry_subjectadmin / rest / auth.py View on Github external
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)
github devilry / devilry-django / devilry / devilry_admin / views / subject_for_period_admin / overview_for_periodadmin.py View on Github external
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',
github devilry / devilry-django / src / devilry_student / devilry_student / views / semesteroverview.py View on Github external
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
github devilry / devilry-django / devilry / devilry_elasticsearch_cache / doctypes / elasticsearch_basenodes_doctypes.py View on Github external
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
github devilry / devilry-django / devilry / devilry_statistics / management / commands / devilry_statistics_make_assignment_with_graded_groups.py View on Github external
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,