Returns a random statement from the database.
(self)
| 426 | session.close() |
| 427 | |
| 428 | def get_random(self): |
| 429 | """ |
| 430 | Returns a random statement from the database. |
| 431 | """ |
| 432 | Statement = self.get_model('statement') |
| 433 | |
| 434 | session = self.Session() |
| 435 | try: |
| 436 | count = self.count() |
| 437 | if count < 1: |
| 438 | raise self.EmptyDatabaseException() |
| 439 | |
| 440 | random_index = random.randrange(0, count) |
| 441 | random_statement = session.query(Statement)[random_index] |
| 442 | |
| 443 | statement = self.model_to_object(random_statement) |
| 444 | |
| 445 | return statement |
| 446 | finally: |
| 447 | session.close() |
| 448 | |
| 449 | def drop(self): |
| 450 | """ |
nothing calls this directly
no test coverage detected