示例#1
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"))
示例#2
0
 def __init__(self, mem, only_system_products=False, parent=None):
     QWidget.__init__(self, parent)
     self.setupUi(self)
     self.mem = mem
     self.tblProducts.setSettings(self.mem.settings, "wdgProducts",
                                  "tblProducts")
     self.tblProducts.table.customContextMenuRequested.connect(
         self.on_tblProducts_customContextMenuRequested)
     if only_system_products == True:
         self.products = ProductManager(self.mem)
         self.products.load_from_db("select * from products order by name")
     else:
         self.products = ProductAllManager(self.mem)
     self.cmb.setCurrentIndex(
         int(self.mem.settings.value("wdgProducts/cmb", "0")))
     self.products.qtablewidget(self.tblProducts)
示例#3
0
 def __init__(self, mem, only_system_products=False, parent=None):
     QWidget.__init__(self, parent)
     self.setupUi(self)
     self.mem = mem
     self.tblProducts.settings(self.mem.settings, "wdgProducts",
                               "tblProducts")
     self.tblProducts.table.customContextMenuRequested.connect(
         self.on_tblProducts_customContextMenuRequested)
     self.tblProducts.table.itemSelectionChanged.connect(
         self.on_tblProducts_itemSelectionChanged)
     if only_system_products == True:
         self.products = ProductManager(self.mem)
         self.products.load_from_db("select * from products order by name")
         self.products.qtablewidget(self.products, self.tblProducts)
     else:
         self.products = ProductAllManager(self.mem)
         self.products.qtablewidget(self.tblProducts)
示例#4
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.sql_insert("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.sql_insert("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.sql_insert("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()