Beispiel #1
0
def invite_url(request, project_id):
    """ 生成邀请码 """

    form = InviteModelForm(data=request.POST)
    if form.is_valid():
        """
        1. 创建随机的邀请码
        2. 验证码保存到数据库
        3. 限制:只有创建者才能邀请
        """
        if request.tracer.user != request.tracer.project.creator:
            form.add_error('period', "无权创建邀请码")
            return JsonResponse({'status': False, 'error': form.errors})

        random_invite_code = uid(request.tracer.user.mobile_phone)
        form.instance.project = request.tracer.project
        form.instance.code = random_invite_code
        form.instance.creator = request.tracer.user
        form.save()

        # 将验邀请码返回给前端,前端页面上展示出来。
        url = "{scheme}://{host}{path}".format(
            scheme=request.scheme,
            host=request.get_host(),
            path=reverse('invite_join', kwargs={'code': random_invite_code}))

        return JsonResponse({'status': True, 'data': url})

    return JsonResponse({'status': False, 'error': form.errors})
Beispiel #2
0
def invite_url(request, project_id):
    """
    生成邀请码
    :param request:
    :param project_id:
    :return:
    """
    form = InviteModelForm(data=request.POST)
    if form.is_valid():
        """
        1、创建随机的邀请码
        2、验证码保存到数据库
        3、限制:只有创建者才能邀请
        """
        if request.tracer.user != request.tracer.project.creator:  # 当前用户不是项目的创建者不能进行邀请
            form.add_error("period", "无权创建邀请码")  # 有效期下面提示
            return JsonResponse({"status": False, "error": form.errors})
        random_invite_code = uid(request.tracer.user.mobile_phone)
        form.instance.project = request.tracer.project
        form.instance.code = random_invite_code
        form.instance.creator = request.tracer.user
        form.save()

        # 将验证码返回给前段,前段页面上展示出来。
        url = "{scheme}://{host}{path}".format(
            scheme=request.scheme,  # 获取http或者https
            host=request.get_host(),  # 主机IP和端口
            path=reverse("invite_join", kwargs={"code": random_invite_code})
            # 反向生成url格式 /invite/join/asdfadiqr-9asudfapsef/
        )
        return JsonResponse({"status": True, "data": url})

    return JsonResponse({"status": False, "error": form.errors})
Beispiel #3
0
def invite_url(request, project_id):
    """生成邀请码"""

    form = InviteModelForm(data=request.POST)
    if form.is_valid():
        """
        表单验证通过后:
        1、只有创建者才能邀请 的限制
        2、创建随机邀请码
        3、验证码保存到数据库
        """
        if request.lxyker.user != request.lxyker.project.creator:
            form.add_error('period', '没有权限')
            return JsonResponse({'status': False, 'errors': form.errors})
        random_invite_code = uid(request.lxyker.user.mobile_phone)
        form.instance.project = request.lxyker.project
        form.instance.code = random_invite_code
        form.instance.creator = request.lxyker.user
        form.save()  # 邀请码保存到数据库

        # 邀请码返回给前端
        url = '{scheme}://{host}{path}'.format(
            scheme=request.scheme,
            host=request.get_host(),
            path=reverse('invite_join', kwargs={'code': random_invite_code}),
        )

        return JsonResponse({'status': True, 'data': url})
    return JsonResponse({'status': False, 'error': form.errors})
Beispiel #4
0
def issues_invite(request, project_id):
    """创建邀请码并返回给前端"""
    form = InviteModelForm(request.POST)
    if form.is_valid():
        # todo 校验用户选中的邀请人数是否在额度范围内

        # 1、只有项目的创建者才能发送邀请链接
        if not request.tracer.project.creator == request.tracer.user:
            form.add_error('period', '无权创建邀请码')
            return JsonResponse({'status': False, 'error': form.errors})

        # 2、设置验证码
        random_invite_code = uid(
            request.tracer.user.mobile_phone)  # 使用用户手机号创建随机码
        form.instance.creator = request.tracer.user
        form.instance.project = request.tracer.project
        form.instance.code = random_invite_code
        form.save()

        # 3、返回邀请码链接给前端,便于前端页面展示
        url = "{scheme}://{host}{path}".format(
            scheme=request.scheme,
            host=request.get_host(),
            path=reverse('web:invite_join',
                         kwargs={'code': random_invite_code}))
        return JsonResponse({'status': True, 'url': url})

    return JsonResponse({'status': False, 'error': form.errors})
Beispiel #5
0
def invite_url(request, project_id):
    """ 生成邀请码 """
    form = InviteModelForm(data=request.POST)
    if form.is_valid():
        """
        1. 创建一个随机的邀请码
        2. 验证码保存到数据库
        3. 只有创建者才能邀请,其他成员无法创建
        """
        if request.tracer.user != request.tracer.project.creator:
            form.add_error('period', '没有权限创建邀请码')
            return JsonResponse({'status': False, 'error': form.errors})
        random_invite_code = uid(request.tracer.user.mobile_phone)
        form.instance.project = request.tracer.project
        form.instance.code = random_invite_code
        form.instance.creator = request.tracer.user
        form.save()

        # 邀请码返回前端,前端展示验证码
        url = '{scheme}://{host}{path}'.format(
            scheme=request.scheme,  # 访问的方法
            host=request.get_host(),  # 返回域名和端口
            path=reverse('invite_join', kwargs={'code': random_invite_code}))
        return JsonResponse({'status': True, 'data': url})
    return JsonResponse({'status': False, 'error': form.errors})
Beispiel #6
0
def issues(request, project_id):
    if request.method == 'GET':
        # 筛选条件
        allow_filter_name = ['issues_type', 'status', 'priority', ]
        condition = {}
        for name in allow_filter_name:
            value_list = request.GET.getlist(name)
            if not value_list:
                continue
            condition[f'{name}__in'] = value_list

        queryset = models.Issues.objects.filter(project_id=project_id).filter(**condition)
        page_object = Pagination(
            current_page=request.GET.get('page'),
            all_count=queryset.count(),
            base_url=request.path_info,
            query_params=request.GET,
            per_page=10,
        )
        issues_object_list = queryset[page_object.start:page_object.end]

        form = IssuesModelForm(request)
        project_issues_type = models.IssuesType.objects.filter(project_id=project_id).values_list('id', 'title')
        project_total_user = [(request.tracer.project.creator_id, request.tracer.project.creator.username)]
        join_user = models.ProjectUser.objects.filter(project_id=project_id).values_list('user_id', 'user__username')
        project_total_user.extend(join_user)
        invite_form = InviteModelForm()
        context = {'form': form,
                   'invite_form': invite_form,
                   'issues_object_list': issues_object_list,
                   'page_html': page_object.page_html(),
                   'filter_list': [
                       {'title': "问题类型", 'filter': CheckFilter('issues_type', project_issues_type, request)},
                       {'title': "状态", 'filter': CheckFilter('status', models.Issues.status_choices, request)},
                       {'title': "优先级", 'filter': CheckFilter('priority', models.Issues.priority_choices, request)},
                       {'title': "指派者", 'filter': SelectFilter('assign', project_total_user, request)},
                       {'title': "关注者", 'filter': SelectFilter('attention', project_total_user, request)},
                   ]
                   }
        return render(request, 'issues.html', context)
    form = IssuesModelForm(request, data=request.POST)
    if form.is_valid():
        form.instance.creator = request.tracer.user
        form.instance.project = request.tracer.project
        form.save()
        return JsonResponse({'status': True})
    return JsonResponse({'status': False, 'error': form.errors})
Beispiel #7
0
def invite_url(request, project_id):

    form = InviteModelForm(data=request.POST)
    if form.is_valid():
        if request.tracer.user != request.tracer.project.creator:
            form.add_error('period', '无权创建邀请码')
            return JsonResponse({'status': False, 'error': form.errors})
        random_invite_code = uid(request.tracer.user.phone)
        form.instance.project = request.tracer.project
        form.instance.code = random_invite_code
        form.instance.creator = request.tracer.user
        form.save()
        url_path = reverse('web:invite_join', kwargs={'code': random_invite_code})
        url = f'{request.scheme}://{request.get_host()}{url_path}'
        return JsonResponse({'status': True, 'data': url})
    return JsonResponse({'status': False, 'error': form.errors})
Beispiel #8
0
def issues(request, project_id):
    if request.method == "GET":
        # 根据URL做筛选,筛选条件(根据用户通过GET传过来的参数实现)
        # ?status=1&status=2&issues_type=1
        allow_filter_name = [
            "issues_type",
            "status",
            "priority",
            "assign",
            "attention",
        ]
        condition = {}
        for name in allow_filter_name:
            value_list = request.GET.getlist(name)  # [1,2]
            if not value_list:
                continue
            condition["{}__in".format(name)] = value_list
        """
        condition = {
            "status__in":[1,2],
            'issues_type':[1,]
        }
        """

        # 分页获取数据
        queryset = models.Issues.objects.filter(project_id=project_id).filter(
            **condition)
        page_object = Pagination(
            current_page=request.GET.get("page"),
            all_count=queryset.count(),
            base_url=request.path_info,
            query_params=request.GET,
            per_page=50,
        )
        issues_object_list = queryset[page_object.start:page_object.end]

        form = IssuesModelForm(request)

        project_issues_type = models.IssuesType.objects.filter(
            project_id=project_id).values_list("id", "title")

        project_total_user = [(
            request.tracer.project.creator_id,
            request.tracer.project.creator.username,
        )]
        join_user = models.ProjectUser.objects.filter(
            project_id=project_id).values_list("user_id", "user__username")
        project_total_user.extend(join_user)

        invite_form = InviteModelForm()
        context = {
            "form":
            form,
            "invite_form":
            invite_form,
            "issues_object_list":
            issues_object_list,
            "page_html":
            page_object.page_html(),
            "filter_list": [
                {
                    "title":
                    "问题类型",
                    "filter":
                    CheckFilter("issues_type", project_issues_type, request),
                },
                {
                    "title":
                    "状态",
                    "filter":
                    CheckFilter("status", models.Issues.status_choices,
                                request),
                },
                {
                    "title":
                    "优先级",
                    "filter":
                    CheckFilter("priority", models.Issues.priority_choices,
                                request),
                },
                {
                    "title": "指派者",
                    "filter": SelectFilter("assign", project_total_user,
                                           request),
                },
                {
                    "title":
                    "关注者",
                    "filter":
                    SelectFilter("attention", project_total_user, request),
                },
            ],
        }
        return render(request, "issues.html", context)

    form = IssuesModelForm(request, data=request.POST)
    if form.is_valid():
        form.instance.project = request.tracer.project
        form.instance.creator = request.tracer.user
        form.save()
        return JsonResponse({"status": True})

    return JsonResponse({"status": False, "error": form.errors})
Beispiel #9
0
def issues(request, project_id):
    """问题首页"""
    if request.method == 'GET':
        form = IssuesModelForm(request)
        invite_form = InviteModelForm()
        # ####### 根据条件查询
        # 根据URL做筛选,筛选条件(根据用户通过GET传过来的参数实现)
        # ?status=1&status=2&issues_type=1
        allow_filter_name = [
            'issues_type', 'priority', 'status', 'assign', 'attention'
        ]
        condition = {}
        for name in allow_filter_name:
            value_list = request.GET.getlist(name)
            if not value_list:
                continue
            condition['{}__in'.format(name)] = value_list
        """
        condition = {
            "status__in":[1,2],
            'issues_type__in':[1,]
        }
        """

        # ####### 分页展示
        queryset = Issues.objects.filter(project_id=project_id).filter(
            **condition)
        page_object = Pagination(current_page=request.GET.get('page'),
                                 all_count=queryset.count(),
                                 base_url=request.path_info,
                                 query_params=request.GET,
                                 per_page=3)
        issues_object_list = queryset[page_object.start:
                                      page_object.end]  # 分页之后的对象

        issues_type_choices = IssuesType.objects.filter(
            project_id=project_id).values_list('id', 'title')
        project_user_choices = [(request.tracer.project.creator.id,
                                 request.tracer.project.creator.username)]
        project_user = ProjectUser.objects.filter(
            project_id=project_id).values_list('user_id', 'user__username')
        project_user_choices.extend(project_user)
        context = {
            'form':
            form,
            'invite_form':
            invite_form,
            'issues_object_list':
            issues_object_list,
            'page_html':
            page_object.page_html(),
            'filter_list': [
                {
                    'title':
                    '问题类型',
                    'filter':
                    CheckFilter('issues_type', issues_type_choices, request)
                },
                {
                    'title': '状态',
                    'filter': CheckFilter('status', Issues.status_choices,
                                          request)
                },
                {
                    'title':
                    '优先级',
                    'filter':
                    CheckFilter('priority', Issues.priority_choices, request)
                },
                {
                    'title': '指派人',
                    'filter': SelectFilter('assign', project_user_choices,
                                           request)
                },
                {
                    'title':
                    '关注者',
                    'filter':
                    SelectFilter('attention', project_user_choices, request)
                },
            ],
            #
            # 'status_list': CheckFilter('status', Issues.status_choices, request),
            # 'priority_list': CheckFilter('priority', Issues.priority_choices, request),
            # 'issues_type_list': CheckFilter('issues_type', issues_type_choices, request)
            #
        }

        return render(request, 'web/issues.html', context)

    # POST方法
    if request.method == 'POST':
        form = IssuesModelForm(request, data=request.POST)
        if form.is_valid():

            form.instance.project_id = project_id
            form.instance.creator = request.tracer.user

            form.save()
            return JsonResponse({'status': True})

        return JsonResponse({'status': False, 'error': form.errors})
Beispiel #10
0
def issues(request, project_id):
    """问题栏"""
    if request.method == "GET":
        # 筛选条件 -- 通过get来实现参数筛选
        allow_filter_name = [
            'issues_type', 'status', 'priority', 'assign', 'attention'
        ]
        condition = {}  # 条件
        for name in allow_filter_name:
            value_list = request.GET.getlist(name)

            if not value_list:
                continue

            condition['{}__in'.format(name)] = value_list

        # 分页获取数据
        form = IssuesModelForm(request)

        issues_obj = Issues.objects.filter(
            project=request.tracer.project).filter(**condition)

        page_object = Pagination(
            current_page=request.GET.get('page'),
            all_count=issues_obj.count(),
            base_url=request.path_info,
            query_params=request.GET,
            per_page=3,
        )
        issues_object_list = issues_obj[page_object.start:page_object.end]

        project_total_user = [(
            request.tracer.project.create_user_id,
            request.tracer.project.create_user.username,
        )]
        join_user = ProjectUser.objects.filter(
            project_id=project_id).values_list('user_id', 'user__username')
        project_total_user.extend(join_user)

        invite_form = InviteModelForm(data=request.POST)

        context = {
            'form':
            form,
            'invite_form':
            invite_form,
            'issues_object_list':
            issues_object_list,
            'page_html':
            page_object.page_html(),
            'filter_list': [
                {
                    'title':
                    '问题类型',
                    'filter':
                    CheckFilter(
                        'issues_type',
                        IssuesType.objects.filter(
                            project_id=project_id).values_list('id', 'title'),
                        request)
                },
                {
                    'title': '状态',
                    'filter': CheckFilter('status', Issues.STATUS_CHOICES,
                                          request)
                },
                {
                    'title':
                    '优先级',
                    'filter':
                    CheckFilter('priority', Issues.PRIORITY_CHOICES, request)
                },
                {
                    'title': '指派者',
                    'filter': SelectFilter('assign', project_total_user,
                                           request)
                },
                {
                    'title':
                    '关注者',
                    'filter':
                    SelectFilter('attention', project_total_user, request)
                },
            ]
        }
        return render(request, 'web/issues.html', context)

    if request.method == "POST":
        form = IssuesModelForm(request, data=request.POST)

        if form.is_valid():
            # 添加问题数据
            form.instance.project = request.tracer.project
            form.instance.create_user = request.tracer.user

            form.save()

            return JsonResponse({'code': 200})

        return JsonResponse({'msg': form.errors, 'code': 416})
Beispiel #11
0
def issues(request, project_id):
    if request.method == 'GET':
        # 根据URL携带的参数做筛选。URL类似:?status=1&status&=2&issues_type=1

        allow_filter_name = [
            'issues_type', 'status', 'priority', 'assign', 'attention'
        ]
        condition = {}
        for name in allow_filter_name:
            value_list = request.GET.get(name)
            if value_list:
                condition['{}__in'.format(name)] = value_list
        queryset = models.Issues.objects.filter(project_id=project_id).filter(
            **condition)
        # 分页获取数据
        page_object = Pagination(
            current_page=request.GET.get('page'),
            all_count=queryset.count(),
            base_url=request.path_info,
            query_params=request.GET,
            per_page=5,
        )
        issues_obj_list = queryset[page_object.start:page_object.end]

        form = IssuesModelForm(request)

        project_issues_type = models.IssuesType.objects.filter(
            project_id=project_id).values_list('id', 'title')

        project_total_user = [(request.lxyker.project.creator_id,
                               request.lxyker.project.creator.username)]
        join_user = models.ProjectUser.objects.filter(
            project_id=project_id).values_list('user_id', 'user__username')
        project_total_user.extend(join_user)

        invite_form = InviteModelForm()

        context = {
            'invite_form':
            invite_form,
            'form':
            form,
            'issues_obj_list':
            issues_obj_list,
            'page_html':
            page_object.page_html(),
            'filter_list': [
                {
                    'title':
                    '问题类型',
                    'filter':
                    CheckFilter('issues_type', project_issues_type, request),
                },
                {
                    'title':
                    '状态',
                    'filter':
                    CheckFilter('status', models.Issues.status_choices,
                                request),
                },
                {
                    'title':
                    '优先级',
                    'filter':
                    CheckFilter('priority', models.Issues.priority_choices,
                                request),
                },
                {
                    'title': '指派者',
                    'filter': SelectFilter('assign', project_total_user,
                                           request),
                },
                {
                    'title':
                    '关注者',
                    'filter':
                    SelectFilter('attention', project_total_user, request),
                },
            ],
        }
        return render(request, 'web/issues.html', context)

    form = IssuesModelForm(request, data=request.POST)
    if form.is_valid():
        # 数据校验无误
        form.instance.project = request.lxyker.project
        form.instance.creator = request.lxyker.user
        form.save()
        return JsonResponse({'status': True})
    return JsonResponse({'status': False, 'error': form.errors})
Beispiel #12
0
def issues(request, project_id):
    """ 问题展示及添加 """
    if request.method == 'GET':
        # 筛选条件(根据用户通过GET传过来的参数
        allow_filter_list = [
            'issues_type', 'status', 'priority', 'assign', 'attention'
        ]
        condition = {}
        for name in allow_filter_list:
            value_list = request.GET.getlist(name)  # 获取所有的值 [1,2,3]
            if not value_list:
                continue

            condition['{}__in'.format(name)] = value_list
        queryset = models.Issues.objects.filter(
            project=request.tracer.project).filter(**condition)
        page_object = Pagination(
            current_page=request.GET.get('page'),
            all_count=queryset.count(),
            base_url=request.path_info,
            query_params=request.GET,
        )
        issues_object_list = queryset[page_object.start:page_object.end]
        form = IssuesModelForm(request)

        issues_type_list = models.IssuesType.objects.filter(
            project_id=project_id).values_list('id', 'title')

        project_total_user = [
            (request.tracer.project.creator_id,
             request.tracer.project.creator.username),
        ]
        project_join_user = models.ProjectUser.objects.filter(
            project_id=project_id).values_list('user_id', 'user__username')

        project_total_user.extend(project_join_user)

        invite_form = InviteModelForm()
        content = {
            'form':
            form,
            'invite_form':
            invite_form,
            'issues_object_list':
            issues_object_list,
            'page_html':
            page_object.page_html(),
            'filter_list': [
                {
                    'title': '问题类型',
                    'filter': CheckFilter('issues_type', issues_type_list,
                                          request)
                },
                {
                    'title':
                    '状态',
                    'filter':
                    CheckFilter('status', models.Issues.status_choices,
                                request)
                },
                {
                    'title':
                    '优先级',
                    'filter':
                    CheckFilter('priority', models.Issues.priority_choices,
                                request)
                },
                {
                    'title': '指派者',
                    'filter': SelectFilter('assign', project_total_user,
                                           request)
                },
                {
                    'title':
                    '关注者',
                    'filter':
                    SelectFilter('attention', project_total_user, request)
                },
            ],
        }
        return render(request, 'issues.html', content)

    form = IssuesModelForm(request, data=request.POST)
    if form.is_valid():
        form.instance.project = request.tracer.project
        form.instance.creator = request.tracer.user
        # 添加问题
        form.save()
        return JsonResponse({'status': True})
    return JsonResponse({'status': False, 'error': form.errors})