Example #1
0
 def list(self, request, *args, **kwargs):
     p = get_paginator(request)
     target_id = self.request.GET.get('target')
     target_content_id = self.request.GET.get('target_content')
     user_id = self.request.user.id if self.request.user.is_authenticated else None
     with connection.cursor() as cursor:
         cursor.execute(
             "SELECT FETCH_ACTIVITIES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
             [
                 p.get("page_size"),
                 p.get("offs3t"),
                 p.get("search"),
                 request.GET.get("order_by"),
                 request.GET.get("verb"),
                 request.GET.get("is_activity"),
                 request.GET.get("is_notify"),
                 '{' + request.GET.get('term_ids') +
                 '}' if request.GET.get('term_ids') else None,
                 target_content_id, target_id, user_id
             ])
         result = cursor.fetchone()[0]
         if result.get("results") is None:
             result["results"] = []
         cursor.close()
         connection.close()
         return Response(result)
Example #2
0
def fetch_terms(request):
    if request.method == "GET":
        p = get_paginator(request)
        with connection.cursor() as cursor:
            cursor.execute(
                "SELECT FETCH_TERMS_WITH_SEARCH(%s, %s, %s, %s, %s, %s)", [
                    p.get("page_size"),
                    p.get("offs3t"),
                    p.get("search"),
                    request.GET.get("order_by"),
                    request.GET.get("taxonomy", None),
                    request.GET.get("pub", None)
                ])
            result = cursor.fetchone()[0]
            if result.get("results") is None:
                result["results"] = []
            cursor.close()
            connection.close()
            return Response(status=status.HTTP_200_OK, data=result)
    if request.method == "POST":
        term, created = models.Term.objects.get_or_create(
            slug=slugify(request.data.get("title")),
            defaults={
                "title": request.data.get("title"),
                "options": {
                    "need_fetch": True
                }
            })
        with connection.cursor() as cursor:
            cursor.execute("SELECT FETCH_TERM_WITH_TAX(%s, %s)",
                           [term.slug, request.GET.get("pub")])
            result = cursor.fetchone()[0]
            cursor.close()
            connection.close()
            return Response(status=status.HTTP_200_OK, data=result)
Example #3
0
def list_following(request):
    if request.user.is_authenticated:
        p = get_paginator(request)
        with connection.cursor() as cursor:
            cursor.execute("SELECT FETCH_LIST_FOLLOWING(%s, %s, %s, %s)", [
                p.get("page_size"),
                p.get("offs3t"), request.user.id,
                request.GET.get("content_type")
            ])
            return Response(cursor.fetchone()[0])
    return Response({})
Example #4
0
def board_messages(request, pk):
    p = get_paginator(request)
    with connection.cursor() as cursor:
        cursor.execute("SELECT FETCH_MESSAGES(%s, %s, %s, %s)", [
            p.get("page_size"),
            p.get("offs3t"),
            p.get("search"), "board_" + str(pk)
        ])
        result = cursor.fetchone()[0]
        if result.get("results") is None:
            result["results"] = []
        cursor.close()
        connection.close()
        return Response(result)
Example #5
0
 def list(self, request, *args, **kwargs):
     p = get_paginator(request)
     with connection.cursor() as cursor:
         cursor.execute("SELECT FETCH_USERS(%s, %s, %s, %s)", [
             p.get("page_size"),
             p.get("offs3t"),
             p.get("search"),
             request.user.id if request.user.is_authenticated else None
         ])
         result = cursor.fetchone()[0]
         if result.get("results") is None:
             result["results"] = []
         cursor.close()
         connection.close()
         return Response(result)
Example #6
0
def fetch_comments(request, app_id, slug):
    action_id = get_action_id(app_id, slug, request.GET.get("uid") is not None)
    if request.method == "GET":
        if action_id is not None:
            parent_id = request.GET.get("parent")
            user_id = request.user.id if request.user.is_authenticated else None
            p = get_paginator(request)
            with connection.cursor() as cursor:
                cursor.execute("SELECT FETCH_COMMENTS(%s, %s, %s, %s, %s, %s)",
                               [
                                   p.get("page_size"),
                                   p.get("offs3t"),
                                   request.GET.get("order_by"), user_id,
                                   parent_id, action_id
                               ])
                result = cursor.fetchone()[0]
                if result.get("results") is None:
                    result["results"] = []
                cursor.close()
                connection.close()
                return Response(status=status.HTTP_200_OK, data=result)
        return Response(status=status.HTTP_200_OK,
                        data={
                            "results": [],
                            "count": 0
                        })
    elif request.method == "POST":
        msg = []
        if action_id is None:
            msg.append({"action": "POST_NOT_PUBLISH"})
        if not request.user.is_authenticated:
            msg.append({"action": "AUTH_REQUIRED"})
        if request.data.get("content") is None or len(
                request.data.get("content")) < 2:
            msg.append({"content": "TO_SHORT"})

        if len(msg) == 0:
            c = Comment(user=request.user,
                        activity_id=action_id,
                        content=request.data.get("content"))
            if request.data.get("parent_comment"):
                c.parent_comment_id = request.data.get("parent_comment")
            c.save()
            return Response(status=status.HTTP_201_CREATED,
                            data=CommentSerializer(c).data)
        return Response(status=status.HTTP_400_BAD_REQUEST, data=msg)
    else:
        return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
Example #7
0
def list_following(request):
    p = get_paginator(request)
    with connection.cursor() as cursor:
        cursor.execute("SELECT FETCH_LIST_FOLLOWING(%s, %s, %s, %s, %s)", [
            p.get("page_size"),
            p.get("offs3t"),
            request.user.id if request.user.is_authenticated else None,
            request.GET.get("content_type"),
            request.GET.get("object_ids")
        ])
        result = cursor.fetchone()[0]
        cursor.close()
        connection.close()
        if result["results"] is None:
            result["results"] = []
        return Response(result)
Example #8
0
def list_repository(request):
    p = get_paginator(request)
    print(p.get("order_by"))
    with connection.cursor() as cursor:
        cursor.execute("SELECT FETCH_REPOSITORIES(%s, %s, %s, %s, %s, %s)",
                       [
                           p.get("page_size"),
                           p.get("offs3t"),
                           p.get("order_by"),
                           p.get("search"),
                           get_all_taxonomies(request.GET.get("taxonomies")),
                           request.GET.get("author")
                       ])
        result = cursor.fetchone()[0]
        if result.get("results") is None:
            result["results"] = []
        return Response(result)
Example #9
0
def fetch_contributions(request, app_id, slug):
    if request.method == "GET":
        p = get_paginator(request)
        contributor = request.GET.get("contributor")
        field = request.GET.get("field")
        with connection.cursor() as cursor:
            cursor.execute(
                "SELECT FETCH_CONTRIBUTIONS(%s, %s, %s, %s, %s, %s, %s)", [
                    p.get("page_size"),
                    p.get("offs3t"),
                    request.GET.get("order_by"), 22, slug, contributor, field
                ])
            result = cursor.fetchone()[0]
            if result.get("results") is None:
                result["results"] = []
            cursor.close()
            connection.close()
            return Response(status=status.HTTP_200_OK, data=result)
Example #10
0
 def list(self, request, *args, **kwargs):
     p = get_paginator(request)
     user_id = request.user.id if request.user.is_authenticated else None
     with connection.cursor() as cursor:
         cursor.execute("SELECT PUBLIC.FETCH_ORDER_ITEMS(%s, %s, %s, %s, %s, %s)",
                        [
                            p.get("page_size"),
                            p.get("offs3t"),
                            request.GET.get("order_by"),
                            request.GET.get("order", None),
                            request.GET.get("shopping_profile"),
                            None
                        ])
         result = cursor.fetchone()[0]
         if result.get("results") is None:
             result["results"] = []
         cursor.close()
         connection.close()
         return Response(status=status.HTTP_200_OK, data=result)
Example #11
0
    def list(self, request, *args, **kwargs):
        p = get_paginator(request)
        target_id = self.request.GET.get('target')
        target_content_id = self.request.GET.get('target_content')
        hash_tag = self.request.GET.get('hash_tag')

        user_id = self.request.user.id if self.request.user.is_authenticated else None
        with connection.cursor() as cursor:
            out = {}
            cursor.execute("SELECT COUNT_ACTIVITIES(%s, %s, %s)",
                           [p.get("search"), target_content_id, target_id])
            out["count"] = cursor.fetchone()[0]
            cursor.execute("SELECT FETCH_ACTIVITIES(%s, %s, %s, %s, %s, %s)", [
                p.get("page_size"),
                p.get("offs3t"),
                p.get("search"), target_content_id, target_id, user_id
            ])
            out["results"] = cursor.fetchone()[0]
            return Response(out)
Example #12
0
def list_ui(request):
    p = get_paginator(request)
    with connection.cursor() as cursor:
        cursor.execute("SELECT FETCH_LIST_UI(%s, %s, %s, %s, %s, %s, %s)", [
            p.get("page_size"),
            p.get("offs3t"),
            p.get("search"),
            request.user.id if request.user.is_authenticated else None,
            '{' + request.GET.get('hash_tags') +
            '}' if request.GET.get('hash_tags') else None,
            request.GET.get("user", None),
            request.GET.get("order_by", None),
        ])
        result = cursor.fetchone()[0]
        if result.get("results") is None:
            result["results"] = []
        cursor.close()
        connection.close()
        return Response(result)
Example #13
0
def list_taxonomy(request):
    p = get_paginator(request)
    if request.GET.get("kind") == "category" and request.GET.get("parent") is not None:
        parents = "{" + request.GET.get("parent") + "}"
    else:
        parents = get_all_taxonomies(request.GET.get("parent"))
    with connection.cursor() as cursor:
        cursor.execute("SELECT FETCH_TAXONOMIES(%s, %s, %s, %s, %s)",
                       [
                           p.get("page_size"),
                           p.get("offs3t"),
                           p.get("search"),
                           request.GET.get("flag"),
                           parents
                       ])
        result = cursor.fetchone()[0]
        if result.get("results") is None:
            result["results"] = []
        return Response(result)
Example #14
0
 def list(self, request, *args, **kwargs):
     p = get_paginator(request)
     with connection.cursor() as cursor:
         cursor.execute(
             "SELECT FETCH_TASKS(%s, %s, %s, %s, %s, %s, %s, %s)", [
                 p.get("page_size"),
                 p.get("offs3t"),
                 p.get("search"),
                 request.user.id if request.user.is_authenticated else None,
                 request.GET.get("board",
                                 None), '{' + request.GET.get('statuses') +
                 '}' if request.GET.get('statuses') else None,
                 request.GET.get("user", None),
                 request.GET.get("parent", None)
             ])
         result = cursor.fetchone()[0]
         if result.get("results") is None:
             result["results"] = []
         cursor.close()
         connection.close()
         return Response(result)
Example #15
0
def board_members(request, pk):
    fields = request.GET.get("fields", 'user,board').split(",")
    p = get_paginator(request)
    with connection.cursor() as cursor:
        cursor.execute(
            "SELECT FETCH_MEMBERS(%s, %s, %s, %s, %s)",
            [p.get("page_size"),
             p.get("offs3t"),
             p.get("search"), None, pk])
        result = cursor.fetchone()[0]
        if result.get("results") is None:
            result["results"] = []
        temp = result["results"]
        result["results"] = []
        for r in temp:
            new_result = {}
            for field in fields:
                new_result[field] = r.get(field)
            result["results"].append(new_result)
        cursor.close()
        connection.close()
        return Response(result)
Example #16
0
 def list(self, request, *args, **kwargs):
     target_id = self.request.GET.get('target')
     target_content_id = self.request.GET.get('target_content')
     destination_id = self.request.GET.get('destination')
     address_id = self.request.GET.get('address')
     hash_tag = self.request.GET.get('hash_tag')
     p = get_paginator(request)
     auth_id = self.request.user.id if self.request.user.is_authenticated else None
     with connection.cursor() as cursor:
         try:
             cursor.execute(
                 "SELECT FETCH_ACTIVITIES(%s, %s, %s, %s, %s, %s, %s, %s)",
                 [
                     p.get("page_size"),
                     p.get("offs3t"), target_content_id, target_id, auth_id,
                     destination_id, address_id,
                     '{' + hash_tag + '}' if hash_tag else None
                 ])
             return Response(cursor.fetchone()[0])
         finally:
             cursor.close()
             connection.close()
Example #17
0
 def list(self, request, *args, **kwargs):
     destination_id = request.GET.get("destination")
     user_id = request.GET.get("user")
     hash_tag = self.request.GET.get('hash_tag')
     p = get_paginator(request)
     auth_id = request.user.id if request.user.is_authenticated else None
     with connection.cursor() as cursor:
         try:
             cursor.execute(
                 "SELECT FETCH_DESTINATIONS(%s, %s, %s, %s, %s, %s, %s)", [
                     p.get("page_size"),
                     p.get("offs3t"),
                     p.get("search"),
                     auth_id,
                     '{' + hash_tag + '}' if hash_tag else None,
                     user_id,
                     destination_id,
                 ])
             return Response(cursor.fetchone()[0])
         finally:
             cursor.close()
             connection.close()