示例#1
0
文件: views.py 项目: ekr/ietfdb
def view_list(request, username=None):
    clist = lookup_community_list(username)

    docs = docs_tracked_by_community_list(clist)
    docs, meta = prepare_document_table(request, docs, request.GET)

    subscribed = request.user.is_authenticated and EmailSubscription.objects.filter(
        community_list=clist, email__person__user=request.user)

    return render(
        request, 'community/view_list.html', {
            'clist': clist,
            'docs': docs,
            'meta': meta,
            'can_manage_list': can_manage_community_list(request.user, clist),
            'subscribed': subscribed,
        })
示例#2
0
文件: views.py 项目: ekr/ietfdb
def untrack_document(request, name, username=None, acronym=None):
    doc = get_object_or_404(Document, docalias__name=name)
    clist = lookup_community_list(username, acronym)
    if not can_manage_community_list(request.user, clist):
        return HttpResponseForbidden(
            "You do not have permission to access this view")

    if request.method == "POST":
        if clist.pk is not None:
            clist.added_docs.remove(doc)

        if request.is_ajax():
            return HttpResponse(json.dumps({'success': True}),
                                content_type='text/plain')
        else:
            return HttpResponseRedirect(clist.get_absolute_url())

    return render(request, "community/untrack_document.html", {
        "name": doc.name,
    })
示例#3
0
文件: views.py 项目: ekr/ietfdb
def manage_list(request, username=None, acronym=None, group_type=None):
    # we need to be a bit careful because clist may not exist in the
    # database so we can't call related stuff on it yet
    clist = lookup_community_list(username, acronym)

    if not can_manage_community_list(request.user, clist):
        return HttpResponseForbidden(
            "You do not have permission to access this view")

    action = request.POST.get('action')

    if request.method == 'POST' and action == 'add_documents':
        add_doc_form = AddDocumentsForm(request.POST)
        if add_doc_form.is_valid():
            if clist.pk is None:
                clist.save()

            for d in add_doc_form.cleaned_data['documents']:
                clist.added_docs.add(d)

            return HttpResponseRedirect("")
    else:
        add_doc_form = AddDocumentsForm()

    if request.method == 'POST' and action == 'remove_document':
        document_pk = request.POST.get('document')
        if clist.pk is not None and document_pk:
            document = get_object_or_404(clist.added_docs, pk=document_pk)
            clist.added_docs.remove(document)

            return HttpResponseRedirect("")

    if request.method == 'POST' and action == 'add_rule':
        rule_type_form = SearchRuleTypeForm(request.POST)
        if rule_type_form.is_valid():
            rule_type = rule_type_form.cleaned_data['rule_type']

        if rule_type:
            rule_form = SearchRuleForm(clist, rule_type, request.POST)
            if rule_form.is_valid():
                if clist.pk is None:
                    clist.save()

                rule = rule_form.save(commit=False)
                rule.community_list = clist
                rule.rule_type = rule_type
                rule.save()
                if rule.rule_type == "name_contains":
                    reset_name_contains_index_for_rule(rule)

                return HttpResponseRedirect("")
    else:
        rule_type_form = SearchRuleTypeForm()
        rule_form = None

    if request.method == 'POST' and action == 'remove_rule':
        rule_pk = request.POST.get('rule')
        if clist.pk is not None and rule_pk:
            rule = get_object_or_404(SearchRule,
                                     pk=rule_pk,
                                     community_list=clist)
            rule.delete()

        return HttpResponseRedirect("")

    rules = clist.searchrule_set.all() if clist.pk is not None else []
    for r in rules:
        r.matching_documents_count = docs_matching_community_list_rule(
            r).count()

    empty_rule_forms = {
        rule_type: SearchRuleForm(clist, rule_type)
        for rule_type, _ in SearchRule.RULE_TYPES
    }

    total_count = docs_tracked_by_community_list(clist).count()

    return render(
        request, 'community/manage_list.html', {
            'clist':
            clist,
            'rules':
            rules,
            'individually_added':
            clist.added_docs.all() if clist.pk is not None else [],
            'rule_type_form':
            rule_type_form,
            'rule_form':
            rule_form,
            'empty_rule_forms':
            empty_rule_forms,
            'total_count':
            total_count,
            'add_doc_form':
            add_doc_form,
        })
示例#4
0
文件: utils.py 项目: ekr/ietfdb
def construct_group_menu_context(request, group, selected, group_type, others):
    """Return context with info for the group menu filled in."""
    kwargs = dict(acronym=group.acronym)
    if group_type:
        kwargs["group_type"] = group_type

    # menu entries
    entries = []
    entries.append(
        ("About", urlreverse("ietf.group.views.group_about", kwargs=kwargs)))
    if group.features.has_documents:
        entries.append(("Documents",
                        urlreverse("ietf.group.views.group_documents",
                                   kwargs=kwargs)))
    if group.features.has_materials and get_group_materials(group).exists():
        entries.append(("Materials",
                        urlreverse("ietf.group.views.materials",
                                   kwargs=kwargs)))
    if group.features.has_reviews:
        import ietf.group.views
        entries.append(("Review requests",
                        urlreverse(ietf.group.views.review_requests,
                                   kwargs=kwargs)))
        entries.append(("Reviewers",
                        urlreverse(ietf.group.views.reviewer_overview,
                                   kwargs=kwargs)))
    if group.type_id in ('rg', 'wg', 'ag', 'team'):
        entries.append(
            ("Meetings", urlreverse("ietf.group.views.meetings",
                                    kwargs=kwargs)))
    entries.append(
        ("History", urlreverse("ietf.group.views.history", kwargs=kwargs)))
    entries.append(
        ("Photos", urlreverse("ietf.group.views.group_photos", kwargs=kwargs)))
    entries.append(
        ("Email expansions", urlreverse("ietf.group.views.email",
                                        kwargs=kwargs)))
    if group.list_archive.startswith("http:") or group.list_archive.startswith(
            "https:") or group.list_archive.startswith("ftp:"):
        if 'mailarchive.ietf.org' in group.list_archive:
            entries.append(("List archive",
                            urlreverse("ietf.group.views.derived_archives",
                                       kwargs=kwargs)))
        else:
            entries.append(
                (mark_safe("List archive »"), group.list_archive))
    if group.has_tools_page():
        entries.append(
            (mark_safe("Tools »"),
             "https://tools.ietf.org/%s/%s/" % (group.type_id, group.acronym)))

    # actions
    actions = []

    is_admin = group.has_role(request.user, group.features.admin_roles)
    can_manage = can_manage_group_type(request.user, group)
    can_edit_group = False  # we'll set this further down

    if group.features.has_milestones:
        if group.state_id != "proposed" and (is_admin or can_manage):
            actions.append(
                (u"Edit milestones",
                 urlreverse('ietf.group.milestones.edit_milestones;current',
                            kwargs=kwargs)))

    if group.features.has_documents:
        clist = CommunityList.objects.filter(group=group).first()
        if clist and can_manage_community_list(request.user, clist):
            import ietf.community.views
            actions.append((u'Manage document list',
                            urlreverse(ietf.community.views.manage_list,
                                       kwargs=kwargs)))

    if group.features.has_materials and can_manage_materials(
            request.user, group):
        actions.append(
            (u"Upload material",
             urlreverse("ietf.doc.views_material.choose_material_type",
                        kwargs=kwargs)))

    if group.features.has_reviews and can_manage_review_requests_for_team(
            request.user, group):
        import ietf.group.views
        actions.append((u"Manage unassigned reviews",
                        urlreverse(ietf.group.views.manage_review_requests,
                                   kwargs=dict(assignment_status="unassigned",
                                               **kwargs))))
        actions.append((u"Manage assigned reviews",
                        urlreverse(ietf.group.views.manage_review_requests,
                                   kwargs=dict(assignment_status="assigned",
                                               **kwargs))))

        if Role.objects.filter(name="secr",
                               group=group,
                               person__user=request.user).exists():
            actions.append(
                (u"Secretary settings",
                 urlreverse(ietf.group.views.change_review_secretary_settings,
                            kwargs=kwargs)))

    if group.state_id != "conclude" and (is_admin or can_manage):
        can_edit_group = True
        actions.append((u"Edit group",
                        urlreverse("ietf.group.views.edit",
                                   kwargs=dict(kwargs, action="edit"))))

    if group.features.customize_workflow and (is_admin or can_manage):
        actions.append((u"Customize workflow",
                        urlreverse("ietf.group.views.customize_workflow",
                                   kwargs=kwargs)))

    if group.state_id in ("active", "dormant") and not group.type_id in [
            "sdo",
            "rfcedtyp",
            "isoc",
    ] and can_manage:
        actions.append((u"Request closing group",
                        urlreverse("ietf.group.views.conclude",
                                   kwargs=kwargs)))

    d = {
        "group": group,
        "selected_menu_entry": selected,
        "menu_entries": entries,
        "menu_actions": actions,
        "group_type": group_type,
        "can_edit_group": can_edit_group,
    }

    d.update(others)

    return d