db.models module

class db.models.AnswerMixin

Bases: IdMixin

course_name = Column(None, String(length=512), ForeignKey('courses.course_name'), table=None, nullable=False)
div_id = Column(None, String(length=512), table=None, nullable=False)
sid = Column(None, String(length=512), table=None, nullable=False)
timestamp = Column(None, DateTime(), table=None, nullable=False)
to_dict()
class db.models.Assignment(**kwargs)

Bases: Base, IdMixin

allow_self_autograde
course
current_index
description
duedate
enforce_due
from_source
id
is_peer
is_timed
name
nofeedback
nopause
peer_async_visible
points
released
threshold_pct
time_limit
visible
class db.models.AssignmentQuestion(**kwargs)

Bases: Base, IdMixin

activities_required
assignment_id
autograde
id
points
question_id
reading_assignment
sorting_priority
timed
which_to_grade
class db.models.AuthEvent(**kwargs)

Bases: Base, IdMixin

client_ip
description
id
origin
time_stamp
user_id
class db.models.AuthGroup(**kwargs)

Bases: Base, IdMixin

description
id
role
class db.models.AuthMembership(**kwargs)

Bases: Base, IdMixin

group_id
id
user_id
class db.models.AuthUser(**kwargs)

Bases: Base, IdMixin

accept_tcp
active
course_id
course_name
created_on
donated
email
first_name
id
last_name
modified_on
password
registration_id
registration_key
reset_password_key
username
class db.models.AuthUserValidator(*, id: Optional[int] = None, username: str, first_name: str, last_name: str, email: str, password: str, created_on: datetime, modified_on: datetime, registration_key: str, reset_password_key: str, registration_id: str, course_id: int, course_name: str, active: bool, donated: bool, accept_tcp: bool)

Bases: auth_user

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'accept_tcp': FieldInfo(annotation=bool, required=True), 'active': FieldInfo(annotation=bool, required=True), 'course_id': FieldInfo(annotation=int, required=True), 'course_name': FieldInfo(annotation=str, required=True, metadata=[StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=512, pattern=None)]), 'created_on': FieldInfo(annotation=datetime, required=True), 'donated': FieldInfo(annotation=bool, required=True), 'email': FieldInfo(annotation=str, required=True, metadata=[StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=512, pattern=None)]), 'first_name': FieldInfo(annotation=str, required=True, metadata=[StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=512, pattern=None)]), 'id': FieldInfo(annotation=Union[int, NoneType], required=False), 'last_name': FieldInfo(annotation=str, required=True, metadata=[StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=512, pattern=None)]), 'modified_on': FieldInfo(annotation=datetime, required=True), 'password': FieldInfo(annotation=str, required=True, metadata=[StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=512, pattern=None)]), 'registration_id': FieldInfo(annotation=str, required=True, metadata=[StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=512, pattern=None)]), 'registration_key': FieldInfo(annotation=str, required=True, metadata=[StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=512, pattern=None)]), 'reset_password_key': FieldInfo(annotation=str, required=True, metadata=[StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=512, pattern=None)]), 'username': FieldInfo(annotation=str, required=True, metadata=[StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=512, pattern=None)])}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

classmethod username_clear_of_css_characters(v)
class db.models.BookAuthor(**kwargs)

Bases: Base

author
book
class db.models.Chapter(**kwargs)

Bases: Base, IdMixin

chapter_label
chapter_name
chapter_num
course_id
id
class db.models.ClickableareaAnswers(**kwargs)

Bases: Base, CorrectAnswerMixin

answer
correct
course_name
div_id
id
percent
sid
timestamp
class db.models.Code(**kwargs)

Bases: Base, IdMixin

acid
code
comment
course_id
emessage
id
language
sid
timestamp
class db.models.CodelensAnswers(**kwargs)

Bases: Base, CorrectAnswerMixin

answer
correct
course_name
div_id
id
percent
sid
source
timestamp
class db.models.Competency(**kwargs)

Bases: Base, IdMixin

competency
id
is_primary
question
question_name
class db.models.CorrectAnswerMixin

Bases: AnswerMixin

correct = Column(None, Web2PyBoolean(length=1), table=None, nullable=False)
percent = Column(None, Float(), table=None)
class db.models.CourseAttribute(**kwargs)

Bases: Base, IdMixin

attr
course_id
id
value
class db.models.CourseInstructor(**kwargs)

Bases: Base, IdMixin

course
id
instructor
paid
verified
class db.models.CourseLtiMap(**kwargs)

Bases: Base, IdMixin

course_id
id
lti_id
class db.models.CoursePractice(**kwargs)

Bases: Base, IdMixin

auth_user_id
course_name
day_points
end_date
flashcard_creation_method
graded
id
interleaving
max_practice_days
max_practice_questions
question_points
questions_to_complete_day
spacing
start_date
class db.models.Courses(**kwargs)

Bases: Base, IdMixin

allow_pairs
base_course
course_name
courselevel
downloads_enabled
id
institution
is_supporter
login_required
new_server
python3
student_price
term_start_date
class db.models.DragndropAnswers(**kwargs)

Bases: Base, CorrectAnswerMixin

answer
correct
course_name
div_id
id
min_height
percent
sid
timestamp
class db.models.EditorBasecourse(**kwargs)

Bases: Base, IdMixin

base_course
editor
id
class db.models.FitbAnswers(**kwargs)

Bases: Base, CorrectAnswerMixin

answer
correct
course_name
div_id
id
percent
sid
timestamp
class db.models.Grade(**kwargs)

Bases: Base, IdMixin

assignment
auth_user
id
is_submit
lis_outcome_url
lis_result_sourcedid
manual_total
score
class db.models.IdMixin

Bases: object

id = Column(None, Integer(), table=None, primary_key=True, nullable=False)
class db.models.InvoiceRequest(**kwargs)

Bases: Base, IdMixin

course_name
email
id
processed
sid
timestamp
class db.models.Library(**kwargs)

Bases: Base, IdMixin

authors
basecourse
build_system
description
for_classes
github_url
id
is_visible
last_build
main_page
shelf_section
social_url
subtitle
title
class db.models.LpAnswers(**kwargs)

Bases: Base, AnswerMixin

answer
correct
course_name
div_id
id
sid
timestamp
class db.models.LtiKey(**kwargs)

Bases: Base, IdMixin

application
consumer
id
secret
class db.models.MchoiceAnswers(**kwargs)

Bases: Base, CorrectAnswerMixin

answer
correct
course_name
div_id
id
percent
sid
timestamp
class db.models.MicroParsonsAnswers(**kwargs)

Bases: Base, CorrectAnswerMixin

answer
correct
course_name
div_id
id
percent
sid
timestamp
class db.models.ParsonsAnswers(**kwargs)

Bases: Base, CorrectAnswerMixin

answer
correct
course_name
div_id
id
percent
sid
source
timestamp
class db.models.Payment(**kwargs)

Bases: Base, IdMixin

charge_id
id
user_courses_id
class db.models.PracticeGrade(**kwargs)

Bases: Base, IdMixin

auth_user
course_name
id
lis_outcome_url
lis_result_sourcedid
score
class db.models.Question(**kwargs)

Bases: Base, IdMixin

author
autograde
base_course
chapter
description
difficulty
feedback
from_source
htmlsrc
id
is_private
mean_clicks_to_correct
name
optional
pct_on_first
practice
qnumber
question
question_type
review_flag
subchapter
timestamp
topic
class db.models.QuestionGrade(**kwargs)

Bases: Base, IdMixin

answer_id
comment
course_name
deadline
div_id
id
score
sid
class db.models.QuestionTag(**kwargs)

Bases: Base, IdMixin

id
question_id
tag_id
class db.models.RunestoneComponentDict(model: Type[Base], validator: Type[BaseModelNone])

Bases: object

class db.models.SelectedQuestion(**kwargs)

Bases: Base, IdMixin

competency
id
points
selected_id
selector_id
sid
class db.models.ShortanswerAnswers(**kwargs)

Bases: Base, AnswerMixin

answer
course_name
div_id
id
sid
timestamp
class db.models.SourceCode(**kwargs)

Bases: Base, IdMixin

acid
available_files
course_id
id
includes
main_code
suffix_code
class db.models.SubChapter(**kwargs)

Bases: Base, IdMixin

chapter_id
id
skipreading
sub_chapter_label
sub_chapter_name
sub_chapter_num
class db.models.SubChapterTaught(**kwargs)

Bases: Base, IdMixin

chapter_label
course_name
id
sub_chapter_label
teaching_date
class db.models.Tag(**kwargs)

Bases: Base, IdMixin

id
tag_name
class db.models.TimedExam(**kwargs)

Bases: Base, AnswerMixin

correct
course_name
div_id
id
incorrect
reset
sid
skipped
time_taken
timestamp
class db.models.TraceBack(**kwargs)

Bases: Base, IdMixin

err_message
hash
hostname
id
path
post_body
query_string
timestamp
traceback
class db.models.UnittestAnswers(**kwargs)

Bases: Base, CorrectAnswerMixin

answer
correct
course_name
div_id
failed
id
passed
percent
sid
timestamp
class db.models.Useinfo(**kwargs)

Bases: Base, IdMixin

act
course_id
div_id
event
id
sid
timestamp
class db.models.UserChapterProgress(**kwargs)

Bases: Base, IdMixin

chapter_id
end_date
id
start_date
status
user_id
class db.models.UserCourse(**kwargs)

Bases: Base, IdMixin

course_id
id
user_id
class db.models.UserExperiment(**kwargs)

Bases: Base, IdMixin

exp_group
experiment_id
id
sid
class db.models.UserState(**kwargs)

Bases: Base, IdMixin

course_name
id
last_page_accessed_on
last_page_chapter
last_page_hash
last_page_scroll_location
last_page_subchapter
last_page_url
user_id
class db.models.UserSubChapterProgress(**kwargs)

Bases: Base, IdMixin

chapter_id
course_name
end_date
id
start_date
status
sub_chapter_id
user_id
class db.models.UserTopicPractice(**kwargs)

Bases: Base, IdMixin

chapter_label
course_name
creation_time
e_factor
i_interval
id
last_completed
last_presented
next_eligible_date
q
question_name
sub_chapter_label
timezoneoffset
user_id
class db.models.UserTopicPracticeCompletion(**kwargs)

Bases: Base, IdMixin

course_name
id
practice_completion_date
user_id
class db.models.UserTopicPracticeFeedback(**kwargs)

Bases: Base, IdMixin

course_name
feedback
id
response_time
timezoneoffset
user_id
class db.models.UserTopicPracticeLog(**kwargs)

Bases: Base, IdMixin

available_flashcards
chapter_label
course_name
e_factor
end_practice
i_interval
id
next_eligible_date
q
question_name
start_practice
sub_chapter_label
timezoneoffset
trials_num
user_id
class db.models.UserTopicPracticeSurvey(**kwargs)

Bases: Base, IdMixin

course_name
id
like_practice
response_time
timezoneoffset
user_id
class db.models.Web2PyBoolean(*args, **kwargs)

Bases: TypeDecorator

cache_ok = True

Indicate if statements using this ExternalType are “safe to cache”.

The default value None will emit a warning and then not allow caching of a statement which includes this type. Set to False to disable statements using this type from being cached at all without a warning. When set to True, the object’s class and selected elements from its state will be used as part of the cache key. For example, using a TypeDecorator:

class MyType(TypeDecorator):
    impl = String

    cache_ok = True

    def __init__(self, choices):
        self.choices = tuple(choices)
        self.internal_only = True

The cache key for the above type would be equivalent to:

>>> MyType(["a", "b", "c"])._static_cache_key
(<class '__main__.MyType'>, ('choices', ('a', 'b', 'c')))

The caching scheme will extract attributes from the type that correspond to the names of parameters in the __init__() method. Above, the “choices” attribute becomes part of the cache key but “internal_only” does not, because there is no parameter named “internal_only”.

The requirements for cacheable elements is that they are hashable and also that they indicate the same SQL rendered for expressions using this type every time for a given cache value.

To accommodate for datatypes that refer to unhashable structures such as dictionaries, sets and lists, these objects can be made “cacheable” by assigning hashable structures to the attributes whose names correspond with the names of the arguments. For example, a datatype which accepts a dictionary of lookup values may publish this as a sorted series of tuples. Given a previously un-cacheable type as:

class LookupType(UserDefinedType):
    '''a custom type that accepts a dictionary as a parameter.

    this is the non-cacheable version, as "self.lookup" is not
    hashable.

    '''

    def __init__(self, lookup):
        self.lookup = lookup

    def get_col_spec(self, **kw):
        return "VARCHAR(255)"

    def bind_processor(self, dialect):
        # ...  works with "self.lookup" ...

Where “lookup” is a dictionary. The type will not be able to generate a cache key:

>>> type_ = LookupType({"a": 10, "b": 20})
>>> type_._static_cache_key
<stdin>:1: SAWarning: UserDefinedType LookupType({'a': 10, 'b': 20}) will not
produce a cache key because the ``cache_ok`` flag is not set to True.
Set this flag to True if this type object's state is safe to use
in a cache key, or False to disable this warning.
symbol('no_cache')

If we did set up such a cache key, it wouldn’t be usable. We would get a tuple structure that contains a dictionary inside of it, which cannot itself be used as a key in a “cache dictionary” such as SQLAlchemy’s statement cache, since Python dictionaries aren’t hashable:

>>> # set cache_ok = True
>>> type_.cache_ok = True

>>> # this is the cache key it would generate
>>> key = type_._static_cache_key
>>> key
(<class '__main__.LookupType'>, ('lookup', {'a': 10, 'b': 20}))

>>> # however this key is not hashable, will fail when used with
>>> # SQLAlchemy statement cache
>>> some_cache = {key: "some sql value"}
Traceback (most recent call last): File "<stdin>", line 1,
in <module> TypeError: unhashable type: 'dict'

The type may be made cacheable by assigning a sorted tuple of tuples to the “.lookup” attribute:

class LookupType(UserDefinedType):
    '''a custom type that accepts a dictionary as a parameter.

    The dictionary is stored both as itself in a private variable,
    and published in a public variable as a sorted tuple of tuples,
    which is hashable and will also return the same value for any
    two equivalent dictionaries.  Note it assumes the keys and
    values of the dictionary are themselves hashable.

    '''

    cache_ok = True

    def __init__(self, lookup):
        self._lookup = lookup

        # assume keys/values of "lookup" are hashable; otherwise
        # they would also need to be converted in some way here
        self.lookup = tuple(
            (key, lookup[key]) for key in sorted(lookup)
        )

    def get_col_spec(self, **kw):
        return "VARCHAR(255)"

    def bind_processor(self, dialect):
        # ...  works with "self._lookup" ...

Where above, the cache key for LookupType({"a": 10, "b": 20}) will be:

>>> LookupType({"a": 10, "b": 20})._static_cache_key
(<class '__main__.LookupType'>, ('lookup', (('a', 10), ('b', 20))))

New in version 1.4.14: - added the cache_ok flag to allow some configurability of caching for TypeDecorator classes.

New in version 1.4.28: - added the ExternalType mixin which generalizes the cache_ok flag to both the TypeDecorator and UserDefinedType classes.

See also

sql_caching

copy(**kw)

Produce a copy of this TypeDecorator instance.

This is a shallow copy and is provided to fulfill part of the TypeEngine contract. It usually does not need to be overridden unless the user-defined TypeDecorator has local state that should be deep-copied.

impl = CHAR(length=1)
process_bind_param(value, dialect)

Receive a bound parameter value to be converted.

Custom subclasses of _types.TypeDecorator should override this method to provide custom behaviors for incoming data values. This method is called at statement execution time and is passed the literal Python data value which is to be associated with a bound parameter in the statement.

The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.

Parameters:
  • value – Data to operate upon, of any type expected by this method in the subclass. Can be None.

  • dialect – the Dialect in use.

See also

types_typedecorator

_types.TypeDecorator.process_result_value()

process_result_value(value, dialect)

Receive a result-row column value to be converted.

Custom subclasses of _types.TypeDecorator should override this method to provide custom behaviors for data values being received in result rows coming from the database. This method is called at result fetching time and is passed the literal Python data value that’s extracted from a database result row.

The operation could be anything desired to perform custom behavior, such as transforming or deserializing data.

Parameters:
  • value – Data to operate upon, of any type expected by this method in the subclass. Can be None.

  • dialect – the Dialect in use.

See also

types_typedecorator

_types.TypeDecorator.process_bind_param()

python_type

alias of bool

class db.models.Web2pySessionRunestone(**kwargs)

Bases: Base, IdMixin

client_ip
created_datetime
id
locked
modified_datetime
session_data
unique_key
class db.models.WebWorkAnswers(**kwargs)

Bases: Base, CorrectAnswerMixin

answer
correct
course_name
div_id
id
percent
sid
timestamp
db.models.register_answer_table(sql_alchemy_cls: Type[Base]) Type[Base]