Пример #1
0
    def _handler(self, account_slug, customer_slug, post=False):
        user = users.get_current_user()
        if user:
            account = Account.all()\
                .filter('user =', user).filter('slug =', account_slug).get()

            customer = Customer.all()\
                .filter('account =', account).filter('slug =', customer_slug).get()

            if post:
                form = CustomerForm(instance=customer, data=self.request.POST)
                if form.is_valid():
                    # Save the data, and redirect to the view page
                    form.save()
                    self.redirect(account.get_absolute_url())
            else:
                form = CustomerForm(instance=customer)

            path = os.path.join(os.path.dirname(__file__), 'templates/customer_details.html')
            self.response.out.write(template.render(path, {
                'account': account,
                'customer': customer,
                'form': form,
                'user': user,
                'logout_url': users.create_logout_url("/")
            }))
        else:
            self.redirect(users.create_login_url(self.request.uri))
Пример #2
0
def customer_register(request):
    customer_form = CustomerForm(request.POST)
    if customer_form.is_valid():
        customer.create(customer_form)
        verify_code_model = request.verify_code_meta['verify_code_model']
        verify_code_model.delete()
        return json_response_from_object(OK, CODE_MESSAGE.get(OK))
    else:
        return json_response(PARAM_REQUIRED, customer_form.errors)
Пример #3
0
def addcustomer():
    form = CustomerForm()
    if form.validate_on_submit():
        customer = Customer(name = form.name.data,
                            user = g.user.id)
        db.session.add(customer)
        db.session.commit()
        flash('customer rajoute')
        return redirect(url_for('addcustomer'))
    return render_template('customer.html',form = form)
Пример #4
0
def customer_add(request):
  if request.method == 'POST':
    form = CustomerForm(request.POST)
    if form.is_valid():
      c = form.save(commit=False)
      c.sn = generate_sn(prefix = 'CTM')
      c.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([c,]))
  else:
    form = CustomerForm()
    return render_to_response('modal/main_form.html',{'action':'Add', 'module':module, 'form': form},context_instance=RequestContext(request))
Пример #5
0
def customer_register(request):
    customer_form = CustomerForm(request.POST)
    if customer_form.is_valid():
        customer_dict = customer_form.cleaned_data
        if customer.isUnregistered(customer_dict['user_name']):
            customer.create(customer_dict)
            verify_code_model = request.verify_code_meta['verify_code_model']
            verify_code_model.delete()
            return json_response_from_object(OK, CODE_MESSAGE.get(OK))
        else:
            return json_response(USER_REGISTERED, CODE_MESSAGE.get(USER_REGISTERED))
    else:
        return json_response(PARAM_REQUIRED, customer_form.errors)
Пример #6
0
def customer_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    try:
      c = Customer.objects.get(sn=postdata.pop('sn')[0])
    except Customer.DoesNotExist:
      raise Http404(module + ' not found')
    form = CustomerForm(postdata, instance=c)
    if form.is_valid():
      c_saved = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([c_saved,]))
  else:
    return HttpResponse('Invalid request.')
Пример #7
0
def edit(request, id):
    customer = get_object_or_404(Customer, id=id)
    if request.method == 'POST':
        form = CustomerForm(request.POST, instance=customer)
        form_valid = form.is_valid()
        if form_valid:
            customer = form.save()
            customer.full_name = request.POST.get('name') + ' ' + request.POST.get('last_name')
            customer.save()

            return HttpResponseRedirect(reverse(mycustomers))

    else:
        form = CustomerForm(instance=customer)
    return render_to_response('customers/edit.html', locals(), context_instance=RequestContext(request))
Пример #8
0
def add(request):
    if request.method == 'POST':
        # if method was post (form submission), fill form with post data
        form = CustomerForm(request.POST)
        form_valid = form.is_valid()
        if form_valid:
            # if form is valid, save it and redirect back to mycustomers
            # commit=False tells form to not save the object to the database just yet and return it instead
            customer = form.save(commit=False)
            # set service_provider to the current customer before we save the object to the database
            customer.service_provider = request.user.service_provider
            customer.full_name = request.POST.get('name') + ' ' + request.POST.get('last_name')
            customer.last_reservation = None
            customer.save()
            return HttpResponseRedirect(reverse(mycustomers))
    else:
        # on get request create empty form
        form = CustomerForm()
    # render form - new (get request) or invalid with error messages (post request)
    return render_to_response('customers/add.html', locals(), context_instance=RequestContext(request))
Пример #9
0
def customer_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    try:
      # c = Customer.objects.get(sn=request.POST['sn'])
      c = Customer.objects.get(sn=postdata.pop('sn')[0])
    except Customer.DoesNotExist:
      raise Http404(module + ' not found')
    # else:
    #   return HttpResponse('Invalid request.')
    form = CustomerForm(postdata, instance=c)
    if form.is_valid():
      c_saved = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([c_saved,]))
  else:
    # if request.GET['id']:
    #   c = Customer.objects.get(pk=int(request.GET['id']))
    #   form = CustomerForm(instance=c)
    #   return render_to_response('modal/main_form.html',{'action':'Edit', 'module':module, 'form': form},context_instance=RequestContext(request))
    # else:
    return HttpResponse('Invalid request.')
Пример #10
0
def index(request, template):
    user = request.user
    devices = Device.objects.all()
    assets = Assets.objects.all()
    pag_list = []

    if user.get_profile().asset_edit:
        pag_list += assets
        if user.get_profile().parts_edit:
            pag_list += devices

    elif user.get_profile().parts_edit:
        pag_list += devices

    cus_form = CustomerForm()
    bom_form = BomForm()
    device_form = DeviceForm()
    asset_form = AssetsFrom()

    if request.method == "POST":
        if request.POST['subname'] == 'add_device':
            try:
                name = request.POST.getlist('bom_sns')
                if len(list(set(name))) == 1 and list(set(name))[0] == '':
                    #全为空
                    pass
                else:
                    new_device = Device()
                    dev = {}
                    for i in name:
                        try:
                            bom = Bom.objects.get(bom_sn=i)
                            if bom.bom_name == u'ser' and dev.has_key(u'ser'):
                                pass
                            else:
                                dev[bom.bom_name] = (bom, bom.bom_sn)

                        except Exception,e:
                            pass
                    if dev.has_key('ser'):
                        new_device.device_sn = dev['ser'][1]
                        bom = Bom.objects.get(bom_sn=dev['ser'][1])
                        bom.bom_status = 'inuse'
                        bom.save()
                        new_device.save()
                        for key in dev:
                            if key != 'ser':
                                new_device.device_boms.add(dev[key][0])
                                dev[key][0].bom_status = 'inuse'
                                dev[key][0].save()

                        new_device.save()
                        return HttpResponseRedirect(reverse('index'))
            except:
                pass
        elif request.POST['subname'] == 'add_cus':
            cus_form = CustomerForm(request.POST)
            if cus_form.is_valid():
                cus_form.save()
                return HttpResponseRedirect(reverse('index'))
            else:
                err_msg = 'error'
        elif request.POST['subname'] == 'add_asset':
            asset_form = AssetsFrom(request.POST)
            if asset_form.is_valid():
                asset_form.save()
                return HttpResponseRedirect(reverse('index'))
        else:
            bom_form = BomForm(request.POST)
            if bom_form.is_valid():
                bom_form.save()
                return HttpResponseRedirect(reverse('index'))
            else:
                err_msg = 'error'

    page = request.GET.get('page', '')
    paginator = Paginator(pag_list,'20')
    try:
        contacts = paginator.page(page)
    except PageNotAnInteger:
        contacts = paginator.page('1')
    except EmptyPage:
        contacts = paginator.page(paginator.num_pages)

    return TemplateResponse(request, template,{'cus_form':cus_form,
                                               'bom_form':bom_form,
                                               'devices':devices,
                                               'asset_form':asset_form,
                                               'contacts':contacts,
                                               'pages':paginator})
Пример #11
0
def newmultiple(request):
    '''This view corresponds to adding a new customer'''

    #  Creating title for the page
    title = 'New Customer'

    #  Creating blank customer record for now.
    customerObj = Customer()

    #  Creating new customer form
    customerForm = CustomerForm()

    #  Creating new subscription formset.
    subscription_formset = inlineformset_factory(Customer, Subscription, fields=('feed','length'),form=SubscriptionForm,extra=1)

    #  Returning form back with pre-populdated data
    context = {
        'title': title,
        'customerForm':customerForm,
        'subscription_formset': subscription_formset,
    }

    #  Bizare way of establishing now a relationship with the blank customer record.
    formset = subscription_formset(instance=customerObj)


    if request.POST:
        #  Creating new customer form object that will be sent to template.
        customerForm = CustomerForm(request.POST)

        #Grabbing email address from form.
        email = customerForm['email'].value()

        #  Saving customer form
        customerFormObj = customerForm.save(commit=False)

        #  Populating formset with post data.
        formset = subscription_formset(request.POST, instance=customerFormObj)

        success_message = 'SUCCESS'

        #  Checking to see if both forms are valid.
        if customerForm.is_valid() and formset.is_valid():

            #  Saving both customer form and subscription form.
            customerForm.save()

            formset.save()

            #  Filling in rest of needed data in local database.
            dbObj = dbInteraction(email)
            dbObj.createCredentials()

            #  Getting customer id this will be sent to the status view.
            customerID = dbObj.retrieveCustomerID()

            #  Getting domain name based on the username that is currently in the database for the user.
            esDomainName = dbObj.retrieveUsername()

            #  Creating Elasticsearch Domain, sending in domain name. This is what the elasticsearch cluster will be called.
            dbObj.createESDomain(str(esDomainName))
            
            #  Creating SQS queue for the data feed that was selected.
            dbObj.createQueueNames()

            #  Created the needed resources in amazon.
            amznObj = amzn(email)
            #  Creating queue in amazon
            amznObj.createQueues()
            #  Creating credentials in amazon.
            amznObj.createCredentials()

        else:
            #  Print errors associated with submitted
            error_message = 'ERROR PLEASE CORRECT FORM FIELD.'

            #Context creation this will hold a success message that indicates there was a problem with form submission.
            context = {
                'title': title,
                'customerForm':customerForm,
                'subscription_formset': formset,
                'success_message': error_message,
            }

            #  Sending site to site form to sitetosite.html template.
            return render(request, 'feeds/newmultiple.html', context)

        #  Creating first context this is a total success of all forms.
        context = {
            'title': title,
            'customerForm':customerForm,
            'subscription_formset': formset,
            'success_message': success_message,
            'customer_id': customerID
        }

        #  Sending site to site form to sitetosite.html template.
        return render(request, 'feeds/newmultiple.html', context)


    #  Sending site to site form to sitetosite.html template.
    return render(request, 'feeds/newmultiple.html', context)