Skip to content

Commit

Permalink
Update import statements
Browse files Browse the repository at this point in the history
  • Loading branch information
greyli committed Sep 8, 2024
1 parent 5cd21c9 commit 45ba82d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
4 changes: 1 addition & 3 deletions moments/core/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from moments.core.extensions import db
from moments.models import Role
from moments.lorem import fake_admin, fake_collect, fake_comment, fake_follow, fake_photo, fake_tag, fake_user


def register_commands(app):
Expand Down Expand Up @@ -34,9 +35,6 @@ def init_app_command():
@click.option('--comment', default=100, help='Quantity of comments, default is 100.')
def lorem_command(user, follow, photo, tag, collect, comment):
"""Generate fake data."""

from moments.lorem import fake_admin, fake_collect, fake_comment, fake_follow, fake_photo, fake_tag, fake_user

db.drop_all()
db.create_all()

Expand Down
22 changes: 11 additions & 11 deletions moments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@
from moments.core.extensions import db, whooshee


# enbale foreign key support for SQLite
@event.listens_for(engine.Engine, 'connect')
def set_sqlite_pragma(dbapi_connection, connection_record):
import sqlite3

if isinstance(dbapi_connection, sqlite3.Connection):
cursor = dbapi_connection.cursor()
cursor.execute('PRAGMA foreign_keys=ON')
cursor.close()


role_permission = db.Table(
'role_permission',
Column('role_id', ForeignKey('role.id', ondelete='CASCADE'), primary_key=True),
Expand Down Expand Up @@ -374,6 +363,17 @@ def __repr__(self):
return f'Notification {self.id}: {self.message}'


# enbale foreign key support for SQLite
@event.listens_for(engine.Engine, 'connect')
def set_sqlite_pragma(dbapi_connection, connection_record):
import sqlite3

if isinstance(dbapi_connection, sqlite3.Connection):
cursor = dbapi_connection.cursor()
cursor.execute('PRAGMA foreign_keys=ON')
cursor.close()


@event.listens_for(User, 'after_delete', named=True)
def delete_avatars(**kwargs):
target = kwargs['target']
Expand Down
28 changes: 7 additions & 21 deletions moments/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ document.addEventListener('DOMContentLoaded', () => {
.then(data => {
elem.textContent = data.count;
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

function updateCollectorsCount(id) {
Expand All @@ -95,9 +93,7 @@ document.addEventListener('DOMContentLoaded', () => {
.then(data => {
elem.textContent = data.count;
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

function updateNotificationsCount() {
Expand All @@ -115,9 +111,7 @@ document.addEventListener('DOMContentLoaded', () => {
elem.textContent = data.count;
}
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

function follow(event) {
Expand All @@ -136,9 +130,7 @@ document.addEventListener('DOMContentLoaded', () => {
updateFollowersCount(id);
toast(data.message);
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

function unfollow(event) {
Expand All @@ -157,9 +149,7 @@ document.addEventListener('DOMContentLoaded', () => {
updateFollowersCount(id);
toast(data.message);
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

function collect(event) {
Expand All @@ -181,9 +171,7 @@ document.addEventListener('DOMContentLoaded', () => {
updateCollectorsCount(id);
toast(data.message);
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

function uncollect(event) {
Expand All @@ -205,9 +193,7 @@ document.addEventListener('DOMContentLoaded', () => {
updateCollectorsCount(id);
toast(data.message);
})
.catch(error => {
handleFetchError(error);
});
.catch(handleFetchError);
}

dayjs.extend(window.dayjs_plugin_relativeTime)
Expand Down

0 comments on commit 45ba82d

Please sign in to comment.