def savephone(request, phone_no=None, cid=None): dajax = Dajax() dajax.assign("#message", "innerHTML", "") if request.user.is_authenticated: if phone_no: customer = Customer.objects.get(id=cid) print customer phone = PhoneNumber() phone.customer = customer phone.phone_no = phone_no phone.save() dajax.assign( "#message", "innerHTML", """ <div class="alert alert-success"> Successfully added phone number to customer {0} <div>""".format( customer.name ), ) dajax.script("LocationReload();") else: dajax.assign( "#message", "innerHTML", """ <div class="alert alert-danger"> Please Enter valid information </div></div>""", ) return dajax.json()
def signup(request, email=None, pwd=None, cpwd=None): dajax = Dajax() print "inside signup" if email and pwd: if pwd == cpwd: if User.objects.filter(email=email) or User.objects.filter(username=email): return simplejson.dumps( { "status": "warning", "message": "A User already exist with this email address.Please select a different email address or login", } ) else: print "################################" staff = Staff() staff.username = email staff.email = email staff.set_password(pwd) staff.save() user = authenticate(username=staff.username, password=pwd) if user: login(request, user) return simplejson.dumps({"status": "reload", "message": "move to dashboard."}) else: return simplejson.dumps({"status": "warning", "message": "Password Mismacthing"}) else: print "Enter Valid Form" return simplejson.dumps({"status": "warning", "message": "Enter Valid Form."}) return dajax.json()
def get_compititor_avg(request,pid): dajax = Dajax() print "Inside Compititor Average PriceAvg " if pid: product = Product.objects.get(id=int(pid)) competitor_aveg = 0 avg = 0 com_sum = 0 if product.competitor.all(): for competitor in product.competitor.all(): com_sum = com_sum+competitor.price avg = com_sum/product.competitor.all().count() competitor_aveg=[product.competitor.all().count(),float(com_sum),avg] print "competatior_avg",avg,competitor_aveg dajax.assign('#compi_avg', 'value','{0}'.format(format(avg,'.2f'))) dajax.assign('#compi_count', 'value','{0}'.format(format(product.competitor.all().count(),'.2f'))) dajax.assign('#compi_sum', 'value','{0}'.format(format(com_sum,'.2f'))) dajax.script("updateCompetitorPrice();") return dajax.json()
def quick_view_faq(request,value=None): print "hello inside the ajax" dajax = Dajax() if value: print 'sucesssssssss' # try: # staff = Staff.objects.get(id=value) # dajax.assign('#ph_head', 'innerHTML', '') # dajax.assign('#ph_image', 'innerHTML', '') # dajax.assign('#ph_name', 'innerHTML', '') # dajax.assign('#ph_email', 'innerHTML', '') # dajax.assign('#ph_mobile', 'innerHTML', '') # dajax.assign('#ph_wechat', 'innerHTML', '') # dajax.assign('#ph_head', 'innerHTML', ''' <i class='fa fa-user'></i> {0} Profile'''.format(staff.get_full_name())) # dajax.assign('#ph_image', 'src', '{0}'.format(staff.image_display())) # dajax.assign('#ph_name', 'innerHTML','{0}'.format(staff.get_full_name())) # dajax.assign('#ph_email', 'innerHTML','{0}'.format(staff.email)) # dajax.assign('#ph_mobile', 'innerHTML','{0}'.format(staff.mobile)) # dajax.assign('#ph_wechat', 'innerHTML','{0}'.format(staff.we_chat)) # dajax.script('QuickView();') # except Staff.DoesNotExist: # pass return dajax.json()
def delete_message(request, iid, type): dajax = Dajax() response_data = {} if iid: if type == "inbox_list": update_emails(request, iid) response_data['type'] = "inbox_list" response_data['id'] = json.dumps(iid) return json.dumps(response_data) elif type == "sent_list": update_sent_emails(request, iid) response_data['type'] = "inbox_list" response_data['id'] = json.dumps(iid) return json.dumps(response_data) elif type == "inbox_detail": update_emails(request, iid) response_data['type'] = "inbox_detail" return json.dumps(response_data) elif type == "sent_detail": response_data['type'] = "sent_detail" email = Emails.objects.get(pk=int(iid)) if not email.from_delete: email.from_delete = True email.save() return json.dumps(response_data) return dajax.json()
def delete_image(request,iid): dajax = Dajax() if iid: ProductGallery.objects.get(id=int(iid)).delete() dajax.script('CheckRemainingCount();') return dajax.json()
def delete_discount(request,did): dajax = Dajax() if did: discount = Discount.objects.get(id=did) discount.delete() dajax.script('Calculation();') return dajax.json()
def delete_slider(request,value=None): dajax = Dajax() if isinstance(request.user,Staff) and request.user.user_type == 'A': try: slider = Slider.objects.get(id=value) slider.delete() dajax.script("LocationReload();") except Slider.DoesNotExist: pass return dajax.json()
def activate_reseller(request,rid): dajax = Dajax() reseller = Reseller.objects.get(id=int(rid)) reseller.is_active = True reseller.save() dajax.script("LocationReload();") return dajax.json()
def activate(request,sid): dajax = Dajax() staff = Staff.objects.get(id=int(sid)) staff.is_active = True staff.save() dajax.script("LocationReload();") return dajax.json()
def image_processing(request,iid,im_type): dajax = Dajax() print "Inside Add Image to Categories" if im_type and iid: image = ProductGallery.objects.get(id=iid) image.image_type = im_type image.save() print "Saved" return dajax.json()
def get_discount(request,product): dajax = Dajax() product = get_object_or_404(Product, id=int(product)) dajax.assign('#discount_rows', 'innerHTML', '') discounts = product.discount.all().order_by('-id') if discounts: for counter,discount in enumerate(discounts): if discount.is_active(): dajax.append('#discount_rows', 'innerHTML',''' <tr id="dis{5}"> <td>{0}</td> <td>{1}</td> <td>{2}%</td> <td>{3}</td> <td>{4}</td> <td><a class="btn btn-success btn-icon btn-circle"><i class="fa fa-check"></i></a></td> <td> <button type="button" onclick="DeleteDiscount({5});" class="btn btn-sm btn-warning"><i class="fa fa-trash"></i> Delete</button> </td> </tr> '''.format(counter+1,discount.name,discount.discount,discount.effe_date.strftime("%d %b %Y"),discount.expi_date.strftime("%d %b %Y"),discount.id)) else: dajax.append('#discount_rows', 'innerHTML',''' <tr id="dis{5}"> <td>{0}</td> <td>{1}</td> <td>{2}%</td> <td>{3}</td> <td>{4}</td> <td><a class="btn btn-danger btn-icon btn-circle"><i class="fa fa-times"></i></a></td> <td> <button type="button" onclick="DeleteDiscount({5});" class="btn btn-sm btn-warning"><i class="fa fa-trash"></i> Delete</button> </td> </tr> '''.format(counter+1,discount.name,discount.discount,discount.effe_date.strftime("%d %b %Y"),discount.expi_date.strftime("%d %b %Y"),discount.id)) dajax.script('ShowDiscountTable();') return dajax.json()
def get_shipping_rate(request,weight,unit): dajax = Dajax() print "inside the Sales tax" dajax.assign('#shipping_rate', 'value', '') if weight and unit: if unit == 'GM': weight = float(weight)/1000 price = 0.0 try: sr = ShippingCharges.objects.filter(min_weight__lte=float(weight),max_weight__gte=float(weight)).order_by('-id')[0] price = sr.amount except: sr = ShippingCharges.objects.filter(min_weight__lte=float(weight),is_infinite=True).order_by('-id')[0] price = sr.amount shipping_rate = float(weight)*float(price) default_rate = float(SiteConfigurations.objects.get().shipping_charge_default) print "Default####",default_rate if shipping_rate < default_rate: shipping_rate = default_rate print "Shipping ######",shipping_rate dajax.assign('#shipping_rate', 'value','{0}'.format(format(shipping_rate,'.2f'))) dajax.script('Calculation();') return dajax.json()
def deactivate_faq(request,value=None): dajax = Dajax() if isinstance(request.user,Staff) and request.user.user_type == 'A' : try: faq = Faq.objects.get(id=value) faq.is_active = False faq.save() dajax.script("LocationReload();") except Faq.DoesNotExist: pass return dajax.json()
def delete_product(request,pid): dajax = Dajax() if pid: product = Product.objects.get(id=int(pid)) name = product.name if request.user.user_type == 'A': product.delete() else: product.is_delete = True product.save() history = ProductHistory() history.product = product history.person = request.user history.act_type = 'DL' history.description = "Delete product" history.save() dajax.assign('#success-head', 'innerHTML', '<strong>Success!</strong>') dajax.assign('#success-body', 'innerHTML', 'The <b> {0} </b> has been deleted successfully .'.format(name)) dajax.script("Success();") return dajax.json()
def delete_repo(request,rid): dajax = Dajax() if isinstance(request.user,Staff) and request.user.user_type == 'P': if rid: Product.objects.get(id=int(rid)).delete() dajax.script('LocationReload();') elif isinstance(request.user,Staff) and request.user.user_type == 'E': if rid: product = Product.objects.get(id=int(rid)) product.is_delete = True product.save() dajax.script('SuccessReturn();') elif isinstance(request.user,Staff) and request.user.user_type == 'A': if rid: product = Product.objects.get(id=int(rid)) product.delete() dajax.script('SuccessReturn();') return dajax.json()
def get_product_details(request,pid): dajax = Dajax() print "Get Product Details" if pid: product = Product.objects.get(id=pid) dajax.assign('#pro_name', 'innerHTML','''{0}'''.format(unidecode(product.name))) dajax.assign('#pro_upc', 'innerHTML','''{0}'''.format(unidecode(product.upc))) dajax.assign('#pro_style', 'innerHTML','''{0}'''.format(unidecode(product.style_number))) dajax.assign('#pro_short', 'innerHTML','''{0}'''.format(product.short_description)) return dajax.json()
def deactivate_reseller(request,rid): dajax = Dajax() print "Inside Deactivate Reseller" reseller = Reseller.objects.get(id=int(rid)) print "Reseller",reseller [s.delete() for s in Session.objects.all() if s.get_decoded().get('_auth_user_id') == reseller.id] print "Session deletd .........." reseller.is_active = False reseller.save() dajax.script("LocationReload();") return dajax.json()
def deactivate(request,sid): dajax = Dajax() print "Inside Deactivate Staff" staff = Staff.objects.get(id=int(sid)) print "Staff",staff [s.delete() for s in Session.objects.all() if s.get_decoded().get('_auth_user_id') == staff.id] print "Session deletd .........." staff.is_active = False staff.save() dajax.script("LocationReload();") return dajax.json()
def check_remaining_count(request,pid): dajax = Dajax() print "Check Remaining Image count when uploading from jfu" if pid: product = Product.objects.get(id=pid) if SiteConfigurations.objects.get().image_count: remaining_count = int(SiteConfigurations.objects.get().image_count) - product.image_count() else: remaining_count = settings.IMAGE_COUNT - product.image_count() dajax.assign('#rem_count', 'innerHTML','''{0}'''.format(remaining_count)) return dajax.json()
def remove_from_download(request, did=None): dajax = Dajax() if isinstance(request.user,Reseller) and request.user.user_type == 'R': if 'download' in request.session: download_list = request.session['download'] selected_item = {} for d in download_list: if d['id'] == did: selected_item = d print selected_item, did download_list.remove(selected_item) request.session['download'] = download_list dajax.script('DownloadPopup();') return dajax.json()
def add_discount(request,product,names,rates,eff_dates,exp_dates): dajax = Dajax() print "inside add discount" print product,names,rates,eff_dates,exp_dates product = get_object_or_404(Product, id=int(product)) print product if len(names) == len(rates) == len(eff_dates) == len(exp_dates): for x in range(0, len(names)): print x,names[x] discount = Discount() discount.product = product discount.name = names[x] discount.discount = rates[x] discount.effe_date = datetime.datetime.strptime(eff_dates[x], '%d/%m/%Y') discount.expi_date = datetime.datetime.strptime(exp_dates[x], '%d/%m/%Y') discount.save() dajax.script('DiscountShow();') else: print "Not a valid form" dajax.script('DiscountError();') return dajax.json()
def contact_admin(request,name=None,email=None,msg=None): dajax = Dajax() dajax.assign('#message', 'innerHTML', '') if name and email and msg: contact = Contact() contact.name = name contact.email = email contact.message = msg contact.save() dajax.assign('#message', 'innerHTML', ''' <div class="alert alert-success"> Thank you "" {0} "" ! Successfully send message with us Our admin teamm will contact you soon </div>'''.format(contact.name)) else: dajax.assign('#message','innerHTML', ''' <div class="alert alert-danger"> Please Enter valid information </div></div>''') return dajax.json()
def get_sales_tax(request,state): dajax = Dajax() print "inside the Sales tax" dajax.assign('#sales_tax', 'value', '') if state: sales_tax = SaleTax.objects.get(id=int(state)) print sales_tax.tax_amount dajax.assign('#sales_tax', 'value','{0}'.format(format(sales_tax.tax_amount,'.2f'))) dajax.script('Calculation();') return dajax.json()
def check_mail(request,check_email=None): dajax = Dajax() if User.objects.filter(email=check_email) or User.objects.filter(username=check_email): print "already exist^^^^^^" dajax.assign('#username-status', 'innerHTML', '''<p style=" margin-top: -8px; color: red; ">*E-Mail Already Exist, Choose another one !</p>''') else: dajax.assign('#username-status', 'innerHTML', '''<p style=" margin-top: -8px; color: green; ">*E-Mail Id Does not Exist</p>''') return dajax.json()
def delete_store(request,sid,lang): dajax = Dajax() print "Inside Delete Store" if sid: ms = Store.objects.get(id=sid) if lang == 'zh': name = ms.name_zh else: name = ms.name ms.delete() print "Delete" dajax.assign('#success-head', 'innerHTML', '<strong>Success!</strong>') dajax.assign('#success-body', 'innerHTML', 'The <b> {0} </b> has been deleted successfully .'.format(name)) dajax.script("Success();") return dajax.json()
def check_upc(request,pid,upc): dajax = Dajax() print "Check UPC" if pid: if Product.objects.filter(upc=upc).exclude(id=pid): dajax.assign('#upc_alert', 'innerHTML',''' <span class="label label-warning">Warning</span> Product UPC Already Exist, Choose another one !''') else: dajax.assign('#upc_alert', 'innerHTML',''' <span class="label label-success">Success</span> Product UPC Does not Exist.''') return dajax.json()
def edit_category(request,nid,name,lang): dajax = Dajax() print "Inside Edit Category" if nid: node = Category.objects.get(id=nid) if lang == 'zh': print "Chinese" node.name_zh = name else: node.name = name node.save() print "Save" dajax.assign('#success-head', 'innerHTML', '<strong>Success!</strong>') dajax.assign('#success-body', 'innerHTML', 'The <b> {0} </b> has been edited successfully .'.format(name)) dajax.script("Success();") return dajax.json()
def delete_category(request,cid,lang): dajax = Dajax() print "Inside Delete Category" if cid: cate = Category.objects.get(id=cid) name = cate.name if lang == 'zh': print "Chinese" name = cate.name_zh else: name = cate.name cate.delete() print "Delete" dajax.assign('#success-head', 'innerHTML', '<strong>Success!</strong>') dajax.assign('#success-body', 'innerHTML', 'The <b> {0} </b> has been added successfully .'.format(name)) dajax.script("Success();") return dajax.json()
def add_sales_tax(request,states,rates): dajax = Dajax() print "Add Sale Taxes" if isinstance(request.user,Staff) and request.user.user_type == 'A': if states and rates: print "List",states,rates if len(states) == len(rates): for x in range(0, len(states)): print x,states[x],rates[x] sale_tax = SaleTax() sale_tax.state = states[x] sale_tax.tax_amount = float(rates[x]) sale_tax.save() dajax.assign('#success-head', 'innerHTML', '<strong>Success!</strong>') dajax.assign('#success-body', 'innerHTML', 'The sale tax has been added successfully .') dajax.script("Success();") else: dajax.assign('#warning-head', 'innerHTML', '<strong>Warning!</strong>') dajax.assign('#warning-body', 'innerHTML', "We're sorry, but something went wrong. Please be sure that you entered a valid form.") dajax.script("Warning();") else: dajax.assign('#warning-head', 'innerHTML', '<strong>Warning!</strong>') dajax.assign('#warning-body', 'innerHTML', "We're sorry, but something went wrong. Please be sure that you entered a valid form.") dajax.script("Warning();") return dajax.json()