Anonymous
Anonymous
Another idea would be to calculate the rankings on the fly by request, but this may cause heavy load, whenever too much requests are coming in.
Matthew
I think you can likely have only one set of tables, without any splitting by league etc. You can still precalculate your records using one set of tables
Jonah
@metaprogrammer good morning/evening
Jonah
I spent some time working with the semi-broken clipboard API to copy postgres and python code out of editor using selenium (you may have noticed all my logins 😜
Jonah
In any case to make basic export possible within the confines of selelnium headless given editors current configuration I think it's necessary to ask for one very small changer
Jonah
when "Copy All" is pressed - could you save the output to a hidden node's data attribute? <div id="python_code_node" bytes="import ponyorm..." />
Jonah
this way the code is accessible to selenium - otherwise I believe the clipboard API will cause much frustration across headless browsers
Jonah
you can read a bit about it here - navigator.clipboard.readText().then(clipText =>
document.getElementById("outbox").innerText = clipText);
Jonah
worthy to mention that I tried this solution and without success
Jonah
https://medium.com/@sahajamit/getting-clipboard-content-from-remote-selenium-chrome-nodes-67a4c4d862bd
Roman
Hi @minskmaz , Is there any issue with copying of visible block of code?
Jonah
yes - it's all nodes that I would have to parse through to make sense of - it's dom
Roman
all those nodes are for highlighting. If you remove html and concatenate the content you should get plain code. I wondering if huge hidden text can affect page performance.
Roman
In puppeteer you can listen to raw response (check get-code XHR)
https://stackoverflow.com/questions/45822058/puppeteer-how-to-listen-to-a-specific-response
Jonah
hm - well I could perhaps give a specific flag which if not present the write to the nodes wouldn't occur
Jonah
checking the link you sent now
Roman
It's only possible with puppeteer (maybe also with phantomjs) but not with selenium
Jonah
yes I could give an unsupprted (by ther server) flag in the url and ediutor js code could do the writes for the one instance
Jonah
https://editor.ponyorm.com/user/someuser/test/designer?client=selenium
Jonah
in the meantime I will look at the nodes and explior concat
Jonah
if you know how to do the concat would you mind giving an example? It looks like spaghetti to me
Roman
sure,
https://stackoverflow.com/questions/822452/strip-html-from-text-javascript
Jonah
thanks I'll patch this in and see if it work Roman
Roman
Good luck :)
Jonah
Roman I got it! Thank you for walking me through it buddy. I'll let you guys know when I have something to show.
Anonymous
How can I make Set optional?
Alexander
Set can be empty
Jim
They are since they can be empty
Anonymous
senpos
hey there
is https://editor.ponyorm.com/ site down?
Alexander
Hi, it works again
senpos
Awesome, thanks!
Anonymous
Hello. I have a problem with my code.
database.py:
from pony import orm
db = orm.Database()
class User(db.Entity):
f_id = orm.Required(int)
db.bind(provider='sqlite', filename=':memory:')
db.generate_mapping(create_tables=True)
bot.py:
from threading import Thread
class BotPollingThread(Thread):
def __init__(self, bot_handler) -> None:
super(BotPollingThread, self).__init__()
self.setDaemon(True)
def run(self) -> None:
with orm.db_session:
user = database.User.get(telegram_id=message.chat.id)
main.py (startpoint):
from bot import BotPollingThread
def main():
BotPollingThread.start()
if __name__ == '__main__':
main()
Anonymous
When thread starting, i get error:
pony.orm.dbapiprovider.OperationalError: no such table: User
Anonymous
But i binded database and made generate_mapping. What is my probem?
Alexander
In order to use database from multiple threads you need to store it in a file
Alexander
Replace filename=':memory:' to filename='db.sqlite'
Anonymous
Ok. I'll try. Thanks
Anonymous
Anonymous
Matthew
@metaprogrammer yes you have a HTTPS issue
Alexander
We'll be able to fix it a bit later
Anonymous
hi all
Anonymous
just getting started with pony ORM
Anonymous
I may have a quaetion..
Anonymous
how do you initialize db_session before running your unit tests with nose2 ?
Anonymous
I used to do this
with orm.db_session:
unittest.TextTestRunner(verbosity=2).run(suite)
Anonymous
however with nose2 i can only specify an entry point for my commands
Anonymous
I would prefere use nose2 than unittest directly
Alexander
Simplest way is to wrap your tests with db_session decorator
Alexander
The other way is
def setUp(self):
rollback()
db_session.__enter__()
def tearDown(self):
rollback()
db_session.__exit__()
Alexander
Or you can wrap test with a separate @db_session decorator
Anonymous
Ok thanks. I might go for the setUp solution as I don't want to wrp every single method
Anonymous
is rollback compulsory ?
Anonymous
do I need to import it to declare it inside my TestClass ?
Anonymous
Thanks!
Alexander
Rollback goal is to return database after test is finished to previous state, so all tests see the same database state
Anonymous
rollback seems to be called within the exit function already
Anonymous
so it might be redundant to call it before
Alexander
It called if there was some exception during the execution of db_session and we want to rollback unfinished transaction
But in case of tests you need to roll back all db_sessions, even successful ones
Anonymous
cheers guys anyway
Anonymous
you rock
Alexander
Or you need to recreate database state before each test
Anonymous
ok i'll give it a try:)
Jan
Hey I have a question about delete hooks. Assume I have a many to many relationship between a and b and I want a cascading deletion between them in the sense that if after a deletion of a any b that that has an empty a set should also be deleted. I wondered how to do that and stumbled upon deletion hooks. but when I try to delete the "to be orphaned" bs in a's before delete hook I get the exception that a is marked for deletion. I worked around this by manually deleting b afterwards but i would prefer something automatic. What's the best way to solve this in pony
Jan
I was doing:
def before_delete(self): # a's hook
delete(b for b in B if not b.a_set)
csa3d
Is there a way to disable cascade delete knowing it might possibly invalidate linkages?
Alexander
What do you mean?
csa3d
Say I have a table of enums
csa3d
And I drop one
csa3d
But that is referenced by another table
csa3d
Deleting an enum will kill all linked refs
csa3d
Which is probably good
csa3d
But I'm fighting this behavior and would prefer to orphan a reference
Alexander
I think you if declare entities as
class Enum(db.Entity):
objects = Set("Object")
class Object(db.Entity):
enum = Optional("Enum", cascade_delete=False)
it should works. Object.enum value will be set to None for deleted enums
csa3d
Ahh, let me try that! This seems like what I was missing
csa3d
So in this case, the use of Object.enum.Required will cause an exception, so use Optional even if required?
Alexander
How it required if you want to orphan a reference
csa3d
If I expect object to always have an Enum, but for some reason that Enum was deprecated..