def submit_news(request): tit = request.POST['title'] test = request.POST['text'] img = request.FILES['img'] n = News(title = tit, text = test, picture = img) n.save() # try: # smtp_server = 'smtp.gmail.com' # smtpObj = smtplib.SMTP(smtp_server, 587) # smtpObj.starttls() # login = '******' # password = '******' # smtpObj.login(login, password) # sender = '*****@*****.**' # message = test # receivers = User.objects.filter(last_name='1') # # #receivers # for r in receivers: # smtpObj.sendmail(sender, r.email, message) # print 1 # # except SMTPException: # print "Error: unable to send email" resize_picture ( n ) # c = RequestContext({'user':request.user}) return HttpResponseRedirect('/news/')
def save_edited(request, _id): inst = Instruction.objects.get(id = _id) inst.name = request.POST['name'] inst.picture = request.FILES['img'] inst.text = request.POST['text'] inst.save() resize_picture(inst) return HttpResponseRedirect('/instructions/')
def add_instruct(request): i = Instruction() i.name = request.POST['name'] i.picture = request.FILES['img'] i.text = request.POST['text'] i.save() resize_picture(i) return HttpResponseRedirect('/instructions/')
def add_prod (request, tp_id): tp = Product_type.objects.all().get(id=tp_id) pr = Product() pr.prod_type = tp pr.name = request.POST['name'] pr.producer = request.POST['producer'] pr.quantity = request.POST['quantity'] pr.sdescription = request.POST['sdescr'] if 'picture' in request.FILES: pr.picture = request.FILES['picture'] if 'userfile' in request.FILES: pr.model = request.FILES['userfile'] pr.save() new_name = 'Entities/static/products/models_' + str(tp.group.id) + '_' + str(tp.id) + '_' + str(pr.id) + '.dae' for i in range(2): try: os.rename(str(pr.model), new_name) pr.model = new_name break; except: os.remove(new_name) else: pr.model = 'Entities/static/products/banana.dae'; pr.save() typ = str(pr.picture).split('.') new_name = 'Entities/static/products/img_' + str(tp.group.id) + '_' + str(tp.id) + '_' + str(pr.id) t = '.' + typ[len(typ) - 1] add_picture(pr, new_name, t) else: pr.picture = 'Entities/static/products/standart.png'; pr.save() price = Price() price.value = request.POST['price'] price.product = pr price.date_init = datetime.today().date() price.save() ch = Characteristic() chr_name = 'ch' + str(1) + '_name' i = 1 while chr_name in request.POST: ch = Characteristic() ch.product = pr; ch.name = request.POST[chr_name] ch.description = request.POST['ch' + str(i) + '_value'] ch.save() i = i + 1 chr_name = 'ch' + str(i) + '_name' resize_picture(pr) return HttpResponseRedirect('/products/' + str(tp.group.id) + '/' + str(tp.id) + '/')
def add_group (request): gr = Product_group() gr.name = request.POST['name'] if 'img' in request.FILES: gr.picture = request.FILES['img'] gr.save() typ = str(gr.picture).split('.') new_name = 'Entities/static/products/img_' + str(gr.id) t = '.' + typ[len(typ) - 1] add_picture(gr, new_name, t) else: gr.picture = 'Entities/static/products/standart.png'; gr.save() resize_picture(gr) return HttpResponseRedirect('/products/')
def add_char (request, pr_id): pr = Product.objects.all().get(id=pr_id) pr.name = request.POST['name'] pr.producer = request.POST['producer'] pr.quantity = request.POST['quantity'] pr.sdescription = request.POST['sdescr'] if 'picture' in request.FILES: pr.picture = request.FILES['picture'] pr.save() typ = str(pr.picture).split('.') pt = Product_type.objects.all().get(id=pr.prod_type.id) new_name = 'Entities/static/products/img_' + str(pt.group.id) + '_' + str(pt.id) + '_' + str(pr.id) t = '.' + typ[len(typ) - 1] add_picture(pr, new_name, t) if 'userfile' in request.FILES: pr.model = request.FILES['userfile'] pr.save() new_name = 'Entities/static/products/models_' + str(tp.group.id) + '_' + str(tp.id) + '_' + str(pr.id) + '.dae' for i in range(2): try: os.rename(str(pr.model), new_name) pr.model = new_name break except: os.remove(new_name) pr.save() resize_picture(pr) price = Price() price.value = request.POST['price'] price.product = pr price.date_init = datetime.today().date() price.save() Characteristic.objects.filter(product=pr).delete() ch = Characteristic() chr_name = str(1) i = 1 while chr_name in request.POST: ch = Characteristic() ch.product = pr; ch.name = request.POST[chr_name] ch.description = request.POST[str(i + 100)] ch.save() i = i + 1 chr_name = str(i) return HttpResponseRedirect('/products/' + str(pr.prod_type.group.id) + '/' + str(pr.prod_type.id) + '/' + str(pr.id) + '/')
def add_type (request, gr_id): gr = Product_group.objects.all().get(id=gr_id) tp = Product_type() tp.group = gr tp.name = request.POST['name'] if 'img' in request.FILES: tp.picture = request.FILES['img'] tp.save() typ = str(tp.picture).split('.') new_name = 'Entities/static/products/img_' + str(gr.id) + '_' + str(tp.id); t = '.' + typ[len(typ) - 1] add_picture(tp, new_name, t) else: tp.picture = 'Entities/static/products/standart.png'; tp.save() resize_picture(tp) return HttpResponseRedirect('/products/' + str(gr.id) + '/')