def addBrand(request): if request.method != 'POST': regis_form = AddBrandForm() context = {'form': regis_form, 'context': 'Add Brand'} return render(request, 'addInviteRegisterBrand.html', context) else: brandName = request.POST.get('brandName') try: if brandName == '': raise Exception("required field Empty") if len(brandName) > 50: messages.success( request, 'Brand Name has tobe less than or equal 50 characters') return redirect('addBrand') if Brand.objects.filter(brandName=brandName).first(): messages.success(request, 'Brand Name is Taken') return redirect('addBrand') if checkChar(brandName) == False: messages.success(request, 'Name cannot contain / , # , and ?') return redirect('addBrand') brand_obj = Brand.objects.create(brandName=brandName, status='No_User') brand_obj.save() return redirect('brandcontrol') except Exception as e: context = {'message': 'error'} return render(request, 'error.html', context)
def brandEdit(request, brandName, context): try: getUserAuth = request.user getBrand = Brand.objects.get(brandName=brandName) if request.method != 'POST': if getUserAuth.groups.filter(name='Admin').exists(): pass elif getUserAuth.username != getBrand.brandName: return HttpResponse('You are not allowed to view this page') context = {'obj': getBrand, 'context': context} return render(request, 'brandEdit.html', context) else: bName = request.POST.get('brandName') brandUrl = request.POST.get('brandUrl') description = request.POST.get('description') if bName == '': raise Exception("required field Empty") if len(bName) > 50: messages.success( request, 'Brand Name has tobe less than or equal 50 characters') return redirect('brandEdit', context=context, brandName=brandName) req = requests.head(brandUrl) if req.status_code == 404: messages.success(request, 'Url\'s not valid') return redirect('brandEdit', context=context, brandName=brandName) if checkChar(bName) == False: messages.success(request, 'Name cannot contain / , # , and ?') return redirect('brandEdit', context=context, brandName=brandName) if getUserAuth.groups.filter(name='Admin').exists(): if getBrand.status == 'Verified': getAuthUser = auth_user.objects.get( username=getBrand.brandName) getAuthUser.username = bName getAuthUser.save() getBrand.brandName = bName getBrand.brandURL = brandUrl getBrand.description = description else: if Brand.objects.filter(brandName=bName).first(): if (request.user.username == bName): pass else: messages.success(request, 'Brand Name is Taken') return redirect('brandEdit', context=context, brandName=brandName) getBrand.brandName = bName getBrand.brandURL = brandUrl getBrand.description = description getAuthUser = auth_user.objects.get( username=getUserAuth.username) getAuthUser.username = bName getAuthUser.save() getBrand.save() if context == 'editBrandPage': return redirect('brandPage', brandName=getBrand.brandName, sort="By Date") else: return redirect('brandcontrol') except Exception as e: context = {'message': 'error'} return render(request, 'error.html', context)
def addProduct(request): if request.method != 'POST': ddCategory = Category.objects.all() ddSubCategory = SubCategory.objects.all() form = ProductForm() context = { 'form': form, 'category': ddCategory, 'subCategory': ddSubCategory, } return render(request, 'addProduct.html', context) else: productName = request.POST.get('productName') brand = request.POST.get('productBrand') category = request.POST.get('category') subCategory = request.POST.get('subCategory') description = request.POST.get('description') videoUrl = request.POST.get('videoUrl') try: brand_Id = Brand.objects.get(brandName=brand) category_Id = Category.objects.get(categoryName=category) subCategory_Id = SubCategory.objects.get( subCategoryName=subCategory, categoryId=category_Id) if productName == '': raise Exception("required field Empty") if brand == '': raise Exception("required field Empty") if category == '': raise Exception("required field Empty") if subCategory == '': raise Exception("required field Empty") if description == '': raise Exception("required field Empty") if videoUrl == '': raise Exception("required field Empty") checkUsr = request.user if checkUsr.groups.filter(name='Brand').exists(): if brand != checkUsr.username: raise Exception("forbidden") else: pass if checkChar(productName) == False: messages.success(request, 'Name cannot contain / , # , and ?') return redirect('addProduct') if len(productName) > 50: messages.success( request, 'Product Name has tobe less than or equal 50 characters') return redirect('addProduct') if Product.objects.select_related('brandId').filter( productName=productName, brandId__brandName=brand_Id.brandName).first(): messages.success(request, 'Product is already exist') return redirect('addProduct') if checkYoutubeUrl(videoUrl) == False: messages.success(request, 'url not valid') return redirect('addProduct') if len(description) < 75: messages.success( request, 'description need to be equal or more than 75 character') return redirect('addProduct') product_obj = Product.objects.create(categoryId=category_Id, subCategoryId=subCategory_Id, brandId=brand_Id, productName=productName, description=description, videoUrl=videoUrl, dtm_crt=datetime.now()) product_obj.save() web_direct = 'success.html' return redirect('addProductPicture', brand=brand_Id.brandName, productName=product_obj.productName) except Exception as e: print(e) context = {'message': 'error'} return render(request, 'error.html', context)
def addEditProduct(request, context, productName, brand): error = 0 try: getProduct = Product.objects.select_related('brandId').get( brandId__brandName=brand, productName=productName) if request.method != 'POST': ddCategory = Category.objects.all() ddSubCategory = SubCategory.objects.all() product = getProduct form = ProductForm() context = { 'form': form, 'product': product, 'category': ddCategory, 'subCategory': ddSubCategory, 'context': context } return render(request, 'addProductEdit.html', context) else: productName = request.POST.get('productName') brand = request.POST.get('productBrand') category = request.POST.get('category') subCategory = request.POST.get('subCategory') description = request.POST.get('description') videoUrl = request.POST.get('videoUrl') error = 1 brand_Id = Brand.objects.get(brandName=brand) category_Id = Category.objects.get(categoryName=category) subCategory_Id = SubCategory.objects.get( subCategoryName=subCategory, categoryId=category_Id) if productName == '': raise Exception("required field Empty") if brand == '': raise Exception("required field Empty") if category == '': raise Exception("required field Empty") if subCategory == '': raise Exception("required field Empty") if description == '': raise Exception("required field Empty") if videoUrl == '': raise Exception("required field Empty") checkUsr = request.user if checkUsr.groups.filter(name='Brand').exists(): if brand != checkUsr.username: raise Exception("forbidden") else: pass if len(productName) > 50: messages.success( request, 'Product Name has tobe less than or equal 50 characters') return redirect('editProduct', context=context, productName=productName, brand=brand) if checkChar(productName) == False: messages.success(request, 'Name cannot contain / , # , and ?') return redirect('editProduct', context=context, productName=productName, brand=brand) if checkYoutubeUrl(videoUrl) == False: messages.success(request, 'url not valid') return redirect('editProduct', context=context, productName=productName, brand=brand) if len(description) < 75: messages.success( request, 'description need to be equal or more than 75 character') return redirect('editProduct', context=context, productName=productName, brand=brand) getProduct.categoryId = category_Id getProduct.subCategoryId = subCategory_Id getProduct.brandId = brand_Id getProduct.productName = productName getProduct.description = description getProduct.videoUrl = videoUrl getProduct.dtm_upd = datetime.now() getProduct.save() if (context == "editAddProduct"): return redirect('addProductPicture', brand=brand_Id.brandName, productName=getProduct.productName) elif (context == "editProductRating"): return redirect('showProduct', brand=brand_Id.brandName, productName=getProduct.productName) elif (context == "editProductBrand"): return redirect('brandPage', brandName=brand_Id.brandName, sort="By Date") except Exception as e: print(e) context = None if error == 0: context = {'message': "product " + productName + " Not Found"} else: context = {'message': 'error'} return render(request, 'error.html', context)
def registerMember (request): if request.method != 'POST': regis_form = UserForm() context = { 'form': regis_form, 'role': 'Member' } return render(request,'registerMember.html', context) else : username = request.POST.get('username') email = request.POST.get('email') password = request.POST.get('password') conf_pass = request.POST.get('confirm_pass') web_direct = '' try: if username == '': raise Exception("required field Empty") if email == '': raise Exception("required field Empty") if password == '': raise Exception("required field Empty") if conf_pass == '': raise Exception("required field Empty") if len(username) > 20: messages.success(request, 'User Name has tobe less than or equal 20 characters') return redirect ('addProduct') if checkChar (username) == False: messages.success(request, 'Name cannot contain / , # , and ?') return redirect ('regularUser') if User.objects.filter(userName = username).first(): messages.success(request, 'Username is Taken') return redirect ('regularUser') if User.objects.filter(email = email).first(): messages.success(request, 'email is Taken') return redirect ('regularUser') check_pass = weakPassword (password) if check_pass != 'True': messages.success(request, check_pass) return redirect ('regularUser') if (conf_pass != password): messages.success(request, 'confirm password should be same as password') return redirect ('regularUser') token = str (uuid.uuid4()) profile_obj = User.objects.create( userName = username, email = email, password = make_password(password), roleId = 'Reg_User', description = '', status = 'Pending', dtm_crt = datetime.now(), verified_at = None, auth_token = token ) profile_obj.save() regisUserAuth(profile_obj) domain = get_current_site(request).domain sendMail (domain, profile_obj ,'verification', '') web_direct = 'token-send.html' return render(request,'token-send.html') except Exception as e: print(e) web_direct = 'error.html' return render(request,web_direct)
def registerMusicStore (request): if request.method != 'POST': regis_form = MusicStoreForm() context = { 'form': regis_form } return render(request,'registerMusicStore.html', context) else: musicStoreName = request.POST.get('username') address = request.POST.get('address') email = request.POST.get('email') password = request.POST.get('password') conf_pass = request.POST.get('confirm_pass') contact = request.POST.get('contact') msPicture = request.FILES['musicStorePicture'] msPicture.name = musicStoreName+'.jpg' msPicture2 = request.FILES['musicStorePicture2'] msPicture2.name = musicStoreName+'2.jpg' msPicture3 = request.FILES['musicStorePicture3'] msPicture3.name = musicStoreName+'3.jpg' description = request.POST.get('description') web_direct = '' try: if musicStoreName == '': raise Exception("required field Empty") if address == '': raise Exception("required field Empty") if email == '': raise Exception("required field Empty") if password == '': raise Exception("required field Empty") if conf_pass == '': raise Exception("required field Empty") if contact == '': raise Exception("required field Empty") if msPicture == '' or msPicture == None: raise Exception("required field Empty") if msPicture2 == '' or msPicture2 == None: raise Exception("required field Empty") if msPicture3 == '' or msPicture3 == None: raise Exception("required field Empty") if description == '': raise Exception("required field Empty") if checkChar (musicStoreName) == False: messages.success(request, 'Name cannot contain / , # , and ?') return redirect ('musicStore') if len(musicStoreName) > 20: messages.success(request, 'Music Store Name has tobe less than or equal 20 characters') return redirect ('musicStore') if User.objects.filter(userName = musicStoreName).first(): messages.success(request, 'Music Store Name is Taken') return redirect ('musicStore') if User.objects.filter(email = email).first(): messages.success(request, 'email is Taken') return redirect ('musicStore') check_pass = weakPassword (password) if check_pass != 'True': messages.success(request, check_pass) return redirect ('musicStore') if (conf_pass != password): messages.success(request, 'confirm password should be same as password') return redirect ('musicStore') token = str (uuid.uuid4()) profile_obj = User.objects.create( userName = musicStoreName, email = email, password = make_password(password), roleId = 'Mus_Store', description = description, status = 'Pending', dtm_crt = datetime.now(), verified_at = None, auth_token = token ) profile_obj.save() mStore_obj = MusicStoreData.objects.create( userID = profile_obj, address = address, musicStorePicture = msPicture, musicStorePicture2 = msPicture2, musicStorePicture3 = msPicture3, contact = contact ) mStore_obj.save() img1 = Image.open(mStore_obj.musicStorePicture.path) img1 = make_square(img1) img1.save(mStore_obj.musicStorePicture.path) img2 = Image.open(mStore_obj.musicStorePicture2.path) img2 = make_square(img2) img2.save(mStore_obj.musicStorePicture2.path) img3 = Image.open(mStore_obj.musicStorePicture3.path) img3 = make_square(img3) img3.save(mStore_obj.musicStorePicture3.path) regisUserAuth(profile_obj) domain = get_current_site(request).domain sendMail(domain, profile_obj, 'verification', '') web_direct = 'token-send.html' except Exception as e: print(e) web_direct = 'error.html' return render(request,web_direct)
def editUserData(request, userName): error = 0 try: context = None getUser = User.objects.get(userName=userName) if request.user.username != getUser.userName: return HttpResponse('You are not allowed to view this page') if getUser.roleId == "Mus_Store": getUser = MusicStoreData.objects.select_related('userID').get( userID__userName=userName) context = 'music store' else: context = 'user data' if request.method != 'POST': context = {'User': getUser, 'context': context} return render(request, 'profileEdit.html', context) else: if context == 'user data': name = request.POST.get('userName') description = request.POST.get('description') error = 1 if name == '': raise Exception("Username Empty") if len(name) > 20: messages.success( request, 'Store Name has tobe less than or equal 20 characters') return redirect('editUserData', userName=userName) if User.objects.filter(userName=name).first(): if (request.user.username == name): pass else: messages.success(request, 'User Name is Taken') return redirect('editUserData', userName=userName) if checkChar(name) == False: messages.success(request, 'Name cannot contain / , # , and ?') return redirect('editUserData', userName=userName) getUser.userName = name getUser.description = description getUser.save() getUserAuth = auth_user.objects.get(username=userName) getUserAuth.username = name getUserAuth.save() return redirect('profilePage', userName=getUserAuth.username) else: name = request.POST.get('userName') address = request.POST.get('address') contact = request.POST.get('contact') description = request.POST.get('description') error = 1 if name == '': raise Exception("Username Empty") if address == '': raise Exception("Username Empty") if contact == '': raise Exception("Username Empty") if User.objects.filter(userName=name).first(): if (request.user.username == name): pass else: messages.success(request, 'User Name is Taken') return redirect('editUserData', userName=userName) if len(name) > 20: messages.success( request, 'Store Name has tobe less than or equal 20 characters') return redirect('editUserData', userName=userName) if checkChar(name) == False: messages.success(request, 'Name cannot contain / , # , and ?') return redirect('editUserData', userName=userName) getUser.address = address getUser.contact = contact getUser.save() getUserData = User.objects.get( userName=getUser.userID.userName) getUserData.userName = name getUserData.description = description getUserData.save() getUserAuth = auth_user.objects.get(username=userName) getUserAuth.username = name getUserAuth.save() return redirect('profilePage', userName=getUserAuth.username) except Exception as e: print(e) if error == 0: context = {'message': "User " + userName + " Not Found"} else: context = {'message': 'error'} return render(request, 'error.html', context)