def language_add(request, template="film/language_add.html"): # fun language_list try: if request.method == 'POST': # method post language_name = request.POST.get("lan_name").lstrip(" ").rstrip( " ") # get data if not language_name: # check null or not messages.add_message(request, messages.ERROR, "language name is not null allow") return redirect("add_language") # redirect else: status = check_language(language_name) # call fun if status: add_language_obj = Language.objects.create( # insert language name name=language_name) else: messages.add_message(request, messages.ERROR, "language name is already exist") return redirect("add_language") messages.add_message(request, messages.SUCCESS, "Data inserted successfully") return redirect("language_list") except Exception as ex: logger.exception(ex.args) return render(request, template, {"lan": Language.objects.all() }) # return language objects in dic and render template
def user_delete(request, id): try: User.objects.get(pk=id).delete() logger.info("User deleted successfully, User ID is = {0}".format(id)) except Exception as ex: logger.exception(ex.args) return redirect("dashboard")
def actor_delete(request, id): # fun actor delete try: Actor.objects.get(pk=id).delete() # get id and delete logger.info("actor deleted successfully, Actor ID is = {0}".format(id)) messages.add_message(request, messages.SUCCESS, "actor deleted successfully") except Exception as ex: # exception logger.exception(ex.args) return redirect("actor_list") # redirect actor list
def language_delete(request, id): # fun language delete try: Language.objects.get(pk=id).delete() # get id and delete logger.info( "language deleted successfully, Language ID is = {0}".format(id)) messages.add_message(request, messages.SUCCESS, "Data deleted successfully") except Exception as ex: # exception logger.exception(ex.args) return redirect("language_list") # redirect language list
def language_check(request): # fun film_list try: language_name = request.POST.get("lan_name") # get name from form id = request.POST.get("id") # get id from remote if id: # check id or not status = check_language(language_name, id) # call fun if not status: return HttpResponse("false") # http response for jquery return HttpResponse("true") else: status = check_language(language_name) # call fun if not status: # check status true or false return HttpResponse("false") # http response for jquery except Exception as ex: # exception logger.exception(ex.args) return HttpResponse("true") # http response for jquery
def check_language(language_name, *args): # check language name exist or not common fun try: if len(args) > 0: # check arguments id = args[0] # we pass id here status = Language.objects.filter( ~Q(id=id), name=language_name ) # check name exist or not and skip selected id if status: # if exist false else true return False else: status = Language.objects.filter( name=language_name) # check name exist or not if status: # if exist false else true return False except Exception as ex: logger.exception(ex.args) return True
def login(request, template="users/login.html"): try: if request.user.is_authenticated: if 'next' in request.GET: return redirect(request.GET["next"]) return redirect("dashboard") if request.method == "POST": user = authenticate(username=request.POST.get("username"), password=request.POST.get("password")) if user is not None and user.is_active and user.is_superuser: # active superusers are allowed to login auth_login(request, user) logger.info("{0} logged in successfully".format(user.username)) return redirect("dashboard") else: messages.add_message(request, messages.ERROR, "Invalid login credentials") except Exception as ex: logger.exception(ex.args) return render(request, template)
def actor_add(request, template="film/actor_add.html"): # fun actor_list try: if request.method == 'POST': # method post first__name = request.POST.get("first_name").lstrip(" ").rstrip( " ") # get data last__name = request.POST.get("last_name").lstrip(" ").rstrip( " ") # get data if not first__name or not last__name: # check null or not messages.add_message(request, messages.ERROR, "language name is not null allow") return redirect('actor_add') # redirect actor add else: add_actor_obj = Actor.objects.create( # insert language name first_name=first__name, last_name=last__name, ) messages.add_message(request, messages.SUCCESS, "Actor inserted successfully") return redirect("actor_list") # redirect to actor list except Exception as ex: # if exception raise logger.exception(ex.args) return render(request, template, {"actor": Actor.objects.all() }) # return actor objects in dic and render template