def post(self): status = "ok" user = self.user if not user: self.redirect('/login') store_name = self.request.get('choose_market') logging.error(store_name) address = self.request.get('address') telephone = self.request.get('telephone') stores_list = list(caching.get_stores()) t = db.GqlQuery('SELECT * FROM UserData WHERE login = :login', login = user.auth_ids) new_user = models.UserData() new_user = list(t)[0] db.delete(t) new_user.store_id = int(store_name) new_user.address = address if re.match('^\+(?:[0-9] ?){6,14}[0-9]$', telephone): new_user.telephone = telephone else: status = "telephone" new_user.put() memcache.set('current_store', None) memcache.set('current_store' + user.auth_ids[0], None) self.render('user_profile_change.html',{'m_user': new_user, 'is_home':1, 'first_name' : user.name, 'last_name' : user.last_name, 'stores_list': stores_list, 'address': new_user.address if new_user.address else "", 'telephone': new_user.telephone if new_user.telephone else "", 'status': status})
def get(self): item_list = self.get_items_from_cart() store_sum = {} if item_list: for items, cost in item_list: logging.error(len(items)) if items: quantity = int(round(cost / items[0].price)) for item in items: if item.store not in store_sum: store_sum[item.store] = 0 store_sum[item.store] += int( round(item.price * quantity)) min_sum = -1 for store, m_sum in store_sum.items(): if min_sum == -1: min_sum = m_sum else: min_sum = min(min_sum, m_sum) store_list = list(caching.get_stores()) categories = list(caching.get_categories()) subcategories = list(caching.get_subcategories()) self.render( 'show_cart.html', { 'subcategories': subcategories, 'categories': categories, 'item_list': item_list, 'store_sum': store_sum, 'store_list': store_list, 'min_sum': min_sum, 'is_home': 1 })
def get(self): item_list = self.get_items_from_cart() store_sum = {} if item_list: for items, cost in item_list: logging.error(len(items)) if items: quantity = int(round(cost / items[0].price)) for item in items: if item.store not in store_sum: store_sum[item.store] = 0 store_sum[item.store] += int(round(item.price * quantity)) min_sum = -1 for store, m_sum in store_sum.items(): if min_sum == -1: min_sum = m_sum else: min_sum = min(min_sum, m_sum) store_list = list(caching.get_stores()) categories = list(caching.get_categories()) subcategories = list(caching.get_subcategories()) self.render('show_cart.html', {'subcategories':subcategories, 'categories':categories, 'item_list':item_list, 'store_sum':store_sum, 'store_list':store_list, 'min_sum':min_sum, 'is_home':1})
def get(self): item_name = self.request.get('name') item = caching.get_one_item(item_name) first_item = None dates = {} if not item or len(item) == 0: item = None else: first_item = item[0] for i in item: dates[i._id] = i.added_date.strftime('%d-%m-%y %H:%M:%S') logging.error(item) categories = list(caching.get_categories()) subcategories = list(caching.get_subcategories()) item_cart = self.session.get('items') store_list = list(caching.get_stores()) self.render( "item_viewer.html", { 'item_name': item_name, 'items': item, 'item': first_item, 'categories': categories, 'subcategories': subcategories, 'store_list': store_list, 'item_cart': item_cart, 'dates': dates, 'is_home': 1 })
def get(self, category_id, subcategory_id): current_store = self.request.get('store') items = caching.get_items_with_subcategory(subcategory_id) total_items_size = len(items) items = items[:min(len(items), items_per_page)] categories = list(caching.get_categories()) subcategories = list(caching.get_subcategories()) item_list = self.get_items_from_cart() store_sum = {} if item_list: for items_, cost in item_list: logging.error(len(items_)) if items_: quantity = int(round(cost / items_[0].price)) for item in items_: if item.store not in store_sum: store_sum[item.store] = 0 store_sum[item.store] += int( round(item.price * quantity)) store_list = list(caching.get_stores()) item_cart = self.session.get('items') store_total = self.session.get('store_total') dates = {} for i in items: dates[i._id] = i.added_date.strftime('%d-%m-%y %H:%M:%S') self.render( "main.html", { 'current_page': 0, 'subcategories': subcategories, 'pagination_count': pagination_count, 'items_per_page': items_per_page, 'total_items_size': total_items_size, 'items': items, 'dates': dates, 'current_store': current_store, 'items_size': len(items) - 1, 'categories': categories, 'item_cart': item_cart, 'cat_num': int(category_id), 'store_total': store_total, 'store_sum': store_sum, 'store_list': store_list, 'item_list': item_list, 'shop_list_data': self.session.get('shop_list_data'), })
def post(self): if self.user_info: data = json.loads(self.request.body) item = data['item'] price = float(data['price']) quantity = int(data['quantity']) last_quantity = int(data['last_quantity']) self.session['items'][item] = quantity * price stores = caching.get_stores() if not self.session.get('store_total'): for store in stores: self.session['store_total'][str(store._id)] = 0 items_list = caching.get_one_item(item) if item not in self.session['quantity']: self.session['quantity'][item] = 0 last_quantity = self.session['quantity'][item] for cur_item in items_list: self.session['store_total'][str( cur_item.store)] += cur_item.price * (quantity - last_quantity) if quantity == 0: del self.session['items'][item] total_sum = 0 for m_item, m_cost in self.session['items'].items(): total_sum += m_cost self.session['quantity'][item] = quantity response = {} response["status"] = 1 response["number"] = total_sum for store in stores: response[str(store._id)] = self.session['store_total'][str( store._id)] self.session['item_count'] = total_sum self.response.out.write(json.dumps(response)) else: self.response.out.write(json.dumps({"status": 0})) logging.error("%s not found" % self.user_info.name)
def get(self, category_id, current_page): current_store = self.request.get('store') items = caching.get_items_with_category(category_id) total_items_size = len(items) start_from = int(current_page) * items_per_page items = items[start_from:min(len(items), start_from + items_per_page)] categories = list(caching.get_categories()) subcategories = list(caching.get_subcategories()) item_cart = self.session.get('items') item_list = self.get_items_from_cart() store_sum = {} if item_list: for items_, cost in item_list: logging.error(len(items_)) if items_: quantity = int(round(cost / items_[0].price)) for item in items_: if item.store not in store_sum: store_sum[item.store] = 0 store_sum[item.store] += int( round(item.price * quantity)) store_list = list(caching.get_stores()) store_total = self.session.get('store_total') self.render( "main.html", { 'current_page': int(current_page), 'subcategories': subcategories, 'current_store': current_store, 'pagination_count': pagination_count, 'items_per_page': items_per_page, 'total_items_size': total_items_size, 'items': items, 'items_size': len(items) - 1, 'categories': categories, 'item_cart': item_cart, 'cat_num': int(category_id), 'store_total': store_total, 'store_sum': store_sum, 'store_list': store_list, 'item_list': item_list, })
def get(self): user = self.user if not user: self.redirect('/login') user = user.to_dict() logging.error(user) stores_list = list(caching.get_stores()) cur_user = list(db.GqlQuery('SELECT * FROM UserData WHERE login = :login', login = user['auth_ids']))[0] self.render('user_profile_change.html',{'m_user': cur_user, 'is_home':1, 'first_name' : user['name'], 'last_name' : user['last_name'], 'stores_list':stores_list, 'address': cur_user.address if cur_user.address else "", 'telephone': cur_user.telephone if cur_user.telephone else "", 'status': ""})
def get(self): user = self.user if not user: self.redirect('/login') user = user.to_dict() logging.error(user) stores_list = list(caching.get_stores()) cur_user = list( db.GqlQuery('SELECT * FROM UserData WHERE login = :login', login=user['auth_ids']))[0] self.render( 'user_profile_change.html', { 'm_user': cur_user, 'is_home': 1, 'first_name': user['name'], 'last_name': user['last_name'], 'stores_list': stores_list, 'address': cur_user.address if cur_user.address else "", 'telephone': cur_user.telephone if cur_user.telephone else "", 'status': "" })
def get(self): item_name = self.request.get('name') item = caching.get_one_item(item_name) first_item = None dates = {} if not item or len(item) == 0: item = None else: first_item = item[0] for i in item: dates[i._id] = i.added_date.strftime('%d-%m-%y %H:%M:%S') logging.error(item) categories = list(caching.get_categories()) subcategories = list(caching.get_subcategories()) item_cart = self.session.get('items') store_list = list(caching.get_stores()) self.render("item_viewer.html", { 'item_name': item_name, 'items': item, 'item': first_item, 'categories': categories, 'subcategories': subcategories, 'store_list': store_list, 'item_cart': item_cart, 'dates': dates, 'is_home': 1 })
def post(self): status = "ok" user = self.user if not user: self.redirect('/login') store_name = self.request.get('choose_market') logging.error(store_name) address = self.request.get('address') telephone = self.request.get('telephone') stores_list = list(caching.get_stores()) t = db.GqlQuery('SELECT * FROM UserData WHERE login = :login', login=user.auth_ids) new_user = models.UserData() new_user = list(t)[0] db.delete(t) new_user.store_id = int(store_name) new_user.address = address if re.match('^\+(?:[0-9] ?){6,14}[0-9]$', telephone): new_user.telephone = telephone else: status = "telephone" new_user.put() memcache.set('current_store', None) memcache.set('current_store' + user.auth_ids[0], None) self.render( 'user_profile_change.html', { 'm_user': new_user, 'is_home': 1, 'first_name': user.name, 'last_name': user.last_name, 'stores_list': stores_list, 'address': new_user.address if new_user.address else "", 'telephone': new_user.telephone if new_user.telephone else "", 'status': status })
def post(self): email = self.request.get('email') user_name = self.request.get('name') password = self.request.get('password') check_password = self.request.get('check_password') last_name = self.request.get('lastname') first_name = self.request.get('firstname') store_name = self.request.get('choose_market') stores_list = list(caching.get_stores()) logging.error(store_name) form_result = "" if password != check_password: form_result = "Two passwords do not match" self.render("signup.html", {'is_home':1, 'form_result':form_result, 'firstname':first_name, 'email':email, 'lastname':last_name, 'name':user_name, 'stores_list':stores_list, 'my_market':store_name}) return if len(password) < 5: form_result = "Password length MUST be more than 4 characters" self.render("signup.html", {'is_home':1, 'form_result':form_result, 'firstname':first_name, 'email':email, 'lastname':last_name, 'name':user_name, 'stores_list':stores_list, 'my_market':store_name}) return unique_properties = ['email_address'] user_data = self.user_model.create_user(user_name, unique_properties, email_address=email, name=first_name, password_raw=password, last_name=last_name, verified=False, store_id = caching.get_store_id_with_name(store_name)) if not user_data[0]: #user_data is a tuple form_result = "User with such username or e-mail already exists" self.render("signup.html", {'is_home':1, 'form_result':form_result, 'firstname':first_name, 'email':email, 'lastname':last_name, 'name':user_name, 'stores_list':stores_list, 'my_market':store_name}) return user = user_data[1] user_id = user.get_id() token = self.user_model.create_signup_token(user_id) t = models.UserData(first_name = first_name, last_name = last_name, login = user_name, store_id = caching.get_store_id_with_name(store_name), email = email) t.put() verification_url = self.uri_for('verification', type='v', user_id=user_id, signup_token=token, _full=True) msg = u""" Сәлем {name}! Осы пошта арқылы abzaloid.appspot.com сайтында біреу тіркелді. Егер өзіңіз болсаңыз, онда келесі үзбе арқылы электронды поштаңызды растауыңызды өтінеміз: {url} Сіздің логиніңіз: {login} Kazakh Shop-ты қолданғаңызға рақмет! Ізгі тілекпен, Kazakh Shop! """ # self.display_message(msg.format(url=verification_url)) message = mail.EmailMessage() message.sender = "Kazakh Shop <*****@*****.**>" message.to = email message.subject = "abzaloid.appspot.com тіркелу" message.body = msg.format(url=verification_url,name=first_name,login=user_name) message.send() try: u = self.auth.get_user_by_password(user_name, password, remember=True, save_session=True) self.session["item_count"] = 0 self.session["add_to_cart_count"] = 0 self.session["items"] = {} self.session["store_total"] = {} self.session['quantity'] = {} self.session['shop_list_data'] = "" self.redirect("/") except (InvalidAuthIdError, InvalidPasswordError) as e: logging.info('Login failed for user %s because of %s', user_name, type(e))
def get(self): stores_list = list(caching.get_stores()) self.render('signup.html',{'is_home':1, 'stores_list':stores_list})
def get(self): user_name = "None" if self.user_info: my_user = self.user user_name = my_user.auth_ids[0] current_store = self.request.get('store') if current_store is None or current_store == "": if memcache.get('current_store' + user_name): current_store = memcache.get('current_store' + user_name) else: if user_name != "None": current_store = caching.get_store_with_id( caching.get_user(user_name, update=True).store_id) else: current_store = caching.get_store_with_id(0) memcache.set('current_store' + user_name, current_store) else: current_store = caching.get_store_with_id(int(current_store)) memcache.set('current_store' + user_name, current_store) data = self.request.get('subcat') subcat = data.split(' ') result = [] for s in subcat: if s is not None: logging.error(s) cur_s = search.getSubCategory(s) result.append(cur_s) result = list(set(result)) categories = list(caching.get_categories()) subcategories = list(caching.get_subcategories()) item_cart = self.session.get('items') item_list = self.get_items_from_cart() store_sum = {} if item_list: for items_, cost in item_list: logging.error(len(items_)) if items_: quantity = int(round(cost / items_[0].price)) for item in items_: if item.store not in store_sum: store_sum[item.store] = 0 store_sum[item.store] += int( round(item.price * quantity)) store_list = list(caching.get_stores()) store_total = self.session.get('store_total') best_subcats_list = [] best_items_list = [] for subcategory in result: if subcategory: best_subcats_list.append(subcategory) best_items_list.append( caching.get_items_with_subcategory(subcategory._id)) self.session['shop_list_data'] = data dates = {} for i in best_items_list: for j in i: dates[j._id] = j.added_date.strftime('%d-%m-%y %H:%M:%S') self.render( 'shopping_list.html', { 'subcategories': subcategories, 'categories': categories, 'item_cart': item_cart, 'store_total': store_total, 'store_sum': store_sum, 'dates': dates, 'store_list': store_list, 'item_list': item_list, 'current_store': current_store, 'best_subcats_list': best_subcats_list, 'best_items_list': best_items_list, 'shop_list_data': self.session.get('shop_list_data') }, )
def get(self, subcategory_id): user_name = "None" if self.user_info: my_user = self.user user_name = my_user.auth_ids[0] current_store = self.request.get('store') if current_store is None or current_store == "": if memcache.get('current_store' + user_name): current_store = memcache.get('current_store' + user_name) else: if user_name != "None": current_store = caching.get_store_with_id( caching.get_user(user_name, update=True).store_id) else: current_store = caching.get_store_with_id(0) memcache.set('current_store' + user_name, current_store) else: current_store = caching.get_store_with_id(int(current_store)) memcache.set('current_store' + user_name, current_store) if 'used_category' not in self.session: self.session['used_category'] = [] if subcategory_id in self.session['used_category']: index = 0 temp = [] for i in self.session['used_category']: if i != subcategory_id: temp.append(i) self.session.pop('used_category') self.session['used_category'] = temp items = [] for subcategory in self.session['used_category']: logging.error(subcategory) items += caching.get_items_with_subcategory(subcategory) total_items_size = len(items) categories = list(caching.get_categories()) subcategories = list(caching.get_subcategories()) item_cart = self.session.get('items') item_list = self.get_items_from_cart() store_sum = {} if item_list: for items_, cost in item_list: logging.error(len(items_)) if items_: quantity = int(round(cost / items_[0].price)) for item in items_: if item.store not in store_sum: store_sum[item.store] = 0 store_sum[item.store] += int( round(item.price * quantity)) store_list = list(caching.get_stores()) store_total = self.session.get('store_total') dates = {} for i in items: dates[i._id] = i.added_date.strftime('%d-%m-%y %H:%M:%S') self.render( "main.html", { 'current_page': 0, 'subcategories': subcategories, 'pagination_count': -1, 'items_per_page': items_per_page, 'total_items_size': total_items_size, 'items': items, 'dates': dates, 'items_size': len(items) - 1, 'current_store': current_store, 'categories': categories, 'item_cart': item_cart, 'store_total': store_total, 'active_subcategories': self.session['used_category'], 'store_sum': store_sum, 'store_list': store_list, 'item_list': item_list, 'shop_list_data': self.session.get('shop_list_data'), })
def get(self, category_id, subcategory_id, current_page): user_name = "None" if self.user_info: my_user = self.user user_name = my_user.auth_ids[0] current_store = self.request.get('store') if current_store is None or current_store == "": if memcache.get('current_store' + user_name): current_store = memcache.get('current_store' + user_name) else: if user_name != "None": current_store = caching.get_store_with_id( caching.get_user(user_name, update=True).store_id) else: current_store = caching.get_store_with_id(0) memcache.set('current_store' + user_name, current_store) else: current_store = caching.get_store_with_id(int(current_store)) memcache.set('current_store' + user_name, current_store) items = caching.get_items_with_subcategory(subcategory_id) total_items_size = len(items) start_from = int(current_page) * items_per_page items = items[start_from:min(len(items), start_from + items_per_page)] categories = list(caching.get_categories()) subcategories = list(caching.get_subcategories()) item_cart = self.session.get('items') item_list = self.get_items_from_cart() store_sum = {} if item_list: for items_, cost in item_list: logging.error(len(items_)) if items_: quantity = int(round(cost / items_[0].price)) for item in items_: if item.store not in store_sum: store_sum[item.store] = 0 store_sum[item.store] += int( round(item.price * quantity)) store_list = list(caching.get_stores()) store_total = self.session.get('store_total') dates = {} for i in items: dates[i._id] = i.added_date.strftime('%d-%m-%y %H:%M:%S') self.render( "main.html", { 'current_page': int(current_page), 'subcategories': subcategories, 'pagination_count': pagination_count, 'items_per_page': items_per_page, 'current_store': current_store, 'total_items_size': total_items_size, 'items': items, 'dates': dates, 'items_size': len(items) - 1, 'categories': categories, 'item_cart': item_cart, 'cat_num': int(category_id), 'subcat_num': int(subcategory_id), 'store_total': store_total, 'store_sum': store_sum, 'store_list': store_list, 'item_list': item_list, 'shop_list_data': self.session.get('shop_list_data'), })