Beispiel #1
0
    def get_queryset(self):
        """
        Returns list of changes to browse.
        """
        # Filtering by translation/project
        if "project" in self.request.GET:
            try:
                self.project, self.subproject, self.translation = get_project_translation(
                    self.request,
                    self.request.GET.get("project", None),
                    self.request.GET.get("subproject", None),
                    self.request.GET.get("lang", None),
                )
            except Http404:
                messages.error(self.request, _("Failed to find matching project!"))

        # Filtering by language
        if self.translation is None and "lang" in self.request.GET:
            try:
                self.language = Language.objects.get(code=self.request.GET["lang"])
            except Language.DoesNotExist:
                messages.error(self.request, _("Failed to find matching language!"))

        # Filtering by user
        if "user" in self.request.GET:
            try:
                self.user = User.objects.get(username=self.request.GET["user"])
            except User.DoesNotExist:
                messages.error(self.request, _("Failed to find matching user!"))

        # Glossary entries
        self.glossary = "glossary" in self.request.GET

        result = Change.objects.prefetch()

        if self.translation is not None:
            result = result.filter(translation=self.translation)
        elif self.subproject is not None:
            result = result.filter(translation__subproject=self.subproject)
        elif self.project is not None:
            result = result.filter(
                Q(translation__subproject__project=self.project) | Q(dictionary__project=self.project)
            )

        if self.language is not None:
            result = result.filter(Q(translation__language=self.language) | Q(dictionary__language=self.language))

        if self.glossary:
            result = result.filter(dictionary__isnull=False)

        if self.user is not None:
            result = result.filter(user=self.user)

        return result
Beispiel #2
0
 def _get_queryset_project(self):
     """Filtering by translation/project."""
     if 'project' in self.request.GET:
         try:
             self.project, self.component, self.translation = \
                 get_project_translation(
                     self.request,
                     self.request.GET.get('project'),
                     self.request.GET.get('component'),
                     self.request.GET.get('lang'),
                 )
         except Http404:
             messages.error(self.request,
                            _('Failed to find matching project!'))
Beispiel #3
0
def monthly_activity(request, project=None, subproject=None, lang=None):
    '''
    Show monthly activity chart.
    '''

    # Process parameters
    project, subproject, translation = get_project_translation(
        request, project, subproject, lang)

    # Get actual stats
    activity = Change.objects.month_stats(project, subproject, translation)

    # Render chart
    return render_activity(activity)
Beispiel #4
0
 def _get_queryset_project(self):
     """
     Filtering by translation/project.
     """
     if "project" in self.request.GET:
         try:
             self.project, self.subproject, self.translation = get_project_translation(
                 self.request,
                 self.request.GET.get("project", None),
                 self.request.GET.get("subproject", None),
                 self.request.GET.get("lang", None),
             )
         except Http404:
             messages.error(self.request, _("Failed to find matching project!"))
Beispiel #5
0
 def _get_queryset_project(self):
     """Filtering by translation/project."""
     if 'project' in self.request.GET:
         try:
             self.project, self.component, self.translation = \
                 get_project_translation(
                     self.request,
                     self.request.GET.get('project'),
                     self.request.GET.get('component'),
                     self.request.GET.get('lang'),
                 )
         except Http404:
             messages.error(
                 self.request,
                 _('Failed to find matching project!')
             )
Beispiel #6
0
def get_json_stats(request, days, step, project=None, subproject=None,
                   lang=None, user=None):
    """
    Parse json stats URL params.
    """
    if project is None and lang is None and user is None:
        project = None
        subproject = None
        translation = None
        language = None
        user = None
    elif user is not None:
        project = None
        subproject = None
        translation = None
        language = None
        user = get_object_or_404(User, username=user)
    elif project is None:
        project = None
        subproject = None
        translation = None
        language = get_object_or_404(Language, code=lang)
        user = None
    else:
        # Process parameters
        project, subproject, translation = get_project_translation(
            request,
            project,
            subproject,
            lang
        )
        language = None
        user = None

    # Get actual stats
    return Change.objects.base_stats(
        days,
        step,
        project,
        subproject,
        translation,
        language,
        user
    )
Beispiel #7
0
def get_json_stats(request, days, step, project=None, subproject=None,
                   lang=None, user=None):
    """
    Parse json stats URL params.
    """
    if project is None and lang is None and user is None:
        project = None
        subproject = None
        translation = None
        language = None
        user = None
    elif user is not None:
        project = None
        subproject = None
        translation = None
        language = None
        user = get_object_or_404(User, username=user)
    elif project is None:
        project = None
        subproject = None
        translation = None
        language = get_object_or_404(Language, code=lang)
        user = None
    else:
        # Process parameters
        project, subproject, translation = get_project_translation(
            request,
            project,
            subproject,
            lang
        )
        language = None
        user = None

    # Get actual stats
    return Change.objects.base_stats(
        days,
        step,
        project,
        subproject,
        translation,
        language,
        user
    )
Beispiel #8
0
def yearly_activity(request, project=None, subproject=None, lang=None):
    '''
    Show yearly activity chart.
    '''

    # Process parameters
    project, subproject, translation = get_project_translation(
        request,
        project,
        subproject,
        lang
    )

    # Get actual stats
    activity = Change.objects.year_stats(
        project,
        subproject,
        translation
    )

    # Render chart
    return render_activity(activity)
Beispiel #9
0
def view_activity(request, project=None, subproject=None, lang=None):
    '''
    Show html with activity charts.
    '''

    # Process parameters
    project, subproject, translation = get_project_translation(
        request, project, subproject, lang)

    if translation is not None:
        kwargs = {
            'project': project.slug,
            'subproject': subproject.slug,
            'lang': translation.language.code,
        }
        monthly_url = reverse('monthly_activity_translation', kwargs=kwargs)
        yearly_url = reverse('yearly_activity_translation', kwargs=kwargs)
    elif subproject is not None:
        kwargs = {
            'project': project.slug,
            'subproject': subproject.slug,
        }
        monthly_url = reverse('monthly_activity_subproject', kwargs=kwargs)
        yearly_url = reverse('yearly_activity_subproject', kwargs=kwargs)
    elif project is not None:
        kwargs = {
            'project': project.slug,
        }
        monthly_url = reverse('monthly_activity_project', kwargs=kwargs)
        yearly_url = reverse('yearly_activity_project', kwargs=kwargs)
    else:
        monthly_url = reverse('monthly_activity', )
        yearly_url = reverse('yearly_activity', )

    return render(request, 'js/activity.html', {
        'yearly_url': yearly_url,
        'monthly_url': monthly_url,
    })
Beispiel #10
0
def view_activity(request, project=None, subproject=None, lang=None):
    '''
    Show html with activity charts.
    '''

    # Process parameters
    project, subproject, translation = get_project_translation(
        request,
        project,
        subproject,
        lang
    )

    if translation is not None:
        kwargs = {
            'project': project.slug,
            'subproject': subproject.slug,
            'lang': translation.language.code,
        }
        monthly_url = reverse(
            'monthly_activity_translation',
            kwargs=kwargs
        )
        yearly_url = reverse(
            'yearly_activity_translation',
            kwargs=kwargs
        )
    elif subproject is not None:
        kwargs = {
            'project': project.slug,
            'subproject': subproject.slug,
        }
        monthly_url = reverse(
            'monthly_activity_subproject',
            kwargs=kwargs
        )
        yearly_url = reverse(
            'yearly_activity_subproject',
            kwargs=kwargs
        )
    elif project is not None:
        kwargs = {
            'project': project.slug,
        }
        monthly_url = reverse(
            'monthly_activity_project',
            kwargs=kwargs
        )
        yearly_url = reverse(
            'yearly_activity_project',
            kwargs=kwargs
        )
    else:
        monthly_url = reverse(
            'monthly_activity',
        )
        yearly_url = reverse(
            'yearly_activity',
        )

    return render(
        request,
        'js/activity.html',
        {
            'yearly_url': yearly_url,
            'monthly_url': monthly_url,
        }
    )
Beispiel #11
0
    def get_queryset(self):
        '''
        Returns list of changes to browse.
        '''
        # Filtering by translation/project
        if 'project' in self.request.GET:
            try:
                self.project, self.subproject, self.translation = \
                    get_project_translation(
                        self.request,
                        self.request.GET.get('project', None),
                        self.request.GET.get('subproject', None),
                        self.request.GET.get('lang', None),
                    )
            except Http404:
                messages.error(self.request,
                               _('Failed to find matching project!'))

        # Filtering by language
        if self.translation is None and 'lang' in self.request.GET:
            try:
                self.language = Language.objects.get(
                    code=self.request.GET['lang'])
            except Language.DoesNotExist:
                messages.error(self.request,
                               _('Failed to find matching language!'))

        # Filtering by user
        if 'user' in self.request.GET:
            try:
                self.user = User.objects.get(username=self.request.GET['user'])
            except User.DoesNotExist:
                messages.error(self.request,
                               _('Failed to find matching user!'))

        # Glossary entries
        self.glossary = 'glossary' in self.request.GET

        result = Change.objects.prefetch()

        if self.translation is not None:
            result = result.filter(translation=self.translation)
        elif self.subproject is not None:
            result = result.filter(translation__subproject=self.subproject)
        elif self.project is not None:
            result = result.filter(
                Q(translation__subproject__project=self.project)
                | Q(dictionary__project=self.project))

        if self.language is not None:
            result = result.filter(
                Q(translation__language=self.language)
                | Q(dictionary__language=self.language))

        if self.glossary:
            result = result.filter(dictionary__isnull=False)

        if self.user is not None:
            result = result.filter(user=self.user)

        return result
Beispiel #12
0
    def get_queryset(self):
        '''
        Returns list of changes to browse.
        '''
        # Filtering by translation/project
        if 'project' in self.request.GET:
            try:
                self.project, self.subproject, self.translation = \
                    get_project_translation(
                        self.request,
                        self.request.GET.get('project', None),
                        self.request.GET.get('subproject', None),
                        self.request.GET.get('lang', None),
                    )
            except Http404:
                messages.error(
                    self.request,
                    _('Failed to find matching project!')
                )

        # Filtering by language
        if self.translation is None and 'lang' in self.request.GET:
            try:
                self.language = Language.objects.get(
                    code=self.request.GET['lang']
                )
            except Language.DoesNotExist:
                messages.error(
                    self.request,
                    _('Failed to find matching language!')
                )

        # Filtering by user
        if 'user' in self.request.GET:
            try:
                self.user = User.objects.get(
                    username=self.request.GET['user']
                )
            except User.DoesNotExist:
                messages.error(
                    self.request,
                    _('Failed to find matching user!')
                )

        # Glossary entries
        self.glossary = 'glossary' in self.request.GET

        result = Change.objects.prefetch()

        if self.translation is not None:
            result = result.filter(
                translation=self.translation
            )
        elif self.subproject is not None:
            result = result.filter(
                translation__subproject=self.subproject
            )
        elif self.project is not None:
            result = result.filter(
                Q(translation__subproject__project=self.project) |
                Q(dictionary__project=self.project)
            )

        if self.language is not None:
            result = result.filter(
                Q(translation__language=self.language) |
                Q(dictionary__language=self.language)
            )

        if self.glossary:
            result = result.filter(
                dictionary__isnull=False
            )

        if self.user is not None:
            result = result.filter(
                user=self.user
            )

        return result