1
- # Python
2
1
from base64 import b64encode
3
2
4
- # Tastypie
5
- from tastypie .resources import ModelResource , Resource , ALL
6
- from api_permissions import *
7
- from tastypie .authentication import ApiKeyAuthentication #,OAuthAuthentication
8
- from tastypie .authorization import DjangoAuthorization , ReadOnlyAuthorization
3
+ from api .permissions import SuperuserAuthorization
9
4
from tastypie import fields
5
+ from tastypie .authentication import Authentication , ApiKeyAuthentication
6
+ from tastypie .authorization import DjangoAuthorization , ReadOnlyAuthorization
7
+ from tastypie .resources import ModelResource , Resource , ALL
8
+
9
+ from .exercise_models import LearningObject , BaseExercise , CourseModule
10
+ from .submission_models import Submission
10
11
11
- # A+
12
- from userprofile .models import UserProfile
13
- from .exercise_models import LearningObject , BaseExercise , CourseModule , CourseInstance
14
- from .submission_models import Submission , SubmittedFile
15
- from api_permissions import SuperuserAuthorization
16
12
17
13
class LearningObjectResource (ModelResource ):
18
14
class Meta :
19
- queryset = LearningObject .objects .all ()
20
- resource_name = 'learning_object'
21
- excludes = []
15
+ queryset = LearningObject .objects .all ()
16
+ resource_name = 'learning_object'
17
+ excludes = []
22
18
23
19
# In the first version GET (read only) requests are
24
20
# allowed and no authentication is required
25
21
allowed_methods = ['get' ]
26
- authentication = Authentication ()
27
- authorization = ReadOnlyAuthorization ()
22
+ authentication = Authentication ()
23
+ authorization = ReadOnlyAuthorization ()
28
24
29
25
30
26
class ExerciseResource (ModelResource ):
31
- submissions = fields .ToManyField ('exercise.api.SubmissionResource' , 'submissions' )
27
+ submissions = fields .ToManyField ('exercise.api.SubmissionResource' , 'submissions' )
32
28
33
29
class Meta :
34
- queryset = BaseExercise .objects .all ()
35
- resource_name = 'exercise'
36
- excludes = []
30
+ queryset = BaseExercise .objects .all ()
31
+ resource_name = 'exercise'
32
+ excludes = []
37
33
38
34
# In the first version GET (read only) requests are
39
35
# allowed and no authentication is required
40
36
allowed_methods = ['get' ]
41
- authentication = Authentication ()
42
- authorization = ReadOnlyAuthorization ()
37
+ authentication = Authentication ()
38
+ authorization = ReadOnlyAuthorization ()
43
39
44
40
class CourseModuleResource (ModelResource ):
45
- learning_objects = fields .ToManyField ('exercise.api.LearningObjectResource' , 'learning_objects' )
41
+ learning_objects = fields .ToManyField ('exercise.api.LearningObjectResource' , 'learning_objects' )
46
42
47
43
class Meta :
48
- queryset = CourseModule .objects .all ()
49
- resource_name = 'coursemodule'
50
- excludes = []
44
+ queryset = CourseModule .objects .all ()
45
+ resource_name = 'coursemodule'
46
+ excludes = []
51
47
52
48
# In the first version GET (read only) requests are
53
49
# allowed and no authentication is required
54
50
allowed_methods = ['get' ]
55
- authentication = Authentication ()
56
- authorization = ReadOnlyAuthorization ()
51
+ authentication = Authentication ()
52
+ authorization = ReadOnlyAuthorization ()
57
53
58
54
class SubmissionResource (ModelResource ):
59
- exercise = fields .ToOneField ('exercise.api.ExerciseResource' , 'exercise' )
60
- grader = fields .ToOneField ('userprofile.api.UserProfileResource' , 'grader' , null = True , blank = True )
61
- submitters = fields .ToManyField ('userprofile.api.UserProfileResource' , 'submitters' , null = True , blank = True )
55
+ exercise = fields .ToOneField ('exercise.api.ExerciseResource' , 'exercise' )
56
+ grader = fields .ToOneField ('userprofile.api.UserProfileResource' , 'grader' , null = True , blank = True )
57
+ submitters = fields .ToManyField ('userprofile.api.UserProfileResource' , 'submitters' , null = True , blank = True )
62
58
63
59
def dehydrate (self , bundle ):
64
60
"""
65
61
This method iterates over the URLs of the files submitted with each
66
62
submission and adds them in the file_urls lists of submissions.
67
63
"""
68
- file_urls = []
64
+ file_urls = []
69
65
for file in bundle .obj .files .all ():
70
66
file_urls .append (file .get_absolute_url ())
71
67
bundle .data .update ({"files" : file_urls })
72
68
return bundle
73
69
74
70
class Meta :
75
- queryset = Submission .objects .all ()
76
- resource_name = 'submission'
77
- excludes = ['feedback' ]
71
+ queryset = Submission .objects .all ()
72
+ resource_name = 'submission'
73
+ excludes = ['feedback' ]
78
74
allowed_methods = ['get' ]
79
75
include_absolute_url = True
80
76
@@ -88,9 +84,8 @@ class Meta:
88
84
}
89
85
90
86
# In this version only superusers are allowed to access
91
- # submissions after being authenticated with OAuth
92
- # authentication = OAuthAuthentication()
93
- authorization = SuperuserAuthorization ()
87
+ # submissions.
88
+ authorization = SuperuserAuthorization ()
94
89
95
90
class SubmissionContentResource (ModelResource ):
96
91
"""
@@ -122,9 +117,9 @@ def dehydrate(self, bundle):
122
117
return bundle
123
118
124
119
class Meta :
125
- queryset = Submission .objects .all ()
126
- resource_name = 'submission_content'
127
- excludes = ['feedback' ]
120
+ queryset = Submission .objects .all ()
121
+ resource_name = 'submission_content'
122
+ excludes = ['feedback' ]
128
123
allowed_methods = ['get' ]
129
124
include_absolute_url = True
130
125
@@ -137,5 +132,5 @@ class Meta:
137
132
"id" : ALL
138
133
}
139
134
140
- authentication = ApiKeyAuthentication ()
141
- authorization = ReadOnlyAuthorization ()
135
+ authentication = ApiKeyAuthentication ()
136
+ authorization = ReadOnlyAuthorization ()
0 commit comments