Пример #1
0
 def __cmp__(self, other):
     # first compare version, high version number first
     vc = upstream_version_compare(self.version, other.version)
     if vc != 0:
         return vc
     # then wilson score
     uc = cmp(wilson_score(self.usefulness_favorable, 
                           self.usefulness_total),
              wilson_score(other.usefulness_favorable,
                           other.usefulness_total))
     if uc != 0:
         return uc
     # last is date
     t1 = datetime.datetime.strptime(self.date_created, '%Y-%m-%d %H:%M:%S')
     t2 = datetime.datetime.strptime(other.date_created, '%Y-%m-%d %H:%M:%S')
     return cmp(t1, t2)
Пример #2
0
 def __cmp__(self, other):
     # first compare version, high version number first
     vc = upstream_version_compare(self.version, other.version)
     if vc != 0:
         return vc
     # then wilson score
     uc = cmp(wilson_score(self.usefulness_favorable, 
                           self.usefulness_total),
              wilson_score(other.usefulness_favorable,
                           other.usefulness_total))
     if uc != 0:
         return uc
     # last is date
     t1 = datetime.datetime.strptime(self.date_created, '%Y-%m-%d %H:%M:%S')
     t2 = datetime.datetime.strptime(other.date_created, '%Y-%m-%d %H:%M:%S')
     return cmp(t1, t2)
Пример #3
0
    def _build(self, review_data, app_version, logged_in_person, useful_votes):
        # all the attributes of review_data may need markup escape,
        # depending on if they are used as text or markup
        self.id = review_data.id
        self.person = review_data.reviewer_username
        displayname = review_data.reviewer_displayname
        # example raw_date str format: 2011-01-28 19:15:21
        cur_t = self._get_datetime_from_review_date(review_data.date_created)

        review_version = review_data.version
        self.useful_total = useful_total = review_data.usefulness_total
        useful_favorable = review_data.usefulness_favorable
        useful_submit_error = review_data.usefulness_submit_error
        delete_error = review_data.delete_error
        modify_error = review_data.modify_error

        # upstream version
        version = GLib.markup_escape_text(upstream_version(review_version))
        # default string
        version_string = _("For version %(version)s") % {
            'version': version,
        }
        # If its for the same version, show it as such
        if (review_version and app_version and upstream_version_compare(
                review_version, app_version) == 0):
            version_string = _("For this version (%(version)s)") % {
                'version': version,
            }

        m = '<small>%s</small>'
        self.version_label.set_markup(m % version_string)

        m = self._whom_when_markup(self.person, displayname, cur_t)
        who_when = Gtk.Label()
        who_when.set_name("subtle-label")
        who_when.set_justify(Gtk.Justification.RIGHT)
        who_when.set_markup(m)

        summary = Gtk.Label()
        try:
            s = GLib.markup_escape_text(review_data.summary.encode("utf-8"))
            summary.set_markup('<b>%s</b>' % s)
        except Exception:
            LOG.exception("_build() failed")
            summary.set_text("Error parsing summary")

        summary.set_ellipsize(Pango.EllipsizeMode.END)
        summary.set_selectable(True)
        summary.set_alignment(0, 0.5)

        text = Gtk.Label()
        text.set_text(review_data.review_text)
        text.set_line_wrap(True)
        text.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
        text.set_selectable(True)
        text.set_alignment(0, 0)

        stars = Star()
        stars.set_rating(review_data.rating)
        a = Gtk.Alignment.new(0.5, 0.5, 0, 0)
        a.add(stars)

        self.header.pack_start(a, False, False, 0)
        self.header.pack_start(summary, False, False, 0)
        self.header.pack_end(who_when, False, False, 0)
        self.body.pack_start(text, False, False, 0)

        current_user_reviewer = False
        if self.person == self.logged_in_person:
            current_user_reviewer = True

        self._build_usefulness_ui(current_user_reviewer, useful_total,
                                  useful_favorable, useful_votes,
                                  useful_submit_error)

        self.flagbox = Gtk.HBox()
        self.flagbox.set_spacing(4)
        self._build_delete_flag_ui(current_user_reviewer, delete_error,
                                   modify_error)
        self.footer.pack_end(self.flagbox, False, False, 0)

        # connect network signals
        self.connect("realize", lambda w: self._on_network_state_change())
        watcher = get_network_watcher()
        watcher.connect("changed",
                        lambda w, s: self._on_network_state_change())
Пример #4
0
    def _build(self, review_data, app_version, logged_in_person, useful_votes):
        # all the attributes of review_data may need markup escape,
        # depending on if they are used as text or markup
        self.id = review_data.id
        self.person = review_data.reviewer_username
        displayname = review_data.reviewer_displayname
        # example raw_date str format: 2011-01-28 19:15:21
        cur_t = self._get_datetime_from_review_date(review_data.date_created)

        review_version = review_data.version
        self.useful_total = useful_total = review_data.usefulness_total
        useful_favorable = review_data.usefulness_favorable
        useful_submit_error = review_data.usefulness_submit_error
        delete_error = review_data.delete_error
        modify_error = review_data.modify_error

        # upstream version
        version = GLib.markup_escape_text(upstream_version(review_version))
        # default string
        version_string = _("For version %(version)s") % {
            'version': version,
        }
        # If its for the same version, show it as such
        if (review_version and
                app_version and
                upstream_version_compare(review_version, app_version) == 0):
            version_string = _("For this version (%(version)s)") % {
                    'version': version,
            }

        m = '<small>%s</small>'
        self.version_label.set_markup(m % version_string)

        m = self._whom_when_markup(self.person, displayname, cur_t)
        who_when = Gtk.Label()
        who_when.set_name("subtle-label")
        who_when.set_justify(Gtk.Justification.RIGHT)
        who_when.set_markup(m)

        summary = Gtk.Label()
        try:
            s = GLib.markup_escape_text(review_data.summary.encode("utf-8"))
            summary.set_markup('<b>%s</b>' % s)
        except Exception:
            LOG.exception("_build() failed")
            summary.set_text("Error parsing summary")

        summary.set_ellipsize(Pango.EllipsizeMode.END)
        summary.set_selectable(True)
        summary.set_alignment(0, 0.5)

        text = Gtk.Label()
        text.set_text(review_data.review_text)
        text.set_line_wrap(True)
        text.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
        text.set_selectable(True)
        text.set_alignment(0, 0)

        stars = Star()
        stars.set_rating(review_data.rating)
        a = Gtk.Alignment.new(0.5, 0.5, 0, 0)
        a.add(stars)

        self.header.pack_start(a, False, False, 0)
        self.header.pack_start(summary, False, False, 0)
        self.header.pack_end(who_when, False, False, 0)
        self.body.pack_start(text, False, False, 0)

        current_user_reviewer = False
        if self.person == self.logged_in_person:
            current_user_reviewer = True

        self._build_usefulness_ui(current_user_reviewer, useful_total,
                                  useful_favorable, useful_votes,
                                  useful_submit_error)

        self.flagbox = Gtk.HBox()
        self.flagbox.set_spacing(4)
        self._build_delete_flag_ui(current_user_reviewer, delete_error,
            modify_error)
        self.footer.pack_end(self.flagbox, False, False, 0)

        # connect network signals
        self.connect("realize", lambda w: self._on_network_state_change())
        watcher = get_network_watcher()
        watcher.connect(
            "changed", lambda w, s: self._on_network_state_change())