use sqlalchemy.sql.expression.text
This commit is contained in:
parent
386284693d
commit
805486e8fc
2 changed files with 10 additions and 6 deletions
|
@ -6,6 +6,7 @@ from datetime import datetime
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.sql.expression import text
|
||||||
|
|
||||||
from utils import datetime2ts, ts2datetime
|
from utils import datetime2ts, ts2datetime
|
||||||
from websocket import trigger_event
|
from websocket import trigger_event
|
||||||
|
@ -125,13 +126,13 @@ class Changelog(db.Model):
|
||||||
break
|
break
|
||||||
return False
|
return False
|
||||||
if trigger:
|
if trigger:
|
||||||
trigger_event('change', {});
|
trigger_event('change', {})
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def apply_change(cls, user, change, trigger=True):
|
def apply_change(cls, user, change, trigger=True):
|
||||||
revision, timestamp, data = change
|
revision, timestamp, data = change
|
||||||
last = cls.query.filter_by(user_id=user.id).order_by('-revision').first()
|
last = cls.query.filter_by(user_id=user.id).order_by(text('-revision')).first()
|
||||||
next_revision = last.revision + 1 if last else 0
|
next_revision = last.revision + 1 if last else 0
|
||||||
if revision >= next_revision:
|
if revision >= next_revision:
|
||||||
c = cls()
|
c = cls()
|
||||||
|
@ -146,7 +147,7 @@ class Changelog(db.Model):
|
||||||
state.db.session.add(c)
|
state.db.session.add(c)
|
||||||
state.db.session.commit()
|
state.db.session.commit()
|
||||||
if trigger:
|
if trigger:
|
||||||
trigger_event('change', {});
|
trigger_event('change', {})
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logger.debug('could not apply change')
|
logger.debug('could not apply change')
|
||||||
|
|
|
@ -7,7 +7,9 @@ import json
|
||||||
import os
|
import os
|
||||||
import tarfile
|
import tarfile
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import urllib.request, urllib.error, urllib.parse
|
import urllib.request
|
||||||
|
import urllib.error
|
||||||
|
import urllib.parse
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
@ -16,6 +18,7 @@ import time
|
||||||
import OpenSSL.crypto
|
import OpenSSL.crypto
|
||||||
import ox
|
import ox
|
||||||
from oxtornado import actions
|
from oxtornado import actions
|
||||||
|
from sqlalchemy.sql.expression import text
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
import utils
|
import utils
|
||||||
|
@ -27,7 +30,7 @@ import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
ENCODING='base64'
|
ENCODING = 'base64'
|
||||||
|
|
||||||
def verify(release):
|
def verify(release):
|
||||||
verified = False
|
verified = False
|
||||||
|
@ -541,7 +544,7 @@ def migrate_11():
|
||||||
import utils
|
import utils
|
||||||
for u in User.query.filter_by(peered=True):
|
for u in User.query.filter_by(peered=True):
|
||||||
peer = utils.get_peer(u.id)
|
peer = utils.get_peer(u.id)
|
||||||
last = Changelog.query.filter_by(user_id=u.id).order_by('-revision').first()
|
last = Changelog.query.filter_by(user_id=u.id).order_by(text('-revision')).first()
|
||||||
if last:
|
if last:
|
||||||
peer.info['revision'] = last.revision
|
peer.info['revision'] = last.revision
|
||||||
listorder = []
|
listorder = []
|
||||||
|
|
Loading…
Reference in a new issue