Beispiel #1
0
def manage_customer_from_project(request, id=None):
    """
        Add/Modify the customer in project
    """
    customer = address = None
    if request.method == 'POST':
        id = request.POST.get('customer_id', None)
    if id:
        customer = get_object_or_404(BusinessUnit, pk=id)
        address = customer.address
    if request.method == 'POST':
        customer_form = CustomerForm(request.POST, instance=customer)
        address_form = AddressForm(request.POST, instance=address)
        if customer_form.is_valid() and address_form.is_valid():
            address = address_form.save()
            customer = customer_form.save(address=address)
        if request.is_ajax():
            if customer_form.is_valid() and address_form.is_valid():
                data = [{'id': customer.pk, 'name': customer.__unicode__()}]
            else:
                data = [{'error': customer_form.errors}]
            return HttpResponse(simplejson.dumps(data),
                                mimetype='application/json')
    else:
        customer_form = CustomerForm(instance=customer)
        address_form = AddressForm(instance=address)
    return render(
        request,
        'customer_from_project.html',
        {
            'customer_form': customer_form,
            'address_form': address_form,
            'customer_id': id
        },
    )
Beispiel #2
0
def manage_business_unit(request, id=None, RedirectView=business_unit_list):
    business_unit = None
    address = None
    if id:
        business_unit = get_object_or_404(BusinessUnit, pk=id)
        address = business_unit.address

    if request.method == 'POST':
        form = BusinessUnitForm(request.POST, instance=business_unit)
        address_form = AddressForm(request.POST, instance=address)
        if form.is_valid() and address_form.is_valid():
            address = address_form.save()
            form.save(address=address)
            messages.success(request, _('Business Unit Saved Sucessfully'))
            return HttpResponseRedirect(reverse(RedirectView))

    else:
        form = BusinessUnitForm(instance=business_unit)
        address_form = AddressForm(instance=address)

    return render(
        request,
        'manage_business_unit.html',
        {
            'form': form,
            'address_form': address_form
        },
    )
Beispiel #3
0
def manage_customer_contact_from_project(request, id=None):
    """
        Add/Modify customer contact in project
    """
    contact = address_contact = contact_profile = None
    customer_id = ''
    if request.method == 'POST':
        id = request.POST.get('contact_profile_id', '')
    if id:
        contact_profile = get_object_or_404(UserProfile, pk=id)
        address_contact = contact_profile.address_contact
        contact = contact_profile.user
        customer_id = contact_profile.business_unit.all()[0].pk
    if request.method == 'POST':
        contact_form = CustomerContactForm(request.POST, instance=contact)
        address_contact_form = AddressForm(request.POST,
                                           instance=address_contact)
        contact_profile_form = CustomerContactProfileForm(
            request.POST, instance=contact_profile)
        if contact_form.is_valid() and address_contact_form.is_valid() \
            and contact_profile_form.is_valid():
            contact = contact_form.save()
            address_contact = address_contact_form.save()
            contact_profile = contact_profile_form.save(
                contact=contact, address=address_contact)
            data = [{
                'id': contact_profile.pk,
                'name': contact_profile.user.first_name
            }]
        else:
            data = [{'error': contact_profile_form.errors}]
        return HttpResponse(simplejson.dumps(data),
                            mimetype='application/json')
    else:
        contact_form = CustomerContactForm(instance=contact)
        address_contact_form = AddressForm(instance=address_contact)
        contact_profile_form = CustomerContactProfileForm(
            instance=contact_profile)
    return render(
        request, 'customer_contact_from_project.html', {
            'contact_profile': contact_profile,
            'contact_form': contact_form,
            'address_contact_form': address_contact_form,
            'contact_profile_form': contact_profile_form,
            'customer_id': customer_id
        })
Beispiel #4
0
def manage_client(request, id=None):
    business_unit = None
    address = project = None
    task_id = ''
    project_id = request.GET.get('id', '')
    project_is_approve = request.GET.get('approve', '')
    if project_id:
        project = Project.objects.get(code=project_id)
    if id:
        business_unit = get_object_or_404(BusinessUnit, pk=id)
        address = business_unit.address

    if request.method == 'POST':
        form = ClientForm(request.POST, instance=business_unit)
        address_form = AddressForm(request.POST, instance=address)
        Name = request.POST.get('name')
        print "Name ", Name
        Client = BusinessUnit.objects.filter(name=Name)
        print "Hello", len(Client)
        if (len(Client) > 0):
            messages.error(request, _('Client Name Already Exists'))
        else:
            if form.is_valid() and address_form.is_valid():
                address = address_form.save()
                task = form.save(address=address)
                task_id = task.id
                messages.success(request, _('Client Saved Successfully'))
                print task_id

    else:
        form = ClientForm(instance=business_unit)
        address_form = AddressForm(instance=address)


#    print request
    return render(
        request, 'client_create.html', {
            'form': form,
            'address_form': address_form,
            'project': project,
            'task_id': task_id
        })
Beispiel #5
0
def manage_myprofile(request):
    """
        Modification of profile of the user.
    """
    profile = request.user.get_profile()
    users_image = profile.users_image
    if not profile:
        raise Http404
    if request.method == 'POST':
        profile_form = MyProfileForm(request.POST, instance = profile)
        address_contact_form = AddressForm(request.POST,
            instance = profile.address_contact, prefix = 'contact')
        address_permanent_form = AddressForm(request.POST,
            instance = profile.address_permanent, prefix = 'permanent')

        if profile_form.is_valid() and address_contact_form.is_valid() \
            and address_permanent_form.is_valid():
            address_contact = address_contact_form.save()
            address_permanent = address_permanent_form.save()

            profile_form.save(address_contact = address_contact,
                address_permanent = address_permanent)
            messages.success(request,
                _('your profile details saved sucessfully'))
    else:
        profile_form = MyProfileForm(instance = profile)
        address_contact_form = AddressForm(instance = profile.address_contact,
            prefix = 'contact')
        address_permanent_form = AddressForm(instance
            = profile.address_permanent, prefix = 'permanent')

    return render(request, 'myprofile.html', {
        'profile_form': profile_form,
        'address_contact_form': address_contact_form,
        'address_permanent_form': address_permanent_form,
        'users_image': users_image
        },
        )# Create your views here.