def actor_edit(request, ids, template="film/actor_add.html"): # fun actor_list try: if request.method == 'POST': # method post and update data first_name = request.POST.get("first_name").lstrip(" ").rstrip( " ") # get data in post method last_name = request.POST.get("last_name").lstrip(" ").rstrip( " ") # get data in post method if not first_name or not last_name: # check null or not (validate data) messages.add_message( request, messages.ERROR, "language name is not null allow in edit") return redirect("actor_edit", id=id) # redirect to edit actor with id else: Actor.objects.filter(pk=id).update( first_name=first_name, last_name=last_name) # update actor logger.info( "actor edit successfully, Language ID is = {0}".format(id)) return redirect("actor_list") obj_actor_edit = Actor.objects.get(pk=id) # method get and render data return render(request, template, {"actor_names": obj_actor_edit}) # render template except Exception as ex: # if exception raise logger.info(ex.args) return render(request, template) # redirect language list
def language_edit(request, id, template="film/language_add.html"): # fun film_list try: if request.method == 'POST': # method post and update data language_name = request.POST.get("lan_name").lstrip(" ").rstrip( " ") # get data in post method if not language_name: messages.add_message( request, messages.ERROR, "language name is not null allow in edit") return redirect("language_edit", id=id) else: status = check_language(language_name, id) if not status: messages.add_message(request, messages.ERROR, "language name is already exist") return redirect("language_edit", id=id) else: Language.objects.filter(pk=id).update(name=language_name) logger.info( "language edit successfully, Language ID is = {0}". format(id)) return redirect("language_list") obj_language_edit = Language.objects.get( pk=id) # method get and render data return render(request, template, {"language_names": obj_language_edit}) # render template except Exception as ex: logger.info(ex.args) return render(request, template) # redirect language list
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 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)