예제 #1
0
    def get(self, request, *args, **kwargs):
        """機能
        カテゴリーナンバーに従い対応するカテゴリーのリストを返す
        カテゴリーナンバーはcategories/models.pyを参照

        endpoint: 'items/category/<int:pk>/items/list/'
        name: ItemCategoryListView
        """
        """テスト項目
        """
        category_number = self.kwargs["pk"]

        if category_number == 999:
            return redirect('item:item_list')

        item_objects = Item.objects.filter(
            category__number=category_number).filter(
                active=True).order_by("-created_at")
        page_obj = paginate_queryset(request, item_objects)
        # 記事がないときはno_item.htmlを表示する
        if item_objects.count() == 0:
            return render(request, TemplateName.NO_ITEMS)
        else:
            print(item_objects.count())
            context = {}
            context = add_aviso_objects(request, context)
            context[ContextKey.ITEM_OBJECTS] = page_obj.object_list
            context[ContextKey.PAGE_OBJ] = page_obj
            return render(request, TemplateName.ITEM_LIST, context)
예제 #2
0
    def get(self, request, *args, **kwargs):
        """機能
        認証したユーザーのfavボタンを押したアイテムを一覧表示する

        endpoint: 'items/user/favorite/'
        name: 'items:item_list_by_favorite'
        """

        # アクセスユーザーの制限
        if request.user.is_anonymous:
            return redirect(ViewName.HOME)

        # 表示するデータを取得
        context = {}
        request_user = User.objects.get(username=request.user.username)
        item_objects = Item.objects.filter(favorite_users=request_user)
        # 表示するデータがない場合は無い旨を示すテンプレートを返す
        if item_objects.count() == 0:
            return render(request, TemplateName.NO_ITEMS)

        # 表示するデータをcontextに格納する
        context = add_aviso_objects(request, context)
        page_obj = paginate_queryset(request, item_objects)
        context[ContextKey.ITEM_OBJECTS] = page_obj.object_list
        context[ContextKey.PAGE_OBJ] = page_obj
        return render(request, TemplateName.ITEM_LIST, context)
예제 #3
0
    def get(self, request, *args, **kwargs):
        """機能
        カテゴリーナンバーに従い対応するカテゴリーのリストを返す。
        ただしユーザーの地域情報(Profile.adm1)に限定したリストである。
        カテゴリーナンバーはcategories/models.pyを参照

        endpoint: 'items/category/<int:pk>/items/list/local/'
        name: -
        """
        """テスト項目
        """

        context = {}
        # ユーザー認証なされていないときはユーザーログインページに飛ばす
        if request.user.is_anonymous is True:
            return redirect("account_login")
        elif Profile.objects.filter(user=request.user).count() == 0:
            return redirect("account_login")
        profile_obj = Profile.objects.get(user=request.user)

        category_number = self.kwargs["pk"]
        if category_number == 999:
            return redirect('item:item_list')

        # categoryObj = Category.objects.get(number=category_number)
        item_objects = Item.objects.filter(
            category__number=category_number).filter(
                adm1=profile_obj.adm1).exclude(
                    active=False).order_by("-created_at")
        page_obj = paginate_queryset(request, item_objects)
        if item_objects.count() == 0:
            return render(request, TemplateName.NO_ITEMS)
        context[ContextKey.ITEM_OBJECTS] = page_obj.object_list
        context[ContextKey.PAGE_OBJ] = page_obj
        return render(request, TemplateName.ITEM_LIST, context)
예제 #4
0
    def get(self, request, *args, **kwargs):
        """
        endpoint: /avisos/all/
        name: "avisos:avisos_alllist"
        """

        if request.user.is_anonymous is True:
            # return redirect('account_login')
            return redirect(ViewName.ACCOUNT_LOGIN)

        elif Profile.objects.filter(user=request.user).exists() is False:
            return redirect('profiles:profile_creating')

        else:

            context = {}
            aviso_objects = Aviso.objects.filter(
                aviso_user=Profile.objects.get(
                    user=request.user)).order_by("-created_at")
            aviso_count = Aviso.objects.filter(aviso_user=Profile.objects.get(
                user=request.user)).filter(checked=False).count()
            page_obj = paginate_queryset(request, aviso_objects)
            context[ContextKey.AVISO_OBJECTS] = page_obj.object_list
            context["aviso_count"] = aviso_count
            context[ContextKey.PAGE_OBJ] = page_obj
            context["type"] = "ALL"
            return render(request, 'avisos/avisos_prototype.html', context)
예제 #5
0
	def get(self, request, *args, **kwargs):
		context = {}
		#ユーザー認証されていないときは、ログインページにつなぐ
		if request.user.is_anonymous == True:
			return redirect(ViewName.ACCOUNT_LOGIN)

		#自分が作成した記事を表示する
		item_objects = Item.objects.filter(user=request.user).exclude(active=False).order_by("-created_at")
		page_obj = paginate_queryset(request, item_objects)

		if item_objects.count() > 0:
			context[ ContextKey.ITEM_OBJECTS ] = page_obj.object_list
			context[ ContextKey.PAGE_OBJ ] = page_obj
			return render(request, TemplateName.ITEM_LIST, context)
		else:
			return render(request, TemplateName.NO_ITEMS, context)
예제 #6
0
 def get(self, request, *args, **kwargs):
     context = {}
     profile_obj = Profile.objects.get(user=request.user)
     # item_objects = Item.objects.filter(direct_message__owner=profile_obj)
     # item_objects = Item.objects.filter(direct_message__participant=profile_obj)
     item_objects = Item.objects.filter(
         Q(direct_message__owner=profile_obj)
         | Q(direct_message__participant=profile_obj))
     page_obj = paginate_queryset(request, item_objects)
     context[ContextKey.ITEM_OBJECTS] = page_obj.object_list
     context[ContextKey.PAGE_OBJ] = page_obj
     context = add_aviso_objects(request, context)
     context["type"] = "ALL"
     return render(request,
                   "items/articles_in_trade/trading_prototype.html",
                   context)
예제 #7
0
 def get(self, request, *args, **kwargs):
     context = {}
     user_obj = request.session["user_obj"]
     item_objects = Item.objects.filter(user=user_obj).exclude(
         active=False).order_by("-created_at")
     # 基本的にItemオブジェクトが0個の場合は存在しないと考えられるが、不足の自体に備えて以下の場合を加えておく
     if item_objects.count() == 0:
         return render(request, TemplateName.NO_ITEMS)
     profile_obj = Profile.objects.get(user=user_obj)
     page_obj = paginate_queryset(request, item_objects)
     context = add_aviso_objects(request, context)
     context['user_obj'] = user_obj
     context['profile_obj'] = profile_obj
     context['json_prodifle_description'] = json.dumps(
         profile_obj.description)
     context[ContextKey.ITEM_OBJECTS] = page_obj.object_list
     context[ContextKey.PAGE_OBJ] = page_obj
     return render(request, TemplateName.USER_ITEM_LIST, context)