예제 #1
0
def loginclient(request):
    template = loader.get_template('front/login.html')
    args = {}
    args['page'] = 'Login'
    if request.method == 'POST':
        form = LoginClientForm(request.POST)
        if form.is_valid():
            # form.save()
            # mcb=MyCustomBackend()
            # if  mcb.authenticateadmin(form.cleaned_data.get('username'),form.cleaned_data.get('password')):
            # print(str(form.cleaned_data.get('email')))
            # print(str(form.cleaned_data.get('password')))
            user = authenticate(username=form.cleaned_data.get('username'),
                                password=form.cleaned_data.get('password'))
            if user:
                next_page = request.GET.get('next', '/')
                login(request, user)
                return HttpResponseRedirect(next_page)

            else:
                messages.error(request, 'Username and password do not match.')
                return redirect('fr_login')
    else:
        form = LoginClientForm()
        args['form'] = form
    return HttpResponse(template.render(args, request))
예제 #2
0
def needloginclient(request):
    args = {}
    if request.method == 'POST':
        form = LoginClientForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data.get('username'),
                                password=form.cleaned_data.get('password'))
            next_page = request.GET.get('next', '/')
            if user:
                login(request, user)
            else:
                messages.error(request, 'Username and password do not match.')
            return HttpResponseRedirect(next_page)
    return HttpResponse(template.render(args, request))
예제 #3
0
def download(request, title, id_wall, w, h):
    template = loader.get_template('front/v_download.html')
    wallpaper = get_object_or_404(Wallpaper, id_wallpaper=id_wall)
    resss = Resolution.objects.filter(w=w, h=h)
    is_original = False
    if not resss:
        is_original = True

    resolution = resss.first()

    max_w = 400
    max_h = 250
    prosen = 0
    if h <= w:
        prosen = h / max_h
    else:
        prosen = w / max_w
    fix_w = int(w / prosen)
    fix_h = int(h / prosen)

    context = {
        'page': 'Download',
        'wallpaper': wallpaper,
        'categories': Category.objects.all(),
        'resolution': resolution,
        'relatedwalls': getrelatedwallpaper(wallpaper, 9, w, h),
        'tags': Tag.objects.all().order_by('?')[:50],
        'w': w,
        'h': h,
        'is_original': is_original,
        'form': LoginClientForm(),
        'wh_thumb': str(fix_w) + 'x' + str(fix_h),
    }

    return HttpResponse(template.render(context, request))
예제 #4
0
def color(request, color, sort='date', page='1'):
    template = loader.get_template('front/v_color.html')
    # category_reco = Category.objects.get(id_category=id)
    # print(sort)
    if sort == 'date':
        walls = Wallpaper.objects.filter(
            colors__contains=color).order_by('-created_at')
    elif sort == 'likes':
        walls = Wallpaper.objects.filter(
            colors__contains=color).order_by('-likes')
    elif sort == 'downloads':
        walls = Wallpaper.objects.filter(
            color__contains=color).order_by('-downloads')
    elif sort == 'views':
        walls = Wallpaper.objects.filter(
            colors__contains=color).order_by('-views')
    else:
        raise Http404
    # print(walls)
    paginator = Paginator(walls, 16)
    context = {
        'page': 'Tag',
        'wallpapers': paginator.page(page),
        'sort': sort,
        'color': color,
        'form': LoginClientForm(),
        # 'admin': User.objects.get(id=request.session['admin']),
    }
    return HttpResponse(template.render(context, request))
예제 #5
0
def category(request, category, sort='date', page='1'):
    print(category)
    template = loader.get_template('front/v_category.html')
    category_reco = Category.objects.get(category=category.replace('-', ' '))
    # print(sort)
    if sort == 'date':
        walls = Wallpaper.objects.filter(
            category=category_reco).order_by('-created_at')
    elif sort == 'likes':
        walls = Wallpaper.objects.filter(
            category=category_reco).order_by('-likes')
    elif sort == 'downloads':
        walls = Wallpaper.objects.filter(
            category=category_reco).order_by('-downloads')
    elif sort == 'views':
        walls = Wallpaper.objects.filter(
            category=category_reco).order_by('-views')
    else:
        raise Http404
    # print(walls)
    paginator = Paginator(walls, 16)
    context = {
        'page': 'Category',
        'wallpapers': paginator.page(page),
        'sort': sort,
        'category': category_reco,
        'form': LoginClientForm(),
        # 'admin': User.objects.get(id=request.session['admin']),
    }
    return HttpResponse(template.render(context, request))
예제 #6
0
def tag(request, tag, sort='date', page='1'):
    # print(tag)
    template = loader.get_template('front/v_tag.html')
    tag_reco = Tag.objects.get(tag=tag.replace('-', ' '))
    # print(sort)
    if sort == 'date':
        walls = Wallpaper_tag.objects.filter(
            tag=tag_reco).order_by('-wallpaper__created_at')
    elif sort == 'likes':
        walls = Wallpaper_tag.objects.filter(
            tag=tag_reco).order_by('-wallpaper__likes')
    elif sort == 'downloads':
        walls = Wallpaper_tag.objects.filter(
            tag=tag_reco).order_by('-wallpaper__downloads')
    elif sort == 'views':
        walls = Wallpaper_tag.objects.filter(
            tag=tag_reco).order_by('-wallpaper__views')
    else:
        raise Http404
    # print(walls)
    paginator = Paginator(walls, 16)
    context = {
        'page': 'Tag',
        'wallpaper_tags': paginator.page(page),
        'sort': sort,
        'tag': tag_reco,
        'form': LoginClientForm(),
        # 'admin': User.objects.get(id=request.session['admin']),
    }
    return HttpResponse(template.render(context, request))
예제 #7
0
def category(request, category, sort='date', page='1'):
	# print(category)
	template = loader.get_template('front/v_category.html')
	try:
		category_reco = Category.objects.get(category=category)
		if sort == 'date':
			walls = Wallpaper.objects.filter(category=category_reco).filter(post_at__lte=datetime.datetime.now(tz=timezone.utc)).order_by('-post_at')
		elif sort == 'likes':
			walls = Wallpaper.objects.filter(category=category_reco).filter(post_at__lte=datetime.datetime.now(tz=timezone.utc)).order_by('-likes')
		elif sort == 'downloads':
			walls = Wallpaper.objects.filter(category=category_reco).filter(post_at__lte=datetime.datetime.now(tz=timezone.utc)).order_by('-downloads')
		elif sort == 'views':
			walls = Wallpaper.objects.filter(category=category_reco).filter(post_at__lte=datetime.datetime.now(tz=timezone.utc)).order_by('-views')
		else:
			walls = []
	except (Category.DoesNotExist):
		walls = []
	# print(walls)
	paginator = Paginator(walls, 16)
	context = {
		'page': 'Category',
		'wallpapers': paginator.page(page),
		'sort': sort,
		'category' : category,
		'form': LoginClientForm(),
		# 'admin': User.objects.get(id=request.session['admin']),
    }
	return HttpResponse(template.render(context, request))
예제 #8
0
def tag(request, tag, sort='date', page='1'):
	# print(tag)
	template = loader.get_template('front/v_tag.html')
	try:
		tag_reco = Tag.objects.get(tag=tag)
		if sort == 'date':
			walls = Wallpaper_tag.objects.filter(tag=tag_reco).filter(wallpaper__post_at__lte=datetime.datetime.now(tz=timezone.utc)).order_by('-wallpaper__post_at')
		elif sort == 'likes':
			walls = Wallpaper_tag.objects.filter(tag=tag_reco).filter(wallpaper__post_at__lte=datetime.datetime.now(tz=timezone.utc)).order_by('-wallpaper__likes')
		elif sort == 'downloads':
			walls = Wallpaper_tag.objects.filter(tag=tag_reco).filter(wallpaper__post_at__lte=datetime.datetime.now(tz=timezone.utc)).order_by('-wallpaper__downloads')
		elif sort == 'views':
			walls = Wallpaper_tag.objects.filter(tag=tag_reco).filter(wallpaper__post_at__lte=datetime.datetime.now(tz=timezone.utc)).order_by('-wallpaper__views')
		else:
			walls = []
	except (Tag.DoesNotExist):
		walls = []

	# print(walls)
	paginator = Paginator(walls, 16)
	context = {
		'page': 'Tag',
		'wallpaper_tags': paginator.page(page),
		'sort': sort,
		'tag' : tag,
		'form': LoginClientForm(),
		# 'admin': User.objects.get(id=request.session['admin']),
    }
	return HttpResponse(template.render(context, request))
예제 #9
0
def search(request):
	queryresult=Wallpaper.objects.none()
	query = request.GET.get('query', '')
	page = request.GET.get('page', 1)
	if query:
		# query = request.GET.get('param', '')

		categories = Category.objects.filter(category__contains= query)
		tags = Tag.objects.filter(tag__contains=query)

		# cari full category & tag
		queryresult |= Wallpaper.objects.filter(category__in= categories).filter(post_at__lte=datetime.datetime.now(tz=timezone.utc))
		

		wall_tags= Wallpaper_tag.objects.filter(tag__in = tags).filter(wallpaper__post_at__lte=datetime.datetime.now(tz=timezone.utc))

		wts=[]
		for wt in wall_tags:
			wts.append(wt.wallpaper.id_wallpaper)

		queryresult |= Wallpaper.objects.filter(id_wallpaper__in= wts).filter(post_at__lte=datetime.datetime.now(tz=timezone.utc))


		# queryresult |= Wallpaper.objects.filter(wallpaper__in= categories)

		# cari full category & tag split
		for q in query.split(' '):
			categories_split= Category.objects.filter(category__contains= q)
			tags_split= Tag.objects.filter(tag__contains=q)

			queryresult |= Wallpaper.objects.filter(category__in= categories_split)

			wts2=[]
			wall_tags2= Wallpaper_tag.objects.filter(tag__in = tags_split).filter(wallpaper__post_at__lte=datetime.datetime.now(tz=timezone.utc))
			for wt2 in wall_tags2:
				wts2.append(wt2.wallpaper.id_wallpaper)

			queryresult |= Wallpaper.objects.filter(id_wallpaper__in= wts2).filter(post_at__lte=datetime.datetime.now(tz=timezone.utc))


		# queryresult= sorted(list(set(queryresult)), key=operator.attrgetter('created_at'))


	template = loader.get_template('front/v_search.html')
	paginator = Paginator(queryresult.order_by('-created_at'), 16)
	
	context = {
		'page': 'Search',
		'query': query,
		'wallpapers': paginator.page(page),
		'sort': 'date',
		'form': LoginClientForm(),
    }
	return HttpResponse(template.render(context, request))
예제 #10
0
def home(request):
    template = loader.get_template('front/v_home.html')
    walls = Wallpaper.objects.all().order_by('-created_at')
    paginator = Paginator(walls, 16)
    form = LoginClientForm()
    context = {
        'page': 'Home',
        'wallpapers': paginator.page(1),
        'sort': 'date',
        'form': form,
        # 'admin': User.objects.get(id=request.session['admin']),
    }
    return HttpResponse(template.render(context, request))
예제 #11
0
def all(request, sort, page):
    template = loader.get_template('front/v_home.html')
    if sort == 'date':
        walls = Wallpaper.objects.all().order_by('-created_at')
    elif sort == 'likes':
        walls = Wallpaper.objects.all().order_by('-likes')
    elif sort == 'downloads':
        walls = Wallpaper.objects.all().order_by('-downloads')
    elif sort == 'views':
        walls = Wallpaper.objects.all().order_by('-views')
    else:
        raise Http404

    paginator = Paginator(walls, 16)
    context = {
        'page': 'Home',
        'wallpapers': paginator.page(page),
        'sort': sort,
        'form': LoginClientForm(),
        # 'admin': User.objects.get(id=request.session['admin']),
    }
    return HttpResponse(template.render(context, request))
예제 #12
0
def wallpaper(request, tags, id):

    template = loader.get_template('front/v_wallpaper.html')
    wallpaper = get_object_or_404(Wallpaper, id_wallpaper=id)
    wallpaper.views += 1
    wallpaper.save()

    is_liked = False
    is_disliked = False
    is_favorited = False

    if request.user.is_authenticated:
        action = User_action.objects.filter(wallpaper=wallpaper,
                                            user=request.user)
        if not action:
            User_action(wallpaper=wallpaper, user=request.user).save()

        act = User_action.objects.get(wallpaper=wallpaper, user=request.user)
        is_liked = act.is_liked
        is_disliked = act.is_disliked
        is_favorited = act.is_favorited

    context = {
        'page': 'Single',
        'wallpaper': wallpaper,
        'categories': Category.objects.all(),
        'tags': Tag.objects.all().order_by('?')[:50],
        # 'relatedwalls': Wallpaper.objects.order_by('?')[:6],
        'relatedwalls': getrelatedwallpaper(wallpaper, 7, None, None),
        'availableresolutions': availableresolutions(wallpaper),
        'form': LoginClientForm(),
        'is_liked': is_liked,
        'is_disliked': is_disliked,
        'is_favorited': is_favorited,
        # 'admin': User.objects.get(id=request.session['admin']),
    }
    return HttpResponse(template.render(context, request))