def TmcEdit(request): """ if CheckAccess(request,'2') != 'OK': return render_to_response("tmc/notaccess/tmc.html") """ try: tmc_id = request.session['tmc_id'] except: return HttpResponseRedirect("/tmc") if request.method == 'POST': form = EditTmcForm(request.POST) if form.is_valid(): tema = form.cleaned_data['tema'] text = form.cleaned_data['text'] project = form.cleaned_data['project'] project_num = form.cleaned_data['project_num'] r = EditTmc(tmc_id, tema, text, project, project_num) if r == 'OK': return HttpResponseRedirect("/tmcdata") d = GetTmcData(tmc_id) data = GetTmcSpec(tmc_id) form = EditTmcForm(None) form.fields['tema'].initial = d[3] form.fields['text'].initial = d[4] form.fields['project'].initial = "%s" % d[26] form.fields['project_num'].initial = d[25] c = RequestContext(request, {'d': d, 'form': form, 'data': data}) c.update(csrf(request)) return render_to_response("tmc/tmcedit.html", c)
def Email2Ruk(email,tmc_id): ### --- Получение данных по заявке --- d = GetTmcData(tmc_id) tmc_txt = d[4] author = d[13] ### --- Кому отправляем --- address = [] address.append(email) m = u""" <p> Прошу подписать Заявку ТМЦ № {tmc} <a href="{kisurl}/tmcdata/?tmc_id={tmc}">Ссылка</a><br><br> {txt}<br> </p> """.format(kisurl=kisurl,tmc=d[0],txt=tmc_txt) subj = 'KIS-messager' em = EmailMessage( subject = subj, body = m, from_email = author, to = address ) em.content_subtype = "html" em.send() ### -- Собираем отправку в лог --- EmailHistory(tmc_id,email,u'Запрос на подпись руководителя')
def TmcData4(request): """ if CheckAccess(request,'2') != 'OK': return render_to_response("tmc/notaccess/tmc.html") """ ## --- Номер заявки --- try: tmc_id = request.GET['tmc_id'] request.session['tmc_id'] = tmc_id except: pass try: tmc_id = request.session['tmc_id'] except: return HttpResponseRedirect("/tmc") d = GetTmcData(tmc_id) data = GetEmailHistory(tmc_id) s = GetLastStatus(tmc_id) c = RequestContext(request, {'d': d, 'data': data, 's': s}) c.update(csrf(request)) return render_to_response("tmc/tmcdata4.html", c)
def TmcData6(request): """ if CheckAccess(request,'2') != 'OK': return render_to_response("tmc/notaccess/tmc.html") """ ## --- Номер заявки --- try: tmc_id = request.GET['tmc_id'] request.session['tmc_id'] = tmc_id except: pass try: tmc_id = request.session['tmc_id'] except: return HttpResponseRedirect("/tmc") if request.method == 'POST': form = GroupForm(request.POST) if form.is_valid(): comment = form.cleaned_data['comment'] group = form.cleaned_data['group'] ChangeTmcGroup(GetUserKod(request), tmc_id, comment, group) d = GetTmcData(tmc_id) data = GetGroupHistory(tmc_id) form = GroupForm(None) s = GetLastStatus(tmc_id) c = RequestContext(request, {'d': d, 'form': form, 'data': data, 's': s}) c.update(csrf(request)) return render_to_response("tmc/tmcdata6.html", c)
def TmcData5(request): """ if CheckAccess(request,'2') != 'OK': return render_to_response("tmc/notaccess/tmc.html") """ ## --- Номер заявки --- try: tmc_id = request.GET['tmc_id'] request.session['tmc_id'] = tmc_id except: pass try: tmc_id = request.session['tmc_id'] except: return HttpResponseRedirect("/tmc") if request.method == 'POST': form = EmailForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] Email2Ruk(email, tmc_id) d = GetTmcData(tmc_id) form = EmailForm(None) s = GetLastStatus(tmc_id) c = RequestContext(request, {'d': d, 'form': form, 's': s}) c.update(csrf(request)) return render_to_response("tmc/tmcdata5.html", c)
def NewSpec(request): """ if CheckAccess(request,'2') != 'OK': return render_to_response("tmc/notaccess/tmc.html") """ try: tmc_id = request.session['tmc_id'] except: return HttpResponseRedirect("/tmc") if request.method == 'POST': form = SpecForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] okei = form.cleaned_data['okei'] q = form.cleaned_data['q'] cost = form.cleaned_data['cost'] analog = form.cleaned_data['analog'] r = NewSpecData(GetUserKod(request), tmc_id, name, okei, q, cost, analog) if r == 'OK': return HttpResponseRedirect("/tmcdata") form = SpecForm(None) form.fields['cost'].initial = '0.00' form.fields['q'].initial = '0.00' d = GetTmcData(tmc_id) c = RequestContext(request, {'form': form, 'd': d}) c.update(csrf(request)) return render_to_response("tmc/newspec.html", c)
def EmailStatusInfo(tmc_id): ### --- Получение данных по заявке --- d = GetTmcData(tmc_id) ### --- Данные по установленному статусу --- s_last = GetStatusHistory(tmc_id)[0] ### --- Группа ТМЦ --- tmcgroup = d[1] author = s_last[10] status_tmc = s_last[3] comment = s_last[8] tmc_txt = d[4] ### --- Кому отправляем --- mail = [] mail.append(d[13]) ### --- Для групп финасы и логистика дополнительная рассылка --- ### --- Группа финансы --- if s_last[11] == '1' or s_last[11] == '8' or s_last[11] == '9' or s_last[11] == '13' or s_last[11] == '16': group = GetGroupEmailList(0,tmcgroup) for item in group: mail.append(item[5]) ### --- Группа логистика --- if s_last[11] == '3' or s_last[11] == '10' or s_last[11] == '9' or s_last[11] == '13' or s_last[11] == '15' or s_last[11] == '16': group = GetGroupEmailList(0,tmcgroup) for item in group: mail.append(item[5]) for address in mail: m = u""" <p> Уведомление о статусе (Заявки ТМЦ)<br><br> Заявка № {tmc} <a href="{kisurl}/tmcdata/?tmc_id={tmc}">Ссылка</a><br> {txt}<br> Статус: {status}<br> Комментарий: {comment}<br> """.format(kisurl=kisurl,tmc=d[0],txt=tmc_txt,status=status_tmc,comment=comment) subj = 'KIS-messager' em = EmailMessage( subject = subj, body = m, from_email = author, to = [address,] ) em.content_subtype = "html" em.send() EmailHistory(tmc_id,address,u'Уведомление о статусе: '+status_tmc)
def TmcData1(request): ## --- Номер заявки --- try: tmc_id = request.GET['tmc_id'] request.session['tmc_id'] = tmc_id except: pass try: tmc_id = request.session['tmc_id'] except: return HttpResponseRedirect("/tmc") ### --- Затираем строку поиска --- request.session['search'] = '' if request.method == 'GET': try: rec_id = request.GET['delete_id'] DelSpec(GetUserKod(request), rec_id) except: pass if request.method == 'POST': nform = NumberForm(request.POST) if nform.is_valid(): n = nform.cleaned_data['n'] spec = GetTmcSpec('%s' % n) PullSpec(GetUserKod(request), tmc_id, spec) form = SpecFileForm(None) d = GetTmcData(tmc_id) data = GetTmcSpec(tmc_id) stspec = GetSpecStatusList() s = GetLastStatus(tmc_id) nform = NumberForm(None) c = RequestContext( request, { 'd': d, 'data': data, 'form': form, 's': s, 'nform': nform, 'stspec': stspec }) c.update(csrf(request)) return render_to_response("tmc/tmcdata1.html", c)
def TmcData7(request): """ if CheckAccess(request,'2') != 'OK': return render_to_response("tmc/notaccess/tmc.html") """ ## --- Номер заявки --- try: tmc_id = request.GET['tmc_id'] request.session['tmc_id'] = tmc_id except: pass try: tmc_id = request.session['tmc_id'] except: return HttpResponseRedirect("/tmc") d = GetTmcData(tmc_id) if request.method == 'POST': form = ShifrForm(request.POST) if form.is_valid(): shifr = form.cleaned_data['shifr'] SetShifr(tmc_id, d[8], GetUserKod(request), shifr) d = GetTmcData(tmc_id) form = ShifrForm(None) form.fields['shifr'].initial = d[23] s = GetLastStatus(tmc_id) c = RequestContext(request, {'d': d, 'form': form, 's': s}) c.update(csrf(request)) return render_to_response("tmc/tmcdata7.html", c)
def GetCsvData(request): tmc_id = request.session['tmc_id'] tmc = GetTmcData(tmc_id) tmcspec = GetTmcSpec(tmc_id) response_data = u"" response_data = response_data + u";Заявка ТМС номер {num} от {date};;;;;;\n".format( num=tmc[0], date=tmc[2]) response_data = response_data + u";Текстовое описание: {text};;;;;;\n".format( text=tmc[4]) response_data = response_data + u";Тема: {tema};;;;;;\n".format( tema=tmc[3]) response_data = response_data + u";Статус: {status};;;;;;\n".format( status=tmc[6]) response_data = response_data + u";Исполнитель (телефон): {worker1} {worker2} ({phone});;;;;;\n".format( worker1=tmc[10], worker2=tmc[9], phone=tmc[12]) response_data = response_data + u";Руководитель: {chif1} {chif2};;;;;;\n".format( chif1=tmc[17], chif2=tmc[16]) response_data = response_data + u";;;;;;;\n;;;;;;;\n" response_data = response_data + u";Состав заявки;;;;;;\n" response_data = response_data + u"№пп;Наименование;Ед.из.;Кол-во;Цена;Аналог;;\n" for row in tmcspec: response_data = response_data + u"{n};{name};{ed};{cou};{price};{analog};;\n".format( n=row[2], name=row[3], ed=row[4], cou=row[5], price=row[6], analog=row[7]) response_data = response_data.encode('cp1251') response = HttpResponse(content_type="text/csv") response[ 'Content-Disposition'] = 'attachment; filename="tmc%s.csv"' % tmc[0] response.write(response_data) return response
def TmcData3(request): """ if CheckAccess(request,'2') != 'OK': return render_to_response("tmc/notaccess/tmc.html") """ ## --- Номер заявки --- try: tmc_id = request.GET['tmc_id'] request.session['tmc_id'] = tmc_id except: pass try: tmc_id = request.session['tmc_id'] except: return HttpResponseRedirect("/tmc") if request.method == 'POST': form = StatusForm(request.POST) if form.is_valid(): comment = form.cleaned_data['comment'] status = form.cleaned_data['status'] r = NewTmcStatus(GetUserKod(request), tmc_id, comment, status) if r == 'OK': EmailStatusInfo(tmc_id) d = GetTmcData(tmc_id) data = GetStatusHistory(tmc_id) form = StatusForm(None) form.fields['status'].choices = GetStatusList(d[5]) s = GetLastStatus(tmc_id) c = RequestContext(request, {'d': d, 'form': form, 'data': data, 's': s}) c.update(csrf(request)) return render_to_response("tmc/tmcdata3.html", c)
def TmcData2(request): """ if CheckAccess(request,'2') != 'OK': return render_to_response("tmc/notaccess/tmc.html") """ ## --- Номер заявки --- try: tmc_id = request.GET['tmc_id'] request.session['tmc_id'] = tmc_id except: pass try: tmc_id = request.session['tmc_id'] except: return HttpResponseRedirect("/tmc") if request.method == 'GET': try: rec_id = request.GET['delete_id'] DeleteDoc(rec_id) except: pass if request.method == 'POST': form = LoadFile(request.POST) if form.is_valid(): try: comment = form.cleaned_data['comment'] file_name = request.FILES['file_load'].name file_data = request.FILES['file_load'].read() file_name = file_name.split('\\')[-1] (path, ext) = os.path.splitext(file_name) file_name = file_name.replace(' ', '_') AddTmcDoc(GetUserKod(request), tmc_id, file_name, comment, ext, file_data) except: pass ### --- Отображение --- if request.method == 'GET': try: doc_id = request.GET['doc_id'] f = GetDoc(doc_id) response = HttpResponse(content_type='application/%s' % f[0][-1:]) attach = u'attachment; filename=\"%s\"' % (f[2]) response['Content-Disposition'] = attach.encode('utf-8') response.write(f[1]) return response except: pass form = LoadFile(None) d = GetTmcData(tmc_id) data = GetTmcDocList(tmc_id) s = GetLastStatus(tmc_id) c = RequestContext(request, {'d': d, 'form': form, 'data': data, 's': s}) c.update(csrf(request)) return render_to_response("tmc/tmcdata2.html", c)