Exemple #1
0
def build_accounts_report(period, filename=None, format='pdf'):
    ''' PDF: List of balances '''
    if not filename:
        filename = get_temp_filename('pdf')

    doc = Document(title=_(u"Accounts balance for %s") \
                         % period.display_name(), landscape=True)

    table = Table(4)
    table.add_header_row([
            Text(_(u"Account Number")),
            Text(_(u"Account Name")),
            Text(_(u"Budget")),
            Text(_(u"Balance"))])

    # column widths
    table.set_column_width(10, 0)
    table.set_column_width(15, 2)
    table.set_column_width(15, 3)

    # column alignments
    table.set_alignment(Table.ALIGN_LEFT, column=0)
    table.set_alignment(Table.ALIGN_LEFT, column=1)
    table.set_alignment(Table.ALIGN_RIGHT, column=2)
    table.set_alignment(Table.ALIGN_RIGHT, column=3)

    accounts = [account_summary(account, period) \
                for account in session.query(Account).all()]
    list_budget = []
    list_balance = []
    for account in accounts:
        table.add_row([
            Text(unicode(account[0])),
            Text(unicode(account[1])),
            Text(formatted_number(account[2])),
            Text(formatted_number(account[3]))])
        list_budget.append(account[2])
        list_balance.append(account[3])

    table.add_row([Text(u''),
                   Text(u'TOTALS', bold=True),
                   Text(formatted_number(sum(list_budget)), bold=True),
                   Text(formatted_number(sum(list_balance)), bold=True)])

    doc.add_element(table)

    gen = PDFGenerator(doc, filename)
    gen.render_document()

    return gen.get_filename()
Exemple #2
0
    def __init__(self, parent, account, *args, **kwargs):
        QtGui.QDialog.__init__(self, parent, *args, **kwargs)

        self.data = session.query(Operation).\
                    filter_by(account=self.account, period=current_period()).\
                    order_by(desc(Operation.invoice_date)).all()

        self.account = account
        title = QtGui.QLabel()
        self.setWindowTitle(_(u"Delete an operation"))
        if self.data == []:
            title.setText(_(u"There is no operation removed for this account"))
            ok_butt = QtGui.QPushButton(_(u"OK"))
            ok_butt.clicked.connect(self.close)

            vbox = QtGui.QVBoxLayout()
            vbox.addWidget(title)
            vbox.addWidget(ok_butt)
            self.setLayout(vbox)
        else:
            title.setText(_(u"Select an operation to delete"))
            title.setAlignment(QtCore.Qt.AlignHCenter)
            title_hbox = QtGui.QHBoxLayout()
            title_hbox.addWidget(title)

            #Combobox widget
            self.box = QtGui.QComboBox()
            for index in xrange(0, len(self.data)):
                op = self.data[index]
                sentence = _(u"%(date)s - %(amount)s to " \
                             u"%(provider)s/%(invoice_num)s " \
                             u"(Order #%(order_num)s)") \
                             % {'order_num': op.order_number, \
                                'invoice_num': op.invoice_number, \
                                'provider': op.provider, \
                                'amount': formatted_number(op.amount), \
                                'date': op.invoice_date.strftime('%x')}
                self.box.addItem(sentence, QtCore.QVariant(op.id))

            combo_hbox = QtGui.QHBoxLayout()
            combo_hbox.addWidget(self.box)

            #delete and cancel hbox
            button_hbox = QtGui.QHBoxLayout()

            #Delete Button widget.
            delete_but = QtGui.QPushButton(_(u"Delete operation"))
            button_hbox.addWidget(delete_but)
            delete_but.clicked.connect(self.delete)
            #Cancel Button widget.
            cancel_but = QtGui.QPushButton(_(u"Cancel"))
            button_hbox.addWidget(cancel_but)
            cancel_but.clicked.connect(self.cancel)

            #Create the QVBoxLayout contenaire.
            vbox = QtGui.QVBoxLayout()
            vbox.addLayout(title_hbox)
            vbox.addLayout(combo_hbox)
            vbox.addLayout(button_hbox)
            self.setLayout(vbox)
Exemple #3
0
    def _format_for_table(self, value):
        ''' formats input value for string in table widget '''
        if isinstance(value, basestring):
            return value

        if isinstance(value, (int, float, long)):
            return formatted_number(value)

        return u"%s" % value
Exemple #4
0
    def _format_for_table(self, value):
        ''' formats input value for string in table widget '''
        if isinstance(value, basestring):
            return value

        if isinstance(value, (int, float, long)):
            return formatted_number(value)

        return u"%s" % value
Exemple #5
0
def build_balance_report(filename=None, format='pdf'):
    ''' PDF: List of balances '''
    if not filename:
        filename = get_temp_filename('pdf')

    doc = Document(title=_(u"List of balances"))

    table = Table(4)
    table.add_header_row([
        Text(_(u"Date")),
        Text(_(u"Type")),
        Text(_(u"Value")),
        Text(_(u"Balance"))
    ])

    # column widths
    table.set_column_width(20, 0)
    table.set_column_width(10, 2)
    table.set_column_width(15, 3)

    # column alignments
    table.set_alignment(Table.ALIGN_LEFT, column=0)
    table.set_alignment(Table.ALIGN_LEFT, column=1)
    table.set_alignment(Table.ALIGN_RIGHT, column=2)
    table.set_alignment(Table.ALIGN_RIGHT, column=3)

    operations = [(op.date_op, op.type_, op.value, op.balance) \
                    for op in Operation.select().order_by(("date_op"))
                    .filter(type_="balance")]

    for operation in operations:
        table.add_row([
            Text(unicode(operation[0])),
            Text(unicode(operation[1])),
            Text(formatted_number(operation[2])),
            Text(formatted_number(operation[3]))
        ])

    doc.add_element(table)

    gen = PDFGenerator(doc, filename)
    gen.render_document()

    return gen.get_filename()
Exemple #6
0
def build_balance_report(filename=None, format='pdf'):
    ''' PDF: List of balances '''
    if not filename:
        filename = get_temp_filename('pdf')

    doc = Document(title=_(u"List of balances"))

    table = Table(4)
    table.add_header_row([
            Text(_(u"Date")),
            Text(_(u"Type")),
            Text(_(u"Value")),
            Text(_(u"Balance"))])

    # column widths
    table.set_column_width(20, 0)
    table.set_column_width(10, 2)
    table.set_column_width(15, 3)

    # column alignments
    table.set_alignment(Table.ALIGN_LEFT, column=0)
    table.set_alignment(Table.ALIGN_LEFT, column=1)
    table.set_alignment(Table.ALIGN_RIGHT, column=2)
    table.set_alignment(Table.ALIGN_RIGHT, column=3)

    operations = [(op.date_op, op.type_, op.value, op.balance) \
                    for op in Operation.select().order_by(("date_op"))
                    .filter(type_="balance")]

    for operation in operations:
        table.add_row([
            Text(unicode(operation[0])),
            Text(unicode(operation[1])),
            Text(formatted_number(operation[2])),
            Text(formatted_number(operation[3]))])

    doc.add_element(table)

    gen = PDFGenerator(doc, filename)
    gen.render_document()

    return gen.get_filename()
Exemple #7
0
    def set_data_for(self):

        self.data = [(op.date_op.strftime(_(u'%x %Hh:%Mmn')), op.type_,
                      formatted_number(op.value), formatted_number(op.balance))
                     for op in Operation.select().order_by(('date_op', 'asc'))]
Exemple #8
0
 def set_data_for(self):
     """ completed the table """
     self._data = [(operation.number.full_name(),
                    formatted_number(operation.amount) + " fcfa",
                   operation.date.strftime(u'%H:%M')) \
                   for operation in Transfer.select().order_by('date')]
Exemple #9
0
def build_operations_report(account, period, filename=None, format='pdf'):
    ''' PDF: List of operations '''
    if not filename:
        filename = get_temp_filename('pdf')
    doc = Document(title=_(u"The list of operations for the period %s.") \
                         % period.display_name(), \
                           landscape=False, stick_sections=True)

    if account == None:
        accounts = session.query(Account).all()
    else:
        accounts = session.query(Account).\
                           filter_by(number=account.number).all()
    flag = False
    for account in accounts:
        operations = [(operation.order_number, operation.invoice_number,\
                      operation.invoice_date.strftime(u'%x'),\
                      operation.provider, operation.amount, operation) \
                      for operation in session.query(Operation).\
                      filter_by(account=account, period=period).\
                      order_by(desc(Operation.invoice_date)).all()]

        if operations:
            section_name = (_(u'%(name)s (%(number)s)'))\
                               % {'name': account.name,\
                                  'number': account.number}
            doc.add_element(Section(section_name))

            doc.add_element(Paragraph(u''))

            table = Table(5)
            # header row
            table.add_header_row([
                    Text(_(u"Order No.")),
                    Text(_(u"Invoice No.")),
                    Text(_(u"Invoice date")),
                    Text(_(u"Provider")),
                    Text(_(u"Amount"))])

            # column widths
            table.set_column_width(10, 0)
            table.set_column_width(10, 1)
            table.set_column_width(15, 2)
            table.set_column_width(15, 4)

            # column alignments
            table.set_alignment(Table.ALIGN_LEFT, column=0)
            table.set_alignment(Table.ALIGN_LEFT, column=1)
            table.set_alignment(Table.ALIGN_LEFT, column=2)
            table.set_alignment(Table.ALIGN_LEFT, column=3)
            table.set_alignment(Table.ALIGN_RIGHT, column=4)

            list_amount = []
            for operation in operations:
                table.add_row([
                    Text(operation[0]),
                    Text(operation[1]),
                    Text(operation[2]),
                    Text(operation[3]),
                    Text(formatted_number(operation[4]))])
                list_amount.append(operation[4])

            table.add_row([Text(u''),
                           Text(u''),
                           Text(u''),
                           Text(u'TOTAL', bold=True),
                           Text(formatted_number(sum(list_amount)), \
                                bold=True)])

            doc.add_element(table)
            flag = True

    if not flag:
        doc.add_element(Paragraph(\
                Text(_(u'It has no operations for this period.'), bold=True)))

    gen = PDFGenerator(doc, filename)
    gen.render_document()

    return gen.get_filename()
Exemple #10
0
    def __init__(self, account, period=current_period(), \
                 parent=0, *args, **kwargs):
        super(OperationWidget, self).__init__(parent=parent, *args, **kwargs)
        ANMPeriodHolder.__init__(self, period, *args, **kwargs)

        # set global account
        self.account = account
        self.main_period = period
        self.balance = account_balance(self.account, period)

        self.table = OperationTableWidget(parent=self, period=self.main_period)

        self.title = ANMPageTitle(_(u"Transactions List for Account " \
                                    u"%(number)s: %(name)s.") \
                                    % {'name': self.account.name, \
                                       'number': self.account.number})

        self.balance_title = ANMPageTitle(_(u"Balance: " u"%(balance)s FCFA") \
                                    % {'balance': \
                                              formatted_number(account_balance(self.account, period))})
        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(self.table)

        formbox = QtGui.QFormLayout()
        self.order_number = QtGui.QLineEdit()
        self.invoice_number = QtGui.QLineEdit()
        self.invoice_date = QtGui.QDateTimeEdit(QtCore.QDate.currentDate())
        self.invoice_date.setDisplayFormat("yyyy-MM-dd")
        # change date if appropriate
        self.adjust_date_field()
        self.provider = QtGui.QLineEdit()
        self.amount = QtGui.QLineEdit()
        self.amount.setValidator(QtGui.QIntValidator())
        butt = QtGui.QPushButton(_(u"Add"))
        butt.clicked.connect(self.add_operation)

        formbox1 = QtGui.QHBoxLayout()
        formbox1.addWidget(QtGui.QLabel(_(u'Order number')))
        formbox1.addWidget(QtGui.QLabel(_(u'Invoice number')))
        formbox1.addWidget(QtGui.QLabel(_(u'Invoice date')))
        formbox1.addWidget(QtGui.QLabel(_(u'Provider')))
        formbox1.addWidget(QtGui.QLabel(_(u'Amount')))
        formbox1.addSpacing(90)

        formbox = QtGui.QHBoxLayout()
        formbox.addWidget(self.order_number)
        formbox.addWidget(self.invoice_number)
        formbox.addWidget(self.invoice_date)
        formbox.addWidget(self.provider)
        formbox.addWidget(self.amount)
        formbox.addWidget(butt)

        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(self.title)
        vbox.addWidget(self.balance_title)
        vbox.addWidget(self.periods_bar)
        vbox.addLayout(formbox1)
        vbox.addLayout(formbox)
        vbox.addLayout(hbox)

        self.setLayout(vbox)
 def map_details(data):
     """helper method to map the details received from omdb to kodi compatible format"""
     result = {}
     if sys.version_info.major == 3:
         for key, value in data.items():
             # filter the N/A values
             if value in ["N/A", "NA"] or not value:
                 continue
             if key == "title":
                 result["title"] = value
             elif key == "year":
                 try:
                     result["year"] = try_parse_int(value.split("-")[0])
                 except Exception:
                     result["year"] = value
             elif key == "rated":
                 result["mpaa"] = value.replace("Rated", "")
             elif key == "released":
                 date_time = arrow.get(value, "DD MMM YYYY")
                 result["premiered"] = date_time.strftime(
                     xbmc.getRegion("dateshort"))
                 try:
                     result["premiered.formatted"] = date_time.format(
                         'DD MMM YYYY', locale=KODI_LANGUAGE)
                 except Exception:
                     result["premiered.formatted"] = value
             elif key == "runtime":
                 result["runtime"] = try_parse_int(value.replace(
                     " min", "")) * 60
             elif key == "genre":
                 result["genre"] = value.split(", ")
             elif key == "director":
                 result["director"] = value.split(", ")
             elif key == "writer":
                 result["writer"] = value.split(", ")
             elif key == "country":
                 result["country"] = value.split(", ")
                 result["country.0"] = value.split(", ")[0]
             elif key == "awards":
                 result["awards"] = value
             elif key == "poster":
                 result["thumbnail"] = value
                 result["art"] = {}
                 result["art"]["thumb"] = value
             elif key == "imdbVotes":
                 result["votes.imdb"] = value
                 result["votes"] = try_parse_int(value.replace(",", ""))
             elif key == "imdbRating":
                 result["rating.imdb"] = value
                 result["rating"] = float(value)
                 result["rating.percent.imdb"] = "%s" % (try_parse_int(
                     float(value) * 10))
             elif key == "metascore":
                 result["metacritic.rating"] = value
                 result["metacritic.rating.percent"] = "%s" % value
             elif key == "imdbID":
                 result["imdbnumber"] = value
             elif key == "BoxOffice":
                 result["boxoffice"] = value
             elif key == "DVD":
                 date_time = arrow.get(value, "DD MMM YYYY")
                 result["dvdrelease"] = date_time.format('YYYY-MM-DD')
                 result["dvdrelease.formatted"] = date_time.format(
                     'DD MMM YYYY', locale=KODI_LANGUAGE)
             elif key == "Production":
                 result["studio"] = value.split(", ")
             elif key == "Website":
                 result["homepage"] = value
             elif key == "plot":
                 result["plot"] = value
                 result["imdb.plot"] = value
             elif key == "type":
                 if value == "series":
                     result["type"] = "tvshow"
                 else:
                     result["type"] = value
                 result["media_type"] = result["type"]
         # rotten tomatoes
             elif key == "tomatoMeter":
                 result["rottentomatoes.meter"] = value
                 result["rottentomatoesmeter"] = value
             elif key == "tomatoImage":
                 result["rottentomatoes.image"] = value
             elif key == "tomatoRating":
                 result["rottentomatoes.rating"] = value
                 result["rottentomatoes.rating.percent"] = "%s" % (
                     try_parse_int(float(value) * 10))
                 result["rating.rt"] = value
             elif key == "tomatoReviews":
                 result["rottentomatoes.reviews"] = formatted_number(value)
             elif key == "tomatoFresh":
                 result["rottentomatoes.fresh"] = value
             elif key == "tomatoRotten":
                 result["rottentomatoes.rotten"] = value
             elif key == "tomatoConsensus":
                 result["rottentomatoes.consensus"] = value
             elif key == "tomatoUserMeter":
                 result["rottentomatoes.usermeter"] = value
             elif key == "tomatoUserRating":
                 result["rottentomatoes.userrating"] = value
                 result["rottentomatoes.userrating.percent"] = "%s" % (
                     try_parse_int(float(value) * 10))
             elif key == "tomatoUserReviews":
                 result["rottentomatoes.userreviews"] = int_with_commas(
                     value)
             elif key == "tomatoeURL":
                 result["rottentomatoes.url"] = value
     else:
         for key, value in data.iteritems():
             # filter the N/A values
             if value in ["N/A", "NA"] or not value:
                 continue
             if key == "title":
                 result["title"] = value
             elif key == "Year":
                 try:
                     result["year"] = try_parse_int(value.split("-")[0])
                 except Exception:
                     result["year"] = value
             elif key == "rated":
                 result["mpaa"] = value.replace("Rated", "")
             elif key == "released":
                 date_time = arrow.get(value, "DD MMM YYYY")
                 result["premiered"] = date_time.strftime(
                     xbmc.getRegion("dateshort"))
                 try:
                     result["premiered.formatted"] = date_time.format(
                         'DD MMM YYYY', locale=KODI_LANGUAGE)
                 except Exception:
                     result["premiered.formatted"] = value
             elif key == "runtime":
                 result["runtime"] = try_parse_int(value.replace(
                     " min", "")) * 60
             elif key == "genre":
                 result["genre"] = value.split(", ")
             elif key == "director":
                 result["director"] = value.split(", ")
             elif key == "writer":
                 result["writer"] = value.split(", ")
             elif key == "country":
                 result["country"] = value.split(", ")
             elif key == "awards":
                 result["awards"] = value
             elif key == "poster":
                 result["thumbnail"] = value
                 result["art"] = {}
                 result["art"]["thumb"] = value
             elif key == "imdbVotes":
                 result["votes.imdb"] = value
                 result["votes"] = try_parse_int(value.replace(",", ""))
             elif key == "imdbRating":
                 result["rating.imdb"] = value
                 result["rating"] = float(value)
                 result["rating.percent.imdb"] = "%s" % (try_parse_int(
                     float(value) * 10))
             elif key == "metascore":
                 result["metacritic.rating"] = value
                 result["metacritic.rating.percent"] = "%s" % value
             elif key == "imdbID":
                 result["imdbnumber"] = value
             elif key == "BoxOffice":
                 result["boxoffice"] = value
             elif key == "DVD":
                 date_time = arrow.get(value, "DD MMM YYYY")
                 result["dvdrelease"] = date_time.format('YYYY-MM-DD')
                 result["dvdrelease.formatted"] = date_time.format(
                     'DD MMM YYYY', locale=KODI_LANGUAGE)
             elif key == "Production":
                 result["studio"] = value.split(", ")
             elif key == "Website":
                 result["homepage"] = value
             elif key == "plot":
                 result["plot"] = value
                 result["imdb.plot"] = value
             elif key == "type":
                 if value == "series":
                     result["type"] = "tvshow"
                 else:
                     result["type"] = value
                 result["media_type"] = result["type"]
         # rotten tomatoes
             elif key == "tomatoMeter":
                 result["rottentomatoes.meter"] = value
                 result["rottentomatoesmeter"] = value
             elif key == "tomatoImage":
                 result["rottentomatoes.image"] = value
             elif key == "tomatoRating":
                 result["rottentomatoes.rating"] = value
                 result["rottentomatoes.rating.percent"] = "%s" % (
                     try_parse_int(float(value) * 10))
                 result["rating.rt"] = value
             elif key == "tomatoReviews":
                 result["rottentomatoes.reviews"] = formatted_number(value)
             elif key == "tomatoFresh":
                 result["rottentomatoes.fresh"] = value
             elif key == "tomatoRotten":
                 result["rottentomatoes.rotten"] = value
             elif key == "tomatoConsensus":
                 result["rottentomatoes.consensus"] = value
             elif key == "tomatoUserMeter":
                 result["rottentomatoes.usermeter"] = value
             elif key == "tomatoUserRating":
                 result["rottentomatoes.userrating"] = value
                 result["rottentomatoes.userrating.percent"] = "%s" % (
                     try_parse_int(float(value) * 10))
             elif key == "tomatoUserReviews":
                 result["rottentomatoes.userreviews"] = int_with_commas(
                     value)
             elif key == "tomatoeURL":
                 result["rottentomatoes.url"] = value
     return result
Exemple #12
0
 def adjust_balance(self, period):
     ''' adjusts the balance by period '''
     self.balance = account_balance(self.account, period)
     self.balance_title.setText(_(u"Balance: " u"%(balance)s FCFA") \
                                 % {'balance': \
                                           formatted_number(self.balance)})
Exemple #13
0
 def set_data_for(self):
     consumptions = consumption()
     consumptions.reverse()
     self.data = [(op[0].strftime(_(u'%x %Hh:%Mmn')),\
                         formatted_number(op[1]))
         for op in consumptions]
Exemple #14
0
 def map_details(data):
     '''helper method to map the details received from omdb to kodi compatible format'''
     result = {}
     for key, value in data.iteritems():
         # filter the N/A values
         if value in ["N/A", "NA"] or not value:
             continue
         if key == "Title":
             result["title"] = value
         elif key == "Year":
             try:
                 result["year"] = try_parse_int(value.split("-")[0])
             except Exception:
                 result["year"] = value
         elif key == "Year":
             result["year"] = value
         if key == "Rated":
             result["mpaa"] = value.replace("Rated", "")
         elif key == "Title":
             result["title"] = value
         elif key == "Released":
             date_time = arrow.get(value, "DD MMM YYYY")
             result["premiered"] = date_time.strftime(
                 xbmc.getRegion("dateshort"))
             try:
                 result["premiered.formatted"] = date_time.format(
                     'DD MMM YYYY', locale=KODI_LANGUAGE)
             except Exception:
                 result["premiered.formatted"] = value
         elif key == "Runtime":
             result["runtime"] = try_parse_int(value.replace(" min",
                                                             "")) * 60
         elif key == "Genre":
             result["genre"] = value.split(", ")
         elif key == "Director":
             result["director"] = value.split(", ")
         elif key == "Writer":
             result["writer"] = value.split(", ")
         elif key == "Country":
             result["country"] = value.split(", ")
         elif key == "Awards":
             result["awards"] = value
         elif key == "Poster":
             result["thumbnail"] = value
             result["art"] = {}
             result["art"]["thumb"] = value
         elif key == "imdbVotes":
             result["votes.imdb"] = value
             result["votes"] = try_parse_int(value.replace(",", ""))
         elif key == "Ratings":
             for rating_item in value:
                 if rating_item["Source"] == "Internet Movie Database":
                     rating = rating_item["Value"]
                     result["rating.imdb.text"] = rating
                     rating = rating.split("/")[0]
                     result["rating.imdb"] = rating
                     result["rating"] = float(rating)
                     result["rating.percent.imdb"] = "%s" % (try_parse_int(
                         float(rating) * 10))
                 elif rating_item["Source"] == "Rotten Tomatoes":
                     rating = rating_item["Value"]
                     result["rottentomatoes.rating.percent"] = rating
                     rating = rating.replace("%", "")
                     # this should be a dedicated rt rating instead of the meter
                     result["rottentomatoes.rating"] = rating
                     result["rating.rt"] = rating
                     result["rottentomatoes.meter"] = rating
                     result["rottentomatoesmeter"] = rating
                     rating = int(rating)
                     if rating < 60:
                         result["rottentomatoes.rotten"] = rating
                         result["rottentomatoes.image"] = "rotten"
                     else:
                         result["rottentomatoes.fresh"] = rating
                         result["rottentomatoes.image"] = "fresh"
                 elif rating_item["Source"] == "Metacritic":
                     rating = rating_item["Value"]
                     result["rating.mc.text"] = rating
                     rating = rating.split("/")[0]
                     result["metacritic.rating"] = rating
                     result["rating.mc"] = rating
                     result["metacritic.rating.percent"] = "%s" % rating
         elif key == "imdbID":
             result["imdbnumber"] = value
         elif key == "BoxOffice":
             result["boxoffice"] = value
         elif key == "DVD":
             date_time = arrow.get(value, "DD MMM YYYY")
             result["dvdrelease"] = date_time.format('YYYY-MM-DD')
             result["dvdrelease.formatted"] = date_time.format(
                 'DD MMM YYYY', locale=KODI_LANGUAGE)
         elif key == "Production":
             result["studio"] = value.split(", ")
         elif key == "Website":
             result["homepage"] = value
         # rotten tomatoes - will probably never work again (OMDBAPI doesnt't provide them anymore)
         elif key == "tomatoReviews":
             result["rottentomatoes.reviews"] = formatted_number(value)
         elif key == "tomatoConsensus":
             result["rottentomatoes.consensus"] = value
         elif key == "tomatoUserMeter":
             result["rottentomatoes.usermeter"] = value
         elif key == "tomatoUserRating":
             result["rottentomatoes.userrating"] = value
             result["rottentomatoes.userrating.percent"] = "%s" % (
                 try_parse_int(float(value) * 10))
         elif key == "tomatoUserReviews":
             result["rottentomatoes.userreviews"] = int_with_commas(value)
         elif key == "tomatoURL":
             result["rottentomatoes.url"] = value
     return result
Exemple #15
0
    def __init__(self, parent=0, *args, **kwargs):
        super(DashbordViewWidget, self).__init__(parent=parent, *args, **kwargs)

        vbox = QtGui.QVBoxLayout()
        hbox = QtGui.QHBoxLayout()
        box_left = QtGui.QHBoxLayout()
        box_rigth = QtGui.QHBoxLayout()
        hbox_alert = QtGui.QVBoxLayout()

        box = QtGui.QListWidget()
        consuption = max_consumption()
        duration_cut = duration()
        avg_conso = average_consumption()
        num_days = estimated_duration()

        #All alerts
        if consuption:
            box.addItem(_(u"The increased consumption is %(conso)s"
                          u" cfa (%(date)s).")\
                          % {'conso': formatted_number(consuption[0]),
                          'date': consuption[1].strftime(u'%x')})
        if duration_cut:
            box.addItem(_(u"The biggest break is %(duration)s (%(date)s).")\
                                % {'duration': duration_cut[0],
                                   'date': duration_cut[1].strftime(u"%x")})
        if avg_conso:
            box.addItem(_(u"The average consumption is %(avg)s FCFA.")
                                % {'avg': formatted_number(avg_conso)})
        if num_days:
            box.addItem(_(u"The end balance is estimated at %(num)s days.")
                                % {'num': num_days})

        tablebox_balance = QtGui.QVBoxLayout()
        tablebox_consumption = QtGui.QVBoxLayout()

        # On recupere la derniere balance
        msg = _("Balance:  {} FCFA")
        balance = last_balance()
        balance = msg.format(0 if not balance else formatted_number(balance))

        self.title = PowerPageTitle(balance)
        self.title_alert = PowerPageTitle(_(u"Statistics"))
        self.title_box_balance = PowerBoxTitle(_(u"Table balances"))
        self.title_box_consumption = PowerBoxTitle(_(u"Table consumptions"))

        self.table_balance = BalanceTableWidget(parent=self)
        self.table_consumption = ConsumptionTableWidget(parent=self)

        # GRAPH
        jinja = Environment(loader=PackageLoader('power_m', 'templates'))
        template = jinja.get_template('chart.html')
        graph1 = template.render(base_url=BASE_URL, type="balance", data=balance_graph()[1],
                                 date=balance_graph()[0])
        graph2 = template.render(base_url=BASE_URL,  type="consuption", data=consumption_graph()[1],
                                 date=consumption_graph()[0])

        label_b = QWebView()
        label_b.setHtml(graph1)
        box_left.addWidget(label_b)
        label_cons = QWebView()
        label_cons.setHtml(graph2)
        box_rigth.addWidget(label_cons)

        hbox_alert.addWidget(self.title_alert)
        hbox_alert.addWidget(box)

        #Combobox widget
        list_type = [_(u"Week"), _(u"Month")]
        self.box_type = QtGui.QComboBox()
        for index in list_type:
            self.box_type.addItem((u"%(type)s") % {"type": index})

        box_combo = QtGui.QHBoxLayout()
        box_combo.addWidget(self.box_type)
        box_combo.addSpacing(930)

        vbox.addWidget(self.title)
        vbox.addLayout(box_combo)
        tablebox_balance.addWidget(self.title_box_balance)
        tablebox_balance.addWidget(self.table_balance)
        tablebox_consumption.addWidget(self.title_box_consumption)
        tablebox_consumption.addWidget(self.table_consumption)
        tab_widget1 = tabbox(box_left, tablebox_balance)
        tab_widget2 = tabbox(box_rigth, tablebox_consumption)

        hbox.addWidget(tab_widget1)
        hbox.addWidget(tab_widget2)
        vbox.addLayout(hbox)
        vbox.addLayout(hbox_alert)

        self.setLayout(vbox)
Exemple #16
0
 def set_data_for(self):
     consumptions = consumption()
     consumptions.reverse()
     self.data = [(op[0].strftime(_(u'%x %Hh:%Mmn')),\
                         formatted_number(op[1]))
         for op in consumptions]
Exemple #17
0
    def set_data_for(self):

        self.data = [(op.date_op.strftime(_(u'%x %Hh:%Mmn')), op.type_,
                     formatted_number(op.value), formatted_number(op.balance))
                     for op in Operation.select().order_by(('date_op', 'asc'))]
Exemple #18
0
 def map_details(data):
     '''helper method to map the details received from omdb to kodi compatible format'''
     result = {}
     for key, value in data.iteritems():
         # filter the N/A values
         if value in ["N/A", "NA"] or not value:
             continue
         if key == "Title":
             result["title"] = value
         elif key == "Year":
             try:
                 result["year"] = try_parse_int(value.split("-")[0])
             except Exception:
                 result["year"] = value
         elif key == "Year":
             result["year"] = value
         if key == "Rated":
             result["mpaa"] = value.replace("Rated", "")
         elif key == "Title":
             result["title"] = value
         elif key == "Released":
             date_time = arrow.get(value, "DD MMM YYYY")
             result["premiered"] = date_time.strftime(xbmc.getRegion("dateshort"))
             try:
                 result["premiered.formatted"] = date_time.format('DD MMM YYYY', locale=KODI_LANGUAGE)
             except Exception:
                 result["premiered.formatted"] = value
         elif key == "Runtime":
             result["runtime"] = try_parse_int(value.replace(" min", "")) * 60
         elif key == "Genre":
             result["genre"] = value.split(", ")
         elif key == "Director":
             result["director"] = value.split(", ")
         elif key == "Writer":
             result["writer"] = value.split(", ")
         elif key == "Country":
             result["country"] = value.split(", ")
         elif key == "Awards":
             result["awards"] = value
         elif key == "Poster":
             result["thumbnail"] = value
             result["art"] = {}
             result["art"]["thumb"] = value
         elif key == "imdbVotes":
             result["votes.imdb"] = value
             result["votes"] = try_parse_int(value.replace(",", ""))
         elif key == "Ratings":
             for rating_item in value:
                 if rating_item["Source"] == "Internet Movie Database":
                     rating = rating_item["Value"]
                     result["rating.imdb.text"] = rating
                     rating = rating.split("/")[0]
                     result["rating.imdb"] = rating
                     result["rating"] = float(rating)
                     result["rating.percent.imdb"] = "%s" % (try_parse_int(float(rating) * 10))
                 elif rating_item["Source"] == "Rotten Tomatoes":
                     rating = rating_item["Value"]
                     result["rottentomatoes.rating.percent"] = rating
                     rating = rating.replace("%", "")
                     # this should be a dedicated rt rating instead of the meter
                     result["rottentomatoes.rating"] = rating
                     result["rating.rt"] = rating
                     result["rottentomatoes.meter"] = rating
                     result["rottentomatoesmeter"] = rating
                     rating = int(rating)
                     if rating < 60:
                         result["rottentomatoes.rotten"] = rating
                         result["rottentomatoes.image"] = "rotten"
                     else:
                         result["rottentomatoes.fresh"] = rating
                         result["rottentomatoes.image"] = "fresh"
                 elif rating_item["Source"] == "Metacritic":
                     rating = rating_item["Value"]
                     result["rating.mc.text"] = rating
                     rating = rating.split("/")[0]
                     result["metacritic.rating"] = rating
                     result["rating.mc"] = rating
                     result["metacritic.rating.percent"] = "%s" % rating
         elif key == "imdbID":
             result["imdbnumber"] = value
         elif key == "BoxOffice":
             result["boxoffice"] = value
         elif key == "DVD":
             date_time = arrow.get(value, "DD MMM YYYY")
             result["dvdrelease"] = date_time.format('YYYY-MM-DD')
             result["dvdrelease.formatted"] = date_time.format('DD MMM YYYY', locale=KODI_LANGUAGE)
         elif key == "Production":
             result["studio"] = value.split(", ")
         elif key == "Website":
             result["homepage"] = value
         # rotten tomatoes - will probably never work again (OMDBAPI doesnt't provide them anymore)
         elif key == "tomatoReviews":
             result["rottentomatoes.reviews"] = formatted_number(value)
         elif key == "tomatoConsensus":
             result["rottentomatoes.consensus"] = value
         elif key == "tomatoUserMeter":
             result["rottentomatoes.usermeter"] = value
         elif key == "tomatoUserRating":
             result["rottentomatoes.userrating"] = value
             result["rottentomatoes.userrating.percent"] = "%s" % (try_parse_int(float(value) * 10))
         elif key == "tomatoUserReviews":
             result["rottentomatoes.userreviews"] = int_with_commas(value)
         elif key == "tomatoURL":
             result["rottentomatoes.url"] = value
     return result
Exemple #19
0
    def __init__(self, parent=0, *args, **kwargs):
        super(DashbordViewWidget, self).__init__(parent=parent,
                                                 *args,
                                                 **kwargs)

        vbox = QtGui.QVBoxLayout()
        hbox = QtGui.QHBoxLayout()
        box_left = QtGui.QHBoxLayout()
        box_rigth = QtGui.QHBoxLayout()
        hbox_alert = QtGui.QVBoxLayout()

        box = QtGui.QListWidget()
        consuption = max_consumption()
        duration_cut = duration()
        avg_conso = average_consumption()
        num_days = estimated_duration()

        #All alerts
        if consuption:
            box.addItem(_(u"The increased consumption is %(conso)s"
                          u" cfa (%(date)s).")\
                          % {'conso': formatted_number(consuption[0]),
                          'date': consuption[1].strftime(u'%x')})
        if duration_cut:
            box.addItem(_(u"The biggest break is %(duration)s (%(date)s).")\
                                % {'duration': duration_cut[0],
                                   'date': duration_cut[1].strftime(u"%x")})
        if avg_conso:
            box.addItem(
                _(u"The average consumption is %(avg)s FCFA.") %
                {'avg': formatted_number(avg_conso)})
        if num_days:
            box.addItem(
                _(u"The end balance is estimated at %(num)s days.") %
                {'num': num_days})

        tablebox_balance = QtGui.QVBoxLayout()
        tablebox_consumption = QtGui.QVBoxLayout()

        # On recupere la derniere balance
        msg = _("Balance:  {} FCFA")
        balance = last_balance()
        balance = msg.format(0 if not balance else formatted_number(balance))

        self.title = PowerPageTitle(balance)
        self.title_alert = PowerPageTitle(_(u"Statistics"))
        self.title_box_balance = PowerBoxTitle(_(u"Table balances"))
        self.title_box_consumption = PowerBoxTitle(_(u"Table consumptions"))

        self.table_balance = BalanceTableWidget(parent=self)
        self.table_consumption = ConsumptionTableWidget(parent=self)

        # GRAPH
        jinja = Environment(loader=PackageLoader('power_m', 'templates'))
        template = jinja.get_template('chart.html')
        graph1 = template.render(base_url=BASE_URL,
                                 type="balance",
                                 data=balance_graph()[1],
                                 date=balance_graph()[0])
        graph2 = template.render(base_url=BASE_URL,
                                 type="consuption",
                                 data=consumption_graph()[1],
                                 date=consumption_graph()[0])

        label_b = QWebView()
        label_b.setHtml(graph1)
        box_left.addWidget(label_b)
        label_cons = QWebView()
        label_cons.setHtml(graph2)
        box_rigth.addWidget(label_cons)

        hbox_alert.addWidget(self.title_alert)
        hbox_alert.addWidget(box)

        #Combobox widget
        list_type = [_(u"Week"), _(u"Month")]
        self.box_type = QtGui.QComboBox()
        for index in list_type:
            self.box_type.addItem((u"%(type)s") % {"type": index})

        box_combo = QtGui.QHBoxLayout()
        box_combo.addWidget(self.box_type)
        box_combo.addSpacing(930)

        vbox.addWidget(self.title)
        vbox.addLayout(box_combo)
        tablebox_balance.addWidget(self.title_box_balance)
        tablebox_balance.addWidget(self.table_balance)
        tablebox_consumption.addWidget(self.title_box_consumption)
        tablebox_consumption.addWidget(self.table_consumption)
        tab_widget1 = tabbox(box_left, tablebox_balance)
        tab_widget2 = tabbox(box_rigth, tablebox_consumption)

        hbox.addWidget(tab_widget1)
        hbox.addWidget(tab_widget2)
        vbox.addLayout(hbox)
        vbox.addLayout(hbox_alert)

        self.setLayout(vbox)
Exemple #20
0
    def __init__(self, parent, *args, **kwargs):
        QtGui.QDialog.__init__(self, parent, *args, **kwargs)

        self.data = Operation.select().order_by("date_op")

        title = QtGui.QLabel()
        self.setWindowTitle(_(u"Delete an operation"))
        if self.data == []:
            title.setText(_(u"There is no operation removed for this account"))
            ok_butt = QtGui.QPushButton(_(u"OK"))
            ok_butt.clicked.connect(self.close)

            vbox = QtGui.QVBoxLayout()
            vbox.addWidget(title)
            vbox.addWidget(ok_butt)
            self.setLayout(vbox)
        else:
            title.setText(_(u"Select a statement has deleted"))
            title.setAlignment(QtCore.Qt.AlignHCenter)
            title_hbox = QtGui.QHBoxLayout()
            title_hbox.addWidget(title)

            #Combobox widget
            # self.box = QtGui.QComboBox()
            # for index in xrange(0, self.data.count()):
            #     op = self.data[index]
            #     sentence = _(u"%(date_op)s - %(type)s - " \
            #                  u"%(value)s/%(balance)s ")\
            #                  % {'date_op': op.date_op, \
            #                     'type': op.type, \
            #                     'value': op.value, \
            #                     'balance': formatted_number(op.balance)}
            #     self.box.addItem(sentence, QtCore.QVariant(op.id))
            self.box = QtGui.QComboBox()
            for index in self.data:
                op = index
                sentence = _(u"%(date_op)s - %(type)s - " \
                             u"%(value)s/%(balance)s ")\
                             % {'date_op': op.date_op, \
                                'type': op.type_, \
                                'value': op.value, \
                                'balance': formatted_number(op.balance)}
                self.box.addItem(sentence, QtCore.QVariant(op.id))

            combo_hbox = QtGui.QHBoxLayout()
            combo_hbox.addWidget(self.box)

            #delete and cancel hbox
            button_hbox = QtGui.QHBoxLayout()

            #Delete Button widget.
            delete_but = QtGui.QPushButton(_(u"Delete"))
            delete_but.clicked.connect(self.delete)
            #Cancel Button widget.
            cancel_but = QtGui.QPushButton(_(u"Cancel"))
            cancel_but.clicked.connect(self.cancel)

            button_hbox.addWidget(cancel_but)
            button_hbox.addWidget(delete_but)
            #Create the QVBoxLayout contenaire.
            vbox = QtGui.QVBoxLayout()
            vbox.addLayout(title_hbox)
            vbox.addLayout(combo_hbox)
            vbox.addLayout(button_hbox)
            self.setLayout(vbox)