예제 #1
0
파일: views.py 프로젝트: likemike91/weblate
def user_page(request, user):
    """User details page."""
    user = get_object_or_404(User, username=user)
    allowed_project_ids = request.user.allowed_project_ids

    # Filter all user activity
    all_changes = Change.objects.last_changes(request.user).filter(user=user)

    # Last user activity
    last_changes = all_changes[:10]

    # Filter where project is active
    user_projects_ids = set(
        all_changes.values_list("translation__component__project", flat=True))
    user_projects = Project.objects.filter(id__in=user_projects_ids
                                           & allowed_project_ids).order()

    return render(
        request,
        "accounts/user.html",
        {
            "page_profile":
            user.profile,
            "page_user":
            user,
            "last_changes":
            last_changes,
            "last_changes_url":
            urlencode({"user": user.username}),
            "user_projects":
            prefetch_project_flags(prefetch_stats(user_projects)),
            "owned_projects":
            prefetch_project_flags(
                prefetch_stats(
                    user.owned_projects.filter(
                        id__in=allowed_project_ids).order())),
            "watched_projects":
            prefetch_project_flags(
                prefetch_stats(
                    user.watched_projects.filter(
                        id__in=allowed_project_ids).order())),
            "user_languages":
            user.profile.languages.all()[:7],
        },
    )
예제 #2
0
파일: views.py 프로젝트: renatofb/weblate
    def get_context_data(self, **kwargs):
        """Create context for rendering page."""
        context = super().get_context_data(**kwargs)
        user = self.object
        request = self.request

        allowed_project_ids = request.user.allowed_project_ids

        # Filter all user activity
        all_changes = Change.objects.last_changes(
            request.user).filter(user=user)

        # Last user activity
        last_changes = all_changes[:10]

        # Filter where project is active
        user_translation_ids = set(
            all_changes.values_list("translation", flat=True))
        user_translations = (Translation.objects.prefetch().filter(
            id__in=user_translation_ids,
            component__project_id__in=allowed_project_ids,
        ).order())

        context["page_profile"] = user.profile
        context["last_changes"] = last_changes.preload()
        context["last_changes_url"] = urlencode({"user": user.username})
        context["page_user_translations"] = prefetch_stats(user_translations)
        context["page_owned_projects"] = prefetch_project_flags(
            prefetch_stats(
                user.owned_projects.filter(
                    id__in=allowed_project_ids).order()))
        context["page_watched_projects"] = prefetch_project_flags(
            prefetch_stats(
                user.watched_projects.filter(
                    id__in=allowed_project_ids).order()))
        context["user_languages"] = user.profile.all_languages[:7]
        context["group_form"] = self.group_form or GroupAddForm()
        context["page_user_groups"] = user.groups.prefetch_related(
            "defining_project").order()
        return context
예제 #3
0
def list_projects(request):
    """List all projects."""
    return render(
        request,
        "projects.html",
        {
            "allow_index": True,
            "projects": prefetch_project_flags(
                prefetch_stats(request.user.allowed_projects)
            ),
            "title": _("Projects"),
        },
    )
예제 #4
0
def show_language(request, lang):
    try:
        obj = Language.objects.get(code=lang)
    except Language.DoesNotExist:
        obj = Language.objects.fuzzy_get(lang)
        if isinstance(obj, Language):
            return redirect(obj)
        raise Http404("No Language matches the given query.")

    if request.method == "POST" and request.user.has_perm("language.edit"):
        if obj.translation_set.exists():
            messages.error(
                request,
                _("Remove all translations using this language first."))
        else:
            obj.delete()
            messages.success(request, _("Language %s removed.") % obj)
            return redirect("languages")

    last_changes = Change.objects.last_changes(
        request.user).filter(language=obj)[:10]
    projects = request.user.allowed_projects
    dicts = projects.filter(glossary__term__language=obj).distinct()
    projects = prefetch_project_flags(
        prefetch_stats(
            projects.filter(component__translation__language=obj).distinct()))

    stats = []
    for project in projects:
        project.language_stats = project.stats.get_single_language_stats(obj)
        stats.append(project.language_stats)
    ProjectLanguageStats.prefetch_many(stats)

    return render(
        request,
        "language.html",
        {
            "allow_index": True,
            "object": obj,
            "last_changes": last_changes,
            "last_changes_url": urlencode({"lang": obj.code}),
            "dicts": dicts,
            "projects": projects,
        },
    )
예제 #5
0
def dashboard_anonymous(request):
    """Home page of Weblate showing list of projects for anonymous user."""
    top_project_ids = cache.get("dashboard-anonymous-projects")
    if top_project_ids is None:
        top_projects = sorted(
            prefetch_stats(request.user.allowed_projects),
            key=lambda prj: -prj.stats.monthly_changes,
        )[:20]
        top_project_ids = {p.id for p in top_projects}
        cache.set("dashboard-anonymous-projects", top_project_ids, 3600)
    top_projects = request.user.allowed_projects.filter(id__in=top_project_ids)

    return render(
        request,
        "dashboard/anonymous.html",
        {
            "top_projects":
            prefetch_project_flags(top_projects),
            "all_projects":
            Metric.objects.get_current(Metric.SCOPE_GLOBAL, 0,
                                       name="projects")["projects"],
        },
    )