def update_item(self): response = reply_object() item_category = Category.objects.get(pk=self.cleaned_data["category"]) price_contact_seller = False if self.cleaned_data["contact_seller"] == 'on': price_contact_seller = True item = SellerItem.objects.get(pk=self.cleaned_data["object_id"], user=get_me(self.request)) item.title = self.cleaned_data["title"] item.sub_title = self.cleaned_data["sub_title"] item.minimum_order_quantity = self.cleaned_data[ "minimum_order_quantity"] item.maximum_order_quantity = self.cleaned_data[ "maximum_order_quantity"] item.description = self.cleaned_data["description"] item.category = item_category item.price = self.cleaned_data["price"] item.contact_seller = price_contact_seller item.save() self.update_image("image1", item) self.update_image("image2", item) self.update_image("image3", item) self.update_image("image4", item) self.update_image("image5", item) response["code"] = settings.APP_CODE["UPDATED"] response["object_id"] = item.id return response
def seller_message_threads(request, page): seller_items = SellerItem.objects.filter(user=get_me(request)) message_threads = MessageThread.objects.select_related().filter( seller_item__in=seller_items) return render_to_response('seller/seller_message_thread.html', context_instance=RequestContext( request, {"message_threads": message_threads}))
def create_item(self): response = reply_object() item_category = Category.objects.get(pk=self.cleaned_data["category"]) price_contact_seller = False if self.cleaned_data["contact_seller"] == 'on': price_contact_seller = True item = SellerItem.objects.create( title=self.cleaned_data["title"], sub_title=self.cleaned_data["sub_title"], minimum_order_quantity=self.cleaned_data["minimum_order_quantity"], maximum_order_quantity=self.cleaned_data["maximum_order_quantity"], description=self.cleaned_data["description"], category=item_category, price=self.cleaned_data["price"], contact_seller=price_contact_seller, user=get_me(self.request)) item.save() #Handle file uploads self.save_image("image1", item) self.save_image("image2", item) self.save_image("image3", item) self.save_image("image4", item) self.save_image("image5", item) response["code"] = settings.APP_CODE["SAVED"] response["object_id"] = item.id return response
def seller_product_edit(request, object_id): """ Seller edit product """ item = get_object_or_404(SellerItem, pk=object_id, user=get_me(request)) form = SellerItemForm( request=request, initial={ "title": item.title, "sub_title": item.sub_title, "minimum_order_quantity": item.minimum_order_quantity, "maximum_order_quantity": item.maximum_order_quantity, "description": item.description, "category": item.category.id, "price": item.price, "contact_seller": item.contact_seller, "object_id": item.id}) seller_item_images = {} for each_image in SellerItemImage.objects.filter(seller_item=item): seller_item_images[each_image.image_key] = each_image.image return render_to_response('seller/seller_product.html', context_instance=RequestContext( request, {"form": form, "images": seller_item_images}))
def save(self): response = reply_object() try: post = Post.objects.get(pk = self.cleaned_data["post_id"]) reply = Reply.objects.create(description = self.cleaned_data["reply_description"], user = get_me(self.request), created_date = datetime.now(), post = post, comment_number = 0, vote_number = 0 ) reply.save() post.reply_number = post.reply_number + 1 post.save() response["code"] = settings.FORUM_CODE["SAVED"] response["reply_number"] = post.reply_number response["new_reply"] = render_to_string("forum/new_reply.html", context_instance = RequestContext(self.request, {"reply" : reply})) except: response["code"] = settings.FORUM_CODE["SYSTEM ERROR"] return response
def seller_product_list(request, page): """ List sellers products """ seller_products = SellerItem.objects.select_related().filter( user=get_me(request)) return render_to_response('seller/seller_product_list.html', context_instance=RequestContext( request, {"seller_products": seller_products}))
def clean(self): if self.cleaned_data["object_id"] == 0 or\ self.cleaned_data["object_id"] == u'' or\ self.cleaned_data["object_id"] == None: if not "image1" in self.request.FILES: self.errors["image1"] = ("Product image is required"), else: seller_item = SellerItem.objects.get( pk=self.cleaned_data["object_id"], user=get_me(self.request)) if not SellerItemImage.objects.filter(image_key="image1", seller_item=seller_item).exists(): self.errors["image1"] = ("Product image is required"), return self.cleaned_data
def message_thread(request, page): user_type = request.user.get_profile().user_type if user_type == settings.APP_USER_TYPE["SELLER"]: seller_items = SellerItem.objects.filter(user=get_me(request)) message_threads = MessageThread.objects.select_related().filter( seller_item__in=seller_items) return render_to_response('seller/seller_message_thread.html', context_instance=RequestContext( request, {"message_threads": message_threads})) elif user_type == settings.APP_USER_TYPE["BUYER"]: message_threads = MessageThread.objects.select_related().filter( buyer=request.user) return render_to_response('buyer/buyer_message_thread.html', context_instance=RequestContext( request, {"message_threads": message_threads}))
def delete_image(self): response = reply_object() try: seller_item = SellerItem.objects.get( pk=self.cleaned_data["object_id"], user=get_me(self.request)) seller_item_image = SellerItemImage.objects.get( seller_item=seller_item, image_key=self.cleaned_data["image_key"]) delete_item_file(seller_item_image.image) seller_item_image.delete() response["code"] = settings.APP_CODE["DELETED"] except: response["code"] = settings.APP_CODE["DELETED"] return response
def delete_seller_item(self): response = reply_object() try: seller_item = SellerItem.objects.get( pk=self.cleaned_data["object_id"], user=get_me(self.request)) for each_image in SellerItemImage.objects.filter( seller_item=seller_item): delete_item_file(each_image.image) each_image.delete() seller_item.delete() response["code"] = settings.APP_CODE["DELETED"] except: response["code"] = settings.APP_CODE["SYSTEM ERROR"] return response
def save(self): response = reply_object() try: user = get_me(self.request) post_type_obj = PostType.objects.get(pk = self.cleaned_data["post_type"]) post = Post.objects.create(title = self.cleaned_data["title"], description = self.cleaned_data["description"], post_type = post_type_obj, user = user, created_date = datetime.now(), reply_number = 0, vote_number = 0 ) post.save() response["code"] = settings.APP_CODE["SAVED"] response["object_id"] = post.id return response except: response["code"] = settings.APP_CODE["SYSTEM ERROR"] return response
def app_user(context): print "here" if not context.user.is_anonymous(): return {"app_user" : get_me(context)} else: return {"app_user" : context.user}