def approve(request, *args, **kwargs): if request.user.is_authenticated and request.user.is_superuser: id_inc = kwargs["id_inc"] qs = pending.objects.all() for obj in qs: # print(obj.id_inc) if int(obj.id_inc) == int(id_inc): # print("heyyyyy") new_obj = Product() new_obj.user_name = obj.user_name new_obj.category = obj.category new_obj.name = obj.name new_obj.desc = obj.desc new_obj.contact_email = obj.contact_email new_obj.contact_phone = obj.contact_phone new_obj.address = obj.address new_obj.image = obj.image new_obj.price = obj.price new_obj.save() obj.delete() return HttpResponseRedirect('../../pending') break return HttpResponseRedirect('../../pending') else: return HttpResponseRedirect('../../../')
def __save_product_info(self, link_to_product): """save info about definite product""" self.__browser.get(link_to_product) img_elements = self.__browser.find_elements_by_css_selector( img_element_selector ) try: address = self.__browser.find_element_by_css_selector( self.ADDRESS_SELECTOR ).text except NoSuchElementException: address = "Адреса нет" try: product = Product.objects.get(link=link_to_product) except Product.DoesNotExist: product = Product(link=link_to_product) product.name = self.__browser.find_element_by_css_selector( self.NAME_SELECTOR ).text product.price = self.__get_product_price() product.address = address product.save() for img_element in img_elements: img_link = img_element.get_attribute(img_link_attribute) Image(link=img_link, product=product).save()