Best Python code snippet using Kiwi_python
issue.py
Source:issue.py
...31 notify_managers_about_new_message_in_chat, notify_managers_issue_in_review32class IssueView(LoginRequiredMixin, TemplateView):33 template_name = ''34 _issue = None35 def get_issue(self):36 if self._issue is not None:37 return self._issue38 iid = self.kwargs.get('iid', None)39 if iid is not None:40 # fixme maybe make error 403?41 issue = get_object_or_404(Issue, id=iid, user_id=self.request.user.id)42 self._issue = issue43 return issue44 def get_context_data(self, **kwargs):45 kwargs.update(dict(issue=self.get_issue()))46 return super().get_context_data(**kwargs)47class IssueChatView(IssueView):48 template_name = 'marer/issue/chat.html'49 def get_context_data(self, **kwargs):50 kwargs['consts'] = consts51 if 'comment_form' not in kwargs:52 kwargs['comment_form'] = IFOPCMessageForm()53 return super().get_context_data(**kwargs)54 def post(self, request, *args, **kwargs):55 action = request.POST.get('action', False)56 if action == 'send_msg':57 comment_form = IFOPCMessageForm(request.POST, request.FILES)58 if comment_form.is_valid():59 new_msg = IssueClarificationMessage()60 new_msg.issue = self.get_issue()61 new_msg.message = comment_form.cleaned_data['message']62 new_msg.user = request.user63 new_msg.save()64 for ffield in ['doc%s' % dnum for dnum in range(1, 9)]:65 ffile = comment_form.cleaned_data[ffield]66 if ffile:67 new_doc = Document()68 new_doc.file = ffile69 new_doc.save()70 new_clarif_doc_link = IssueFinanceOrgProposeClarificationMessageDocument()71 new_clarif_doc_link.clarification_message = new_msg72 new_clarif_doc_link.name = ffile.name73 new_clarif_doc_link.document = new_doc74 new_clarif_doc_link.save()75 new_other_propose_doc = IssueProposeDocument()76 new_other_propose_doc.issue = self.get_issue()77 new_other_propose_doc.name = ffile.name78 new_other_propose_doc.document = new_doc79 new_other_propose_doc.type = consts.DOCUMENT_TYPE_OTHER80 new_other_propose_doc.save()81 notify_managers_about_new_message_in_chat(new_msg)82 url = reverse('issue_chat', args=[self._issue.id])83 return HttpResponseRedirect(url)84class IssueRedirectView(LoginRequiredMixin, RedirectView):85 permanent = False86 def get(self, request, *args, **kwargs):87 iid = kwargs.get('iid', None)88 issue = None89 if iid is not None:90 # fixme maybe make error 403?91 issue = get_object_or_404(Issue, id=iid, user_id=request.user.id)92 if issue.status == consts.ISSUE_STATUS_REGISTERING:93 self.pattern_name = 'issue_registering'94 elif issue.status == consts.ISSUE_STATUS_REVIEW:95 self.pattern_name = 'issue_additional_documents_requests'96 elif issue.status == consts.ISSUE_STATUS_FINISHED:97 self.pattern_name = 'issue_finished'98 elif issue.status == consts.ISSUE_STATUS_CANCELLED:99 self.pattern_name = 'issue_finished'100 return super().get(request, *args, **kwargs)101class IssueRegisteringView(IssueView):102 template_name = 'marer/issue/registering.html'103 def get(self, request, *args, **kwargs):104 if 'base_form' not in kwargs:105 if self.get_issue():106 initial = dict(107 product=self.get_issue().product,108 org_search_name=self.get_issue().get_issuer_name(),109 comment=self.get_issue().comment,110 )111 else:112 initial = dict()113 kwargs['base_form'] = IssueRegisteringForm(initial=initial)114 kwargs['issue'] = self.get_issue()115 kwargs['products'] = get_finance_products()116 kwargs['dadata_token'] = settings.DADATA_TOKEN117 return super().get(request, *args, **kwargs)118 def return_errors(self, base_form, *args, **kwargs):119 kwargs.update(dict(base_form=base_form))120 return self.get(self.request, *args, **kwargs)121 def create_issuer(self, user_owner, inn, kpp, ogrn, full_name, short_name):122 issuer = Issuer(123 user=user_owner,124 inn=inn,125 kpp=kpp,126 ogrn=ogrn,127 full_name=full_name,128 short_name=short_name,129 )130 issuer.save()131 return issuer132 def post(self, request, *args, **kwargs):133 if self.get_issue() and 'issue_registering' not in self.get_issue().editable_dashboard_views():134 return self.get(request, *args, **kwargs)135 base_form = IssueRegisteringForm(request.POST)136 if base_form.is_valid():137 # todo go to next stage if we can138 need_to_notify_for_issue_create = False139 if not self.get_issue():140 issuer = self.create_issuer(141 user_owner=request.user,142 inn=request.POST.get('issuer_inn'),143 kpp=request.POST.get('issuer_kpp'),144 ogrn=request.POST.get('issuer_ogrn'),145 full_name=request.POST.get('issuer_full_name'),146 short_name=request.POST.get('issuer_short_name')147 )148 issuer_inn = request.POST.get('issuer_inn')149 if issuer_inn:150 old_issue = Issue.objects.filter(issuer_inn=issuer_inn).order_by('-id').first()151 else:152 old_issue = None153 if old_issue:154 new_issue = deepcopy(old_issue)155 new_issue.pk = None156 new_issue.manager = None157 new_issue.manager_id = None158 new_issue.user = request.user159 new_issue.status = consts.ISSUE_STATUS_REGISTERING160 new_issue.application_doc = None161 new_issue.bg_doc = None162 new_issue.contract_of_guarantee = None163 new_issue.transfer_acceptance_act = None164 new_issue.additional_doc = None165 new_issue.bg_contract_doc = None166 new_issue.save(create_docs=False)167 related_names = [168 'org_bank_accounts', 'org_beneficiary_owners', 'issuer_founders_legal',169 'issuer_founders_physical', 'issuer_licences', 'org_management_collegial',170 'org_management_directors', 'org_management_others'171 ]172 for name in related_names:173 for obj in getattr(old_issue, name).all():174 obj.issue_id = new_issue.id175 obj.pk = None176 obj.save()177 else:178 new_issue = Issue(179 issuer=issuer,180 product=base_form.cleaned_data['product'],181 status=consts.ISSUE_STATUS_REGISTERING,182 user=request.user,183 ) # todo set values184 # new_issue.fill_from_issuer()185 need_to_notify_for_issue_create = True186 self._issue = new_issue187 issue = self.get_issue()188 issue.comment = base_form.cleaned_data['comment']189 issue.product = base_form.cleaned_data['product']190 issue.save()191 # todo issue process registering form192 product = issue.get_product()193 product.set_issue(issue)194 processed_valid = product.process_registering_form(request)195 if need_to_notify_for_issue_create:196 notify_manager_about_user_created_issue(issue)197 else:198 notify_manager_about_user_updated_issue(issue)199 if issue.issuer_already_has_an_agent:200 url = reverse('issue_registering', args=[issue.id])201 return HttpResponseRedirect(url)202 action = request.POST.get('action', 'save')203 if action == 'save':204 url = reverse('cabinet_requests')205 return HttpResponseRedirect(url)206 elif action == 'next':207 if processed_valid and not issue.check_stop_factors_validity:208 issue.status = consts.ISSUE_STATUS_CANCELLED209 issue.save()210 url = reverse('issue_finished', args=[issue.id])211 return HttpResponseRedirect(url)212 if processed_valid:213 url = reverse('issue_survey', args=[issue.id])214 return HttpResponseRedirect(url)215 return self.return_errors(base_form, *args, **kwargs)216class IssueSurveyView(IssueView):217 template_name = 'marer/issue/survey.html'218 def get(self, request, *args, **kwargs):219 kwargs['survey_template'] = self.get_issue().get_product().survey_template_name220 kwargs.update(self.get_issue().get_product().get_survey_context_part())221 return super().get(request, *args, **kwargs)222 def post(self, request, *args, **kwargs):223 if self.get_issue() and 'issue_survey' not in self.get_issue().editable_dashboard_views():224 return self.get(request, *args, **kwargs)225 all_ok = self.get_issue().get_product().process_survey_post_data(request)226 action = request.POST.get('action', 'save')227 if action == 'save':228 url = reverse('cabinet_requests')229 return HttpResponseRedirect(url)230 elif action == 'next' and all_ok:231 if self.get_issue().agent_comission and not self.get_issue().agent_commission_passed:232 return self.get(request, *args, **kwargs)233 notify_manager_about_user_updated_issue(self.get_issue())234 url = reverse('issue_scoring', args=[self.get_issue().id])235 return HttpResponseRedirect(url)236 else:237 return self.get(request, *args, **kwargs)238class IssueRemoteAdditionalDocumentsRequests(TemplateView, ContextMixin, View):239 _issue = None240 def get_issue(self):241 if self._issue is not None:242 return self._issue243 iid = self.kwargs.get('iid', None)244 if iid is not None:245 # fixme maybe make error 403?246 issue = get_object_or_404(Issue, id=iid)247 self._issue = issue248 return issue249 def get_context_data(self, **kwargs):250 kwargs['cert_hash'] = self.get_cert_thumb()251 kwargs['consts'] = consts252 kwargs['issue'] = self.get_issue()253 if 'comment_form' not in kwargs:254 kwargs['comment_form'] = IFOPCMessageForm()255 return super().get_context_data(**kwargs)256 def get_cert_thumb(self):257 dta = self.request.COOKIES.get('cert_thumb', None)258 if not dta:259 dta = self.request.session.get('cert_thumb', None)260 return dta261 def get_cert_sign(self):262 dta = self.request.COOKIES.get('cert_sign', None)263 if not dta:264 dta = self.request.session.get('cert_sign', None)265 return dta266 def is_authenticated_by_cert(self):267 thumb = self.get_cert_thumb()268 sign = self.get_cert_sign()269 # todo check INN for cert and issue issuer270 if thumb and sign:271 return True272 else:273 return False274 def get(self, request, *args, **kwargs):275 if 'logout' in request.GET:276 logout(request)277 if not self.is_authenticated_by_cert():278 self.template_name = 'marer/auth/remote_sign_login.html'279 login_form = LoginSignForm()280 if 'login_form' not in kwargs:281 kwargs.update(dict(login_form=login_form))282 elif self.get_issue().status == consts.ISSUE_STATUS_REGISTERING:283 self.template_name = 'marer/issue/remote_sign_docs_for_registering.html'284 else:285 self.template_name = 'marer/issue/remote_adrs.html'286 return super().get(request, *args, **kwargs)287 def post(self, request, *args, **kwargs):288 if not self.is_authenticated_by_cert():289 login_form = LoginSignForm(request.POST)290 if login_form.is_valid():291 request.COOKIES['cert_thumb'] = login_form.cleaned_data['cert']292 request.COOKIES['cert_sign'] = login_form.cleaned_data['signature']293 request.session['cert_thumb'] = login_form.cleaned_data['cert']294 request.session['cert_sign'] = login_form.cleaned_data['signature']295 url = reverse('issue_remote_add_docs_requests', args=[self.get_issue().id])296 response = HttpResponseRedirect(url)297 return response298 return self.get(request, *args, **kwargs)299class IssueRemoteSignView(TemplateView, ContextMixin, View):300 _issue = None301 def get_context_data(self, **kwargs):302 kwargs['cert_hash'] = self.get_cert_thumb()303 kwargs['consts'] = consts304 kwargs['issue'] = self.get_issue()305 return super().get_context_data(**kwargs)306 def get_issue(self):307 if self._issue is not None:308 return self._issue309 iid = self.kwargs.get('iid', None)310 if iid is not None:311 # fixme maybe make error 403?312 issue = get_object_or_404(Issue, id=iid)313 self._issue = issue314 return issue315 def get_cert_thumb(self):316 dta = self.request.COOKIES.get('cert_thumb', None)317 if not dta:318 dta = self.request.session.get('cert_thumb', None)319 return dta320 def get_cert_sign(self):321 dta = self.request.COOKIES.get('cert_sign', None)322 if not dta:323 dta = self.request.session.get('cert_sign', None)324 return dta325 def is_authenticated_by_cert(self):326 thumb = self.get_cert_thumb()327 sign = self.get_cert_sign()328 # todo check INN for cert and issue issuer329 if thumb and sign:330 return True331 else:332 return False333 def get(self, request, *args, **kwargs):334 if 'logout' in request.GET:335 logout(request)336 if not self.is_authenticated_by_cert():337 self.template_name = 'marer/auth/remote_sign_login.html'338 login_form = LoginSignForm()339 if 'login_form' not in kwargs:340 kwargs.update(dict(login_form=login_form))341 elif self.get_issue().status == consts.ISSUE_STATUS_REGISTERING:342 self.template_name = 'marer/issue/remote_sign_docs_for_registering.html'343 else:344 self.template_name = 'marer/issue/remote_sign_docs.html'345 return super().get(request, *args, **kwargs)346 def post(self, request, *args, **kwargs):347 if not self.is_authenticated_by_cert():348 login_form = LoginSignForm(request.POST)349 if login_form.is_valid():350 request.COOKIES['cert_thumb'] = login_form.cleaned_data['cert']351 request.COOKIES['cert_sign'] = login_form.cleaned_data['signature']352 request.session['cert_thumb'] = login_form.cleaned_data['cert']353 request.session['cert_sign'] = login_form.cleaned_data['signature']354 url = reverse('issue_remote_for_sign', args=[self.get_issue().id])355 response = HttpResponseRedirect(url)356 # response.set_cookie('cert_thumb', login_form.cleaned_data['cert'])357 # response.set_cookie('cert_thumb', login_form.cleaned_data['signature'])358 return response359 return self.get(request, args, kwargs)360class IssueRemoteSurveyView(TemplateView, ContextMixin, View):361 _issue = None362 def get_context_data(self, **kwargs):363 kwargs['cert_hash'] = self.get_cert_thumb()364 kwargs['consts'] = consts365 kwargs['issue'] = self.get_issue()366 return super().get_context_data(**kwargs)367 def get_issue(self):368 if self._issue is not None:369 return self._issue370 iid = self.kwargs.get('iid', None)371 if iid is not None:372 # fixme maybe make error 403?373 issue = get_object_or_404(Issue, id=iid)374 self._issue = issue375 return issue376 def get_cert_thumb(self):377 dta = self.request.COOKIES.get('cert_thumb', None)378 if not dta:379 dta = self.request.session.get('cert_thumb', None)380 return dta381 def get_cert_sign(self):382 dta = self.request.COOKIES.get('cert_sign', None)383 if not dta:384 dta = self.request.session.get('cert_sign', None)385 return dta386 def is_authenticated_by_cert(self):387 thumb = self.get_cert_thumb()388 sign = self.get_cert_sign()389 # todo check INN for cert and issue issuer390 if thumb and sign:391 return True392 else:393 return False394 def get(self, request, *args, **kwargs):395 if 'logout' in request.GET:396 logout(request)397 if not self.is_authenticated_by_cert():398 self.template_name = 'marer/auth/remote_sign_login.html'399 login_form = LoginSignForm()400 if 'login_form' not in kwargs:401 kwargs.update(dict(login_form=login_form))402 else:403 self.template_name = 'marer/issue/remote_survey.html'404 kwargs['survey_template'] = self.get_issue().get_product().survey_template_name405 kwargs.update(self.get_issue().get_product().get_survey_context_part())406 return super().get(request, *args, **kwargs)407 def post(self, request, *args, **kwargs):408 if not self.is_authenticated_by_cert():409 login_form = LoginSignForm(request.POST)410 if login_form.is_valid():411 request.COOKIES['cert_thumb'] = login_form.cleaned_data['cert']412 request.COOKIES['cert_sign'] = login_form.cleaned_data['signature']413 request.session['cert_thumb'] = login_form.cleaned_data['cert']414 request.session['cert_sign'] = login_form.cleaned_data['signature']415 url = reverse('issue_remote_survey', args=[self.get_issue().id])416 response = HttpResponseRedirect(url)417 # response.set_cookie('cert_thumb', login_form.cleaned_data['cert'])418 # response.set_cookie('cert_thumb', login_form.cleaned_data['signature'])419 return response420 else:421 if self.get_issue() and 'issue_survey' not in self.get_issue().editable_dashboard_views():422 return self.get(request, *args, **kwargs)423 all_ok = self.get_issue().get_product().process_survey_post_data(request)424 if all_ok:425 notify_manager_about_user_updated_issue(self.get_issue())426 if request.POST.get('action', '') == 'fill_application_doc':427 url = reverse('issue_remote_for_sign', args=[self.get_issue().id])428 return HttpResponseRedirect(url)429 return self.get(request, args, kwargs)430class IssueScoringView(IssueView):431 template_name = 'marer/issue/scoring.html'432 def get_context_data(self, **kwargs):433 kwargs['consts'] = consts434 return super().get_context_data(**kwargs)435 def post(self, request, *args, **kwargs):436 if self.get_issue() and 'issue_scoring' not in self.get_issue().editable_dashboard_views():437 return self.get(request, *args, **kwargs)438 proposes_docs = IssueProposeDocument.objects.filter(439 issue=self.get_issue())440 for pdoc in proposes_docs:441 pdoc_files_key = 'propose_doc_%s' % pdoc.id442 pdoc_files_del_key = 'propose_doc_%s_del' % pdoc.id443 pdoc_file = request.FILES.get(pdoc_files_key, None)444 pdoc_del_mark = request.POST.get(pdoc_files_del_key, None)445 if pdoc_file:446 if pdoc.document:447 pdoc.document.file = pdoc_file448 pdoc.document.save()449 else:450 new_doc = Document()451 new_doc.file = pdoc_file452 new_doc.save()453 pdoc.document = new_doc454 pdoc.save()455 if pdoc_del_mark:456 pdoc.document = None457 pdoc.save(chain_docs_update=False)458 action = request.POST.get('action', '')459 if action == 'send_to_review' and self.get_issue().can_send_for_review:460 self.get_issue().status = consts.ISSUE_STATUS_REVIEW461 self.get_issue().save()462 notify_managers_issue_in_review(self.get_issue())463 url = reverse('issue_additional_documents_requests', args=[self.get_issue().id])464 return HttpResponseRedirect(url)465 elif action == 'save':466 url = reverse('cabinet_requests')467 return HttpResponseRedirect(url)468 return self.get(request, *args, **kwargs)469class IssueAdditionalDocumentsRequestsView(IssueView):470 template_name = 'marer/issue/additional_documents_requests.html'471 def get_context_data(self, **kwargs):472 kwargs['consts'] = consts473 if 'email_form' not in kwargs:474 kwargs['email_form'] = EmailForm()475 if 'comment_form' not in kwargs:476 kwargs['comment_form'] = IFOPCMessageForm()477 return super().get_context_data(**kwargs)478 def post(self, request, *args, **kwargs):479 action = request.POST.get('action', False)480 if action == 'send_mail':481 email_form = EmailForm(request.POST)482 if email_form.is_valid():483 client_email = [email_form.cleaned_data['email']]484 html_template_filename = 'mail/events_for_send_to_user_client/user_sending_documents_to_underwrite.html'485 context = dict(486 issue_id=self.get_issue().id487 )488 if html_template_filename:489 msg_tmpl = get_template(html_template_filename)490 message = msg_tmpl.render(context or {})491 send_mail('ÐокÑменÑÑ Ð½Ð° ÑоглаÑование', '', None, client_email, html_message=message)492 elif action == 'send_msg':493 comment_form = IFOPCMessageForm(request.POST, request.FILES)494 if comment_form.is_valid():495 if self.get_issue() and 'issue_additional_documents_requests' not in self.get_issue().editable_dashboard_views():496 return self.get(request, *args, **kwargs)497 new_msg = IssueClarificationMessage()498 new_msg.issue = self.get_issue()499 new_msg.message = comment_form.cleaned_data['message']500 new_msg.user = request.user501 new_msg.save()502 for ffield in ['doc%s' % dnum for dnum in range(1, 9)]:503 ffile = comment_form.cleaned_data[ffield]504 if ffile:505 new_doc = Document()506 new_doc.file = ffile507 new_doc.save()508 new_clarif_doc_link = IssueFinanceOrgProposeClarificationMessageDocument()509 new_clarif_doc_link.clarification_message = new_msg510 new_clarif_doc_link.name = ffile.name511 new_clarif_doc_link.document = new_doc512 new_clarif_doc_link.save()513 new_other_propose_doc = IssueProposeDocument()514 new_other_propose_doc.issue = self.get_issue()515 new_other_propose_doc.name = ffile.name516 new_other_propose_doc.document = new_doc517 new_other_propose_doc.type = consts.DOCUMENT_TYPE_OTHER518 new_other_propose_doc.save()519 notify_managers_about_new_message_in_chat(new_msg)520 url = reverse('issue_chat', args=[self._issue.id])521 return HttpResponseRedirect(url)522class IssueAdditionalDocumentsRequestView(IssueView):523 template_name = 'marer/issue/additional_documents_request.html'524 def _get_clarification(self):525 clarif_id = self.kwargs.get('adrid', None)526 if clarif_id:527 clarification = get_object_or_404(IssueClarification, id=clarif_id)528 return clarification529 return None530 def get(self, request, *args, **kwargs):531 clarification = self._get_clarification()532 if clarification:533 kwargs['clarification'] = clarification534 kwargs['consts'] = consts535 if 'comment_form' not in kwargs:536 kwargs['comment_form'] = IFOPCMessageForm()537 return super().get(request, *args, **kwargs)538 def post(self, request, *args, **kwargs):539 comment_form = IFOPCMessageForm(request.POST, request.FILES)540 if comment_form.is_valid():541 if self.get_issue() and 'issue_additional_documents_requests' not in self.get_issue().editable_dashboard_views():542 return self.get(request, *args, **kwargs)543 clarification = self._get_clarification()544 clarification_change = True545 if not clarification:546 propose_id = request.GET.get('pid', 0)547 clarification = IssueClarification()548 clarification.initiator = consts.IFOPC_INITIATOR_ISSUER549 clarification.issue = self.get_issue()550 clarification.save()551 clarification_change = False552 new_msg = IssueClarificationMessage()553 new_msg.clarification = clarification554 new_msg.message = comment_form.cleaned_data['message']555 new_msg.user = request.user556 new_msg.save()557 for ffield in ['doc%s' % dnum for dnum in range(1, 9)]:558 ffile = comment_form.cleaned_data[ffield]559 if ffile:560 new_doc = Document()561 new_doc.file = ffile562 new_doc.save()563 new_clarif_doc_link = IssueFinanceOrgProposeClarificationMessageDocument()564 new_clarif_doc_link.clarification_message = new_msg565 new_clarif_doc_link.name = ffile.name566 new_clarif_doc_link.document = new_doc567 new_clarif_doc_link.save()568 if clarification_change:569 notify_about_user_adds_message(new_msg)570 else:571 notify_about_user_created_clarification(clarification)572 url = reverse(573 'issue_additional_documents_request',574 args=[self.get_issue().id, clarification.id]575 )576 return HttpResponseRedirect(url)577 else:578 kwargs['comment_form'] = comment_form579 return self.get(request, *args, **kwargs)580class IssueFinishedView(IssueView):581 template_name = 'marer/issue/finished.html'582 def get_context_data(self, **kwargs):583 kwargs['consts'] = consts584 return super().get_context_data(**kwargs)585class IssueCancelledView(IssueView):586 template_name = 'marer/issue/cancelled.html'587class IssueAdditionalDocumentSignView(LoginRequiredMixin, ContextMixin, View):588 _issue = None589 def get_issue(self):590 if self._issue is not None:591 return self._issue592 iid = self.kwargs.get('iid', None)593 if iid is not None:594 # fixme maybe make error 403?595 issue = get_object_or_404(Issue, id=iid, user_id=self.request.user.id)596 self._issue = issue597 return issue598 def get_context_data(self, **kwargs):599 kwargs.update(dict(issue=self.get_issue()))600 return super().get_context_data(**kwargs)601 def post(self, request, *args, **kwargs):602 doc_id = request.POST.get('document', None)603 doc = None604 sign = request.POST.get('signature', '')605 response_dict = dict(606 document=doc_id,607 sign_state=consts.DOCUMENT_SIGN_NONE,608 )609 if str(doc_id) == str(self.get_issue().application_doc_id):610 doc = self.get_issue().application_doc611 pdoc = IssueProposeDocument()612 pdoc.issue = self.get_issue()613 pdoc.id = -1 # saving avoid614 pdoc.name = 'ÐаÑвление на пÑедоÑÑавление банковÑкой гаÑанÑии'615 if doc_id and self.get_issue().propose_documents.filter(document_id=doc_id).exists():616 pdoc = IssueProposeDocument.objects.filter(document_id=doc_id)[0]617 doc = pdoc.document618 else:619 pdoc = None620 raw_check_sign_class = settings.FILE_SIGN_CHECK_CLASS621 if raw_check_sign_class is not None and raw_check_sign_class != '':622 raw_check_sign_class = str(raw_check_sign_class)623 check_sign_module_name, check_sign_class_name = raw_check_sign_class.rsplit('.', 1)624 check_sign_module = importlib.import_module(check_sign_module_name)625 check_sign_class = getattr(check_sign_module, check_sign_class_name)626 temp_sign_file = NamedTemporaryFile(delete=False)627 sign_bytes = sign.encode('utf-8')628 temp_sign_file.write(sign_bytes)629 try:630 sign_is_correct = check_sign_class.check_file_sign(doc.file.path, temp_sign_file.name)631 except Exception:632 sign_is_correct = False633 if sign_is_correct:634 final_sign_file = ContentFile(sign_bytes)635 final_sign_file.name = os.path.basename(doc.file.name) + '.sig'636 doc.sign = final_sign_file637 doc.save()638 if pdoc:639 notify_manager_about_user_sign_document(pdoc)640 response_dict['sign_state'] = consts.DOCUMENT_SIGN_VERIFIED641 else:642 response_dict['sign_state'] = consts.DOCUMENT_SIGN_CORRUPTED643 temp_sign_file.close()644 os.unlink(temp_sign_file.name)645 return HttpResponse(json.dumps(response_dict), content_type="application/json")646 @method_decorator(csrf_exempt)647 def dispatch(self, *args, **kwargs):648 return super().dispatch(*args, **kwargs)649class IssueRemoteDocumentSignView(ContextMixin, View):650 _issue = None651 def get_issue(self):652 if self._issue is not None:653 return self._issue654 iid = self.kwargs.get('iid', None)655 if iid is not None:656 # fixme maybe make error 403?657 issue = get_object_or_404(Issue, id=iid)658 self._issue = issue659 return issue660 def get_context_data(self, **kwargs):661 kwargs.update(dict(issue=self.get_issue()))662 return super().get_context_data(**kwargs)663 def post(self, request, *args, **kwargs):664 doc_id = request.POST.get('document', None)665 doc = None666 sign = request.POST.get('signature', '')667 response_dict = dict(668 document=doc_id,669 sign_state=consts.DOCUMENT_SIGN_NONE,670 )671 if str(doc_id) == str(self.get_issue().application_doc_id):672 doc = self.get_issue().application_doc673 pdoc = IssueProposeDocument()674 pdoc.issue = self.get_issue()675 pdoc.id = -1 # saving avoid676 pdoc.name = 'ÐаÑвление на пÑедоÑÑавление банковÑкой гаÑанÑии'677 elif doc_id and self.get_issue().propose_documents.filter(document_id=doc_id).exists():678 pdoc = IssueProposeDocument.objects.filter(document_id=doc_id)[0]679 doc = pdoc.document680 else:681 pdoc = None682 raw_check_sign_class = settings.FILE_SIGN_CHECK_CLASS683 if raw_check_sign_class is not None and raw_check_sign_class != '':684 raw_check_sign_class = str(raw_check_sign_class)685 check_sign_module_name, check_sign_class_name = raw_check_sign_class.rsplit('.', 1)686 check_sign_module = importlib.import_module(check_sign_module_name)687 check_sign_class = getattr(check_sign_module, check_sign_class_name)688 temp_sign_file = NamedTemporaryFile(delete=False)689 sign_bytes = sign.encode('utf-8')690 temp_sign_file.write(sign_bytes)691 try:692 sign_is_correct = check_sign_class.check_file_sign(doc.file.path, temp_sign_file.name)693 except Exception:694 sign_is_correct = False695 if sign_is_correct:696 final_sign_file = ContentFile(sign_bytes)697 final_sign_file.name = os.path.basename(doc.file.name) + '.sig'698 doc.sign = final_sign_file699 doc.save()700 notify_manager_about_user_sign_document(pdoc)701 response_dict['sign_state'] = consts.DOCUMENT_SIGN_VERIFIED702 if self.get_issue().status == consts.ISSUE_STATUS_REGISTERING \703 and self.get_issue().check_all_application_required_fields_filled() \704 and self.get_issue().is_all_required_propose_docs_filled \705 and self.get_issue().application_doc \706 and self.get_issue().application_doc.sign_state == consts.DOCUMENT_SIGN_VERIFIED:707 self.get_issue().status = consts.ISSUE_STATUS_REVIEW708 self.get_issue().save()709 else:710 response_dict['sign_state'] = consts.DOCUMENT_SIGN_CORRUPTED711 temp_sign_file.close()712 os.unlink(temp_sign_file.name)713 return HttpResponse(json.dumps(response_dict), content_type="application/json")714 @method_decorator(csrf_exempt)715 def dispatch(self, *args, **kwargs):...
tests.py
Source:tests.py
...57 task = self.create_task(name=task_name, stories=[story_name])58 # link stories59 self.bot.link_stories()60 # check that Story 1 and task are linked to each other61 story = self.repo.get_issue(number=story.number)62 task = self.repo.get_issue(number=task.number)63 self.assertIn("[ ] [{}".format(story_name), task.body)64 self.assertIn("[ ] [{}]".format(task_name), story.body)65 def test02_multiple_stories(self):66 """SBT-00267 #. Create story 1.68 #. Create story 2. 69 #. Create task 1 under Story 1 and Story 2.70 #. Link stories.71 #. Check that Story 1, Story 2 and task 1 are linked to each other.72 """73 # create story 174 story_1_name = self.random_string()75 story_1 = self.create_story(name=story_1_name)76 # create story 277 story_2_name = self.random_string()78 story_2 = self.create_story(name=story_2_name)79 # create task 180 task_name = self.random_string()81 task = self.create_task(name=task_name, stories=[story_1_name, story_2_name])82 # link stories83 self.bot.link_stories()84 # Check that Story 1, Story 2 and task 1 are linked to each other85 story_1 = self.repo.get_issue(number=story_1.number)86 story_2 = self.repo.get_issue(number=story_2.number)87 task = self.repo.get_issue(number=task.number)88 self.assertIn("[ ] [{}".format(story_1_name), task.body)89 self.assertIn("[ ] [{}".format(story_2_name), task.body)90 self.assertIn("[ ] [{}]".format(task_name), story_1.body)91 self.assertIn("[ ] [{}]".format(task_name), story_2.body)92 def test03_test_close_reopen_task(self):93 """SBT-00394 #. Create story 1.95 #. Create task 1 under Story 1.96 #. Link stories.97 #. Check that Story 1 and task are linked to each other.98 #. Close task 1, check that task 1 checkbox is checked.99 #. Reopen task 1, check that task 1 checkbox is unchecked.100 """101 # create story 1102 story_name = self.random_string()103 story = self.create_story(name=story_name)104 # create task 1105 task_name = self.random_string()106 task = self.create_task(name=task_name, stories=[story_name])107 # link stories108 self.bot.link_stories()109 # check that stories have been linked110 story = self.repo.get_issue(number=story.number)111 task = self.repo.get_issue(number=task.number)112 self.assertIn("[ ] [{}]".format(task_name), story.body)113 # close task 1114 task.edit(state="closed")115 # link stories116 self.bot.link_stories()117 # check that task checkbox is checked in story page118 story = self.repo.get_issue(number=story.number)119 self.assertIn("[x] [{}]".format(task_name), story.body)120 # reopen task 1121 task.edit(state="open")122 # link stories123 self.bot.link_stories()124 # check that task 1 checkbox is ubchecked in story page125 story = self.repo.get_issue(number=story.number)...
test_parent_status_updates.py
Source:test_parent_status_updates.py
...5 # Abe adds an issue to a sprint6 jira.add_issues_to_sprint(self.sprint_id, [self.issue_keys[0]])7 # Abe does a bunch of transitions on the subtasks, the parent issue8 # updates its status automatically9 parent = jira.get_issue(self.issue_keys[0])10 subtasks = parent['fields']['subtasks']11 jira.assign_issue(subtasks[0]['key'])12 jira.assign_issue(subtasks[1]['key'])13 self.wait_for(lambda: self.assertEqual(14 jira.get_issue(self.issue_keys[0])['fields']['status']['name'],15 "Backlog"16 ))17 jira.transition_issue(subtasks[0]['key'], "In Progress")18 self.wait_for(lambda: self.assertEqual(19 jira.get_issue(self.issue_keys[0])['fields']['status']['name'],20 "In Progress"21 ))22 jira.transition_issue(subtasks[0]['key'], "Archive", "Won't Do")23 self.wait_for(lambda: self.assertEqual(24 jira.get_issue(self.issue_keys[0])['fields']['status']['name'],25 "Backlog"26 ))27 jira.transition_issue(subtasks[0]['key'], "Done")28 self.wait_for(lambda: self.assertEqual(29 jira.get_issue(self.issue_keys[0])['fields']['status']['name'],30 "In Progress"31 ))32 jira.transition_issue(subtasks[1]['key'], "Done")33 self.wait_for(lambda: self.assertEqual(34 jira.get_issue(self.issue_keys[0])['fields']['status']['name'],35 "PO Review"36 ))37 jira.transition_issue(subtasks[1]['key'], "In Progress")38 self.wait_for(lambda: self.assertEqual(39 jira.get_issue(self.issue_keys[0])['fields']['status']['name'],40 "In Progress"41 ))42 # Abe backlogs the issue, the issue status goes back to "Backlog"43 jira.remove_issues_from_sprint([self.issue_keys[0]])44 self.wait_for(lambda: self.assertEqual(45 jira.get_issue(self.issue_keys[0])['fields']['status']['name'],46 "Backlog"47 ))48 self.assertEqual(49 jira.get_issue(self.issue_keys[0])['fields']['assignee'], None...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!