Пример #1
0
    def __init__(self, mem, parent = 0,  flags = False):
        QMainWindow.__init__(self, None)
        self.setupUi(self)
        self.showMaximized()
        
        self.mem=mem
        self.mem.con.inactivity_timeout.connect(self.inactivity_timeout)
        
        database_update(self.mem.con, "caloriestracker", __versiondatetime__, "Qt")
        
        self.w=QWidget()       
        self.statusBar.addWidget(QLabel(self.mem.con.url_string()))

        self.mem.load_db_data() ##CARGA TODOS LOS DATOS Y LOS VINCULA       
  
        if self.mem.con.is_superuser():
            self.setWindowTitle(self.tr("Calories Tracker 2019-{0} \xa9 (Admin mode)").format(__versiondatetime__.year))#print ("Xulpymoney 2010-{0} © €".encode('unicode-escape'))
            self.setWindowIcon(self.mem.qicon_admin())
        else:
            self.setWindowTitle(self.tr("Calories Tracker 2019-{0} \xa9").format(__versiondatetime__.year))
            
        self.lblUsers=QLabel()
        self.lblUsers.setText(self.tr("Select a user")+" ")
        self.tbUsers.addWidget(self.lblUsers)
        self.cmbUsers=QComboBox()
        self.tbUsers.addWidget(self.cmbUsers)
        self.mem.data.users.qcombobox(self.cmbUsers, self.mem.user, icons=True)
        self.cmbUsers.currentIndexChanged.connect(self.on_cmbUsers_currentIndexChanged)
        
        # Adds biometric data if empty
        if self.mem.user.last_biometrics.datetime==None:
            self.on_actionBiometricsAdd_triggered()
Пример #2
0
    def __init__(self, mem, parent=0, flags=False):
        QMainWindow.__init__(self, None)
        self.setupUi(self)
        self.showMaximized()

        self.mem = mem
        self.mem.insertProducts = ProductManager(self.mem)
        self.mem.updateProducts = ProductManager(self.mem)
        self.mem.deleteProducts = ProductManager(self.mem)
        self.mem.insertCompanies = CompanySystemManager(self.mem)
        self.mem.updateCompanies = CompanySystemManager(self.mem)
        self.mem.deleteCompanies = CompanySystemManager(self.mem)
        self.mem.insertFormats = FormatSystemManagerHeterogeneus(self.mem)
        self.mem.updateFormats = FormatSystemManagerHeterogeneus(self.mem)
        self.mem.deleteFormats = FormatSystemManagerHeterogeneus(self.mem)

        database_update(self.mem.con, "caloriestracker", __versiondatetime__,
                        "Qt")

        self.w = QWidget()
        self.statusBar.addWidget(QLabel(self.mem.con.url_string()))

        self.mem.load_db_data()  ##CARGA TODOS LOS DATOS Y LOS VINCULA

        self.setWindowTitle(
            self.tr(
                "Calories Tracker 2019-{0} (Product maintenance mode)").format(
                    __versiondatetime__.year)
        )  #print ("Xulpymoney 2010-{0} © €".encode('unicode-escape'))
        self.setWindowIcon(QIcon(":/caloriestracker/books.png"))
Пример #3
0
def on_database_created(connectionqt):
    from caloriestracker.database_update import database_update
    from caloriestracker.version import __versiondatetime__
    from caloriestracker.ui.myqwidgets import qmessagebox
    database_update(connectionqt, "caloriestracker", __versiondatetime__,
                    "Console")
    connectionqt.commit()
    qmessagebox(
        qApp.translate(
            "Mem",
            "Calories Tracker have been correctly installed. Please login again"
        ))
    exit(qApp.exec_())
Пример #4
0
    def run(self, args=None):   
        self.args=self.parser.parse_args(args)
        self.addDebugSystem(self.args.debug) #Must be before QCoreApplication
        #Changing types of args
        self.args.system=int(self.args.system)

        self.con=self.connection()
        if self.con.is_active()==False:
            exit(1)
        
        database_update(self.con, "caloriestracker", __versiondatetime__, "Console")
        
        self.load_db_data(False)

        self.user=self.data.users.find_by_id(1)
Пример #5
0
 def on_cmdCreate_released(self):
     if qmessagebox_question(
             self.tr("Do you want to create {} database in {}?".format(
                 self.txtDB.text(),
                 self.cmbLanguage.currentText()))) == True:
         admin = AdminPG(self.txtUser.text(), self.txtPass.text(),
                         self.txtServer.text(), self.txtPort.text())
         if admin.db_exists(self.txtDB.text()) == True:
             qmessagebox("Database already exists")
             return
         if admin.create_db(self.txtDB.text()) == True:
             newcon = admin.connect_to_database(self.txtDB.text())
             database_update(newcon, "caloriestracker", __versiondatetime__,
                             "Qt")
             qmessagebox(
                 self.
                 tr("Database created. Please run Calories Tracker and login"
                    ))
             logging.info("App correctly closed")
             self.close()
         else:
             logging.error("Something went wrong")
Пример #6
0
 def on_cmdCreate_released(self):
     respuesta = QMessageBox.warning(
         self, self.windowTitle(),
         self.tr("Do you want to create {} database in {}?".format(
             self.txtDB.text(), self.cmbLanguage.currentText())),
         QMessageBox.Ok | QMessageBox.Cancel)
     if respuesta == QMessageBox.Ok:
         admin = AdminPG(self.txtUser.text(), self.txtPass.text(),
                         self.txtServer.text(), self.txtPort.text())
         if admin.db_exists(self.txtDB.text()) == True:
             qmessagebox("Database already exists", self.mem.app_resouce())
             return
         if admin.create_db(self.txtDB.text()) == True:
             newcon = admin.connect_to_database(self.txtDB.text())
             database_update(newcon, "caloriestracker", __versiondatetime__,
                             "Qt")
             qmessagebox(
                 self.
                 tr("Database created. Please run Calories Tracker and login"
                    ), self.mem.app_resource())
             logging.info("App correctly closed")
             self.close()
         else:
             logging.error("Something went wrong")
Пример #7
0
def parse_contribution_dump_generate_files_and_validates_them(
        auxiliar_con, contribution_dump):
    ## 1. SETS A NEW DATABASE CALORIESTRACKER_CONTRIBUTION TO DEFAULT
    datestr = dtnaive2string(datetime.now(), "%Y%m%d%H%M")
    database = "caloriestracker_contribution"
    admin = AdminPG(auxiliar_con.user, auxiliar_con.password,
                    auxiliar_con.server, auxiliar_con.port)
    if admin.db_exists(database) == True:
        admin.drop_db(database)
    admin.create_db(database)
    newcon = admin.connect_to_database(database)
    database_update(newcon, "caloriestracker", __versiondatetime__, "Console")
    print("1. After setting database to default", *print_table_status(newcon))

    ## 2. ADDS CONTRIBUTOR PERSONAL DATA TO CALORIESTRACKER_CONTRIBUTION
    newcon.load_script(contribution_dump)
    newcon.commit()
    print("2. After loading personal data from collaborator",
          *print_table_status(newcon))

    ## 3. GENERATES SYSTEM.SQL FILE AND RETURN TO CONTRIBUTOR
    mem_temporary = MemInit(
    )  #It's an internal and temporaray Mem. Better to pass parameters
    mem_temporary.con = newcon
    mem_temporary.debuglevel = "DEBUG"
    if mem_temporary.con.is_active() == False:
        exit(1)
    mem_temporary.load_db_data(False)
    mem_temporary.user = mem_temporary.data.users.find_by_id(1)

    ## GENERATING XXXXXXXXXXXX.sql
    package_sql_filename = "XXXXXXXXXXXX.sql".format(datestr)
    package_sql = open(package_sql_filename, "w")
    package_sql.write("select;\n")  #For no personal data empty files

    companies_map = {}
    products_map = {}
    formats_map = {}

    #companies
    new_system_companies_id = mem_temporary.con.cursor_one_field(
        "select max(id)+1 from companies")
    new_system_companies = CompanySystemManager(mem_temporary)
    for company in mem_temporary.data.companies.arr:
        if company.system_company == False:
            question = input_YN(
                "Do you want to convert this company '{}' to a system one?".
                format(company), "Y")
            if question == True:
                system_company = CompanySystem(mem_temporary, company.name,
                                               company.last,
                                               new_system_companies_id)
                new_system_companies.append(system_company)
                companies_map[company.string_id()] = system_company.string_id()
                new_system_companies_id = new_system_companies_id + 1
                package_sql.write(
                    system_company.insert_string("companies") + ";\n")
                mem_temporary.data.companies.append(
                    system_company
                )  ##Appends new sistem company to mem_temporary.data
                #print ("Company will change from {} to {}".format(company.string_id(), system_company.string_id()))

    #products
    new_system_products_id = mem_temporary.con.cursor_one_field(
        "select max(id)+1 from products")
    new_system_products = ProductManager(mem_temporary)
    for product in mem_temporary.data.products.arr:
        if product.system_product == False:
            question = input_YN(
                "Do you want to convert this product '{}' to a system one?".
                format(product.fullName()), "Y")
            #Selects a company
            if product.company != None:
                if product.system_company == False:
                    company = mem_temporary.data.companies.find_by_id_system(
                        *CompanySystem.string_id2tuple(companies_map[
                            product.company.string_id()]))
                else:
                    company = product.company
                system_company = True
            else:
                company = None
                system_company = None
            #Create product
            if question == True:
                system_product = Product(
                    mem_temporary, product.name, product.amount, product.fat,
                    product.protein, product.carbohydrate, company,
                    product.last, product.elaboratedproducts_id,
                    product.languages, product.calories, product.salt,
                    product.cholesterol, product.sodium, product.potassium,
                    product.fiber, product.sugars, product.saturated_fat,
                    system_company, new_system_products_id)
                new_system_products.append(system_product)
                products_map[product.string_id()] = system_product.string_id()
                new_system_products_id = new_system_products_id + 1
                #print ("Product will change from {} to {}".format(product, system_product))
                #if company!=None:
                #    print ("Its company will change from {} to {}".format(product.company.string_id(), company.string_id()))
                package_sql.write(
                    system_product.insert_string("products") + ";\n")

    #formats
    new_system_formats_id = mem_temporary.con.cursor_one_field(
        "select max(id)+1 from formats")
    for product in mem_temporary.data.products.arr:
        if product.system_product == False:
            product.needStatus(1)
            if product.formats.length() == 0:
                continue
            for format in product.formats.arr:
                question = input_YN(
                    "Do you want to convert this format '{}' to a system one?".
                    format(format), "Y")
                if question == True:
                    system_product = new_system_products.find_by_string_id(
                        new_system_products,
                        products_map[format.product.string_id(
                        )])  #Recently created in systemproducts
                    system_format = Format(mem_temporary, format.name,
                                           system_product,
                                           system_product.system_product,
                                           format.amount, format.last,
                                           new_system_formats_id)
                    system_product.needStatus(1)  #Creates empty format manager
                    system_product.formats.append(system_format)
                    formats_map[format.string_id()] = system_format.string_id()
                    new_system_formats_id = new_system_formats_id + 1
                    package_sql.write(
                        system_format.insert_string("formats") + ";\n")
                    #print ("Format will change from {} to {}".format(format.string_id(), system_format.string_id()))

    package_sql.close()

    ## GENERATING COLLABORATION UPDATE FOR COLLABORATOR
    return_sql_filename = "XXXXXXXXXXXX_version_needed_update_first_in_github.sql"
    return_sql = open(return_sql_filename, "w")
    return_sql.write("select;\n")  #For no personal data empty files
    #COMPANIES
    for origin, destiny in companies_map.items():  #k,v strings_id
        origin_personal_company = mem_temporary.data.companies.find_by_string_id(
            origin)
        #destiny_system_company=new_system_companies.find_by_string_id(destiny)
        #Delete old personal companies
        return_sql.write("-- " + origin_personal_company.fullName() + "\n")
        return_sql.write("delete from personalcompanies where id=" +
                         str(origin_personal_company.id) + ";\n")
        return_sql.write("\n")

    #PRODUCTS
    for origin, destiny in products_map.items():
        origin_personal_product = ProductManager.find_by_string_id(
            mem_temporary.data.products, origin)
        destiny_system_product = ProductManager.find_by_string_id(
            new_system_products, destiny)
        #Delete old personal products
        return_sql.write("-- " + origin_personal_product.fullName() + "\n")
        return_sql.write(
            b2s(
                mem_temporary.con.mogrify(
                    "delete from personalproducts where id=%s;",
                    (origin_personal_product.id, ))) + "\n")
        #UPDATING PRODUCTS IN THE REST OF TABLES
        for table in ['formats', 'meals', 'products_in_elaboratedproducts']:
            return_sql.write(
                b2s(
                    mem_temporary.con.mogrify(
                        "update " + table +
                        " set products_id=%s, system_product=%s where products_id=%s and system_product=%s;",
                        (destiny_system_product.id,
                         destiny_system_product.system_product,
                         origin_personal_product.id,
                         origin_personal_product.system_product))) + "\n")
        #Formats
        for format in origin_personal_product.formats.arr:
            #Delete old personal formats
            return_sql.write("-- " + origin_personal_product.fullName() + "-" +
                             format.name + "\n")
            return_sql.write(
                b2s(
                    mem_temporary.con.mogrify(
                        "delete from personalformats where id=%s;",
                        (format.id, ))) + "\n")

        return_sql.write("\n")
    return_sql.close()
    print(
        "3. After generating files collaboration. Emulates launching update_table",
        *print_table_status(newcon))

    ## 5. GENERATES MEALS OF PERSONAL PRODUCTS FOR TESTING
    for origin, destiny in products_map.items():
        origin_personal_product = ProductManager.find_by_string_id(
            mem_temporary.data.products, origin)
        destiny_system_product = ProductManager.find_by_string_id(
            new_system_products, destiny)
        meal = Meal(mem_temporary, datetime.now(), origin_personal_product,
                    100, mem_temporary.user,
                    origin_personal_product.system_product, None)
        meal.save()

    ## 4. TRIES SYSTEM.SQL
    newcon.load_script("XXXXXXXXXXXX.sql")
    print("4. After trying XXXXXXXXXXXX.sql", *print_table_status(newcon))

    ## 5. TRIES CONTRIBUTOR SCRIPT
    newcon.load_script(
        "XXXXXXXXXXXX_version_needed_update_first_in_github.sql")
    print("5. After updating contributor database",
          *print_table_status(newcon))

    question = input_YN(
        "Do you want to add {}.sql to caloriestracker/sql/?".format(datestr),
        "?")
    if question == True:
        system(
            "mv XXXXXXXXXXXX.sql caloriestracker/sql/{}.sql".format(datestr))
        system(
            "mv XXXXXXXXXXXX_version_needed_update_first_in_github.sql {}_version_needed_update_first_in_github.sql"
            .format(datestr))

    newcon.commit()
    newcon.disconnect()