Coverage for marvin.models : 97%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" marvin.models ~~~~~~~~~~~~~
Here we define the models we use in marvin. If this module grows too large, make it a package and split it up into smaller pieces.
"""
""" Movies are the first thing the user will search for.
Through a movie the user can find streams related to this movie. Most metadata should be fetched automatically from IMDb/TMDB. """
#: Identifies the movie uniquely. Do not make assumptions about the nature of this field #: as it might change without notice. Is completely unrelated to other IDs found elsewhere #: for the same movie, like on IMDb or similar sites. #: Namespaced identification of some resource, like a movies ID om IMDb, or it's ID on #: YouTube/Vimeo, or just a URI if we don't know the site already. Format like "imdb:tt01" #: or "youtube:Fq00mCqBMY8". #: The title of the movie. Note that this field is *not sufficient* to uniquely identify a #: movie. Always use IDs if you need to do that. #: What kind of movie is this? E.g. actual movie, episode, clip found on internet? #: Time added to database #: Year the movies was first shown #: Small cover art, 300px-ish #: An aggregate of number of streams available # Movie duration, in seconds # IMDb rating # Number of votes on IMDb # Score from metacritic # A measurement of how relevant this movie is, used for search ranking purposes
""" Create new movie object.
:param kwargs: Set object properties directly from the constructor. """
""" A dict representation of the movie that can be used for serialization. """ 'href': url_for('moviedetailview', movie_id=self.id, _external=True), 'external_id': self.external_id, 'title': self.title, 'category': self.category, 'datetime_added': self.datetime_added, 'year': self.year, 'cover_img': self.cover_img, 'number_of_streams': self.number_of_streams, 'imdb_rating': self.imdb_rating, 'imdb_votes': self.number_of_imdb_votes, 'metascore': self.metascore, 'duration_in_s': self.duration_in_s, '_links': { 'createStream': url_for('createstreamview', movie_id=self.id, _external=True), }, }
""" Calculate a new relevancy rating for the movie.
The IMDb rating is weighted the most, contributing a potential 200 points out of a 325 max, while the metascore ranking can contribute another 100 points, 25 points for number of votes, and then the score is discounted by a factor of .99 for each year since it's relase. """
""" The form used to validate new movie objects. """
""" A collection of related, timecoded entries that accompanies a movie.
Entries in a stream will usually have some common theme, like annoucing new actors that enter the screen, or providing references for topics mentioned in a movie. """
#: Unique identifier for this stream. Do not make assumptions about it's format, subject to change. #: A user chosen name for the stream. Users can change this at their own discretion, do not assume to #: be constant. #: Short description of the stream #: Foreign key to a movie #: The movie this stream is associated to. #: Foreign key to the user that created the stream #: The user that created the stream #: Whether the stream is visible public. Must be set explicitly to True by the user when he/she #: considers the stream done.
""" Create new stream.
:param movie: The movie this stream should be associated to. :param creator: The user that created the stream. :param kwargs: Set object properties from constructor. """
""" Get a dict representation of the stream suitable for serialization. """ 'href': url_for('streamdetailview', stream_id=self.id, _external=True), 'name': self.name, 'published': self.public, 'description': self.description, 'author': { 'username': self.creator.username, 'href': url_for('userdetailview', user_id=self.creator.id, _external=True), }, '_links': { 'createEntry': url_for('createentryview', stream_id=self.id, _external=True), 'entries': url_for('streamentryview', stream_id=self.id, _external=True), 'publish': url_for('publishstreamview', stream_id=self.id, _external=True), 'unpublish': url_for('unpublishstreamview', stream_id=self.id, _external=True), } } 'href': url_for('moviedetailview', movie_id=self.movie_id, _external=True), 'title': self.movie.title, }
""" A form used to validate new streams. """
# explicitly define which fields should be considered 'name', 'description', )
""" User-created content that appears at a given time in the movie. """
#: Unique identifier #: The time this entry should appear, in ms since the beginning of the stream #: The title of the entry #: The type of content, e.g. 'text', 'wiki', 'imdb:actor', etc. #: The content of the entry, as a JSON data structure info={ 'form_field_class': JSONField, #'validators': JSONValidator(), }, ) #: Foreign key to a stream db.ForeignKey('stream.id'), nullable=False, ) #: The stream this entry belongs to
""" Create new entry.
:param stream: The stream this entry should be associated to. :param kwargs: Properties of the stream that can be set from the constructor. """
""" Get a dict representation of the entry suitable for serialization. """ 'href': url_for('entrydetailview', entry_id=self.id, _external=True), 'entry_point_in_ms': self.entry_point_in_ms, 'content_type': self.content_type, 'content': self.content, 'title': self.title, 'stream': { 'href': url_for('streamdetailview', stream_id=self.stream_id, _external=True), 'name': self.stream.name, }, }
""" Form used to validate new entries. """
# explicitly declare which fields to consider in the form 'entry_point_in_ms', 'content_type', 'content', 'title', )
""" A user of the app. """
#: Unique identifier for this user #: The users chosen username #: The user's email address #: A string in the format method$salt$hash, where method for now will be scrypt:N:p:r, #: with N, p and r can be chosen to be arbitrary strong on a given machine. #: Date and time of signup
""" Create a new user.
:param kwargs: All properties can be set directory from the constructor. """
""" Same as self.is_authenticated(). """
""" Same as self.is_authenticated(). """ return self.is_authenticated()
return self.username
""" Used to tell the difference between authenticated users and anonymous users. """ # pylint: disable=no-self-use
""" A dict representation of the user.
:param include_personal_data: Whether to include sensitive data such as email. """ 'username': self.username, 'href': url_for('userdetailview', user_id=self.id), 'streams': [{ 'href': url_for('streamdetailview', stream_id=s.id, _external=True), 'name': s.name, 'published': s.public, 'movie': { 'href': url_for('moviedetailview', movie_id=s.movie.id, _external=True), 'title': s.movie.title, }, } for s in streams], }
""" Get a auth token the user can use to authenticate agains the service. """ # The data keys should be as short as possible to keep the token short # The user's id 'i': self.id, # Time of issue 't': time(), # Last characters of user's hashed password, makes sure the key is automatically # expired if the user changes password 'p': self.password_hash[-10:], }
""" Verify that an auth_data is valid for this user.
In pracice this means checking that the password in the given data is still valid and has not expired yet. """
""" Represents an anonymous user. """
""" Same as self.is_authenticated(). """
""" Same as self.is_authenticated(). """ return self.is_authenticated()
return 'Anonymous'
""" Used to tell anonymous users apart from authenticated users. Always returns False. """ # pylint: disable=no-self-use
""" Form used to validate new user creation. """
'username', 'email', )
""" Form used to validate user logins. """
|