示例#1
0
文件: views.py 项目: simensma/sherpa
def index(request):
    enrollments = Enrollment.get_active()

    if 'search' in request.GET:
        for q in request.GET['search'].split():
            enrollments = enrollments.filter(
                Q(address1__icontains=q) |
                Q(address2__icontains=q) |
                Q(address3__icontains=q) |
                Q(zipcode__icontains=q) |
                Q(area__icontains=q) |
                Q(users__name__icontains=q) |
                Q(users__phone__icontains=q) |
                Q(users__email__icontains=q) |
                Q(users__memberid__icontains=q) |
                Q(transactions__transaction_id__icontains=q) |
                Q(transactions__order_number__icontains=q)
            )

    enrollments = enrollments.prefetch_related(
        'users',
        'users__pending_user',
        'transactions',
    ).order_by('-date_modified')
    paginator = Paginator(enrollments, 20)
    try:
        enrollments = paginator.page(request.GET.get('page', 1))
    except InvalidPage:
        enrollments = paginator.page(1)

    context = {
        'enrollments': enrollments,
        'search': request.GET.get('search'),
    }
    return render(request, 'common/admin/enrollment/index.html', context)
示例#2
0
    def setUp(self):
        super(EnrollmentModelTestCase, self).setUp()

        e = Enrollment()

        e.integration = Integration.objects.filter(
            name=BASE_TEST_INTEGRATION_NAME).first()

        e.policy = e.integration.policy
        e.username = BASE_TEST_USERNAME
        e.expires_at = timezone.now() + datetime.timedelta(minutes=10)

        e.save()
示例#3
0
 def create_enrollment(request):
     enrollment = Enrollment(state='registration')
     enrollment.save()
     request.session['enrollment'] = enrollment.pk
     return enrollment
 def create(self, validated_data):
     enrollment = Enrollment()
     enrollment.course_id = self.initial_data.get('course_id')
     enrollment.student_id = self.initial_data.get('student_id')
     enrollment.save()
     return enrollment