2.3.1.4. 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¶
- kind¶
- name¶
- nofeedback¶
- nopause¶
- peer_async_visible¶
- points¶
- questions¶
- released¶
- threshold_pct¶
- time_limit¶
- updated_date¶
- visible¶
- visible_on¶
- class db.models.AssignmentQuestion(**kwargs)¶
Bases:
Base,IdMixin- activities_required¶
- assignment_id¶
- async_mode¶
- 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.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(*, 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, id: Optional[int] = None)¶
Bases:
auth_user- model_config: ClassVar[ConfigDict] = {'from_attributes': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod username_clear_of_css_characters(v)¶
- 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¶
- cps¶
- edit_distance¶
- 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.CourseInstructor(**kwargs)¶
Bases:
Base,IdMixin- course¶
- id¶
- instructor¶
- paid¶
- verified¶
- 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¶
- domain_name¶
- downloads_enabled¶
- id¶
- institution¶
- is_supporter¶
- login_required¶
- new_server¶
- python3¶
- state¶
- student_price¶
- term_start_date¶
- timezone¶
- class db.models.DeadlineException(**kwargs)¶
Bases:
Base,IdMixin- allowLink¶
- assignment_id¶
- course_id¶
- duedate¶
- id¶
- sid¶
- time_limit¶
- visible¶
- class db.models.DictableMixin¶
Bases:
object- dict()¶
- from_dict(data: dict)¶
- update_from_dict(data: dict)¶
- class db.models.DragndropAnswers(**kwargs)¶
Bases:
Base,CorrectAnswerMixin- answer¶
- correct¶
- course_name¶
- div_id¶
- id¶
- min_height¶
- percent¶
- sid¶
- timestamp¶
- class db.models.EncryptedString(*args: Any, **kwargs: Any)¶
Bases:
TypeDecorator- impl¶
alias of
String
- process_bind_param(value, dialect)¶
Receive a bound parameter value to be converted.
Custom subclasses of
_types.TypeDecoratorshould 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
Dialectin 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.TypeDecoratorshould 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
Dialectin use.
See also
types_typedecorator
_types.TypeDecorator.process_bind_param()
- python_type¶
alias of
str
- 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.Installation(**kwargs)¶
Bases:
Base,IdMixin- base_courses¶
- course_count_bucket¶
- first_seen¶
- id¶
- instance_id¶
- institution¶
- last_seen¶
- region¶
- student_count_bucket¶
- version¶
- class db.models.InvoiceRequest(**kwargs)¶
Bases:
Base,IdMixin- amount¶
- course_name¶
- email¶
- id¶
- processed¶
- sid¶
- timestamp¶
- class db.models.Library(**kwargs)¶
Bases:
Base,IdMixin- authors¶
- basecourse¶
- build_system¶
- default_language¶
- description¶
- for_classes¶
- github_url¶
- id¶
- is_visible¶
- last_build¶
- last_deploy¶
- main_page¶
- postbuild_hook¶
- prebuild_hook¶
- repo_path¶
- shelf_section¶
- social_url¶
- source_path¶
- subtitle¶
- target¶
- title¶
- class db.models.LpAnswers(**kwargs)¶
Bases:
Base,AnswerMixin- answer¶
- correct¶
- course_name¶
- div_id¶
- id¶
- sid¶
- timestamp¶
- class db.models.Lti1p3Assignment(**kwargs)¶
Bases:
Base,IdMixin,DictableMixinRunestone to LMS assignment (“lineitem”) mapping. A RS assignment may be associated with multiple LTI assignments if there are multiple LMS courses attached to one RS course.
- id¶
- lti1p3_course¶
- lti1p3_course_id¶
- lti_lineitem_id¶
- rs_assignment¶
- rs_assignment_id¶
- class db.models.Lti1p3Conf(**kwargs)¶
Bases:
Base,IdMixin,DictableMixin” Configuration for an LTI 1.3 platform host. May be shared across multiple deployments.
- auth_login_url¶
- auth_token_url¶
- client_id¶
- id¶
- issuer¶
- key_set_url¶
- product_family_code¶
- token_audience¶
- version¶
- class db.models.Lti1p3Course(**kwargs)¶
Bases:
Base,IdMixin,DictableMixin” Data associating a use of a Runestone course with an LMS. Potentially many-to-one.
A single LMS course might be associated with multiple RS courses (to use multiple books in the course of a term).
A RS course should ONLY be associated with a single LMS course.
On a particular host (LMS) there may or may not be multiple deployments of a tool (Runestone) depending on the model the host is using: https://www.imsglobal.org/spec/lti/v1p3#tool-deployment
So, we are storing necessary deployment info for each course without trying to dedpulicate.
- course_name¶
- deployment_id¶
- id¶
- lineitems_url¶
- lti1p3_config_id¶
- lti1p3_course_id¶
- lti_config¶
- name_service_url¶
- rs_course¶
- rs_course_id¶
- class db.models.Lti1p3User(**kwargs)¶
Bases:
Base,IdMixin,DictableMixinRunestone to LTI 1.3 user mapping.
Although in general, a user in Runestone is likely to be associated with a single LTI user, it is possible that a user in Runestone (defined by institution email) is associated with multiple LTI users across multiple deployments.
So, each user mapping is associated with a particular lti1p3 course (RS<–>LMS mapping)
- id¶
- lti1p3_course_id¶
- lti_user_id¶
- rs_user¶
- rs_user_id¶
- class db.models.MatchingAnswers(**kwargs)¶
Bases:
Base,CorrectAnswerMixin- answer¶
- correct¶
- course_name¶
- div_id¶
- id¶
- percent¶
- sid¶
- timestamp¶
- 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.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¶
- owner¶
- pct_on_first¶
- practice¶
- qnumber¶
- question¶
- question_json¶
- question_type¶
- review_flag¶
- subchapter¶
- tags¶
- timestamp¶
- topic¶
- class db.models.QuestionGrade(**kwargs)¶
Bases:
Base,IdMixin- answer_id¶
- comment¶
- course_name¶
- deadline¶
- div_id¶
- id¶
- score¶
- sid¶
- class db.models.RunestoneComponentDict(model: 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¶
- filename¶
- id¶
- includes¶
- main_code¶
- owner¶
- suffix_code¶
- class db.models.SpliceAnswers(**kwargs)¶
Bases:
Base,CorrectAnswerMixin- answer¶
- correct¶
- course_name¶
- div_id¶
- id¶
- percent¶
- sid¶
- timestamp¶
- 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.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¶
- local_vars¶
- 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.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: Any, **kwargs: Any)¶
Bases:
TypeDecorator- cache_ok: Optional[bool] = True¶
Indicate if statements using this
ExternalTypeare “safe to cache”.The default value
Nonewill emit a warning and then not allow caching of a statement which includes this type. Set toFalseto disable statements using this type from being cached at all without a warning. When set toTrue, the object’s class and selected elements from its state will be used as part of the cache key. For example, using aTypeDecorator: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_okflag to allow some configurability of caching forTypeDecoratorclasses.New in version 1.4.28: - added the
ExternalTypemixin which generalizes thecache_okflag to both theTypeDecoratorandUserDefinedTypeclasses.See also
sql_caching
- copy(**kw)¶
Produce a copy of this
TypeDecoratorinstance.This is a shallow copy and is provided to fulfill part of the
TypeEnginecontract. It usually does not need to be overridden unless the user-definedTypeDecoratorhas local state that should be deep-copied.
- impl: Union[TypeEngine[Any], Type[TypeEngine[Any]]] = CHAR(length=1)¶
- process_bind_param(value, dialect)¶
Receive a bound parameter value to be converted.
Custom subclasses of
_types.TypeDecoratorshould 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
Dialectin 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.TypeDecoratorshould 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
Dialectin 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]¶