예제 #1
0
def cost():
    tool = Isilon_Tools()
    name = session['selected']
    myform = MyForm()
    myform.name = name[1]

    if myform.validate_on_submit():
        '''Set variables from form data for the database'''
        cust_fname = myform.cust_fname.data
        cust_lname = myform.cust_lname.data
        cost_cent = myform.cost_center.data
        work_order = myform.work_order.data
        sc_account = current_user

        try:
            '''Get quota info'''
            quota_info = tool.get_quota_info(name)

            '''Set current quota == current_quota + 100GB'''
            current_thresh = int(quota_info['threshold'])
            tool.update_quota(name, current_thresh)
            new_thresh = tool.get_quota_size(name)
            new_thresh_GB = pro_utils.convert_to_GB(new_thresh)
        except:
            return render_template('404.html', error="Could not add space to quota....")

        '''Add data to database'''
        quota_add = Quota_Update.create(
                cust_fname=cust_fname,
                cust_lname=cust_lname,
                sc_account=sc_account,
                cost_cent=cost_cent,
                work_order=work_order,
                quota_path=quota_info['path'],
                quota_id=name,
                quota_before=current_thresh,
                quota_after=new_thresh
            )

        '''Send email'''
        cost_dict = {
                'cust_fname': cust_fname,
                'cust_lname': cust_lname,
                'cost_cent': cost_cent,
                'quota_id': name,
                'work_order': work_order,
                'sc_account': sc_account,
                'quota_before': current_thresh,
                'quota_after': new_thresh,
                'quota_path': quota_info['path']
            }

        email_status = pro_utils.send_email(cost_dict)

        return render_template('finish.html', name=name,
            new_limit=new_thresh_GB, email_status=email_status)

    print myform.errors
    return render_template('cost.html', form=myform,
        btn_txt="Add Space", title="Enter Customer Name & Cost Center")