mediagoblin.util.send_email now supports both list() and string() in the 'to_addrs...
[mediagoblin.git] / mediagoblin / models.py
CommitLineData
8e1e744d 1# GNU MediaGoblin -- federated, autonomous media hosting
e5572c60
ML
2# Copyright (C) 2011 Free Software Foundation, Inc
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
db1a438f 17import datetime, uuid
4ad5af85 18
d232e0f6 19from mongokit import Document, Set
4329be14 20
4ad5af85 21from mediagoblin.auth import lib as auth_lib
d232e0f6
CAW
22
23
7bf3f5db
CAW
24###################
25# Custom validators
26###################
27
28########
29# Models
30########
31
32
d232e0f6 33class User(Document):
73a6e206
CAW
34 __collection__ = 'users'
35
d232e0f6
CAW
36 structure = {
37 'username': unicode,
24181820 38 'email': unicode,
d232e0f6
CAW
39 'created': datetime.datetime,
40 'plugin_data': dict, # plugins can dump stuff here.
41 'pw_hash': unicode,
24181820 42 'email_verified': bool,
4d75522b 43 'status': unicode,
db1a438f 44 'verification_key': unicode
d232e0f6
CAW
45 }
46
24181820 47 required_fields = ['username', 'created', 'pw_hash', 'email']
fc9bb821
CAW
48
49 default_values = {
24181820 50 'created': datetime.datetime.utcnow,
4d75522b 51 'email_verified': False,
db1a438f 52 'status': u'needs_email_verification',
67e63926 53 'verification_key': uuid.uuid4 }
fc9bb821 54
4ad5af85
CAW
55 def check_login(self, password):
56 """
57 See if a user can login with this password
58 """
59 return auth_lib.bcrypt_check_password(
60 password, self['pw_hash'])
61
d232e0f6 62
4d75522b
CAW
63class MediaEntry(Document):
64 __collection__ = 'media_entries'
65
66 structure = {
67 'uploader': User,
68 'title': unicode,
69 'created': datetime.datetime,
70 'description': unicode,
71 'media_type': unicode,
72 'media_data': dict, # extra data relevant to this media_type
73 'plugin_data': dict, # plugins can dump stuff here.
74ae6b11
CAW
74 'tags': [unicode],
75 'state': unicode,
76
77 # The following should be lists of lists, in appropriate file
78 # record form
79 'media_files': list,
80 'attachment_files': list,
81 'queue_files': list,
82
83 # This one should just be a single file record
84 'thumbnail_file': [unicode]}
4d75522b
CAW
85
86 required_fields = [
74ae6b11 87 'uploader', 'title', 'created', 'media_type']
4d75522b
CAW
88
89 default_values = {
74ae6b11
CAW
90 'created': datetime.datetime.utcnow,
91 'state': u'unprocessed'}
4d75522b
CAW
92
93 def main_mediafile(self):
94 pass
95
96
d232e0f6
CAW
97REGISTER_MODELS = [MediaEntry, User]
98
4329be14 99
d232e0f6
CAW
100def register_models(connection):
101 """
102 Register all models in REGISTER_MODELS with this connection.
103 """
db61f7d1
CAW
104 connection.register(REGISTER_MODELS)
105