def index_for_weixiao(request): user = request.user category = NewTileCategory.objects.all() # content_type = ContentType.objects.get_for_model(Tile) if request.user.is_authenticated(): #用户登录日志 log = Access_log() log.type = 2 log.user = user log.url = request.get_full_path() log.save() category = category.filter(is_tips=1) # category_pks = [c.id for c in category] tiles = Tile.objects.get_tiles_edu(user) else: tiles = Tile.objects.get_tiles_all_unlogin() ctx = {} cid = request.GET.get('cid',2000) ty = request.GET.get('ty','') if ty == "pic": q = Q(new_type_id__in=[1,4]) elif ty == "video": q = Q(new_type_id=2) else: q = Q() try: show_type = True if int(cid) in [2120,2121,2122,2200,2210,2220,2230,2240] else False except: show_type = False cat_obj = get_object_or_404(NewTileCategory, pk=cid) cat_list_pks = helpers.category_sub_and_par(cat_obj) tiles = tiles.filter(new_category_id__in=cat_list_pks).filter(q) top = request.GET.get('top') if top: tiles = tiles.filter(microsecond__lte=top) else: try: top = tiles[0].microsecond except: top = '' # recommend_tiles = tiles.order_by("-n_comments")[0:10] recommend_tiles = [rt.tile for rt in TileRecommend.objects.all()[0:10]] month_themes = get_month_theme() local_url = reverse('kinger_edu_index') ctx.update({"tiles": tiles,"category":category,"channel":"edu",'month_themes':month_themes,'top':top,\ "recommend_tiles":recommend_tiles,"cid":cid,"show_type":show_type,"ty":ty,"local_url":local_url}) print "the end --------------------------------------------" if request.is_ajax(): page = int(request.GET.get("page",'1')) start = (page - 1) * 15 end = page * 15 tiles = tiles[start:end] ctx['tiles'] = tiles return ctx
def access_log(self, request): ''' 增加 用户用户登录日志 ``GET`` `account/access_log/ <http://192.168.1.222:8080/v1/account/access_log/>`_ ''' if request.user.is_authenticated(): #用户登录日志 log = Access_log() log.type = 3 log.user = request.user log.url = request.get_full_path() log.save() return {"uid": request.user.id}
def life_edu(request, template_name = "kinger/revision/edu_index.html"): """""" user = request.user category = NewTileCategory.objects.all() content_type = ContentType.objects.get_for_model(Tile) if request.user.is_authenticated(): #用户登录日志 log = Access_log() log.type = 2 log.user = user log.url = request.get_full_path() log.save() category = category.filter(is_tips=2) tiles = Tile.objects.get_tiles_life(user) else: tiles = Tile.objects.get_life_tiles_all_unlogin() ctx = {} cid = request.GET.get('cid',3000) ty = request.GET.get('ty','') if ty == "pic": q = Q(new_type_id__in=[1,4]) elif ty == "video": q = Q(new_type_id=2) else: q = Q() cat_obj = get_object_or_404(NewTileCategory, pk=cid) cat_list_pks = helpers.category_sub_and_par(cat_obj) tiles = tiles.filter(new_category_id__in=cat_list_pks).filter(q).order_by("-microsecond") # recommend_tiles = [t for t in tiles.order_by("-n_comments")[0:10]] recommend_tiles = [rt.tile for rt in TileRecommend.objects.all()[0:10]] local_url = reverse('kinger_life_edu_index') ctx.update({"tiles": tiles, "content_type": content_type,"category":category,"ty":ty,\ "recommend_tiles":recommend_tiles,"channel":"life","cid":cid,"show_type":True,"local_url":local_url}) if request.is_ajax(): page = int(request.GET.get("page",'1')) start = (page - 1) * 15 end = page * 15 tiles = tiles[start:end] ctx['tiles'] = tiles template_name = "kinger/revision/edu_index_container.html" return render(request, template_name, ctx) return render(request, template_name, ctx)
def index(request, template_name="kinger/tile_index.html"): """ 家长页面首页, 选择分类使会用 ``request.session`` 记录 `channel` 分类.用于详情页查询. :param channel: ``string``, 分别是 *Baby* 默认项, *推荐 - tips*, *所有 - all* 分类. :param tag_q: ``string``, 数据格式如: *1,3,4*. 服务于 *tips* 分类,根据标签 ``id`` 过滤 :params type_id: ``int``, 单个 id. 服务于 *baby* 分类。 """ site = get_domain_redirct(request) print site,'site-----------------' if site: template_name="oa/site/index.html" ctx = {'channel':'site_index'} if request.user.is_authenticated(): ctx.update({'user_login':request.user}) school = site.school auth_form = AuthenticationForm if request.method == 'POST': form = auth_form(request.POST) if request.is_ajax(): return helpers.ajax_validate_error(form) if form.is_valid(): identification, password, remember_me = (form.cleaned_data['identification'], form.cleaned_data['password'], form.cleaned_data['remember_me']) user = authenticate(identification=identification,password=password) try: profile = user.get_profile() except: p = Profile() p.user = user p.save() if user.is_active: login(request, user) # log = Access_log() # log.type = 1 # log.user = user # log.url = request.get_full_path() # log.save() if remember_me: request.session.set_expiry(userena_settings.USERENA_REMEMBER_ME_DAYS[1] * 86400) else: request.session.set_expiry(0) messages.success(request, _('You have been signed in.')) # Whereto now? return redirect(request.get_full_path()) else: return redirect(reverse('userena_disabled', kwargs={'username': user.username})) else: form = AuthenticationForm() school_actives = school_active(site,17) student_actives = school_active(site,18) articals = get_parts(site,19) news = get_parts(site,10) print news,'nnnnnnnnnnnnnn' announces = get_parts(site,9) tip = get_tip(site) start_teachers = get_start(site.school,'teacher') start_students = get_start(site.school,'student') tiles = Tile.objects.get_tiles_all_unlogin()[0:4] links = Link.objects.filter(site=site) parent_domain = get_parent_domain(request) ctx.update({'form':form,'school_actives':school_actives,'student_actives':student_actives,\ 'articals':articals,'news':news,'announces':announces,'tip':tip,'links':links,\ 'start_teachers':start_teachers,'start_students':start_students,'tiles':tiles,\ 'site':site,'parent_domain':parent_domain}) return render(request, template_name,ctx) else: channel_ctx = {} channel = request.GET.get("channel",'all') user = request.user category = TileCategory.objects.all() if request.user.is_authenticated(): #用户登录日志 log = Access_log() log.type = 2 log.user = user log.url = request.get_full_path() log.save() tags = [] types = [] if channel == "baby": current_time = datetime.datetime.now() category = category.filter(is_tips=False) parent_category = category.filter(parent__pk=0).exclude(pk=10) tiles = Tile.objects.get_tiles_baby(user).filter(category__parent__in=parent_category) record_tiles = Tile.objects.get_tiles_baby(user).filter(category__parent__id=10) today_daily_tiles = get_daily_category_tiles(record_tiles, category, current_time) #today_daily_tiles = get_daily_category_tiles(tiles, category, current_time) latest_active = get_daily_activitie_tiles(user) latest_cookbook = get_daily_cook_books(user,current_time) is_read = 1 if CookbookRead.objects.filter(user=user,cookbook=latest_cookbook,is_read=True) else 0 # 根据页面上得到category过滤返回的瓦片分类 scat_id = request.GET.get("scat_id", '') scat_pks = [int(x) for x in filter(None, scat_id.split(","))] if scat_pks: category_list = TileCategory.objects.filter(pk__in=scat_pks) q_category = Tile.objects.get_q_category(category_list) tiles = tiles.filter(q_category) book_item = cook_book_item(latest_cookbook) template_name = "kinger/tile_index_baby.html" channel_ctx = {"scat_id":scat_id, "parent_category":parent_category, "book_item":book_item, "current_time":current_time,\ "today_daily_tiles":today_daily_tiles,"latest_active":latest_active,"latest_cookbook":latest_cookbook,"is_read":is_read} elif channel == "tips": category = category.filter(is_tips=True) parent_category = category.filter(parent__pk=0).exclude(pk=10) tiles = Tile.objects.get_tiles_edu(user).filter(category__parent__in=parent_category) # 根据页面上得到category过滤返回的瓦片分类 scat_id = request.GET.get("scat_id", '31') scat_pks = [int(x) for x in filter(None, scat_id.split(","))] if scat_pks: category_list = TileCategory.objects.filter(pk__in=scat_pks) q_category = Tile.objects.get_q_category(category_list) tiles = tiles.filter(q_category) channel_ctx = {"scat_id":scat_id, "parent_category":parent_category} else: # 个人的以及推荐的 tiles = Tile.objects.get_tiles_all_login(user) daily_category = get_daily_category() if daily_category: tiles = tiles.exclude(category__parent=daily_category) else: # 公开推荐的 channel = "all" tiles = Tile.objects.get_tiles_all_unlogin() ctx = {} content_type = ContentType.objects.get_for_model(Tile) ctx.update({"tiles": tiles, "content_type": content_type, "channel": channel,"category":category}) ctx.update(channel_ctx) request.session['kinger_channel'] = channel if request.is_ajax(): page = int(request.GET.get("page",'1')) start = (page - 1) * 15 end = page * 15 tiles = tiles[start:end] ctx['tiles'] = tiles template_name = "kinger/tile_index_container.html" return render(request, template_name, ctx) return render(request, template_name, ctx)
def signin(request, auth_form=AuthenticationForm, template_name='userena/signin_form.html', redirect_field_name=REDIRECT_FIELD_NAME, redirect_signin_function=signin_redirect, extra_context=None): """ Signin using email or username with password. Signs a user in by combining email/username with password. If the combination is correct and the user :func:`is_active` the :func:`redirect_signin_function` is called with the arguments ``REDIRECT_FIELD_NAME`` and an instance of the :class:`User` whois is trying the login. The returned value of the function will be the URL that is redirected to. A user can also select to be remembered for ``USERENA_REMEMBER_DAYS``. :param auth_form: Form to use for signing the user in. Defaults to the :class:`AuthenticationForm` supplied by userena. :param template_name: String defining the name of the template to use. Defaults to ``userena/signin_form.html``. :param redirect_field_name: Form field name which contains the value for a redirect to the successing page. Defaults to ``next`` and is set in ``REDIRECT_FIELD_NAME`` setting. :param redirect_signin_function: Function which handles the redirect. This functions gets the value of ``REDIRECT_FIELD_NAME`` and the :class:`User` who has logged in. It must return a string which specifies the URI to redirect to. :param extra_context: A dictionary containing extra variables that should be passed to the rendered template. The ``form`` key is always the ``auth_form``. **Context** ``form`` Form used for authentication supplied by ``auth_form``. """ form = auth_form user_mobile = None if request.method == 'POST': mobile = request.POST['identification'] match = re.findall(r'^0{0,1}(13[0-9]|15[0-9]|18[0-9])[0-9]{8}$',mobile) if match: try: user_mobile = mobile profile = Profile.objects.get(mobile=user_mobile) user = profile.user data = request.POST.copy() data['identification'] = user.username form = auth_form(data, request.FILES) except: form = auth_form(request.POST, request.FILES) else: form = auth_form(request.POST, request.FILES) if form.is_valid(): identification, password, remember_me = (form.cleaned_data['identification'], form.cleaned_data['password'], form.cleaned_data['remember_me']) user = authenticate(identification=identification, password=password) try: profile = user.get_profile() except: p = Profile() p.user = user p.save() if user.is_active: login(request, user) log = Access_log() log.type = 1 log.user = user log.url = request.get_full_path() log.save() if remember_me: request.session.set_expiry(userena_settings.USERENA_REMEMBER_ME_DAYS[1] * 86400) else: request.session.set_expiry(0) if userena_settings.USERENA_USE_MESSAGES: messages.success(request, _('You have been signed in.'), fail_silently=True) # Whereto now? redirect_to = redirect_signin_function( request.REQUEST.get(redirect_field_name), user) print redirect_to,'rrrrrrrrrrrrrrrrr' if is_teacher(user): if len(redirect_to) > 1: return redirect(redirect_to) return redirect('oa_home') return redirect(redirect_to) else: return redirect(reverse('userena_disabled', kwargs={'username': user.username})) if not extra_context: extra_context = dict() if user_mobile: form = auth_form(request.POST, request.FILES) extra_context.update({ 'form': form, 'next': request.REQUEST.get(redirect_field_name), 'lack_perm':request.REQUEST.get('lack_perm'), #'next': userena_settings.USERENA_SIGNIN_REDIRECT_URL, }) return ExtraContextTemplateView.as_view(template_name=template_name, extra_context=extra_context)(request)
def baby_index(request, template_name = "kinger/revision/baby_index.html"): """""" date_tiles = [dt[0].date() for dt in get_baby_tile_date(request.user)] date_act = [da[0].date() for da in get_active_date(request.user)] cookbook_date = get_cookbook_date(request.user) if cookbook_date: date_coo = [dc[0] + datetime.timedelta(days=-1) for dc in get_cookbook_date(request.user)] dates = date_tiles + date_act + date_coo else: dates = date_tiles + date_act dates = sorted(list(set(dates)),reverse=True) effective_date = [str(x) for x in dates] current_date = datetime.datetime.now().date() effective_date.append(str(current_date)) channel_ctx = {} user = request.user category = NewTileCategory.objects.all() content_type = ContentType.objects.get_for_model(Tile) tiles = [] #用户登录日志 log = Access_log() log.type = 2 log.user = user log.url = request.get_full_path() log.save() current_time = datetime.datetime.now() category = category.filter(is_tips=0) tiles = Tile.objects.get_tiles_baby(user).filter(new_category__in=category).exclude(new_category__parent_id=1130).exclude(new_category_id=9) record_tiles = Tile.objects.get_tiles_baby(user).filter(new_category__parent_id=1130) today_daily_tiles = get_daily_category_tiles(record_tiles, category, current_time) latest_active = get_daily_activitie_tiles(user) latest_cookbook = get_daily_cook_books(user,current_time) is_read = 1 if CookbookRead.objects.filter(user=user,cookbook=latest_cookbook,is_read=True) else 0 book_item = cook_book_item(latest_cookbook) channel_ctx = {"book_item":book_item, "current_time":current_time,"today_daily_tiles":today_daily_tiles,\ "latest_active":latest_active,"latest_cookbook":latest_cookbook,"is_read":is_read,"channel":"baby"} ctx = {} cid = request.GET.get('cid',1000) cat_obj = get_object_or_404(NewTileCategory, pk=cid) cat_list_pks = helpers.category_sub_and_par(cat_obj) tiles = tiles.filter(new_category_id__in=cat_list_pks) top = request.GET.get('top') if top: tiles = tiles.filter(microsecond__lte=top) else: try: top = tiles[0].microsecond except: top = '' ctx.update({"tiles": tiles, "content_type": content_type,"category":category,"effective_date":effective_date,"top":top,"cid":cid}) ctx.update(channel_ctx) if request.is_ajax(): page = int(request.GET.get("page",'1')) start = (page - 1) * 15 end = page * 15 tiles = tiles[start:end] ctx['tiles'] = tiles print tiles,'tiles---------------------------------' template_name = "kinger/revision/baby_index_container.html" return render(request, template_name, ctx) return render(request, template_name, ctx)
def signin(request, auth_form=AuthenticationForm, template_name='oa/site/index.html', redirect_field_name=REDIRECT_FIELD_NAME, redirect_signin_function=signin_redirect, extra_context=None): """""" form = auth_form user_mobile = None if request.method == 'POST': mobile = request.POST['identification'] match = re.findall(r'^0{0,1}(13[0-9]|15[0-9]|18[0-9])[0-9]{8}$',mobile) if match: try: user_mobile = mobile profile = Profile.objects.get(mobile=user_mobile) user = profile.user data = request.POST.copy() data['identification'] = user.username form = auth_form(data, request.FILES) except: form = auth_form(request.POST, request.FILES) else: form = auth_form(request.POST, request.FILES) if form.is_valid(): identification, password, remember_me = (form.cleaned_data['identification'], form.cleaned_data['password'], form.cleaned_data['remember_me']) user = authenticate(identification=identification, password=password) try: profile = user.get_profile() except: p = Profile() p.user = user p.save() if user.is_active: login(request, user) log = Access_log() log.type = 1 log.user = user log.url = request.get_full_path() log.save() if remember_me: request.session.set_expiry(userena_settings.USERENA_REMEMBER_ME_DAYS[1] * 86400) else: request.session.set_expiry(0) if userena_settings.USERENA_USE_MESSAGES: messages.success(request, _('You have been signed in.'), fail_silently=True) # Whereto now? redirect_to = redirect_signin_function( request.REQUEST.get(redirect_field_name), user) return redirect(redirect_to) else: return redirect(reverse('userena_disabled', kwargs={'username': user.username})) if not extra_context: extra_context = dict() if user_mobile: form = auth_form(request.POST, request.FILES) extra_context.update({ 'form': form, 'next': request.REQUEST.get(redirect_field_name), #'next': userena_settings.USERENA_SIGNIN_REDIRECT_URL, }) return ExtraContextTemplateView.as_view(template_name=template_name, extra_context=extra_context)(request)
qs = Tile.objects.get_tiles_edu(request.user) if ids: qs = qs.filter(tags__pk__in=ids.split(",")) try: category_ids = request.GET.get("category_id", "") if category_ids: qs = qs.filter(category__pk__in=category_ids.split(",")) except Exception, e: pass try: log = Access_log() log.type = 2 log.user = request.user log.url = request.get_full_path() log.save() except: pass mictime = request.GET.get("mictime", "") if mictime: qs = qs.filter(microsecond__lte=mictime) #return query_range_filter(request.GET, qs, "tiles") rs = query_range_filter(request.GET, qs, "tiles") self.cache_last_tile_id(rs,request.user) return rs def for_baby_with_promotion(self, request):