def int_add_product(request): c1_all = Category.objects.filter(level=1) if request.method == 'POST': pro = request.POST.get('product') description = request.POST.get('description') cost = request.POST.get('cost') tags = request.POST.get('tag') status = request.POST.get('status') u = request.POST.get('person') user = User.objects.get(username=u) workplace = user.userprofile.primary_workplace li = [] c1 = request.POST.get('category1') if c1: li.append(c1) c2 = request.POST.get('category2') if c2: li.append(c2) c3 = request.POST.get('category3') if c3: li.append(c3) index = request.POST.get('i') categories = Category.objects.filter(pk__in=li) image0 = request.FILES.get('image0', None) p = {} if len(pro) > 3: product = pro p = Products.objects.create(product=product, producer=workplace, description=description, user=user, cost=cost) p.set_tags(tags) if image0: i = Images() x = i.upload_image(image=image0, user=user) p.image = x p.save() for c in categories: Product_Categories.objects.create(product=p, category=c, level=c.level) return redirect('/internal/add_product') else: p = Products.objects.last() c1_all = Category.objects.filter(level=1) return render(request, 'activities/p/add_product.html', { 'c1_all': c1_all, 'p': p })
def add_product(request): if request.method == 'POST': response = {} r_value = {} r_inputs = [] r_html = {} r_elements = [] product = request.POST.get('product') description = request.POST.get('description') tags = request.POST.get('tag') li = [] a = request.POST.get('A') if a: li.append('A') b = request.POST.get('B') if b: li.append('B') c = request.POST.get('C') if c: li.append('C') o = request.POST.get('O') if o: li.append('O') user = request.user workplace = request.user.userprofile.primary_workplace image0 = request.FILES.get('image0', None) p = Products.objects.create(product=product, producer=workplace, description=description, user=user) p.set_tags(tags) p.set_target_segments(li) if image0: i = Images() x = i.upload_image(image=image0, user=user) p.image = x p.save() r_elements = ['products_list'] r_html['products_list'] = render_to_string( 'workplace/one_product.html', {'product': p}) response['html'] = r_html response['elements'] = r_elements response['prepend'] = True return redirect('/products/' + p.slug) # return HttpResponse(json.dumps(response), content_type="application/json") else: return render(request, 'products/add_product.html')
def add_product(request): if request.method == 'POST': response = {} r_value = {} r_inputs = [] r_html = {} r_elements = [] product = request.POST.get('product') description = request.POST.get('description') tags = request.POST.get('tag') li = [] a = request.POST.get('A') if a: li.append('A') b = request.POST.get('B') if b: li.append('B') c = request.POST.get('C') if c: li.append('C') o = request.POST.get('O') if o: li.append('O') user = request.user workplace = request.user.userprofile.primary_workplace image0 = request.FILES.get('image0', None) p = Products.objects.create(product=product, producer=workplace, description=description, user=user) p.set_tags(tags) p.set_target_segments(li) if image0: i = Images() x = i.upload_image(image=image0, user=user) p.image = x p.save() r_elements = ['products_list'] r_html['products_list'] = render_to_string('workplace/one_product.html', {'product': p}) response['html'] = r_html response['elements'] = r_elements response['prepend'] = True return redirect('/products/'+p.slug) # return HttpResponse(json.dumps(response), content_type="application/json") else: return render(request, 'products/add_product.html')
def set_logo(self, image, user): i = Images() a = i.upload_image(image=image, user=user) self.logo = a
def edit_add_lead(request, slug): user = request.user direct = [f.name for f in Leads._meta.get_fields()] response = {} if slug == 'new': if request.method == 'POST': if request.POST.get('lead'): now = datetime.now() ls = {} if user.is_authenticated(): ls = Leads.objects.filter(user=user, date__range=[now-timedelta(days=1), now]) if len(ls) < 100: if user.is_authenticated(): wp = user.userprofile.primary_workplace l = Leads.objects.create(lead=request.POST['lead'], user=user, workplace=wp) else: l = Leads.objects.create(lead=request.POST['lead'], name=request.POST['user_name'], email=request.POST['user_email'], company_name=request.POST['user_company'], mobile_number=request.POST['user_mobile']) t = Thread(target=leads_mail, args=(l.id, 'created')) t.start() dictionary = {} for key in request.POST: if key in direct: try: dictionary[key] = request.POST[key] except: tb = traceback.format_exc() elif key == 'city': l.set_tags(request.POST[key]) elif key == 'other': l.set_tags(request.POST[key]) if key == 'anonymous1': l.anonymous = False l.save() for key in dictionary: setattr(l, key, dictionary[key]) l.save() image1 = request.FILES.get('photo', None) if image1: i = Images() x = i.upload_image(image=image1, user=user) l.image = x l.save() response['l_id'] = l.id doc1 = request.FILES.get('doc1', None) if doc1: d = Document() x = d.upload_doc(doc=doc1, user=user) l.doc = x l.save() return redirect('/leads/') else: return HttpResponse() else: first_time = True if user.is_authenticated(): lg = Leads.objects.filter(user=user) if len(lg) > 1: first_time = False return render(request, 'leads/edit.html', {'first_time': False}) else: l = Leads.objects.get(slug=slug) dictionary = {} if request.method == 'POST' and user == l.user: for key in request.POST: if key in direct: try: dictionary[key] = request.POST[key] except: tb = traceback.format_exc() elif key == 'city': l.set_tags(request.POST[key]) elif key == 'other': l.set_tags(request.POST[key]) if key == 'anonymous1': l.anonymous = False l.save() for key in dictionary: setattr(l, key, dictionary[key]) l.save() image1 = request.FILES.get('photo', None) if image1: i = Images() x = i.upload_image(image=image1, user=user) l.image = x l.save() response['l_id'] = l.id doc1 = request.FILES.get('doc', None) if doc1: d = Document() x = d.upload_doc(doc=doc1, user=user) l.doc = x l.save() response['l_id'] = l.id return HttpResponse(json.dumps(response), content_type="application/json") else: dictionary = {'lead': l, 'first_time': True} return render(request, 'leads/edit.html', dict(list(l.__dict__.items()) + list(dictionary.items())))
def edit_add_product(request, id): user = request.user wp = user.userprofile.primary_workplace workplace = wp response = {} c = {} pl = Products.objects.filter(producer=workplace).last() if pl: c = Product_Categories.objects.filter(product=pl.id).order_by('level') dd = pl.delivery_details dc = pl.delivery_charges minimum = pl.minimum else: dd = '' dc = '' minimum = '' c1_all = Category.objects.filter(level=1) c1_1 = itemgetter(0, 1, 2)(c1_all) c1_2 = itemgetter(3, 4, 13)(c1_all) c1_3 = itemgetter(2, 5)(c1_all) c1_4 = itemgetter(6, 7, 12, 13)(c1_all) c1_5 = itemgetter(9, 8, 6)(c1_all) c1_6 = itemgetter(10, 11)(c1_all) # c1_7 = itemgetter(6, 7, 12)(c1_all) c1_8 = itemgetter(13, 14, 15)(c1_all) if id == 'new': return redirect('/products/add_product/') # dictionary = {} # ps = Products() # p = None # if request.method == 'POST': # if request.POST.get('product'): # p = Products.objects.create(product=request.POST['product'], user=user, producer=wp, # delivery_details=dd, delivery_charges=dc, minimum=minimum) # if c: # p.set_prod_category(c) # up = user.userprofile # up.points += 5 # up.save() # response['p_id'] = p.id # image1 = request.FILES.get('photo', None) # if image1: # image = StringIO() # image1.save(image, image1.name.split('.')[-1]) # # i = Images() # # x = i.upload_image(image=image1, user=user) # # p.image = x # # p.save() # response['p_id'] = p.id # # else: # # p_t = Products() # # # # return HttpResponse(json.dumps(response), # # content_type="application/json") # if user.userprofile.product_email: # no_prod_con = False # else: # no_prod_con = True # return render(request, 'products/edit.html', {'c1_all': c1_all, 'c1_1': c1_1, 'c1_2': c1_2, # 'c1_3': c1_3, 'c1_4': c1_4, 'c1_5': c1_5, 'c1_6': c1_6, # 'c1_8': c1_8, 'p': p, 'c': c, 'first_time': True, # 'no_prod_con': no_prod_con, 'delivery_details': dd, # 'delivery_charges': dc, 'minimum': minimum}) else: p = Products.objects.get(id=id) dictionary = {} direct = [f.name for f in Products._meta.get_fields()] if request.method == 'POST' and user.userprofile.primary_workplace == p.producer: for key in request.POST: if key in direct: try: dictionary[key] = request.POST[key] except: tb = traceback.format_exc() else: li = [] li.append(request.POST.get('category1')) li.append(request.POST.get('category2')) li.append(request.POST.get('category3')) p.set_categories(li) for key in dictionary: setattr(p, key, dictionary[key]) p.save() image1 = request.FILES.get('photo', None) if image1: i = Images() x = i.upload_image(image=image1, user=user) p.image = x p.save() response['p_id'] = p.id return HttpResponse(json.dumps(response), content_type="application/json") else: c = Product_Categories.objects.filter( product=p.id).order_by('level') dictionary = { 'c1_all': c1_all, 'c1_1': c1_1, 'c1_2': c1_2, 'c1_3': c1_3, 'c1_4': c1_4, 'c1_5': c1_5, 'c1_6': c1_6, 'c1_8': c1_8, 'product': p, 'c': c, 'first_time': True } return render( request, 'products/edit.html', dict(list(p.__dict__.items()) + list(dictionary.items())))
def add_product(request): # return redirect('/products/edit_add/new') c1_all = Category.objects.filter(level=1) user = request.user workplace = request.user.userprofile.primary_workplace if request.method == 'POST': # email of the uploader, only for the first product product_email = request.POST.get('u_email') # phone of the uploader, only for the first product product_phone = request.POST.get('u_phone') up = user.userprofile up.set_product_contacts(product_email=product_email, product_phone=product_phone) pro = request.POST.get('product') description = request.POST.get('description') cost = request.POST.get('cost') tags = request.POST.get('tag') status = request.POST.get('status') up.points += 5 up.save() li = [] c1 = request.POST.get('category1') if c1: li.append(c1) c2 = request.POST.get('category2') if c2: li.append(c2) c3 = request.POST.get('category3') if c3: li.append(c3) index = request.POST.get('i') categories = Category.objects.filter(pk__in=li) workplace = request.user.userprofile.primary_workplace image0 = request.FILES.get('image0', None) p = {} if len(pro) > 3: product = pro p = Products.objects.create(product=product, producer=workplace, description=description, user=user, cost=cost) if image0: i = Images() x = i.upload_image(image=image0, user=user) p.image = x p.save() for c in categories: Product_Categories.objects.create(product=p, category=c, level=c.level) todaydate = date.today() startdate = todaydate + timedelta(days=1) enddate = startdate - timedelta(days=1) node = '''We have just listed a few products on behalf of <a href="/workplace/{0}">{1}</a>. Have a look at our profile for more details.'''.format( workplace.slug, workplace) pp = Products.objects.filter(date__range=[enddate, startdate], user=user) if len(pp) < 2: n = Node.objects.create(post=node, user=user, category='D', w_type=workplace.workplace_type) if image0: n.images = [x] response = {} response['alert'] = render_to_string('products/add_prod_alert.html', {'p': p}) return HttpResponse(json.dumps(response), content_type="application/json") else: p = Products.objects.filter(producer=workplace).last() if user.userprofile.product_email: no_prod_con = False else: no_prod_con = True c = {} if p: c = Product_Categories.objects.filter( product=p.id).order_by('level') c1_all = Category.objects.filter(level=1) c1_1 = itemgetter(0, 1, 2)(c1_all) c1_2 = itemgetter(3, 4, 13)(c1_all) c1_3 = itemgetter(2, 5)(c1_all) c1_4 = itemgetter(6, 7, 12, 13)(c1_all) c1_5 = itemgetter(9, 8, 6)(c1_all) c1_6 = itemgetter(10, 11)(c1_all) # c1_7 = itemgetter(6, 7, 12)(c1_all) c1_8 = itemgetter(13, 14, 15)(c1_all) return render( request, 'products/add_product.html', { 'c1_all': c1_all, 'c1_1': c1_1, 'c1_2': c1_2, 'c1_3': c1_3, 'c1_4': c1_4, 'c1_5': c1_5, 'c1_6': c1_6, 'c1_8': c1_8, 'p': p, 'c': c, 'first_time': False, })