def course_posts(request, courseid): context = {} mycourse = BBSCourse.objects.get(id=courseid) isHaving = 1 if not request.user.is_authenticated(): return HttpResponseRedirect('/login/') courses = get_courses(request.user) if mycourse not in courses: isHaving = 0 myuser = BBSUser.objects.get(user=request.user) if myuser.U_NewUser == 0: logout(request) return HttpResponseRedirect('/login/') posts = BBSPost.objects.filter(P_Course=mycourse, P_Parent=None) timeposts = list(posts) timepBlist = [] for tp in timeposts: re = UserHasCourse.objects.get(UserID=tp.P_User, CourseID=mycourse) pB = postBind(myuser, tp, re.Score) timepBlist.append(pB) timepBlist.reverse() likepBlist = sorted(timepBlist, key=lambda rank: rank.post.P_LikeNum, reverse=True) context['timepBs'] = timepBlist context['likepBs'] = likepBlist context['isHaving'] = isHaving context['course'] = mycourse context['user'] = myuser return render(request, 'web/course_posts.html', context)
def friend_list_page(request,loc,ex_user,template): if template: template = 'friend_list_page.html' else: template = 'friend_list.html' is_me = False username = request.user.username if ex_user: try: if request.user == User.objects.get(username = ex_user): is_me = True except ObjectDoesNotExist: raise Http404 result = FRIEND_MAPPING[loc](username = username,ex_username = ex_user) else : is_me = True result = FRIEND_MAPPING[loc](username = username) if len(list(result))>0: pass else: result = None return render_to_response(template, context_instance = RequestContext(request, { 'paginate_by' : ITEMS_PER_PAGE, 'friend_list' : result, 'is_me' : is_me, 'ex_username':ex_user, }))
def get(self, *args, **kwargs): firstDate = self.request.GET.get('search_date_from', None) secondDate = self.request.GET.get('search_date_to', None) if firstDate and secondDate: dateFrom = datetime.datetime.strptime(firstDate, "%Y-%m-%d") dateTo = datetime.datetime.strptime(secondDate, "%Y-%m-%d") listCompetit = AddRequest.objects.filter( userid=self.request.user.id, acepted=True).values_list('competit_id').distinct() levelArray = [] for x in listCompetit: maxlevel = CompetitGrid.objects.filter( competitid_id__in=x, memberwin=self.request.user.id).order_by( 'levelgrid').values_list('levelgrid').first() if maxlevel: levelArray.append(int(maxlevel[0]) + 1) else: levelArray.append(int(maxlevel[0])) placeArray = list( map(lambda x: str(2**(x - 1) + 1) + '--' + str(2**x), levelArray)) listCompetit = Competition.objects.filter(date__lte=dateTo, date__gte=dateFrom, id__in=listCompetit) return render(self.request, 'personal_results.html', { 'competit': listCompetit, 'place': placeArray }) return render(self.request, 'personal_results.html')
def xuetang_notice(request,source): if not request.user.is_authenticated(): return HttpResponseRedirect('/login/') myuser = BBSUser.objects.get(user=request.user) bestposts = BBSPost.objects.filter(P_Parent=None, P_Type=type_dic['大讨论区'],P_Section=sec_dic[source]) bestposts = list(bestposts) bestposts = sorted(bestposts, key=lambda x: x.P_Time, reverse=True) posts = bestposts courses = get_courses(request.user) return render(request, 'web/xuetang_list.html', {'user':myuser,'posts': posts,'title':title_dic[source],'source':source,'courses':courses})
def bbs_list(request): if not request.user.is_authenticated(): return HttpResponseRedirect('/login/') bestposts = BBSPost.objects.filter(P_Parent=None,P_Type=type_dic['大讨论区']) bestposts = list(bestposts) bestposts = sorted(bestposts,key=lambda x:x.P_LikeNum,reverse=True) posts = bestposts courses = get_courses(request.user) return render(request, 'index.html',{'posts':posts,'courses':courses})
def cart_create(request,**kwargs): login_url="/login/" prod = get_object_or_404(Product, pk=kwargs['pk']) try: c=list(Cart1.objects.values().get(product_id=prod.id,user_id=request.user.id)) c = Cart1.objects.get(product_id=prod.id, user_id=request.user.id) c.units = c.units + 1 c.save() except: c=Cart1(units=1,product=prod,user=request.user) c.save() return redirect('cart_html',request.user.id)
def place_order(request, **kwargs): try: c = list(Cart1.objects.values().filter(user_id=request.user.id)) for i in c: prod = get_object_or_404(Product, pk=i['product_id']) order = Order(product=prod, user=request.user, units=i['units']) order.save() car = Cart1.objects.get(id=i['id']) car.delete() except: pass return redirect('order_html', request.user.id)
def get_context_data(self, **kwargs): context = super(SubcategoryList, self).get_context_data(**kwargs) category = context.get('category_list') context['categoryID'] = category.id print(type(category)) subcategory = list( Subcategory.objects.values( 'category__id', 'id', 'title', 'image', 'description').filter(category_id=category.id)) context.update({ 'user_permissions': self.request.user.get_all_permissions(), 'subcategory': subcategory, }) return context
def get_context_data(self, **kwargs): context = super(SubcategoryProductList, self).get_context_data(**kwargs) subcategory = context.get('subcategory_list') context['subcategoryID'] = subcategory.id print(type(subcategory)) product = list( Product.objects.values( 'subcategory__id', 'id', 'title', 'image', 'price', 'rating', 'description').filter(subcategory_id=subcategory.id)) context.update({ 'user_permissions': self.request.user.get_all_permissions(), 'product': product, }) return context
def get_context_data(self,**kwargs): context = super(CartListView, self).get_context_data(**kwargs) user = context.get('user_list') # import ipdb # ipdb.set_trace() # pass context['userID'] = user.id print(type(user)) cart = list( Cart1.objects.values('product__id','product__title', 'product__image', 'product__price', 'units').filter(user_id=user.id)) total=0 for i in cart: total+=i['product__price']*i['units'] context.update({ 'user_permissions': self.request.user.get_all_permissions(), 'cart':cart, 'total':total, }) return context
def get_context_data(self, **kwargs): context = super(OrderListView, self).get_context_data(**kwargs) user = context.get('user_list') context['userID'] = user.id print(type(user)) order = list( Order.objects.values( 'product__id', 'product__title', 'product__description', 'product__image', 'product__price', 'units', 'date').order_by('date').filter(user_id=user.id)) context.update({ 'user_permissions': self.request.user.get_all_permissions(), 'order': order, }) return context
def course_post_list(request,courseid): context = {} mycourse = BBSCourse.objects.get(id=courseid) hasnotes = 0 if not request.user.is_authenticated(): return HttpResponseRedirect('/login/') courses = get_courses(request.user) if mycourse not in courses: return HttpResponseRedirect('/') myuser = BBSUser.objects.get(user=request.user) posts = BBSPost.objects.filter(P_Course=mycourse, P_Parent=None) allnotes = BBSPost.objects.filter(P_Course=mycourse, P_Type=type_dic['笔记贴']) if len(allnotes) != 0: hasnotes = 1 mynotesrelas = UserHasNode.objects.filter(UserID=myuser) mynotes = [] posts = list(posts) for mynotesrela in mynotesrelas: mynotes.append(mynotesrela.PostID) newposts = [] for post in posts: if post.P_Type == type_dic['笔记贴'] and (post not in mynotes): continue if post.P_Type == type_dic['大讨论区']: continue newposts.append(post) newposts.reverse() context['posts'] = newposts context['course'] = mycourse context['user'] = myuser context['courses'] = courses context['hasnotes'] = hasnotes return render(request,'web/course_bbs_list.html',context)
def get_context_data(self, **kwargs): context = super(ProductList, self).get_context_data(**kwargs) category = context.get('category_list') context['categoryID'] = category.id print(type(category)) product = list( Category.objects.values('id', 'product__id', 'product__title', 'product__image', 'product__description', 'product__price', 'product__rating').filter(id=category.id)) for i in product: if i['product__id'] is None: product = None context.update({ 'user_permissions': self.request.user.get_all_permissions(), 'product': product, }) return context