コード例 #1
0
ファイル: views.py プロジェクト: pombredanne/verbatim
def language_list(request):
    """returns the list of localised language names, with 'default'"""
    tr_default = _("Default")
    if tr_default != "Default":
        tr_default = u"%s | \u202dDefault" % tr_default
    choices = lang_choices()
    choices.insert(0, ('', tr_default))
    return choices
コード例 #2
0
ファイル: forms.py プロジェクト: notz/pootle
def language_list():
    """Returns the list of localised language names, with 'default'."""
    tr_default = _("Default")

    if tr_default != "Default":
        tr_default = u"%s | \u202dDefault" % tr_default

    from pootle.i18n.override import lang_choices

    choices = lang_choices()
    choices.insert(0, ('', tr_default))

    return choices
コード例 #3
0
ファイル: forms.py プロジェクト: ChrisOelmueller/pootle
def language_list(request):
    """Returns the list of localised language names, with 'default'."""
    tr_default = _("Default")

    if tr_default != "Default":
        tr_default = u"%s | \u202dDefault" % tr_default

    from pootle.i18n.override import lang_choices

    choices = lang_choices()
    choices.insert(0, ('', tr_default))

    return choices
コード例 #4
0
ファイル: models.py プロジェクト: notz/pootle
class PootleProfile(models.Model):
    objects = PootleProfileManager()

    class Meta:
        db_table = 'pootle_app_pootleprofile'

    # This is the only required field
    user = models.OneToOneField(User, unique=True, db_index=True)

    unit_rows = models.SmallIntegerField(default=9,
                                         verbose_name=_("Number of Rows"))
    input_height = models.SmallIntegerField(default=5, editable=False)
    languages = models.ManyToManyField('pootle_language.Language',
                                       blank=True,
                                       limit_choices_to=~Q(code='templates'),
                                       related_name="user_languages",
                                       verbose_name=_("Languages"),
                                       db_index=True)
    projects = models.ManyToManyField('pootle_project.Project',
                                      blank=True,
                                      db_index=True,
                                      verbose_name=_("Projects"))
    ui_lang = models.CharField(max_length=50,
                               blank=True,
                               null=True,
                               choices=(choice for choice in lang_choices()),
                               verbose_name=_('Interface Language'))
    alt_src_langs = models.ManyToManyField(
        'pootle_language.Language',
        blank=True,
        db_index=True,
        limit_choices_to=~Q(code='templates'),
        related_name="user_alt_src_langs",
        verbose_name=_("Alternative Source Languages"))

    def natural_key(self):
        return (self.user.username, )

    natural_key.dependencies = ['auth.User']

    def __unicode__(self):
        username = self.user.username

        if email_re.match(username):
            username = username.strip().rsplit('@', 1)[0]

        return username

    def get_absolute_url(self):
        return l('/accounts/%s/' % self.user.username)

    @cached_property
    def get_email_hash(self):
        return md5_f(self.user.email).hexdigest()

    def gravatar_url(self, size=80):
        if not self.get_email_hash:
            return ''

        return 'http://www.gravatar.com/avatar/%s?s=%d&d=mm' % \
            (self.get_email_hash, size)

    def _get_status(self):
        #FIXME: what's this for?
        return "Foo"

    status = property(_get_status)
    isopen = property(lambda self: True)

    def _get_pootle_user(self):
        if self.user_id is not None:
            return self.user
        else:
            return AnonymousUser()

    pootle_user = property(_get_pootle_user)

    def get_unit_rows(self):
        return min(max(self.unit_rows, 5), 49)

    def getuserstatistics(self):
        """Get user statistics for user statistics links."""
        userstatistics = []

        userstatistics.append({
            'text':
            _('Suggestions Accepted'),
            'count':
            self.suggester.filter(state='accepted').count()
        })
        userstatistics.append({
            'text':
            _('Suggestions Pending'),
            'count':
            self.suggester.filter(state='pending').count()
        })
        userstatistics.append({
            'text': _('Suggestions Reviewed'),
            'count': self.reviewer.count()
        })
        userstatistics.append({
            'text': _('Submissions Made'),
            'count': self.submission_set.count()
        })

        return userstatistics

    def getquicklinks(self):
        """Gets a set of quick links to user's project-languages."""
        from pootle_app.models.permissions import check_profile_permission
        projects = self.projects.all()
        quicklinks = []
        for language in self.languages.iterator():
            langlinks = []
            if projects.count():
                tps = language.translationproject_set.filter(
                    project__in=self.projects.iterator()).iterator()
                for translation_project in tps:
                    isprojectadmin = check_profile_permission(
                        self, 'administrate', translation_project.directory)

                    langlinks.append({
                        'code': translation_project.project.code,
                        'name': translation_project.project.fullname,
                        'isprojectadmin': isprojectadmin,
                    })

            islangadmin = check_profile_permission(self, 'administrate',
                                                   language.directory)
            quicklinks.append({
                'code': language.code,
                'name': language.localname(),
                'islangadmin': islangadmin,
                'projects': langlinks
            })
            quicklinks.sort(cmp=locale.strcoll, key=lambda dict: dict['name'])

        return quicklinks
コード例 #5
0
class PootleProfile(models.Model):
    objects = PootleProfileManager()

    class Meta:
        db_table = 'pootle_app_pootleprofile'

    # This is the only required field
    user = models.OneToOneField(User, unique=True, db_index=True)

    unit_rows = models.SmallIntegerField(default=9,
                                         verbose_name=_("Number of Rows"))
    input_height = models.SmallIntegerField(default=5, editable=False)

    # TODO: Remove these two fields once bug 2652 has been fixed
    languages = models.ManyToManyField('pootle_language.Language',
                                       blank=True,
                                       limit_choices_to=~Q(code='templates'),
                                       related_name="user_languages",
                                       verbose_name=_("Languages"),
                                       db_index=True)
    projects = models.ManyToManyField('pootle_project.Project',
                                      blank=True,
                                      db_index=True,
                                      verbose_name=_("Projects"))

    ui_lang = models.CharField(max_length=50,
                               blank=True,
                               null=True,
                               choices=(choice for choice in lang_choices()),
                               verbose_name=_('Interface Language'))
    alt_src_langs = models.ManyToManyField(
        'pootle_language.Language',
        blank=True,
        db_index=True,
        limit_choices_to=~Q(code='templates'),
        related_name="user_alt_src_langs",
        verbose_name=_("Alternative Source Languages"))

    def natural_key(self):
        return (self.user.username, )

    natural_key.dependencies = ['auth.User']

    def __unicode__(self):
        username = self.user.username

        if email_re.match(username):
            username = username.strip().rsplit('@', 1)[0]

        return username

    def get_absolute_url(self):
        return l('/accounts/%s/' % self.user.username)

    @cached_property
    def get_email_hash(self):
        try:
            return md5(self.user.email).hexdigest()
        except UnicodeEncodeError:
            return None

    def gravatar_url(self, size=80):
        if not self.get_email_hash:
            return ''

        return 'http://www.gravatar.com/avatar/%s?s=%d&d=mm' % \
            (self.get_email_hash, size)

    isopen = property(lambda self: True)

    def _get_pootle_user(self):
        if self.user_id is not None:
            return self.user
        else:
            return AnonymousUser()

    pootle_user = property(_get_pootle_user)

    def get_unit_rows(self):
        return min(max(self.unit_rows, 5), 49)

    def pending_suggestion_count(self, tp):
        """Returns the number of pending suggestions for the user in the given
        translation project.

        :param tp: a :cls:`TranslationProject` object.
        """
        return self.suggester.filter(translation_project=tp,
                                     state='pending').count()

    def accepted_suggestion_count(self, tp):
        """Returns the number of accepted suggestions for the user in the given
        translation project.

        :param tp: a :cls:`TranslationProject` object.
        """
        return self.suggester.filter(translation_project=tp,
                                     state='accepted').count()

    def rejected_suggestion_count(self, tp):
        """Returns the number of rejected suggestions for the user in the given
        translation project.

        :param tp: a :cls:`TranslationProject` object.
        """
        return self.suggester.filter(translation_project=tp,
                                     state='rejected').count()

    def total_submission_count(self, tp):
        """Returns the number of submissions the current user has done from the
        editor in the given translation project.

        :param tp: a :cls:`TranslationProject` object.
        """
        return Submission.objects.filter(
            submitter=self,
            translation_project=tp,
            type=SubmissionTypes.NORMAL,
        ).count()

    def overwritten_submission_count(self, tp):
        """Returns the number of submissions the current user has done from the
        editor and have been overwritten by other users in the given
        translation project.

        :param tp: a :cls:`TranslationProject` object.
        """
        return Submission.objects.filter(
            submitter=self,
            translation_project=tp,
            type=SubmissionTypes.NORMAL,
        ).exclude(unit__submitted_by=self, ).count()

    @property
    def contributions(self):
        """Get user contributions grouped by language and project.

        :return: List of tuples containing the following information::

            [
              ('Language 1', [
                  ('Project 1', [
                      {
                        'id': 'foo-bar',
                        'count': 0,
                        'url': 'foo/bar',
                      },
                      {
                        'id': 'bar-foo',
                        'count': 3,
                        'url': 'baz/blah',
                      },
                      {
                        'id': 'baz-blah',
                        'count': 5,
                        'url': 'bar/baz',
                      },
                  ]),
                  ('Project 2', [
                      ...
                  ]),
              ]),
              ('LanguageN', [
                  ('Project N', [
                      ...
                  ]),
                  ('Project N+1', [
                      ...
                  ]),
              ]),
            ]
        """
        # TODO: optimize — we need a schema that helps reduce the number
        # of needed queries for these kind of data retrievals
        contributions = []
        username = self.user.username

        languages = Language.objects.filter(
            translationproject__submission__submitter=self,
            translationproject__submission__type=SubmissionTypes.NORMAL,
        ).distinct()

        for language in languages:
            translation_projects = TranslationProject.objects.filter(
                language=language,
                submission__submitter=self,
                submission__type=SubmissionTypes.NORMAL,
            ).distinct().order_by('project__fullname')

            tp_user_stats = []
            # Retrieve tp-specific stats for this user
            for tp in translation_projects:
                tp_stats = [
                    {
                        'id':
                        'suggestions-pending',
                        'count':
                        self.pending_suggestion_count(tp),
                        'url':
                        dispatch.translate(tp,
                                           'user-suggestions',
                                           user=username),
                    },
                    {
                        'id':
                        'suggestions-accepted',
                        'count':
                        self.accepted_suggestion_count(tp),
                        'url':
                        dispatch.translate(
                            tp,
                            'user-suggestions-accepted',
                            user=username,
                        ),
                    },
                    {
                        'id':
                        'suggestions-rejected',
                        'count':
                        self.rejected_suggestion_count(tp),
                        'url':
                        dispatch.translate(
                            tp,
                            'user-suggestions-rejected',
                            user=username,
                        ),
                    },
                    {
                        'id':
                        'submissions-total',
                        'count':
                        self.total_submission_count(tp),
                        'url':
                        dispatch.translate(tp,
                                           'user-submissions',
                                           user=username),
                    },
                    {
                        'id':
                        'submissions-overwritten',
                        'count':
                        self.overwritten_submission_count(tp),
                        'url':
                        dispatch.translate(
                            tp,
                            'user-submissions-overwritten',
                            user=username,
                        ),
                    },
                ]

                tp_user_stats.append((tp, tp_stats))

            contributions.append((language, tp_user_stats))

        return contributions