Esempio n. 1
0
    def get_user_profile(self, request, user_name):

        template = "user.html"
        user = get_object_or_404(User, user_name=user_name)
        user_render = {}

        if 'username' in request.session:

            session_user = request.session['username']
            session_id = request.session['user']
            companies = Company.objects.all()
            followed_company = Followers.objects.filter(user=session_id)
            products_company = Products.objects.all().count()
            check_follow = UserFollow.objects.filter(follower_user=session_id,
                                                     following=user.pk)

            user_render['session_user'] = session_user
            user_render['profile_image_form'] = UserProfileImage()
            user_render['cover_image_form'] = UserCoverImage()
            user_render['update_user_profile'] = UpdateUserProfile(
                instance=User.objects.get(pk=session_id))
            user_render['companies_may_know'] = companies
            user_render['followed_company'] = followed_company
            user_render['products_company'] = products_company
            user_render['post_form'] = PostForm()
            user_render['session_profile'] = User.objects.get(pk=session_id)
            user_render['check_follow'] = check_follow

        elif 'company_name' in request.session:

            session_company = request.session['company_name']
            session_id = request.session['pk']
            company = Company.objects.get(pk=session_id)
            product_form = ProductForm()
            categories = Categories.objects.filter(company=company.pk)

            user_render['session_company'] = session_company
            user_render['company'] = company
            user_render['product_form'] = product_form
            user_render['categories'] = categories
            user_render['sum_categories'] = get_categories(request, session_id)
            user_render['post_form'] = PostForm()

        posts_all = Posts.objects.filter(user=user.pk).order_by('-posted_date')
        paginator = Paginator(posts_all, settings.PAGINATOR_ITEMS)
        page = request.GET.get('page')

        try:
            posts = paginator.page(page)
        except PageNotAnInteger:
            posts = paginator.page(1)
        except EmptyPage:
            posts = paginator.page(paginator.num_pages)

        user_render['user_posts'] = posts
        user_render['user'] = user

        return render(request, template, user_render)
Esempio n. 2
0
    def get_home_page(self, request):

        if 'company_name' in request.session:

            company_name = request.session['company_name']
            company_id = request.session['pk']
            product_form = ProductForm()
            category_form = CategoryForm()
            products_company = Products.objects.filter(
                company=company_id).order_by('-posted_date')
            product_category = Categories.objects.all()

            home_render = {
                'company': Company.objects.get(name_dotted=company_name),
                'session_company': company_name,
                'sum_categories': get_categories(request, company_id),
                'product_form': product_form,
                'category_form': category_form,
                'products_company': products_company,
                'product_category': product_category,
                'categories': Categories.objects.filter(company=company_id),
                'post_form': PostForm()
            }

        elif 'username' in request.session:

            session_user = request.session['username']
            user = User.objects.get(user_name=session_user)
            post_form = PostForm()
            users_products = Products.objects.all()
            product_category = Categories.objects.all()

            home_render = {
                'session_user': session_user,
                'user': user,
                'post_form': post_form,
                'users_products': self.get_users_products(request),
                'product_category': product_category,
                'session_profile': User.objects.get(pk=request.session['user'])
            }

        else:

            products_users = Products.objects.all().order_by('-posted_date')
            product_category = Categories.objects.all()
            other_pictures = ProductPictures.objects.filter(
                product=products_users)

            home_render = {
                'products_users': products_users,
                'product_category': product_category,
            }

        return render(request, "home.html", home_render)
Esempio n. 3
0
    def get_advertisments_page(self, request):

        if 'company_name' in request.session:

            company_name = request.session['company_name']
            company_id = request.session['pk']
            product_form = ProductForm()
            category_form = CategoryForm()
            advertisments_company = Advertisments.objects.filter(
                company=company_id).order_by('-posted_date')

            advertisments_render = {
                'company': Company.objects.get(name_dotted=company_name),
                'session_company': company_name,
                'sum_categories': get_categories(request, company_id),
                'product_form': product_form,
                'category_form': category_form,
                'advertisments_company': advertisments_company,
                'categories': Categories.objects.filter(company=company_id),
                'post_form': PostForm()
            }

        elif 'username' in request.session:

            session_user = request.session['username']
            user = User.objects.get(user_name=session_user)
            post_form = PostForm()
            advertisments_users = Advertisments.objects.all().order_by(
                '-posted_date')
            advertisments_place = Advertisments.objects.filter(
                company__country=user.country).order_by('-posted_date')

            advertisments_render = {
                'session_user': session_user,
                'user': user,
                'post_form': post_form,
                'advertisments_users': advertisments_users,
                'advertisments_place': advertisments_place,
                'session_profile':
                User.objects.get(pk=request.session['user']),
                'category_comp': Company.objects.all()
            }

        else:

            advertisments_users = Advertisments.objects.all().order_by(
                '-posted_date')

            advertisments_render = {
                'advertisments_users': advertisments_users,
                'category_comp': Company.objects.all()
            }

        return render(request, "advertisments.html", advertisments_render)
Esempio n. 4
0
    def get_user_interess_page(self, request, user_name):

        template = "userinteress.html"
        user = get_object_or_404(User, user_name=user_name)
        interess_render = {}

        if 'username' in request.session:

            session_user = request.session['username']
            session_id = request.session['user']
            companies = Company.objects.all()
            followed_company = Followers.objects.filter(user=session_id)
            products_company = Products.objects.all().count()
            check_follow = UserFollow.objects.filter(follower_user=session_id,
                                                     following=user.pk)

            interess_render['session_user'] = session_user
            interess_render['profile_image_form'] = UserProfileImage()
            interess_render['cover_image_form'] = UserCoverImage()
            interess_render['update_user_profile'] = UpdateUserProfile(
                instance=User.objects.get(pk=session_id))
            interess_render['companies_may_know'] = companies
            interess_render['followed_company'] = followed_company
            interess_render['products_company'] = products_company
            interess_render['post_form'] = PostForm()
            interess_render['session_profile'] = User.objects.get(
                pk=session_id)
            interess_render['check_follow'] = check_follow

        elif 'company_name' in request.session:

            session_company = request.session['company_name']
            session_id = request.session['pk']
            company = Company.objects.get(pk=session_id)
            product_form = ProductForm()
            categories = Categories.objects.filter(company=company.pk)

            interess_render['session_company'] = session_company
            interess_render['company'] = company
            interess_render['product_form'] = product_form
            interess_render['categories'] = categories
            interess_render['sum_categories'] = get_categories(
                request, session_id)
            interess_render['post_form'] = PostForm()
            interess_render['trades'] = ProductTrade.objects.filter(
                user=user.pk,
                product__company=company.pk).order_by('-started_date')

        interess_render['interesses'] = ProductInteress.objects.filter(
            user=user.pk).order_by('-interess_date')
        interess_render['user'] = user

        return render(request, template, interess_render)
Esempio n. 5
0
    def get_user_followers_page(self, request, user_name):

        template = "userfollowers.html"
        user = get_object_or_404(User, user_name=user_name)
        followers_render = {}

        if 'username' in request.session:

            session_user = request.session['username']
            session_id = request.session['user']
            products_company = Products.objects.all().count()
            follow_users = User.objects.all()
            check_follow = UserFollow.objects.filter(follower_user=session_id,
                                                     following=user.pk)

            followers_render['session_user'] = session_user
            followers_render['profile_image_form'] = UserProfileImage()
            followers_render['cover_image_form'] = UserCoverImage()
            followers_render['update_user_profile'] = UpdateUserProfile(
                instance=User.objects.get(pk=session_id))
            followers_render['follow_users'] = follow_users
            followers_render['products_company'] = products_company
            followers_render['post_form'] = PostForm()
            followers_render['session_profile'] = User.objects.get(
                pk=session_id)
            followers_render['check_follow'] = check_follow

        elif 'company_name' in request.session:

            session_company = request.session['company_name']
            session_id = request.session['pk']
            company = Company.objects.get(pk=session_id)
            product_form = ProductForm()
            categories = Categories.objects.filter(company=company.pk)

            followers_render['session_company'] = session_company
            followers_render['company'] = company
            followers_render['product_form'] = product_form
            followers_render['categories'] = categories
            followers_render['sum_categories'] = get_categories(
                request, session_id)
            followers_render['post_form'] = PostForm()

        followers_render['followers'] = UserFollow.objects.filter(
            following=user.pk).order_by('-follow_date')
        followers_render['user'] = user

        return render(request, template, followers_render)
Esempio n. 6
0
    def get_posts_page(self, request):

        if 'company_name' in request.session:
            company_name = request.session['company_name']
            company_id = request.session['pk']
            product_form = ProductForm()
            category_form = CategoryForm()
            product_category = Categories.objects.all()
            posts_all = self.get_companies_posts(request)

            paginator = Paginator(posts_all, settings.PAGINATOR_ITEMS)
            page = request.GET.get('page')

            try:
                posts = paginator.page(page)
            except PageNotAnInteger:
                posts = paginator.page(1)
            except EmptyPage:
                posts = paginator.page(paginator.num_pages)

            posts_render = {
                'company': Company.objects.get(name_dotted=company_name),
                'session_company': company_name,
                'sum_categories': get_categories(request, company_id),
                'product_form': product_form,
                'category_form': category_form,
                'product_category': product_category,
                'categories': Categories.objects.filter(company=company_id),
                'post_form': PostForm(),
                'posts': posts,
            }

        elif 'username' in request.session:

            session_user = request.session['username']
            user = User.objects.get(user_name=session_user)
            post_form = PostForm()
            product_category = Categories.objects.all()
            companies = Company.objects.all()
            posts_all = self.get_users_posts(request)
            follow_users = User.objects.all()

            paginator = Paginator(posts_all, settings.PAGINATOR_ITEMS)
            page = request.GET.get('page')

            try:
                posts = paginator.page(page)
            except PageNotAnInteger:
                posts = paginator.page(1)
            except EmptyPage:
                posts = paginator.page(paginator.num_pages)

            posts_render = {
                'session_user': session_user,
                'user': user,
                'post_form': post_form,
                'companies_may_know': companies,
                'product_category': product_category,
                'session_profile':
                User.objects.get(pk=request.session['user']),
                'posts': posts,
                'follow_users': follow_users,
            }
        else:
            product_category = Categories.objects.all()
            posts_all = Posts.objects.all().order_by('-posted_date')

            paginator = Paginator(posts_all, settings.PAGINATOR_ITEMS)
            page = request.GET.get('page')

            try:
                posts = paginator.page(page)
            except PageNotAnInteger:
                posts = paginator.page(1)
            except EmptyPage:
                posts = paginator.page(paginator.num_pages)

            posts_render = {
                'product_category': product_category,
                'posts': posts,
                'category_comp': Company.objects.all()
            }
        return render(request, "posts.html", posts_render)