def index(request, khoa_hoc_id): if not request.session.has_key('username'): return redirect('trangchu') khoa_hoc = KhoaHoc.objects.get(ma_khoa_hoc=khoa_hoc_id) ds_chuyen_nganh = ChuyenNganh.objects.all() ds_bai = BaiViet.objects.filter(khoa_hoc_id=khoa_hoc_id, trang_thai='on').order_by('ma_bai')[::-1] temp = loader.get_template('web/khoahoc.html') query = request.GET.get("q") if query: ds_bai = BaiViet.objects.filter(ten_bai__icontains=query) paginator = Paginator(ds_bai, 6) pageNumber = request.GET.get('page') try: ds_bai = paginator.page(pageNumber) except PageNotAnInteger: ds_bai = paginator.page(1) except EmptyPage: ds_bai = paginator.page(paginator.num_pages) user = "" if request.session.has_key('username'): username = request.session['username'] user = User.objects.get(username=username) if request.GET.get("btnlogout"): del request.session['username'] user = "" return redirect('trangchu') if request.GET.get("btnlogin"): u = User() u.username = request.GET['username'] u.mat_khau = request.GET['password'] u.mat_khau = hashlib.sha256(b"u.mat_khau").hexdigest() try: user = User.objects.get(username=u.username, mat_khau=u.mat_khau) except: user = "" return redirect('trangchu') if request.GET.get("btnlogout"): del request.session['username'] user = "" return redirect('trangchu') context = { "khoa_hoc": khoa_hoc, "q": query, "ds_chuyen_nganh": ds_chuyen_nganh, "ds_bai": ds_bai, "user": user, # "username":username, } return HttpResponse(temp.render(context))
def index(request): """ :type request: object """ temp = loader.get_template('index.html') ds_khoa_hoc = "" query = request.GET.get("q") if query: ds_khoa_hoc = KhoaHoc.objects.filter(ten_khoa_hoc__icontains = query) user = "" loaiuser = "" if request.session.has_key('username'): username = request.session['username'] user = User.objects.get(username=username) loaiuser = LoaiUser.objects.get(pk = user.loai_user_id) if request.GET.get("btnlogout"): del request.session['username'] user = loaiuser = "" return redirect('trangchu') else: if request.GET.get("btnlogin"): u = User() u.username = request.GET['username'] u.mat_khau = request.GET['password'] u.mat_khau = hashlib.sha256(b"u.mat_khau").hexdigest() try: user = User.objects.get(username=u.username, mat_khau= u.mat_khau) except: user = loaiuser = "" if user: request.session['username'] = user.username return redirect('index') context = { "ds_khoa_hoc": ds_khoa_hoc, "user":user, "q": query, "loaiuser": loaiuser, } return HttpResponse(temp.render(context))
def them(request): user = "" loaiuser = "" if request.session.has_key('username'): username = request.session['username'] user = User.objects.get(username=username) loaiuser = LoaiUser.objects.get(pk=user.loai_user_id) if request.GET.get("btnlogout"): del request.session['username'] user = loaiuser = "" return redirect('trangchu') else: return redirect('index') if request.method == "POST": u = User() u.username = request.GET.get('txtusername') u.mat_khau = request.GET.get('txtpassword1') u.mat_khau = hashlib.sha256(b"u.mat_khau").hexdigest() u.ho_ten = request.GET.get('txthoten') u.img = "uploads/imguser.png" u.gioi_tinh = " " u.loai_user_id = 1 u.save() return redirect('nguoidung_ds') context = {"title": "nguoi dung | them", "user": user} template = loader.get_template('nguoidung_them.html') return HttpResponse(template.render(context, request))
def index(request, chuyen_nganh_id): danh_muc = ChuyenNganh.objects.get(ma_chuyen_nganh=chuyen_nganh_id) ds_chuyen_nganh = ChuyenNganh.objects.all() ds_khoa_hoc = KhoaHoc.objects.filter( chuyen_nganh_id=chuyen_nganh_id).order_by('ma_khoa_hoc')[::-1] temp = loader.get_template('web/danhmuc.html') query = request.GET.get("q") if query: ds_khoa_hoc = KhoaHoc.objects.filter(ten_khoa_hoc__icontains=query) paginator = Paginator(ds_khoa_hoc, 6) pageNumber = request.GET.get('page') try: ds_khoa_hoc = paginator.page(pageNumber) except PageNotAnInteger: ds_khoa_hoc = paginator.page(1) except EmptyPage: ds_khoa_hoc = paginator.page(paginator.num_pages) user = "" if request.session.has_key('username'): username = request.session['username'] user = User.objects.get(username=username) if request.GET.get("btnlogout"): del request.session['username'] user = "" return redirect('trangchu') if request.GET.get("btnlogin"): u = User() u.username = request.GET['username'] u.mat_khau = request.GET['password'] u.mat_khau = hashlib.sha256(b"u.mat_khau").hexdigest() try: user = User.objects.get(username=u.username, mat_khau=u.mat_khau) except: user = "" return redirect('trangchu') if request.GET.get("btndangki"): u = User() u.username = request.GET.get('txtusername') u.mat_khau = request.GET.get('txtpassword1') u.mat_khau = hashlib.sha256(b"u.mat_khau").hexdigest() u.ho_ten = request.GET.get('txthoten') u.img = "uploads/imguser.png" u.gioi_tinh = " " u.loai_user_id = 2 u.save() return redirect('trangchu') context = { "ds_khoa_hoc": ds_khoa_hoc, "q": query, "ds_chuyen_nganh": ds_chuyen_nganh, "danh_muc": danh_muc, "user": user, # "username":username, } return HttpResponse(temp.render(context))
def index(request): temp = loader.get_template('web/lienhe.html') user = "" if request.session.has_key('username'): username = request.session['username'] user = User.objects.get(username=username) if request.GET.get("btnlogout"): del request.session['username'] user = "" return redirect('trangchu') if request.GET.get("btnlogin"): u = User() u.username = request.GET['username'] u.mat_khau = request.GET['password'] u.mat_khau = hashlib.sha256(b"u.mat_khau").hexdigest() try: user = User.objects.get(username=u.username, mat_khau=u.mat_khau) except: user = "" return redirect('lienhe') if request.GET.get("btndangki"): u = User() u.username = request.GET.get('txtusername') u.mat_khau = request.GET.get('txtpassword1') u.mat_khau = hashlib.sha256(b"u.mat_khau").hexdigest() u.ho_ten = request.GET.get('txthoten') u.img = "uploads/imguser.png" u.gioi_tinh = " " u.loai_user_id = 2 u.save() return redirect('lienhe') context = { "user": user, # "username":username, } return HttpResponse(temp.render(context))
def index(request): """ :type request: object """ ds_chuyen_nganh = ChuyenNganh.objects.all() ds_khoa_hoc = KhoaHoc.objects.order_by("ma_khoa_hoc")[:6] temp = loader.get_template('web/home.html') query = request.GET.get("q") if query: ds_khoa_hoc = KhoaHoc.objects.filter(ten_khoa_hoc__icontains=query) user = "" if request.session.has_key('username'): username = request.session['username'] user = User.objects.get(username=username) if request.GET.get("btnlogout"): del request.session['username'] user = "" return redirect('trangchu') else: if request.GET.get("btnlogin"): u = User() u.username = request.GET['username'] u.mat_khau = request.GET['password'] u.mat_khau = hashlib.sha256(b"u.mat_khau").hexdigest() try: user = User.objects.get(username=u.username, mat_khau=u.mat_khau) except: user = "" if user: request.session['username'] = user.username return redirect('trangchu') if request.GET.get("btndangki"): u = User() u.username = request.GET.get('txtusername') u.mat_khau = request.GET.get('txtpassword1') u.mat_khau = hashlib.sha256(b"u.mat_khau").hexdigest() u.ho_ten = request.GET.get('txthoten') u.img = "uploads/imguser.png" u.gioi_tinh = " " u.loai_user_id = 2 u.save() return redirect('trangchu') context = { "ds_chuyen_nganh": ds_chuyen_nganh, "ds_khoa_hoc": ds_khoa_hoc, "user": user, "q": query, } return HttpResponse(temp.render(context))