Commit | Line | Data |
---|---|---|
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 | ||
4ad5af85 CAW |
17 | import datetime |
18 | ||
d232e0f6 | 19 | from mongokit import Document, Set |
4329be14 | 20 | |
4ad5af85 | 21 | from 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 | 33 | class 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, |
d232e0f6 CAW |
44 | } |
45 | ||
24181820 | 46 | required_fields = ['username', 'created', 'pw_hash', 'email'] |
fc9bb821 CAW |
47 | |
48 | default_values = { | |
24181820 | 49 | 'created': datetime.datetime.utcnow, |
4d75522b CAW |
50 | 'email_verified': False, |
51 | # TODO: shouldn't be active by default, must have email registration | |
eb298615 | 52 | 'status': u'active'} |
fc9bb821 | 53 | |
4ad5af85 CAW |
54 | def check_login(self, password): |
55 | """ | |
56 | See if a user can login with this password | |
57 | """ | |
58 | return auth_lib.bcrypt_check_password( | |
59 | password, self['pw_hash']) | |
60 | ||
d232e0f6 | 61 | |
4d75522b CAW |
62 | class MediaEntry(Document): |
63 | __collection__ = 'media_entries' | |
64 | ||
65 | structure = { | |
66 | 'uploader': User, | |
67 | 'title': unicode, | |
68 | 'created': datetime.datetime, | |
69 | 'description': unicode, | |
70 | 'media_type': unicode, | |
71 | 'media_data': dict, # extra data relevant to this media_type | |
72 | 'plugin_data': dict, # plugins can dump stuff here. | |
74ae6b11 CAW |
73 | 'tags': [unicode], |
74 | 'state': unicode, | |
75 | ||
76 | # The following should be lists of lists, in appropriate file | |
77 | # record form | |
78 | 'media_files': list, | |
79 | 'attachment_files': list, | |
80 | 'queue_files': list, | |
81 | ||
82 | # This one should just be a single file record | |
83 | 'thumbnail_file': [unicode]} | |
4d75522b CAW |
84 | |
85 | required_fields = [ | |
74ae6b11 | 86 | 'uploader', 'title', 'created', 'media_type'] |
4d75522b CAW |
87 | |
88 | default_values = { | |
74ae6b11 CAW |
89 | 'created': datetime.datetime.utcnow, |
90 | 'state': u'unprocessed'} | |
4d75522b CAW |
91 | |
92 | def main_mediafile(self): | |
93 | pass | |
94 | ||
95 | ||
d232e0f6 CAW |
96 | REGISTER_MODELS = [MediaEntry, User] |
97 | ||
4329be14 | 98 | |
d232e0f6 CAW |
99 | def register_models(connection): |
100 | """ | |
101 | Register all models in REGISTER_MODELS with this connection. | |
102 | """ | |
db61f7d1 CAW |
103 | connection.register(REGISTER_MODELS) |
104 |