Skip to main content

Signals django not working on ubuntu server

I have a site on the server where I work with signals.py The problem is that when I add a db file through the admin panel signals.py does not work EXACTLY ON THE SERVER on my computer everything works fine But there is another model involving signals.py and it works great

models.py The model that works

class History(models.Model):
    tg_id = models.BigIntegerField(verbose_name='Telegram ID')
    amount = models.FloatField(verbose_name='Кол-во')
    date = models.DateTimeField(verbose_name='Дата транзакции')

Problem model

class database_sqlite3(models.Model):
    file = models.FileField(verbose_name='Файл', upload_to='db_file/',
                            help_text='Вы можете добавить сюда базу пользователей')

app.py

from django.apps import AppConfig


class MainConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'main'
    verbose_name = "Бот"
    def ready(self):
        import main.signals

signals.py The model that works

@receiver(post_save, sender=History)
def create_profile(sender, instance, created, **kwargs):
    if created:
        obj = User.objects.get(tg_id=int(instance.tg_id))
        wallet = obj.wallet
        if wallet == None:
            wallet = 0
        else:
            pass
        User.objects.filter(tg_id=instance.tg_id).update(wallet=wallet + instance.amount)0

Problem model

@receiver(post_save, sender=database_sqlite3)
def create_profile(sender, instance, created, **kwargs):
    if created:
        env = Env()
        env.read_env()
        gre = psycopg2.connect(
            database=env.str('POSTGRES_DB'),
            user=env.str('POSTGRES_USER'),
            password=env.str('POSTGRES_PASSWORD'),
            host=env.str('POSTGRES_HOST'),
            port=env.str('POSTGRES_PORT')
        )
        cur_gre = gre.cursor()
        conn = sqlite3.connect(str(instance.file))
        cursor = conn.cursor()
        table_names = cursor.execute("SELECT name FROM sqlite_master WHERE type='table';").fetchall()
        table_name = []
        for i in table_names:
            table_name.append(i[0])
        if 'main_admin_bot' in table_name:
            cursore = conn.execute(f"SELECT * FROM main_admin_bot").fetchall()
            for i in cursore:
                try:
                    sql = f'''INSERT INTO main_admin_bot ("tg_id","name") VALUES (%s,%s)'''
                    date = (i[1], i[2])
                    try:
                        try:
                            cur_gre.execute(sql, date)
                        except psycopg2.errors.InvalidTextRepresentation:
                            pass
                    except psycopg2.errors.InFailedSqlTransaction:
                        pass
                    gre.commit()
                except psycopg2.errors.UniqueViolation:
                    pass
        if 'main_attempts' in table_name:
            cursore = conn.execute(f"SELECT * FROM main_attempts").fetchall()
            for i in cursore:
                try:
                    sql = f'''INSERT INTO main_attempts ("ids","count") VALUES (%s,%s)'''
                    date = (i[1], i[2])
                    try:
                        try:
                            cur_gre.execute(sql, date)
                        except psycopg2.errors.InvalidTextRepresentation:
                            pass
                    except psycopg2.errors.InFailedSqlTransaction:
                        pass
                    gre.commit()
                except psycopg2.errors.UniqueViolation:
                    pass
        if 'main_blacklist' in table_name:
            cursore = conn.execute(f"SELECT * FROM main_blacklist").fetchall()
            for i in cursore:
                try:
                    sql = f'''INSERT INTO main_blacklist ("words","job") VALUES (%s,%s)'''
                    bools = None
                    if i[2] == 0:
                        bools = False
                    else:
                        bools = True
                    date = (i[1], bools)
                    try:
                        try:
                            cur_gre.execute(sql, date)
                        except psycopg2.errors.InvalidTextRepresentation:
                            pass
                    except psycopg2.errors.InFailedSqlTransaction:
                        pass
                    gre.commit()
                except psycopg2.errors.UniqueViolation:
                    pass
        if 'main_channel' in table_name:
            cursore = conn.execute(f"SELECT * FROM main_channel").fetchall()
            for i in cursore:
                try:
                    sql = f'''INSERT INTO main_channel ("channel_id","ids") VALUES (%s,%s)'''
                    date = (i[1], i[2])
                    try:
                        try:
                            cur_gre.execute(sql, date)
                        except psycopg2.errors.InvalidTextRepresentation:
                            pass
                    except psycopg2.errors.InFailedSqlTransaction:
                        pass
                    gre.commit()
                except psycopg2.errors.UniqueViolation:
                    pass

        if 'main_parse_user' in table_name:
            cursore = conn.execute(f"SELECT * FROM main_parse_user").fetchall()
            for i in cursore:
                sql = f'''INSERT INTO main_parse_user ("user_id","group_id", "username","bio", "first_name") VALUES (%s,%s,%s,%s,%s) ON CONFLICT (user_id) DO UPDATE SET (group_id,username,bio,first_name) = (EXCLUDED.group_id,EXCLUDED.username,coalesce(main_parse_user.bio, EXCLUDED.bio),EXCLUDED.first_name)'''
                date = (i[1], i[2], i[3], i[4], i[5])
                try:
                    try:
                        cur_gre.execute(sql, date)
                    except psycopg2.errors.InvalidTextRepresentation:
                        pass
                except psycopg2.errors.InFailedSqlTransaction:
                    pass
                gre.commit()
        if 'main_token' in table_name:
            cursore = conn.execute(f"SELECT * FROM main_token").fetchall()
            for i in cursore:
                try:
                    sql = f'''INSERT INTO main_token ("ids","bot_token") VALUES (%s,%s)'''
                    date = (i[1], i[2])
                    try:
                        try:
                            cur_gre.execute(sql, date)
                        except psycopg2.errors.InvalidTextRepresentation:
                            pass
                    except psycopg2.errors.InFailedSqlTransaction:
                        pass
                    gre.commit()
                except psycopg2.errors.UniqueViolation:
                    pass
        if 'main_trycountuser' in table_name:
            cursore = conn.execute(f"SELECT * FROM main_trycountuser").fetchall()
            for i in cursore:
                print(i)
                try:
                    sql = f'''INSERT INTO main_trycountuser ("ids","count") VALUES (%s,%s)'''
                    date = (int(i[1]), int(i[2]))
                    try:
                        try:
                            cur_gre.execute(sql, date)
                        except psycopg2.errors.InvalidTextRepresentation:
                            pass
                    except psycopg2.errors.InFailedSqlTransaction:
                        pass
                    gre.commit()
                except psycopg2.errors.UniqueViolation:
                    pass
        if 'main_user' in table_name:
            cursore = conn.execute(f"SELECT * FROM main_user").fetchall()
            for i in cursore:
                try:
                    sql = f'''INSERT INTO main_user ("tg_id" ,"username", "name" , "try_count", "activate","linkedin","language","wallet") VALUES (%s,%s,%s,%s,%s,%s,%s,%s)'''
                    bools = None
                    if i[5] == 0:
                        bools = False
                    else:
                        bools = True
                    date = (i[1], i[2], i[3], i[4], bools, i[6], i[7], i[8])
                    try:
                        try:
                            cur_gre.execute(sql, date)
                        except psycopg2.errors.InvalidTextRepresentation:
                            pass
                    except psycopg2.errors.InFailedSqlTransaction:
                        pass
                    gre.commit()
                except psycopg2.errors.UniqueViolation:
                    pass
        if 'main_users_db' in table_name:
            cursore = conn.execute("SELECT * FROM main_users_db").fetchall()
            for i in cursore:
                sqlz = f'''INSERT INTO main_parse_user ("user_id","group_id", "username","bio", "first_name") VALUES (%s,%s,%s,%s,%s) ON CONFLICT (user_id) DO UPDATE SET (group_id,username,bio,first_name) = (EXCLUDED.group_id,EXCLUDED.username,coalesce(main_parse_user.bio, EXCLUDED.bio),EXCLUDED.first_name)'''
                date = (i[0], i[4], i[1], str(i[2]), i[5])
                try:
                    try:
                        cur_gre.execute(sqlz, date)
                    except psycopg2.errors.InvalidTextRepresentation:
                        pass
                except psycopg2.errors.InFailedSqlTransaction:
                    pass
                gre.commit()

        if 'user_parse' in table_name:
            cursore = conn.execute("SELECT * FROM user_parse").fetchall()
            for i in cursore:
                sqlz = f'''INSERT INTO main_parse_user ("user_id","group_id", "username","bio", "first_name") VALUES (%s,%s,%s,%s,%s) ON CONFLICT (user_id) DO UPDATE SET (group_id,username,bio,first_name) = (EXCLUDED.group_id,EXCLUDED.username,coalesce(main_parse_user.bio, EXCLUDED.bio),EXCLUDED.first_name)'''
                date = (i[1], i[0], i[2], str(i[3]), i[4])
                try:
                    try:
                        cur_gre.execute(sqlz, date)
                    except psycopg2.errors.InvalidTextRepresentation:
                        pass
                except psycopg2.errors.InFailedSqlTransaction:
                    pass
                gre.commit()
        if 'main_parser' in table_name:
            cursor = conn.execute("SELECT * FROM main_parser").fetchall()
            for i in cursor:
                sql = f'''INSERT INTO main_parse_user ("user_id","group_id", "username","bio", "first_name") VALUES (%s,%s,%s,%s,%s) ON CONFLICT (user_id) DO UPDATE SET (group_id,username,bio,first_name) = (EXCLUDED.group_id,EXCLUDED.username,coalesce(main_parse_user.bio, EXCLUDED.bio),EXCLUDED.first_name)'''
                date = (i[1], i[2], i[3], i[4], i[5])
                try:
                    try:
                        cur_gre.execute(sql, date)
                    except psycopg2.errors.InvalidTextRepresentation:
                        pass
                except psycopg2.errors.InFailedSqlTransaction:
                    pass
                gre.commit()
        if 'bot_user' in table_name:
            cursor = conn.execute("SELECT * FROM bot_user").fetchall()
            for i in cursor:
                try:
                    sql = f'''INSERT INTO main_user ("tg_id", "username", "name", "try_count", "activate") VALUES (%s,%s,%s,%s,%s)'''
                    bools = None
                    if i[4] == 0:
                        bools = False
                    else:
                        bools = True
                    date = (i[0], i[1], i[2], i[3], bools)
                    try:
                        try:
                            cur_gre.execute(sql, date)
                        except psycopg2.errors.InvalidTextRepresentation:
                            pass
                    except psycopg2.errors.InFailedSqlTransaction:
                        pass
                    gre.commit()
                except psycopg2.errors.UniqueViolation:
                    pass

        if 'main_trypricetype' in table_name:
            cursor = conn.execute("SELECT * FROM main_trypricetype").fetchall()
            for i in cursor:
                try:
                    sql = f'''INSERT INTO "main_trypricetype" ("searchtype", "price") VALUES (%s,%s)'''
                    date = (i[1], i[2])
                    try:
                        try:
                            cur_gre.execute(sql, date)
                        except psycopg2.errors.InvalidTextRepresentation:
                            pass
                    except psycopg2.errors.InFailedSqlTransaction:
                        pass
                    gre.commit()
                except psycopg2.errors.UniqueViolation:
                    pass
        if 'main_database_sqlite3' in table_name:
            cursor = conn.execute("SELECT * FROM main_database_sqlite3").fetchall()
            for i in cursor:
                try:
                    sql = f'''INSERT INTO "main_database_sqlite3" ("file") VALUES (%s)'''
                    date = (i[1],)
                    try:
                        try:
                            cur_gre.execute(sql, date)
                        except psycopg2.errors.InvalidTextRepresentation:
                            pass
                    except psycopg2.errors.InFailedSqlTransaction:
                        pass
                    gre.commit()
                except psycopg2.errors.UniqueViolation:
                    pass
        if 'main_history' in table_name:
            cursor = conn.execute("SELECT * FROM main_history").fetchall()
            for i in cursor:
                try:
                    sql = f'''INSERT INTO "main_history" ("tg_id","amount","date") VALUES (%s,%s,%s)'''
                    date = (i[1], i[2], i[3])
                    try:
                        try:
                            cur_gre.execute(sql, date)
                        except psycopg2.errors.InvalidTextRepresentation:
                            pass
                    except psycopg2.errors.InFailedSqlTransaction:
                        pass
                    gre.commit()
                except psycopg2.errors.UniqueViolation:
                    pass
        if 'main_webapp' in table_name:
            cursor = conn.execute("SELECT * FROM main_webapp").fetchall()
            for i in cursor:
                try:
                    sql = f'''INSERT INTO "main_webapp" ("id","image","url","name","text") VALUES (%s,%s,%s,%s,%s)'''
                    date = (i[0], i[1], i[2], i[3], i[4])
                    try:
                        try:
                            cur_gre.execute(sql, date)
                        except psycopg2.errors.InvalidTextRepresentation:
                            pass
                    except psycopg2.errors.InFailedSqlTransaction:
                        pass
                    gre.commit()
                except psycopg2.errors.UniqueViolation:
                    pass
        conn.close()
        os.remove(str(instance.file))

I added to the app/init.py file but nothing worked



source https://stackoverflow.com/questions/74855140/signals-django-not-working-on-ubuntu-server

Comments

Popular posts from this blog

ValueError: X has 10 features, but LinearRegression is expecting 1 features as input

So, I am trying to predict the model but its throwing error like it has 10 features but it expacts only 1. So I am confused can anyone help me with it? more importantly its not working for me when my friend runs it. It works perfectly fine dose anyone know the reason about it? cv = KFold(n_splits = 10) all_loss = [] for i in range(9): # 1st for loop over polynomial orders poly_order = i X_train = make_polynomial(x, poly_order) loss_at_order = [] # initiate a set to collect loss for CV for train_index, test_index in cv.split(X_train): print('TRAIN:', train_index, 'TEST:', test_index) X_train_cv, X_test_cv = X_train[train_index], X_test[test_index] t_train_cv, t_test_cv = t[train_index], t[test_index] reg.fit(X_train_cv, t_train_cv) loss_at_order.append(np.mean((t_test_cv - reg.predict(X_test_cv))**2)) # collect loss at fold all_loss.append(np.mean(loss_at_order)) # collect loss at order plt.plot(np.log(al...

Sorting large arrays of big numeric stings

I was solving bigSorting() problem from hackerrank: Consider an array of numeric strings where each string is a positive number with anywhere from to digits. Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array. I know it works as follows: def bigSorting(unsorted): return sorted(unsorted, key=int) But I didnt guess this approach earlier. Initially I tried below: def bigSorting(unsorted): int_unsorted = [int(i) for i in unsorted] int_sorted = sorted(int_unsorted) return [str(i) for i in int_sorted] However, for some of the test cases, it was showing time limit exceeded. Why is it so? PS: I dont know exactly what those test cases were as hacker rank does not reveal all test cases. source https://stackoverflow.com/questions/73007397/sorting-large-arrays-of-big-numeric-stings

How to load Javascript with imported modules?

I am trying to import modules from tensorflowjs, and below is my code. test.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title </head> <body> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script> <script type="module" src="./test.js"></script> </body> </html> test.js import * as tf from "./node_modules/@tensorflow/tfjs"; import {loadGraphModel} from "./node_modules/@tensorflow/tfjs-converter"; const MODEL_URL = './model.json'; const model = await loadGraphModel(MODEL_URL); const cat = document.getElementById('cat'); model.execute(tf.browser.fromPixels(cat)); Besides, I run the server using python -m http.server in my command prompt(Windows 10), and this is the error prompt in the console log of my browser: Failed to loa...