Esempio n. 1
0
 def get_context_data(self, **kwargs):
     context = {}
     context['cje_list'] = ExpenseCorrectiveJournalEntry.objects.filter(
         school=get_school(self.request.session)).exclude(
             approval_status=APPROVAL_STATUS_APPROVED).filter(
                 correction_to__in=self.get_queryset())
     return super().get_context_data(**context)
Esempio n. 2
0
 def import_action(self, request, form):
     school = get_school(request.session)
     resource = self.resource_class(school=school, user=request.user)
     import_formats = self.formats
     context = {}
     input_format = import_formats[int(form.cleaned_data['input_format'])]()
     import_file = form.cleaned_data['import_file']
     # first always write the uploaded file to disk as it may be a
     # memory file or else based on settings upload handlers
     tmp_storage = self.write_to_tmp_storage(import_file, input_format)
     # then read the file, using the proper format-specific mode
     # warning, big files may exceed memory
     try:
         dataset = self.make_dataset(tmp_storage, input_format)
     except UnicodeDecodeError as e:
         return HttpResponse(
             (u"<h1>Imported file has a wrong encoding: %s</h1>" % e))
     result = resource.import_data(dataset,
                                   dry_run=True,
                                   raise_errors=False,
                                   file_name=import_file.name,
                                   user=request.user)
     context['result'] = result
     context['model'] = self.model.__name__
     if not result.has_errors():
         context['confirm_form'] = ConfirmImportForm(
             initial={
                 'import_file_name': tmp_storage.name,
                 'original_file_name': import_file.name,
                 'input_format': form.cleaned_data['input_format'],
             })
     return TemplateResponse(request, 'confirm_import.html', context)
Esempio n. 3
0
 def process_dataset(self, dataset, file_name, request):
     school = get_school(request.session)
     resource = self.resource_class(school=school, user=request.user)
     return resource.import_data(dataset,
                                 dry_run=False,
                                 raise_errors=True,
                                 file_name=file_name,
                                 user=request.user)
Esempio n. 4
0
 def form_valid(self, form):
     student_account = form.cleaned_data['student']
     notes = form.cleaned_data['notes']
     user = self.request.user
     school = get_school(self.request.session)
     for ledger_account in RevenueLedgerAccount.objects.all():
         amount = form.cleaned_data[ledger_account.name]
         if amount is not None and amount > 0:
             revenue = RevenueTransaction.objects.create(
                 school=school,
                 student=student_account,
                 ledger_account=ledger_account,
                 amount=amount,
                 notes=notes,
                 created_by=user,
             )
             self.add_object_to_session(revenue.pk)
     return redirect(self.success_url)
Esempio n. 5
0
 def form_valid(self, form):
     new_user = form.save()
     user_membership = UserSchoolMembership.objects.create(
         user=new_user, school=get_school(self.request.session))
     return redirect(self.get_success_url(user_membership.pk))