Exemplo n.º 1
0
def user_register(request):
    form = UserCreationForm(request.POST or None)
    if form.is_valid():
        username = form.cleaned_data.get('username')
        email = form.cleaned_data.get('email')
        password = form.cleaned_data.get('password1')
        new_user=MyUser.objects.create_user(
            username=username,
            email=email,
            password=password
            )
        # send signal to admin to let him know that a new user's registered
        notify.send(
        sender=new_user, 
        recipient=MyUser.objects.get(username='******'), 
        verb='registered',
        ) 
        messages.success(request, 'Thanks for your register, now you can login your account.')
        return redirect('login')
    context = {
        'form':form,
        'action':'',
        'btn':'Register',
    }
    return render(request, 'account/forms.html', context)
Exemplo n.º 2
0
 def make_invoice_submit(self, request, queryset):
     """
     批量提交开票申请
     """
     i = ''
     n = 0
     for obj in queryset:
         if not obj.submit:
             i = fm_Invoice.objects.create(invoice=obj)
             obj.submit = True
             obj.save()
             #新的开票申请 通知财务部5
             for j in User.objects.filter(groups__id=5):
                 notify.send(request.user,
                             recipient=j,
                             verb='提交了开票申请',
                             description="合同名称:%s %s" %
                             (obj.contract.name, obj.period))
         else:
             n += 1
     if i:
         self.message_user(request, '%s 个开票申请已成功提交到财务' % i)
     if n:
         self.message_user(request,
                           '%s 个开票申请已提交过,不能再次提交' % n,
                           level=messages.ERROR)
Exemplo n.º 3
0
 def save_formset(self, request, form, formset, change):
     instances = formset.save(commit=False)
     for obj in formset.deleted_objects:
         obj.delete()
     if instances:
         sum_income = formset.instance.__total__
         invoice_amount = instances[0].invoice.invoice.amount
         obj_invoice = Invoice.objects.get(id=instances[-1].invoice.id)
         invoice_in_contract = Invoice.objects.filter(invoice__contract__id = instances[-1].invoice.invoice.contract.id)
         obj_contract = Contract.objects.get(id=instances[-1].invoice.invoice.contract.id)
         try:
             obj_project = Project.objects.get(contract__id=instances[-1].invoice.invoice.contract.id)
         except:
             obj_project = False
         if sum_income <= invoice_amount:
             for instance in instances:
                 instance.save()
             formset.save_m2m()
             obj_invoice.income = sum_income
             #最后一次到账的日期,更新到财务发票的到款日期
             obj_invoice.income_date = instances[-1].date
             obj_invoice.save()
             #更新合同的首尾款到款日期、到款总额、
             if instances[-1].invoice.invoice.period == "FIS":
                 obj_contract.fis_date = instances[-1].date
                 #如果首款有多张发票
                 invoice_in_contract = invoice_in_contract.filter(invoice__period="FIS")
                 if invoice_in_contract:
                     sum_income = sum([invoice_temp.income for invoice_temp in invoice_in_contract if invoice_temp.income])
                 obj_contract.fis_amount_in = sum_income
                 #合同的首款<bill金额的总和,在项目管理中的状态为待处理,尾款已到。
                 if obj_project:
                     if (sum_income >= obj_contract.fis_amount) and (obj_project.status < 2):
                         obj_project.status = 2
             if instances[-1].invoice.invoice.period == "FIN":
                 obj_contract.fin_date = instances[-1].date
                 # 如果尾款有多张发票
                 invoice_in_contract = invoice_in_contract.filter(invoice__period="FIN")
                 if invoice_in_contract:
                     sum_income = sum([invoice_temp.income for invoice_temp in invoice_in_contract if invoice_temp.income])
                 obj_contract.fin_amount_in = sum_income
                 if obj_project:
                     if sum_income >= obj_contract.fin_amount and (obj_project.status < 10):
                         obj_project.status = 3
             obj_contract.save()
             if obj_project:
                 obj_project.save()
             #新的到账 通知财务部5
             for j in User.objects.filter(groups__id=5):
                 notify.send(request.user, recipient=j, verb='填写一笔新到账',description="发票号:%s 到账金额:%s"%(obj_invoice,sum_income))
             #新到账 通知相应的销售
             notify.send(request.user,recipient=obj_invoice.invoice.contract.salesman,verb='填写一笔新到账',description="发票号:%s 到账金额:%s"%(obj_invoice,sum_income))
         else:
             messages.set_level(request, messages.ERROR)
             self.message_user(request, '进账总额 %.2f 超过开票金额 %.2f' % (sum_income, invoice_amount),
                               level=messages.ERROR)
Exemplo n.º 4
0
def notify_comment_or_reply_create(self,
                                   comment_form,
                                   main_comment,
                                   lecture,
                                   context,
                                   redirect_link=None):
    if main_comment is not None:
        main_comment = int(main_comment)

    try:
        main_comment_instance = Comment.objects.get(id=main_comment)
    except Comment.DoesNotExist:
        main_comment = None
    else:
        main_comment = main_comment_instance

    if comment_form.is_valid():
        comment_content = comment_form.cleaned_data['content']
        new_comment = Comment.objects.create_comment(
            user=self.request.user,
            content=comment_content,
            path=lecture.get_comment_path,
            lecture=lecture,
            main_comment=main_comment)

        #get a list of affected users
        affected_users = new_comment.get_affected_users
        print(affected_users)
        if main_comment is None:
            #then it's a question
            creator = context['current_course'].uploaded_by

            notify.send(
                sender=self.request.user,
                verb=f"{self.request.user.email} asked a question on {lecture}",
                action=new_comment,
                target=lecture,
                recipient=creator,
                affected_users=affected_users)

        else:
            #it's a reply
            recipient = main_comment.user
            notify.send(
                sender=self.request.user,
                verb=f"{self.request.user.email} replyed you on {lecture}",
                action=new_comment,
                target=lecture,
                recipient=recipient,
                affected_users=affected_users)

    if redirect_link:
        return redirect(redirect_link)
    else:
        #i want to see the main comment thread, and not just a reply
        return redirect(main_comment)
Exemplo n.º 5
0
 def save_model(self, request, obj, form, change):
     if obj.check is False and not obj.note:
         messages.set_level(request, messages.ERROR)
         self.message_user(request, '不通过核验时需要进行备注', level=messages.ERROR)
     else:
         obj.save()
         #样品信息核对,提醒相应销售人员
         notify.send(request.user,
                     recipient=obj.project.contract.salesman,
                     verb='核对了样品信息',
                     description="项目名称:%s 样品名称:%s" %
                     (obj.project.name, obj.project.contract.name))
Exemplo n.º 6
0
 def make_pass(self, request, queryset):
     rows_updated = queryset.update(check=True)
     if rows_updated:
         self.message_user(request, '%s 个样品核验通过' % rows_updated)
         #样品信息核对,提醒相应销售人员
         notify.send(request.user,
                     recipient=queryset[0].project.contract.salesman,
                     verb='核对了样品信息',
                     description="项目名称:%s 此次核对的样品数量:%s" %
                     (queryset[0].project.name, rows_updated))
     else:
         self.message_user(request,
                           '%s 未成功操作标记核验通过' % rows_updated,
                           level=messages.ERROR)
Exemplo n.º 7
0
 def save_model(self, request, obj, form, change):
     if obj.result is None:
         obj.date = None
         obj.staff = None
     else:
         obj.date = date.today()
         obj.staff = request.user
     obj.save()
     #样品提取成功,提醒相应销售人员
     notify.send(
         request.user,
         recipient=obj.sample.project.contract.salesman,
         verb='核对了样品信息',
         description="项目名称:%s 样品名称:%s" %
         (obj.sample.project.name, obj.sample.project.contract.name))
Exemplo n.º 8
0
 def make_receive(self, request, queryset):
     # 批量记录合同回寄时间戳
     rows_updated = queryset.update(receive_date=datetime.now())
     for obj in queryset:
         if rows_updated:
             #合同寄到日 通知项目管理2
             for j in User.objects.filter(groups__id=2):
                 notify.send(request.user, recipient=j, verb='客户收到新合同',\
                             description="合同号:%s\t合同名称:%s\t合同联系人:%s\t电话:%s"%\
                                         (obj.contract_number,obj.name,obj.contacts,obj.contact_phone))
             self.message_user(request, '%s 个合同寄到登记已完成' % rows_updated)
         else:
             self.message_user(request,
                               '%s 未能成功登记' % rows_updated,
                               level=messages.ERROR)
Exemplo n.º 9
0
 def make_pass(self, request, queryset):
     rows_updated = queryset.update(result=True,
                                    date=date.today(),
                                    staff=request.user)
     if rows_updated:
         self.message_user(request, '%s 个样品建库合格' % rows_updated)
         #样品建库合格,提醒相应销售人员
         notify.send(request.user,
                     recipient=queryset[0].project.contract.salesman,
                     verb='样品建库合格',
                     description="项目名称:%s 此次核对的样品数量:%s" %
                     (queryset[0].project.name, rows_updated))
     else:
         self.message_user(request,
                           '%s 未能操作标记为建库合格' % rows_updated,
                           level=messages.ERROR)
Exemplo n.º 10
0
 def create(self, request, *args, **kwargs):
     user = request.user
     data = request.data
     if user.is_authenticated:
         if user.id == int(data.get("user")):
             product = data.get("product")
             product_item = Product.objects.get(id=product)
             seller = product_item.seller.user_id
             description = f"You have a new Question for the {product_item}."
             notify.send(sender=None, recipient=seller, description=description)
             return super().create(request, *args, **kwargs)
         elif user.role == "support" or user.role == "admin":
             return super().create(request, *args, **kwargs)
         else:
             raise exceptions.PermissionDenied()
     else:
         raise exceptions.PermissionDenied()
Exemplo n.º 11
0
 def save_model(self, request, obj, form, change):
     if obj.invoice_code and not obj.date:
         obj.date = datetime.now()
     elif not obj.invoice_code:
         obj.date = None
     if obj.tracking_number and not obj.send_date:
         obj.send_date = datetime.now()
     elif not obj.tracking_number:
         obj.send_date = None
     obj.save()
     #开出发票后,通知相应销售人员。
     notify.send(request.user, recipient=obj.invoice.contract.salesman, verb='开出发票',description="发票号码:%s 开票金额:%s"%(obj.invoice_code,obj.invoice.amount))
     #通知市场人员,内容:抬头,金额,对应销售员。
     for j in User.objects.filter(groups__id=4):
         notify.send(request.user, recipient=j, verb='开出发票',description="发票抬头:%s\t开票金额:%s\t销售人员:%s%s"
                                                                        %(obj.invoice.title.title,obj.invoice.amount,
                                                                          obj.invoice.contract.salesman.first_name,
                                                                          obj.invoice.contract.salesman.last_name))
Exemplo n.º 12
0
 def create(self, request, *args, **kwargs):
     user = request.user
     data = request.data
     if user.is_authenticated:
         if user.id == int(data.get("user")):
             product = data.get("product")
             product_item = Product.objects.get(id=product)
             seller = product_item.seller.user_id
             description = f"You have a new Answer for your product {product_item}."
             notify.send(sender=None, recipient=seller, description=description)
             reply_to = data.get("parent")
             query = ProductQuery.objects.get(id=reply_to)
             user = query.user
             description = f'You have a new Answer for you question "{query}" on the product "{product_item}".'
             notify.send(sender=None, recipient=user, description=description)
             return super().create(request, *args, **kwargs)
         elif user.role == "support" or user.role == "admin":
             return super().create(request, *args, **kwargs)
         else:
             raise exceptions.PermissionDenied()
     else:
         raise exceptions.PermissionDenied()
Exemplo n.º 13
0
 def save_model(self, request, obj, form, change):
     if obj.result is None:
         obj.date = None
         obj.staff = None
         obj.type = None
         obj.sample_code = None
         obj.lib_code = None
         obj.index = None
         obj.length = None
         obj.volume = None
         obj.concentration = None
         obj.total = None
         obj.note = None
     else:
         obj.date = date.today()
         obj.staff = request.user
     obj.save()
     #样品建库合格,提醒相应销售人员
     notify.send(request.user,
                 recipient=obj.project.contract.salesman,
                 verb='样品建库合格',
                 description="项目名称:%s 样品名称:%s" %
                 (obj.project.name, obj.project.contract.name))
Exemplo n.º 14
0
 def save_model(self, request, obj, form, change):
     """
     1、新增快递单号时自动记录时间戳
     """
     if obj.tracking_number and not obj.send_date:
         obj.send_date = datetime.now()
     elif not obj.tracking_number:
         obj.send_date = None
     if Contract.objects.filter(id=obj.id):
         if obj.receive_date and Contract.objects.filter(
                 id=obj.id)[0].receive_date != obj.receive_date:
             #合同寄到日有变动就 通知项目管理2
             for j in User.objects.filter(groups__id=2):
                 notify.send(request.user, recipient=j, verb='客户收到新合同',\
                             description="合同号:%s\t合同名称:%s\t合同联系人:%s\t电话:%s"%\
                                         (obj.contract_number,obj.name,obj.contacts,obj.contact_phone))
     else:
         if obj.receive_date:
             #新增合同时,就有寄到日有变动就 通知项目管理2
             for j in User.objects.filter(groups__id=2):
                 notify.send(request.user, recipient=j, verb='客户收到新合同',\
                             description="合同号:%s\t合同名称:%s\t合同联系人:%s\t电话:%s"%\
                                         (obj.contract_number,obj.name,obj.contacts,obj.contact_phone))
     obj.save()
Exemplo n.º 15
0
def generate_notification(sender, instance, created, **kwargs):
    notify.send(instance, verb='commented')