Ejemplo n.º 1
0
 def get_last_created_unit_info(self):
     return {
         "display_datetime": dateformat.format(self.creation_time),
         "creation_time": int(dateformat.format(self.creation_time, 'U')),
         "unit_source": truncatechars(self, 50),
         "unit_url": self.get_translate_url(),
     }
Ejemplo n.º 2
0
 def get_last_created_unit_info(self):
     return {
         "display_datetime": dateformat.format(self.creation_time),
         "creation_time": int(dateformat.format(self.creation_time, 'U')),
         "unit_source": truncatechars(self, 50),
         "unit_url": self.get_translate_url(),
     }
Ejemplo n.º 3
0
 def submission_info(self):
     return {
         "profile_url": self.display_user.get_absolute_url(),
         "email": self.display_user.email_hash,
         "displayname": self.display_user.display_name,
         "username": self.display_user.username,
         "display_datetime": dateformat.format(self.creation_time),
         "type": self.type,
         "mtime": int(dateformat.format(self.creation_time, 'U'))}
Ejemplo n.º 4
0
Archivo: proxy.py Proyecto: arky/pootle
 def submission_info(self):
     return {
         "profile_url": self.display_user.get_absolute_url(),
         "email": self.display_user.email_hash,
         "displayname": self.display_user.display_name,
         "username": self.display_user.username,
         "display_datetime": dateformat.format(self.creation_time),
         "type": self.type,
         "mtime": int(dateformat.format(self.creation_time, 'U'))}
Ejemplo n.º 5
0
    def update_tmserver(self):
        obj = {
            'id': self.id,
            # 'revision' must be an integer for statistical queries to work
            'revision': self.revision,
            'project': self.store.translation_project.project.fullname,
            'path': self.store.pootle_path,
            'source': self.source,
            'target': self.target,
            'username': '',
            'fullname': '',
            'email_md5': '',
        }

        if self.submitted_on:
            obj.update({
                'iso_submitted_on': self.submitted_on.isoformat(),
                'display_submitted_on': dateformat.format(self.submitted_on),
            })

        if self.submitted_by:
            obj.update({
                'username': self.submitted_by.username,
                'fullname': self.submitted_by.full_name,
                'email_md5': md5(self.submitted_by.email).hexdigest(),
            })

        get_tm_broker().update(self.store.translation_project.language.code,
                               obj)
Ejemplo n.º 6
0
    def get_unit_data(self, unit):
        """Return dict with data to import for a single unit."""
        fullname = (unit['submitted_by__full_name'] or
                    unit['submitted_by__username'])

        email_md5 = None
        if unit['submitted_by__email']:
            email_md5 = md5(unit['submitted_by__email']).hexdigest()

        iso_submitted_on = unit.get('submitted_on', None)

        display_submitted_on = None
        if iso_submitted_on:
            display_submitted_on = dateformat.format(
                dateparse.parse_datetime(str(iso_submitted_on))
            )

        return {
            '_index': self.INDEX_NAME,
            '_type': unit['store__translation_project__language__code'],
            '_id': unit['id'],
            'revision': int(unit['revision']),
            'project': unit['store__translation_project__project__fullname'],
            'path': unit['store__pootle_path'],
            'username': unit['submitted_by__username'],
            'fullname': fullname,
            'email_md5': email_md5,
            'source': unit['source_f'],
            'target': unit['target_f'],
            'iso_submitted_on': iso_submitted_on,
            'display_submitted_on': display_submitted_on,
        }
Ejemplo n.º 7
0
    def update_tmserver(self):
        obj = {
            'id': self.id,
            # 'revision' must be an integer for statistical queries to work
            'revision': self.revision,
            'project': self.store.translation_project.project.fullname,
            'path': self.store.pootle_path,
            'source': self.source,
            'target': self.target,
            'username': '',
            'fullname': '',
            'email_md5': '',
        }
        if self.changed and self.change.submitted_on:
            obj.update({
                'iso_submitted_on':
                self.change.submitted_on.isoformat(),
                'display_submitted_on':
                dateformat.format(self.change.submitted_on),
            })

        if self.changed and self.change.submitted_by:
            obj.update({
                'username':
                self.change.submitted_by.username,
                'fullname':
                self.change.submitted_by.full_name,
                'email_md5':
                md5(force_bytes(self.change.submitted_by.email)).hexdigest(),
            })

        get_tm_broker().update(self.store.translation_project.language.code,
                               obj)
Ejemplo n.º 8
0
    def get_unit_data(self, unit):
        """Return dict with data to import for a single unit."""
        fullname = unit["submitted_by__full_name"] or unit["submitted_by__username"]

        email_md5 = None
        if unit["submitted_by__email"]:
            email_md5 = md5(unit["submitted_by__email"].encode("utf-8")).hexdigest()

        mtime = None
        if unit["submitted_on"]:
            mtime = int(dateformat.format(unit["submitted_on"], "U"))

        index_name = (
            INDEX_PREFIX + unit["store__translation_project__language__code"].lower()
        )
        return {
            "_index": index_name,
            "_id": unit["id"],
            "revision": unit["revision"],
            "project": unit["store__translation_project__project__fullname"],
            "path": unit["store__pootle_path"],
            "username": unit["submitted_by__username"],
            "fullname": fullname,
            "email_md5": email_md5,
            "source": unit["source_f"],
            "target": unit["target_f"],
            "mtime": mtime,
        }
Ejemplo n.º 9
0
    def get_unit_data(self, unit):
        """Return dict with data to import for a single unit."""
        fullname = (unit['submitted_by__full_name']
                    or unit['submitted_by__username'])

        email_md5 = None
        if unit['submitted_by__email']:
            email_md5 = md5(unit['submitted_by__email']).hexdigest()

        mtime = None
        if unit['submitted_on']:
            mtime = int(dateformat.format(unit['submitted_on'], 'U'))

        return {
            '_index': self.INDEX_NAME,
            '_type': unit['store__translation_project__language__code'],
            '_id': unit['id'],
            'revision': int(unit['revision']),
            'project': unit['store__translation_project__project__fullname'],
            'path': unit['store__pootle_path'],
            'username': unit['submitted_by__username'],
            'fullname': fullname,
            'email_md5': email_md5,
            'source': unit['source_f'],
            'target': unit['target_f'],
            'mtime': mtime,
        }
Ejemplo n.º 10
0
 def submission_info(self):
     return {
         "email": self.display_user.email_hash,
         "displayname": self.display_user.display_name,
         "username": self.display_user.username,
         "type": self.type,
         "mtime": int(dateformat.format(self.creation_time, "U")),
     }
Ejemplo n.º 11
0
 def get_entries_group_data(self, context):
     result = []
     for entry_group in context['entries_group']:
         result.append({
             "display_datetime": dateformat.format(entry_group['datetime']),
             "iso_datetime": entry_group['datetime'].isoformat(),
             "via_upload": entry_group.get('via_upload', False),
         })
     return result
Ejemplo n.º 12
0
 def get_entries_group_data(self, context):
     result = []
     for entry_group in context["entries_group"]:
         timestamp = None
         entry_datetime = entry_group["datetime"]
         if entry_datetime is not None:
             timestamp = (int(dateformat.format(entry_datetime, "U")), )
         result.append({"timestamp": timestamp})
     return result
Ejemplo n.º 13
0
 def get_entries_group_data(self, context):
     result = []
     for entry_group in context['entries_group']:
         timestamp = None
         entry_datetime = entry_group['datetime']
         if entry_datetime is not None:
             timestamp = int(dateformat.format(entry_datetime, 'U')),
         result.append({
             'timestamp': timestamp,
         })
     return result
Ejemplo n.º 14
0
 def get_entries_group_data(self, context):
     result = []
     for entry_group in context['entries_group']:
         display_dt = entry_group['datetime']
         if display_dt is not None:
             display_dt = dateformat.format(display_dt)
             iso_dt = entry_group['datetime'].isoformat()
         else:
             iso_dt = None
         result.append({
             "display_datetime": display_dt,
             "iso_datetime": iso_dt,
             "via_upload": entry_group.get('via_upload', False)})
     return result
Ejemplo n.º 15
0
 def get_entries_group_data(self, context):
     result = []
     for entry_group in context['entries_group']:
         display_dt = entry_group['datetime']
         if display_dt is not None:
             display_dt = dateformat.format(display_dt)
             iso_dt = entry_group['datetime'].isoformat()
         else:
             iso_dt = None
         result.append({
             "display_datetime": display_dt,
             "iso_datetime": iso_dt,
             "via_upload": entry_group.get('via_upload', False),
         })
     return result
Ejemplo n.º 16
0
def do_dateformat(value, use_format='c'):
    """Formats a `value` date using `format`.

    :param value: a datetime object.
    :param use_format: a format string accepted by
        :func:`django.utils.formats.get_format` or
        :func:`django.utils.dateformat.format`. If none is set, the current
        locale's default format will be used.
    """
    try:
        use_format = get_format(use_format)
    except AttributeError:
        pass

    return dateformat.format(value, use_format)
Ejemplo n.º 17
0
 def get_entries_group_data(self, context):
     result = []
     for entry_group in context['entries_group']:
         display_dt = entry_group['datetime']
         if display_dt is not None:
             display_dt = dateformat.format(display_dt)
             iso_dt = entry_group['datetime'].isoformat()
             relative_time = timesince(
                 calendar.timegm(entry_group['datetime'].timetuple()))
         else:
             iso_dt = None
             relative_time = None
         result.append({
             "display_datetime": display_dt,
             "iso_datetime": iso_dt,
             "relative_time": relative_time,
             "via_upload": entry_group.get('via_upload', False),
         })
     return result
Ejemplo n.º 18
0
 def get_event_groups_data(self, context):
     result = []
     for event_group in context['event_groups']:
         display_dt = event_group['datetime']
         if display_dt is not None:
             display_dt = dateformat.format(display_dt)
             iso_dt = event_group['datetime'].isoformat()
             relative_time = timesince(
                 calendar.timegm(event_group['datetime'].timetuple()),
                 self.request_lang)
         else:
             iso_dt = None
             relative_time = None
         result.append({
             "display_datetime": display_dt,
             "iso_datetime": iso_dt,
             "relative_time": relative_time,
             "via_upload": event_group.get('via_upload', False),
         })
     return result
Ejemplo n.º 19
0
 def get_po_mtime(self, mtime):
     return ('%s.%06d' %
             (int(dateformat.format(mtime, 'U')), mtime.microsecond))
Ejemplo n.º 20
0
    def get_submission_info(self):
        """Returns a dictionary describing the submission.

        The dict includes the user (with link to profile and gravatar),
        a type and translation_action_type describing the action performed,
        and when it was performed.
        """
        result = {}

        if self.unit is not None:
            result.update({
                'unit_source': truncatechars(self.unit, 50),
                'unit_url': self.unit.get_translate_url(),
            })

            if self.quality_check is not None:
                check_name = self.quality_check.name
                result.update({
                    'check_name': check_name,
                    'check_display_name': check_names.get(check_name, check_name),
                    'checks_url': reverse('pootle-checks-descriptions'),
                })

        if (self.suggestion and
            self.type in (SubmissionTypes.SUGG_ACCEPT, SubmissionTypes.SUGG_REJECT)):
            displayuser = self.suggestion.reviewer
        else:
            # Sadly we may not have submitter information in all the
            # situations yet
            # TODO check if it is true
            if self.submitter:
                displayuser = self.submitter
            else:
                User = get_user_model()
                displayuser = User.objects.get_nobody_user()

        result.update({
            "profile_url": displayuser.get_absolute_url(),
            "email": displayuser.email_hash,
            "displayname": displayuser.display_name,
            "username": displayuser.username,
            "display_datetime": dateformat.format(self.creation_time),
            "iso_datetime": self.creation_time.isoformat(),
            "type": self.type,
            "mtime": int(dateformat.format(self.creation_time, 'U')),
        })

        #TODO Fix bug 3011 and remove the following code related
        # to TranslationActionTypes.

        if self.type in SubmissionTypes.EDIT_TYPES:
            translation_action_type = None
            try:
                if self.field == SubmissionFields.TARGET:
                    if self.new_value != '':
                        # Note that we analyze current unit state:
                        # if this submission is not last unit state
                        # can be changed
                        if self.unit.state == TRANSLATED:

                            if self.old_value == '':
                                translation_action_type = \
                                    TranslationActionTypes.TRANSLATED
                            else:
                                translation_action_type = \
                                    TranslationActionTypes.EDITED
                        elif self.unit.state == FUZZY:
                            if self.old_value == '':
                                translation_action_type = \
                                    TranslationActionTypes.PRE_TRANSLATED
                            else:
                                translation_action_type = \
                                    TranslationActionTypes.EDITED
                    else:
                        translation_action_type = TranslationActionTypes.REMOVED
                elif self.field == SubmissionFields.STATE:
                    # Note that a submission where field is STATE
                    # should be created before a submission where
                    # field is TARGET

                    translation_action_type = {
                        TRANSLATED: TranslationActionTypes.REVIEWED,
                        FUZZY: TranslationActionTypes.NEEDS_WORK
                    }.get(int(to_python(self.new_value)), None)

            except AttributeError:
                return result

            result['translation_action_type'] = translation_action_type

        return result
Ejemplo n.º 21
0
 def get_po_mtime(self, mtime):
     return (
         '%s.%06d'
         % (int(dateformat.format(mtime, 'U')),
            mtime.microsecond))
Ejemplo n.º 22
0
    def get_submission_info(self):
        """Returns a dictionary describing the submission.

        The dict includes the user (with link to profile and gravatar),
        a type and translation_action_type describing the action performed,
        and when it was performed.
        """
        result = {}

        if self.unit is not None:
            result.update({
                'source': truncatechars(self.unit, 50),
                'uid': self.unit.id,
            })

            if self.quality_check is not None:
                check_name = self.quality_check.name
                result.update({
                    'check':
                    check_name,
                    'check_displayname':
                    check_names.get(check_name, check_name),
                })

        if (self.suggestion and self.type
                in (SubmissionTypes.SUGG_ACCEPT, SubmissionTypes.SUGG_REJECT)):
            displayuser = self.suggestion.reviewer
        else:
            # Sadly we may not have submitter information in all the
            # situations yet
            # TODO check if it is true
            if self.submitter:
                displayuser = self.submitter
            else:
                User = get_user_model()
                displayuser = User.objects.get_nobody_user()

        result.update({
            "email": displayuser.email_hash,
            "displayname": displayuser.display_name,
            "username": displayuser.username,
            "type": self.type,
            "mtime": int(dateformat.format(self.creation_time, 'U')),
        })

        # TODO Fix bug 3011 and remove the following code related to
        # TranslationActionTypes.

        if self.type in SubmissionTypes.EDIT_TYPES:
            translation_action_type = None
            try:
                if self.field == SubmissionFields.TARGET:
                    if self.new_value != '':
                        # Note that we analyze current unit state:
                        # if this submission is not last unit state
                        # can be changed
                        if self.unit.state == TRANSLATED:

                            if self.old_value == '':
                                translation_action_type = \
                                    TranslationActionTypes.TRANSLATED
                            else:
                                translation_action_type = \
                                    TranslationActionTypes.EDITED
                        elif self.unit.state == FUZZY:
                            if self.old_value == '':
                                translation_action_type = \
                                    TranslationActionTypes.PRE_TRANSLATED
                            else:
                                translation_action_type = \
                                    TranslationActionTypes.EDITED
                    else:
                        translation_action_type = \
                            TranslationActionTypes.REMOVED
                elif self.field == SubmissionFields.STATE:
                    # Note that a submission where field is STATE
                    # should be created before a submission where
                    # field is TARGET

                    translation_action_type = {
                        TRANSLATED: TranslationActionTypes.REVIEWED,
                        FUZZY: TranslationActionTypes.NEEDS_WORK
                    }.get(int(to_python(self.new_value)), None)

            except AttributeError:
                return result

            result['translation_action_type'] = translation_action_type

        return result
Ejemplo n.º 23
0
    def get_submission_message(self):
        """Returns a message describing the submission.

        The message includes the user (with link to profile and gravatar), a
        message describing the action performed, and when it was performed.
        """
        unit = {}
        source = {}

        if self.unit is not None:
            unit = {
                'source': escape(truncatechars(self.unit, 50)),
                'url': self.unit.get_translate_url(),
            }
            source = {
                'source_string': '<i><a href="%(url)s">%(source)s</a></i>' %
                    unit,
            }

            if self.quality_check is not None:
                check_name = self.quality_check.name
                unit.update({
                    'check_name': check_name,
                    'check_display_name': check_names.get(check_name, check_name),
                    'checks_url': reverse('pootle-checks-descriptions'),
                })
                source.update({
                    'check_name': '<a href="%(checks_url)s#%(check_name)s">'
                                  '%(check_display_name)s</a>' % unit,
                })

        if (self.suggestion and
            self.type in (SubmissionTypes.SUGG_ACCEPT, SubmissionTypes.SUGG_REJECT)):
            displayuser = self.suggestion.reviewer
        else:
            # Sadly we may not have submitter information in all the
            # situations yet
            # TODO check if it is true
            if self.submitter:
                displayuser = self.submitter
            else:
                User = get_user_model()
                displayuser = User.objects.get_nobody_user()

        action_bundle = {
            "profile_url": displayuser.get_absolute_url(),
            "gravatar_url": displayuser.gravatar_url(20),
            "displayname": escape(displayuser.display_name),
            "username": displayuser.username,
            "display_datetime": dateformat.format(self.creation_time),
            "iso_datetime": self.creation_time.isoformat(),
            "action": "",
        }

        msg = {
            SubmissionTypes.REVERT: _(
                'reverted translation for %(source_string)s',
                source
            ),
            SubmissionTypes.SUGG_ACCEPT: _(
                'accepted suggestion for %(source_string)s',
                source
            ),
            SubmissionTypes.SUGG_ADD: _(
                'added suggestion for %(source_string)s',
                source
            ),
            SubmissionTypes.SUGG_REJECT: _(
                'rejected suggestion for %(source_string)s',
                source
            ),
            SubmissionTypes.UPLOAD: _(
                'uploaded a file'
            ),
            SubmissionTypes.MUTE_CHECK: _(
                'muted %(check_name)s for %(source_string)s',
                source
            ),
            SubmissionTypes.UNMUTE_CHECK: _(
                'unmuted %(check_name)s for %(source_string)s',
                source
            ),
        }.get(self.type, None)

        #TODO Look how to detect submissions for "sent suggestion", "rejected
        # suggestion"...

        #TODO Fix bug 3011 and replace the following code with the appropiate
        # one in the dictionary above.

        if msg is None:
            try:
                if self.field == SubmissionFields.TARGET:
                    if self.new_value != '':
                        # Note that we analyze current unit state:
                        # if this submission is not last unit state
                        # can be changed
                        if self.unit.state == TRANSLATED:
                            if self.old_value == '':
                                msg = _('translated %(source_string)s', source)
                            else:
                                msg = _('edited %(source_string)s', source)
                        elif self.unit.state == FUZZY:
                            if self.old_value == '':
                                msg = _('pre-translated %(source_string)s',
                                        source)
                            else:
                                msg = _('edited %(source_string)s', source)
                    else:
                        msg = _('removed translation for %(source_string)s',
                                source)
                elif self.field == SubmissionFields.STATE:
                    # Note that a submission where field is STATE
                    # should be created before a submission where
                    # field is TARGET
                    msg = {
                        TRANSLATED: _('reviewed %(source_string)s', source),
                        FUZZY: _('marked as needs work %(source_string)s', source)
                    }.get(int(to_python(self.new_value)), '')
                else:
                    msg = _('unknown action %(source_string)s', source)
            except AttributeError:
                return ''

        action_bundle['action'] = msg

        return mark_safe(
            u'<div class="last-action">'
            '  <a href="%(profile_url)s">'
            '    <img src="%(gravatar_url)s" />'
            '    <span title="%(username)s">%(displayname)s</span>'
            '  </a>'
            '  <span class="action-text">%(action)s</span>'
            '  <time class="extra-item-meta js-relative-date"'
            '    title="%(display_datetime)s" datetime="%(iso_datetime)s">&nbsp;'
            '  </time>'
            '</div>'
            % action_bundle)