コード例 #1
0
ファイル: ajax_combos.py プロジェクト: wearetherobots/acs40
def add_payment_responsible(request, registration_pk):
    registration = Registration.objects.select_related(
        'custom_payment_responsible').filter(pk=registration_pk).first()
    if not registration:
        return JsonResponse({}, status=400)

    name = request.POST.get('name', '')

    if not registration.custom_payment_responsible:
        person = Person()
        person.first_name = name_format(name)
        person.save()

        registration.custom_payment_responsible = person
    else:
        person = registration.custom_payment_responsible
        person.first_name = name_format(name)
        person.save()

    registration.payment_responsible = person
    registration.save()

    response = {
        'id': person.id,
        'name': person.first_name,
    }

    return JsonResponse(response)
コード例 #2
0
def editable_contact(request):

    editables = ['first_name', 'last_name', 'email']

    if not any(key in request.POST for key in editables):
        return JsonResponse({}, status=400, safe=False)

    pk = request.POST.get('pk', 0)
    contact = get_object_or_404(RegistrationContact, pk=pk)

    response = {}

    if 'first_name' in request.POST:
        response['first_name'] = contact.first_name = name_format(
            request.POST['first_name'])

    if 'last_name' in request.POST:
        response['last_name'] = contact.last_name = name_format(
            request.POST['last_name'])

    if 'email' in request.POST:
        response['email'] = contact.email = remove_spaces(
            request.POST['email'])

    contact.save()

    return JsonResponse(response, status=200, safe=False)
コード例 #3
0
def xeditable_person_edit(request):
    request_data = request.POST

    pk = request_data.get('pk')
    name = request_data.get('name')
    value = request_data.get('value')

    person = Person.objects.get(pk=pk)

    response = {}

    if name == 'first_name':
        response['value'] = person.first_name = name_format(value)

    if name == 'last_name':
        response['value'] = person.last_name = name_format(value)

    if name == 'email':
        response['value'] = person.email = remove_spaces(value)

    person.save()

    return JsonResponse(response)
コード例 #4
0
def field_inline(request, task_id=None):
    if request.is_ajax():
        pk = request.POST.get('pk')
        name = request.POST.get('name')
        model = request.POST.get('model')
        value = request.POST.get('value')
        registration_id = request.POST.get('registration_id')
        section = request.POST.get('section')

        registration = get_object_or_404(Registration, pk=registration_id)

        if len(value) > 1:
            value = value

        extras = {}

        date_fields = [
            'start_date', 'end_date', 'birth_date', 'payment_date',
            'received_date', 'signature_date', 'flight_return',
            'flight_departure'
        ]

        # format dates accordingly
        if name in date_fields:
            value = parser.parse(value)
        if model == 'Address':
            Model = Address

            if name in ['address1', 'address2', 'zip_code']:
                value = text_format(value)

        elif model == 'Profile':
            Model = Profile

            if name == 'emergency_contact_relationship':
                value = text_format(value)

            if name == 'allergies':
                value = text_area_format(value)

        elif model == 'Phone':
            Model = Phone

            if name in ['number']:
                value = text_format(value)

        elif model == 'User':
            Model = get_user_model()

            if name in ['first_name', 'last_name']:
                value = name_format(value)

            if name == 'email':
                value = remove_spaces(value)

        elif model == 'Sibling':
            Model = Sibling

            if name in ['name', 'last_name']:
                value = name_format(value)

            if name in ['other']:
                value = text_format(value)

        elif model == 'Registration':
            Model = Registration
            if name in ['last_school', 'recommender']:
                value = text_format(value)

            if name in ['last_grade_select']:
                name = 'grade'

        elif model == 'Note':
            Model = Note
        elif model == 'RegistrationFinance':
            Model = RegistrationFinance
            obj, created = Model.objects.get_or_create(
                registration_id=registration_id)
            pk = obj.pk
        elif model == 'RegistrationVisa':
            Model = RegistrationVisa
            obj, created = Model.objects.get_or_create(
                registration_id=registration_id)
            pk = obj.pk

        elif model == 'RegistrationFlight':
            Model = RegistrationFlight

            obj, created = Model.objects.get_or_create(
                registration_id=registration_id)

            pk = obj.pk

            if name in ['airport_code', 'itinerary', 'note']:
                value = text_format(value)

            if name == ['comission', 'amount']:
                value = value.replace('$', '')

        if name == 'with_agency' or name == 'returning_student' or name == 'special':
            if value == '0':
                value = False
            elif value == '1':
                value = True

        # AAIICA-458 if PUBLIC SCHOOL then travels with adastra is YES
        if name == 'program':
            program = get_object_or_404(Program, pk=value)

            RegistrationVisa.objects.get_or_create(registration=registration)

        obj = Model.objects.filter(id=pk)

        values = {name: value}

        if name == 'special' and value:
            values['payment_plan'] = None

        if name == "country" and model == "Address":
            values["state"] = None
            values["city"] = None

        if name == "state" and model == "Address":
            values["city"] = None

        result = obj.update(**values)

        save_registration_activities(request, registration, name, section)
        # Update nemonic if model is registration
        if model == 'Registration':
            obj[0].save()

        if name in date_fields:
            value = request.POST.get('value')

        response_data = {'value': value, 'result': result, 'extras': extras}

        if result:
            return HttpResponse(json.dumps(response_data),
                                content_type="application/json")
        else:
            return HttpResponse(
                'There was an error updating the requested field.', status=500)
コード例 #5
0
ファイル: api_views.py プロジェクト: wearetherobots/acs40
def payment_plan_form_create(request):
    request_data = json.loads(request.body)

    registration_id = request_data['registration_id']
    first_name = request_data['first_name']
    last_name = request_data['last_name']
    signature_date = datetime.strptime(request_data['signature_date'],
                                       '%Y-%m-%d')
    responsible_option = request_data['responsible']
    period = request_data['period']
    service_ids = request_data.get('service_ids', [])

    registration = Registration.objects.select_related(
        'costumer__profile__address', 'program__program_base', 'consultant',
        'registrationfinance', 'academic_period',
        'custom_payment_responsible').filter(pk=registration_id).first()
    if not registration:
        return JsonResponse({'registration': 'not found'}, status=400)

    category = AttachmentCategory.objects.filter(
        name='Payment Plan Form').first()
    if not category:
        return JsonResponse({'category': 'not found'}, status=400)

    if not registration.program:
        return JsonResponse({'program': 'not found'}, status=400)

    country = Country.objects.filter(pk=request_data['country_id']).first()
    if not country:
        return JsonResponse({'country': 'not found'}, status=400)

    state = State.objects.filter(pk=request_data['state_id']).first()
    if not state:
        return JsonResponse({'state': 'not found'}, status=400)

    city = City.objects.filter(pk=request_data['city_id']).first()
    if not city:
        return JsonResponse({'city': 'not found'}, status=400)

    period_display = ''
    for choices in Duration.REG_DURATION_CHOICES:
        if choices[0] == period:
            period_display = choices[1]
            break

    payment_plans = Attachment.objects.filter(
        category__name='payment plan form',
        registration=registration).values_list('name', flat=True)

    if responsible_option == 'o':
        if registration.custom_payment_responsible:
            responsible = registration.custom_payment_responsible
        else:
            responsible = Person()

        responsible.first_name = name_format(request_data['custom_name'])
        responsible.save()

        registration.custom_payment_responsible = responsible
        registration.payment_responsible = responsible
        registration.save()
    else:
        responsible = Person.objects.filter(
            pk=request_data['responsible']).first()
        if not responsible:
            return JsonResponse({'responsible': 'not found'}, status=400)

        registration.payment_responsible = responsible
        registration.save()

    witness = Person.objects.filter(pk=request_data['witness_id']).first()
    if not witness:
        return JsonResponse({'witness': 'not found'}, status=400)

    program_period = ProgramPeriod.objects.filter(
        program=registration.program,
        period_academic=registration.academic_period).first()

    program_base = registration.program

    finance = registration.registrationfinance
    finance.signature_date = signature_date
    finance.payment_plan = request_data['payment_plan']
    finance.payment_responsible = responsible
    finance.save()

    costumer = registration.costumer
    costumer.first_name = first_name
    costumer.last_name = last_name
    costumer.save()

    address = costumer.profile.address
    address.country = country
    address.state = state
    address.city = city
    address.save()

    number = int(finance.payment_plan)

    program_invoice, created = ProgramInvoice.objects.get_or_create(
        program_period__id=program_period.pk)

    payments = Payment.objects.filter(
        payment_form__number=(number - 1),
        payment_form__program_invoice=program_invoice,
        period=period).exclude(~Q(id__in=service_ids), is_service=True)

    has_flight = False
    for payment in payments:
        if payment.default_service == 1:
            has_flight = True
            break

    student_name = registration.get_customer_short_name().replace(' ', '_')

    filename = u"{}-PPF{}_{}".format(student_name, number,
                                     signature_date.strftime('%Y%m%d'))
    filename = _enumerate_file(filename, payment_plans)

    pdf_context = {
        'registration': registration,
        'program_base': program_base,
        'costumer': costumer,
        'consultant': registration.consultant,
        'finance': finance,
        'address': address,
        'program_period': program_period,
        'witness': witness,
        'responsible': responsible,
        'initials': _get_initials(responsible.get_full_name()),
        'payments': payments,
        'has_flight': has_flight,
        'number': number,
        'period_display': period_display
    }

    template = get_template('pdf/payment_plan.html')

    file = BytesIO()

    html = template.render(pdf_context)

    pisa.CreatePDF(html.encode('utf-8'),
                   dest=file,
                   encoding='utf-8',
                   link_callback=_fetch_resources)

    attachment = Attachment()
    attachment.registration = registration
    attachment.category = category
    attachment.file = ContentFile(file.getvalue(), filename + '.pdf')
    attachment.name = filename
    attachment.save()

    context = {}

    if responsible_option == 'o':
        context['custom_responsible'] = {
            'id': responsible.pk,
            'name': responsible.first_name
        }

    return JsonResponse(context)