Exemplo n.º 1
0
def check_NGRate():
    NG_monitor_type = "NG_range"
    parmeter_stands = Configuration.objects.get(Type=NG_monitor_type)
    # limit_value = [parmeter_stands.Min, parmeter_stands.Max]
    parmeter_stands_min = str(parmeter_stands.Min)
    parmeter_stands_receiver = str(parmeter_stands.Reminders)
    sql_remenber = 'select "SN" from "PartItem" where "NGRate" >= \'' + parmeter_stands_min + '\''
    cur = connection.cursor()
    cur.execute(sql_remenber)
    data = cur.fetchall()
    data = str(data)
    if len(data) > 0:
        email_1 = []
        receiver_list = parmeter_stands_receiver.split(',')
        for i in range(len(receiver_list)):
            email_1.append(receiver_list[i] + '@wistron.com')
        subject = "NG reported rate of abnormal equipment"
        content = """
<pre>
Dear All,
    The follow equipment NG rate have reached or exceed the standard.

    Please click the link below to see the detail information:
    <a href="http://10.41.95.106:90/index">index AEMSLite</a>


--------------------------------------------------------------------------------------------
    THIS EMAIL WAS SENT BY AEMS Lite SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
</pre>
"""
        mail.sendmail(email_1, content, subject)
    else:
        return restful.ok(message="partName is normal")
Exemplo n.º 2
0
def check_NGRate():
    try:
        NG_monitor_type = "NG_range"
        parmeter_stands = Configuration.objects.get(Type=NG_monitor_type)
        parmeter_stands_min = str(parmeter_stands.Min)
        parmeter_stands_max = str(parmeter_stands.Max)
        parmeter_stands_receiver = str(parmeter_stands.Reminders)
        sql_warning = 'select count(*) from "PartItem" where "UseStatus"=\'normal\' and "NGRate" >= \'' + parmeter_stands_min + '\' and "NGRate" <= \'' + parmeter_stands_max + '\''
        sql_danger = 'select count(*) from "PartItem" where "UseStatus"=\'normal\' and "NGRate" > \'' + parmeter_stands_max + '\''
        cur = connection.cursor()
        cur.execute(sql_warning)
        data_warning = cur.fetchall()
        cur = connection.cursor()
        cur.execute(sql_danger)
        data_danger = cur.fetchall()
        Total = int(data_warning[0][0]) + int(data_danger[0][0])
        Warning = data_warning[0][0]
        danger = data_danger[0][0]
        if int(data_warning[0][0]) > 0 or int(data_danger[0][0]) > 0:
            email_1 = []
            receiver_list = parmeter_stands_receiver.split(',')
            mail_user_data_info = list(
                User.objects.filter(Name__in=receiver_list).values("Email"))
            for i in range(0, len(mail_user_data_info)):
                email_1.append(mail_user_data_info[i]['Email'])
            # for i in range(len(receiver_list)):
            #     email_1.append(receiver_list[i] + '@wistron.com')
            subject = "AEMS Lite System Notification for NG Reported "
            content = """
<pre>
Dears,
    AEMS Lite system found that the equipment NG rate have reached or exceed the standard.
    Total: """ + str(Total) + """
    Exceeding Standard: """ + str(danger) + """
    Warning: """ + str(Warning) + """


THIS EMAIL WAS SENT BY PTS SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
AEMS Lite System http://10.41.95.89:90/index/
</pre>
"""
            mail.sendmail(email_1, content, subject)
            return [Total, Warning, danger]
        else:
            return [0, 0, 0]
    except Exception as e:
        return repr(e)
Exemplo n.º 3
0
def merge_form_sub(request):
    if request.method == "POST":
        checked_id_array = request.POST.getlist('ids[]')
        own_id = request.session.get('user_Id')
        time_id = int(time.time())
        try:
            budget_user = BudgetCodeForm.objects.filter(
                Id__in=checked_id_array).values("Signer").distinct("Signer")
            singer_num = budget_user.count()
            if singer_num == 1:
                BudgetCodeForm.objects.filter(
                    Id__in=list(checked_id_array)).update(MergeId=time_id,
                                                          BillingType=1,
                                                          Status="Process")
                # 邮件发送合并表单的要签核的信息给签核人
                subject = "Apply Budge Code eForm to You Review"
                budget_user = list(budget_user)
                sign_user = User.objects.get(Name=budget_user[0]['Signer'])
                email_1 = sign_user.Email
                sign_user_name = sign_user.Name
                apply_user = User.objects.get(Id=own_id)
                apply_user = apply_user.Name
                content = """
<pre>
Dear """ + sign_user_name + """,
    """ + apply_user + """apply a maintain_monitor code eform waiting for your review/approval.
    You can click the below link to approve or reject. Thank you!
    <a href="http://10.41.95.106:90/index">index-sign AEMSLite</a>
    


    THIS EMAIL WAS SENT BY AEMS Lite SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
    AEMS Lite System <a href="http://10.41.95.106:90/index/">
</pre>
"""
                mail.sendmail([
                    email_1,
                ], content, subject)
                return restful.ok(message='BudgetCodeForm merged success')
            else:
                return restful.params_error(
                    message="merged form signer different")
        except Exception as e:
            return restful.params_error(message=repr(e))
Exemplo n.º 4
0
def budget_delete_type(request):
    if request.method == "POST":
        try:
            del_id = request.POST['del_id']
            budget_ob = BudgetCodeForm.objects.get(Id=del_id)
            if budget_ob.Status == "Draft" or budget_ob.Status == "Reject" or budget_ob.Status == "Cancel":
                BudgetCodeForm.objects.filter(Id=del_id).delete()
                return restful.ok(message="form delete success")

            if budget_ob.Status == "Process":
                BudgetCodeForm.objects.filter(Id=del_id).update(
                    Status="Cancel", MergeId=None)
                cancel_budget = BudgetCodeForm.objects.get(Id=del_id)
                cancel_budget_Name = cancel_budget.Signer
                cancel_budget_principal = cancel_budget.Pic

                mail_user = User.objects.get(Name=cancel_budget_Name)
                mail_principal = User.objects.get(Name=cancel_budget_principal)
                email_1 = mail_user.Email
                email_2 = mail_principal.Email
                subject = "Reject Budge Code eForm"
                content = """
<pre>
Dear """ + str(cancel_budget_principal) + """,
    """ + str(cancel_budget_Name
                ) + """has canceled the maintain_monitor code eform.
    The reason is:""" + str(cancel_budget.SignRemarks) + """




    -------------------------------------------------------------------------------
    THIS EMAIL WAS SENT BY PTS SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
    AEMS Lite System <a href="http://10.41.95.106:90/index/">
</pre>
 """
                mail.sendmail([email_1, email_2], content, subject)
                return restful.ok(message='BudgetCodeForm cancel success',
                                  data={})
        except Exception as e:
            return restful.params_error(message=repr(e))
Exemplo n.º 5
0
def merge_rejected(request):
    if request.method == "POST":
        bud_id = request.POST['bud_id']
        bud_merged_id = request.POST['bud_merged_id']
        bud_budgetcode = request.POST['budget_cod_text']
        bud_signremarks = request.POST['budget_text']
        sign_id = request.session['user_Id']
        try:
            user = User.objects.get(Id=sign_id)
            sign_budget_ob = BudgetCodeForm.objects.get(Id=bud_id)
            if user.Name != sign_budget_ob.Signer:
                return restful.params_error(message="you need connect admin")
            else:
                if bud_merged_id == "null":
                    if sign_budget_ob.Status == "Cancel":
                        return restful.params_error("this form had Canceled")
                    else:
                        BudgetCodeForm.objects.filter(Id=bud_id).update(
                            BudgetCode=bud_budgetcode,
                            SignRemarks=bud_signremarks,
                            Status='Reject')
                        sign_pincipal = sign_budget_ob.Pic
                        mail_user = User.objects.get(Name=sign_pincipal)
                        email_1 = mail_user.Email
                        subject = "Reject Budge Code eForm"
                        content = """
<pre>
Dear """ + sign_pincipal + """,
    """ + sign_budget_ob.Signer + """has rejected your maintain_monitor code eform.
The reason is:""" + bud_signremarks + """




-------------------------------------------------------------------------------
THIS EMAIL WAS SENT BY AEMS Lite SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
</pre>
"""
                        mail.sendmail([
                            email_1,
                        ], content, subject)
                        return restful.ok(message='BudgetCodeForm rejected')
                else:
                    if sign_budget_ob.Status == "Cancel":
                        return restful.params_error("this form had Cancel")
                    else:
                        BudgetCodeForm.objects.filter(
                            MergeId=bud_merged_id).update(
                                BudgetCode=bud_budgetcode,
                                SignRemarks=bud_signremarks,
                                Status='Reject')
                        sign_pincipal = sign_budget_ob.Pic
                        mail_user = User.objects.get(Name=sign_pincipal)
                        # 此表单为签核同意的表单提交信息 发送email给负责人
                        email_1 = mail_user.Email
                        subject = "Reject Budge Code eForm"
                        content = """
<pre>
Dear """ + sign_pincipal + """,
    """ + sign_budget_ob.Signer + """has rejected your maintain_monitor code eform.
The reason is:""" + bud_signremarks + """




-------------------------------------------------------------------------------
THIS EMAIL WAS SENT BY AEMS Lite SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
</pre>
"""
                        mail.sendmail([
                            email_1,
                        ], content, subject)
                        # num = BudgetCodeForm.objects.filter(Status="Process", SignerId=sign_id).count()
                        # num1 = []
                        # num1.insert(0, num)
                        return restful.ok(message='BudgetCodeForm rejected')
        except Exception as e:
            return restful.params_error(message=repr(e))
Exemplo n.º 6
0
def merge_signed(request):
    if request.method == "POST":
        bud_id = request.POST['bud_id']
        bud_merged_id = request.POST['bud_merged_id']
        bud_budgetcode = request.POST['budget_cod_text']
        bud_signremarks = request.POST['budget_text']
        sign_id = request.session['user_Id']
        try:
            user = User.objects.get(Id=sign_id)
            sign_budget_ob = BudgetCodeForm.objects.get(Id=bud_id)

            if user.Name != sign_budget_ob.Signer:
                return restful.params_error(message="you need connect admin")
            else:
                if bud_merged_id == "null":
                    bud_obj = BudgetCodeForm.objects.get(Id=bud_id)
                    if bud_obj.Status == "Cancel":
                        return restful.params_error("this form had Canceled")
                    else:
                        BudgetCodeForm.objects.filter(Id=bud_id).update(
                            BudgetCode=bud_budgetcode,
                            SignRemarks=bud_signremarks,
                            Status='Approve')
                        sign_pincipal = sign_budget_ob.Pic
                        mail_user = User.objects.get(Name=sign_pincipal)
                        email_1 = mail_user.Email
                        subject = "Approve Budge Code eForm"
                        content = """
<pre>
Dear """ + sign_pincipal + """,
    """ + sign_budget_ob.Signer + """has approved your maintain_monitor code eform. 
     please seen the below link address:

    Please click the link below to see the detail information:
    <a href="http://10.41.95.106:90/index">index AEMS Lite</a>


-----------------------------------------------------------------------------------------
THIS EMAIL WAS SENT BY AEMS Lite SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
</pre>
 """
                        mail.sendmail([
                            email_1,
                        ], content, subject)
                        return restful.ok(
                            message='BudgetCodeForm approved success')
                else:
                    bud_ob_merged = BudgetCodeForm.objects.get(Id=bud_id)
                    if bud_ob_merged.Status == "Cancel":
                        return restful.params_error("this form had Cancel")
                    else:
                        BudgetCodeForm.objects.filter(
                            MergeId=bud_merged_id).update(
                                BudgetCode=bud_budgetcode,
                                SignRemarks=bud_signremarks,
                                Status='Approve')
                        sign_pincipal = sign_budget_ob.Pic
                        mail_user = User.objects.get(Name=sign_pincipal)
                        email_1 = mail_user.Email
                        subject = "Approve Budge Code eForm"
                        content = """
<pre>
Dear """ + sign_pincipal + """,
    """ + sign_budget_ob.Signer + """has approved your maintain_monitor code eform. 
     please seen the below link address:

    Please click the link below to see the detail information:
    <a href="http://10.41.95.106:90/index">index AEMS Lite</a>


-----------------------------------------------------------------------------------------
THIS EMAIL WAS SENT BY AEMS Lite SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
</pre>
"""
                        mail.sendmail([
                            email_1,
                        ], content, subject)
                        return restful.ok(
                            message='BudgetCodeForm signed success')
        except Exception as e:
            return restful.params_error(message=repr(e))
Exemplo n.º 7
0
    def post(self, request):
        bud_id = request.POST.get('bud_id')
        bud_depart = request.POST.get('Department')
        bud_req = request.POST.get('Remark')
        bud_num_type = request.POST.get('bud_num_type')
        bud_num = request.POST.get('bud_num')
        bud_time = request.POST.get('bud_time')
        bud_principal = request.POST.get('bud_principal')
        bud_machine_name = request.POST.get('bud_machine_name')
        bud_machine_type = request.POST.get('bud_machine_type')
        bud_request_type = request.POST.get('bud_request_type')
        bud_price = request.POST.get('bud_price')
        bud_qty = request.POST.get('bud_qty')
        bud_qty_type = request.POST.get('bud_qty_type')
        # bud_total_price = request.POST['bud_total_price']
        bud_money_type = request.POST.get('bud_money_type')
        bud_customer = request.POST.get('bud_customer')
        bud_mach_type = request.POST.get('bud_mach_type')
        bud_project_code = request.POST.get('bud_project_code')
        #
        bud_user = request.POST.get('bud_user')
        bud_reason = request.POST.get('bud_reason')
        created_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        # upload_tool = request.POST.get('upload_tool')
        own_id = request.session.get('user_Id')
        # name_current = own_id.Name
        # url_num = genurlnum()
        time_num = int(time.time())
        time_num = str(time_num)
        file = request.FILES.get('upload_file')
        if len(bud_time) == 0:
            bud_time = None
        if file:
            file_name = file.name
            file_sp_name = file_name.split('.')[0]
            file_ven_name = file_sp_name + time_num + '.' + file_name.split(
                '.')[1]
            file_path = os.path.join(settings.MEDIA_ROOT, file_ven_name)
            with open(file_path, 'wb') as f:
                for chunk in file.chunks():
                    f.write(chunk)
            f.close()
            file_url = request.build_absolute_uri(settings.MEDIA_URL +
                                                  file_ven_name)
        else:
            file_sp_name = ""
            file_url = ""
        if bud_id != "":
            try:
                depart = Department.objects.get(Department=bud_depart)
                depart_id = depart.Id
                user = User.objects.get(Name=bud_user)
                user_id = user.Id
                cus = Customer.objects.get(Customer=bud_customer)
                cus_id = cus.Id
                pic_user = User.objects.get(Name=bud_principal)
                pic_user_id = pic_user.Id
                BudgetCodeForm.objects.filter(Id=bud_id).update(
                    DepartmentId=depart_id,
                    Department=bud_depart,
                    Remark=bud_req,
                    Attachment=file_sp_name,
                    ApplyDate=created_time,
                    ExternalNumberEffectiveDate=bud_time,
                    ExternalNumberType=bud_num_type,
                    ExternalNumber=bud_num,
                    PicId=pic_user_id,
                    Pic=bud_principal,
                    ProductName=bud_machine_name,
                    Model=bud_machine_type,
                    PurchaseType=bud_request_type,
                    UnitPrice=bud_price,
                    Quantity=bud_qty,
                    Unit=bud_qty_type,
                    Currency=bud_money_type,
                    CustomerId=cus_id,
                    Customer=bud_customer,
                    TypeOfMachine=bud_mach_type,
                    ProjectCode=bud_project_code,
                    ApplyReason=bud_reason,
                    SignerId=user_id,
                    Signer=bud_user,
                    Status='Process',
                    CreatedTime=created_time,
                    UpdatedTime=UpdatedTime,
                    OwnerId=own_id,
                    AttachmentPath=file_url)
                # 邮件发送创建的表单给签核的人去签核表单信息
                subject = "Apply Budge Code eForm to You Review"
                email_1 = user.Email
                email_2 = pic_user.Email
                apply_er = User.objects.get(Id=own_id).Name
                content = """
<pre>
Dear """ + bud_user + """,
    """ + apply_er + """modify a maintain_monitor code eform waiting for your review/approval.
    You can click the below link to approve or reject. Thank you!
    <a href="http://10.41.95.106:90/index">index-sign AEMSLite</a>
    


    THIS EMAIL WAS SENT BY AEMS Lite SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
    AEMS Lite System <a href="http://10.41.95.106:90/index/">
</pre>
"""
                mail.sendmail([email_1, email_2], content, subject)
                return restful.ok(message='BudgetCodeForm modify success')
            except Exception as e:
                return restful.params_error(message=repr(e))
        else:
            try:
                depart = Department.objects.get(Department=bud_depart)
                depart_id = depart.Id
                user = User.objects.get(Name=bud_user)
                user_id = user.Id
                cus = Customer.objects.get(Customer=bud_customer)
                cus_id = cus.Id
                pic_user = User.objects.get(Name=bud_principal)
                pic_user_id = pic_user.Id
                BudgetCodeForm.objects.create(
                    DepartmentId=depart_id,
                    Department=bud_depart,
                    Remark=bud_req,
                    Attachment=file_sp_name,
                    ApplyDate=created_time,
                    ExternalNumberEffectiveDate=bud_time,
                    ExternalNumberType=bud_num_type,
                    ExternalNumber=bud_num,
                    PicId=pic_user_id,
                    Pic=bud_principal,
                    ProductName=bud_machine_name,
                    Model=bud_machine_type,
                    PurchaseType=bud_request_type,
                    UnitPrice=bud_price,
                    Quantity=bud_qty,
                    Unit=bud_qty_type,
                    Currency=bud_money_type,
                    CustomerId=cus_id,
                    Customer=bud_customer,
                    TypeOfMachine=bud_mach_type,
                    ProjectCode=bud_project_code,
                    ApplyReason=bud_reason,
                    SignerId=user_id,
                    Signer=bud_user,
                    Status='Process',
                    CreatedTime=created_time,
                    UpdatedTime=UpdatedTime,
                    OwnerId=own_id,
                    AttachmentPath=file_url)
                # 邮件发送创建的表单给签核的人去签核表单信息
                subject = "Apply Budge Code eForm to You Review"
                email_1 = user.Email
                email_2 = pic_user.Email
                apply_er = User.objects.get(Id=own_id).Name
                content = """
<pre>
Dear """ + bud_user + """,
    """ + apply_er + """create a maintain_monitor code eform waiting for your review/approval.
    You can click the below link to approve or reject. Thank you!
    <a href="http://10.41.95.106:90/index">index-sign AEMSLite</a>
    


    THIS EMAIL WAS SENT BY AEMS Lite SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
    AEMS Lite System <a href="http://10.41.95.106:90/index/">
</pre>
"""
                mail.sendmail([email_1, email_2], content, subject)
                return restful.ok(message='BudgetCodeForm create success')
            except Exception as e:
                return restful.params_error(message=repr(e))
Exemplo n.º 8
0
    def post(self, request):
        password = genPassword()
        employee_id = request.POST['userid']
        name = request.POST['username']
        email = request.POST['mail']
        role = request.POST['role']
        department = request.POST['department']
        updated_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        created_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        try:
            user = User.objects.exclude(EmployeeId=employee_id).filter(
                Email=email)
            user_employee = User.objects.get(EmployeeId=employee_id)
            if len(user) != 0:
                return restful.params_error(message="user email had used")
            if len(user) == 0 and user_employee:
                User.objects.filter(EmployeeId=employee_id).update(
                    IsActivated=True,
                    Name=name,
                    Password=password,
                    Email=email,
                    Role=role,
                    CreatedTime=created_time,
                    UpdatedTime=updated_time)
                subject = "Inform Your New Password in AEMS Lite System"
                content = """
<pre>
Dear """ + str(name) + """,
    AEMS Lite System has automatically generated a new password for you:
    Your Account is: """ + employee_id + """
    Your Password is:""" + password + """
    Please use your e-mail as user name and this password to login AEMSLite system. After you login, 
    please remember to change it.
    <a href="http://10.41.95.106:90/login">Login AEMS Lite System</a>

   ---------------------------------------------------------------------------------------
    THIS EMAIL WAS SENT BY AEMS Lite SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
</pre>
 """

                mail.sendmail([
                    email,
                ], content, subject)
                return restful.ok(message="user add success")
        except:
            try:
                user = User.objects.get(Name=name)
                if user:
                    return restful.params_error(message='user name had used')
            except:
                try:
                    user = User.objects.get(Email=email)
                    if user:
                        return restful.params_error(
                            message="user email had used")
                except:
                    try:
                        department_ob = Department.objects.get(
                            Department=department)
                        department_id = department_ob.Id
                        User.objects.create(EmployeeId=employee_id,
                                            Name=name,
                                            Password=password,
                                            Email=email,
                                            Role=role,
                                            CreatedTime=created_time,
                                            UpdatedTime=updated_time,
                                            DepartmentId=department_id)
                        subject = "Inform Your New Password in AEMS Lite System"
                        content = """
<pre>
Dear """ + str(name) + """,
    AEMS Lite System has automatically generated a new password for you:
    Your Account is: """ + employee_id + """
    Your Password is:""" + password + """
    Please use your e-mail as user name and this password to login AEMSLite system. After you login, 
    please remember to change it.
    <a href="http://10.41.95.106:90/login">Login AEMS Lite System</a>

   ---------------------------------------------------------------------------------------
    THIS EMAIL WAS SENT BY AEMS Lite SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
</pre>
"""

                        mail.sendmail([
                            email,
                        ], content, subject)
                        return restful.ok(message='User created success')
                    except:
                        User.objects.create(EmployeeId=employee_id,
                                            Name=name,
                                            Password=password,
                                            Email=email,
                                            Role=role,
                                            CreatedTime=created_time,
                                            UpdatedTime=updated_time)
                        subject = "Inform Your New Password in AEMS Lite System"
                        content = """
<pre>
Dear """ + str(name) + """,
    AEMS Lite System has automatically generated a new password for you:
    Your Account is: """ + employee_id + """
    Your Password is:""" + password + """
    Please use your e-mail as user name and this password to login AEMSLite system. After you login, 
    please remember to change it.
    <a href="http://10.41.95.106:90/login">Login AEMS Lite System</a>

   ---------------------------------------------------------------------------------------
    THIS EMAIL WAS SENT BY AEMS Lite SERVER AUTOMATICALLY. PLEASE DON'T DIRECTLY REPLY!!!
</pre>
 """
                        mail.sendmail([
                            email,
                        ], content, subject)
                        return restful.ok(message='User add success')