Commits (22)
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
'use strict'; 'use strict';
var app = angular.module('courses', [ var app = angular.module('courses', [
'courses.controller',
'courses.filters',
'ngResource', 'ngResource',
'timtec-models', 'timtec-models',
'directive.fixedBar', 'directive.fixedBar',
......
(function(angular){ (function(angular){
'use strict'; 'use strict';
var app = angular.module('courses'); var app = angular.module('courses.controller', []);
app.controller('CoursesAdminController', [ app.controller('CoursesAdminController', [
'$scope', '$uibModal', '$window', 'Course', 'Lesson', 'FormUpload', '$scope', '$uibModal', '$window', 'Course', 'Lesson', 'FormUpload',
......
(function(angular){ (function(angular){
'use strict'; 'use strict';
var app = angular.module('courses'); var app = angular.module('courses.filters');
app.filter('capfirst', function() { app.filter('capfirst', function() {
return function(text) { return function(text) {
......
...@@ -80,21 +80,6 @@ ...@@ -80,21 +80,6 @@
}; };
}]); }]);
/**
* Give a function that send _method=OPTIONS to django rest_framework
* URL informed and return a promise with result.
*/
app.factory('getRestOptions', ['$http', function($http){
return function(url){
return $http({
method:'POST',
url: url,
data:'_method=OPTIONS',
headers:{'Content-Type':'application/x-www-form-urlencoded'}
});
};
}]);
/** /**
* Provide a Course Professor class. The property Class.fields contains the * Provide a Course Professor class. The property Class.fields contains the
...@@ -102,7 +87,7 @@ ...@@ -102,7 +87,7 @@
*/ */
app.factory('CourseProfessor', ['$resource', function($resource) { app.factory('CourseProfessor', ['$resource', function($resource) {
return $resource('/api/course_professor/:id', {'id':'@id'}, { return $resource(BASE_API_URL + '/course_professor/:id', {'id':'@id'}, {
'update': { 'update': {
'method': 'PUT' 'method': 'PUT'
} }
...@@ -116,7 +101,7 @@ ...@@ -116,7 +101,7 @@
*/ */
app.factory('CourseAuthor', ['$resource', function($resource) { app.factory('CourseAuthor', ['$resource', function($resource) {
return $resource('/api/course_author/:id', {'id':'@id'}, { return $resource(BASE_API_URL + '/course_author/:id', {'id':'@id'}, {
'update': { 'update': {
'method': 'PUT' 'method': 'PUT'
} }
...@@ -128,8 +113,8 @@ ...@@ -128,8 +113,8 @@
* Provide a Course class. The property Class.fields contains the * Provide a Course class. The property Class.fields contains the
* list of fields that reflects Course model in Django * list of fields that reflects Course model in Django
*/ */
app.factory('Course', ['$resource', 'getRestOptions', function($resource, getRestOptions) { app.factory('Course', ['$resource', function($resource) {
var Course = $resource('/api/course/:id', {'id':'@id'}); var Course = $resource(BASE_API_URL + '/api/course/:id', {'id':'@id'});
Course.prototype.isDraft = function() { return this.status === 'draft'; }; Course.prototype.isDraft = function() { return this.status === 'draft'; };
Course.prototype.isListed = function() { return this.status === 'listed'; }; Course.prototype.isListed = function() { return this.status === 'listed'; };
...@@ -149,11 +134,6 @@ ...@@ -149,11 +134,6 @@
return this.$save(); return this.$save();
}; };
getRestOptions('/api/course').success(function(data) {
Course.fields = angular.copy(data.actions.POST);
});
return Course; return Course;
}]); }]);
...@@ -175,7 +155,7 @@ ...@@ -175,7 +155,7 @@
'method': 'PUT' 'method': 'PUT'
} }
}; };
var Professor = $resource('/api/user/:id', {'id':'@id'}, resourceConfig); var Professor = $resource(BASE_API_URL + '/user/:id', {'id':'@id'}, resourceConfig);
Professor.prototype.getName = function() { Professor.prototype.getName = function() {
var name = this.name; var name = this.name;
if(!name && (this.first_name || this.last_name)) { if(!name && (this.first_name || this.last_name)) {
...@@ -194,7 +174,7 @@ ...@@ -194,7 +174,7 @@
var resourceConfig = { var resourceConfig = {
'update': {'method': 'PUT'} 'update': {'method': 'PUT'}
}; };
var Lesson = $resource('/api/lessons/:id', {'id':'@id'}, resourceConfig); var Lesson = $resource(BASE_API_URL + '/lessons/:id', {'id':'@id'}, resourceConfig);
Lesson.prototype.countVideos = function() { Lesson.prototype.countVideos = function() {
return (this.units || []).reduce(function(c, u){ return (this.units || []).reduce(function(c, u){
return u.video ? c + 1 : c; return u.video ? c + 1 : c;
...@@ -217,7 +197,7 @@ ...@@ -217,7 +197,7 @@
*/ */
app.factory('SimpleLesson', ['$resource', function($resource){ app.factory('SimpleLesson', ['$resource', function($resource){
var resourceConfig = {}; var resourceConfig = {};
var SimpleLesson = $resource('/api/simple_lessons/:id', {'id':'@id'}, resourceConfig); var SimpleLesson = $resource(BASE_API_URL + '/simple_lessons/:id', {'id':'@id'}, resourceConfig);
SimpleLesson.prototype.countVideos = function() { SimpleLesson.prototype.countVideos = function() {
return (this.units || []).reduce(function(c, u){ return (this.units || []).reduce(function(c, u){
return u.video ? c + 1 : c; return u.video ? c + 1 : c;
...@@ -235,19 +215,19 @@ ...@@ -235,19 +215,19 @@
}]); }]);
app.factory('CourseStudent', function($resource){ app.factory('CourseStudent', function($resource){
return $resource('/api/course_student/:id', return $resource(BASE_API_URL + '/course_student/:id',
{'id' : '@id'}, {'id' : '@id'},
{'update': {'method': 'PUT'} }); {'update': {'method': 'PUT'} });
}); });
app.factory('CertificationProcess', function($resource){ app.factory('CertificationProcess', function($resource){
return $resource('/api/certification_process/:certificateId', return $resource(BASE_API_URL + '/certification_process/:certificateId',
{'certificateId' : '@id'}, {'certificateId' : '@id'},
{'update': {'method': 'PUT'} }); {'update': {'method': 'PUT'} });
}); });
app.factory('CourseCertification', function($resource){ app.factory('CourseCertification', function($resource){
return $resource('/api/course_certification/:link_hash', return $resource(BASE_API_URL + '/course_certification/:link_hash',
{'link_hash' : '@id' }, {'link_hash' : '@id' },
{'update': {'method': 'PUT'} }); {'update': {'method': 'PUT'} });
}); });
...@@ -256,13 +236,13 @@ ...@@ -256,13 +236,13 @@
* Basic model class to Evaluation * Basic model class to Evaluation
*/ */
app.factory('Evaluation', function($resource){ app.factory('Evaluation', function($resource){
return $resource('/api/evaluation/:id', {'id' : '@id'}, { return $resource(BASE_API_URL + '/evaluation/:id', {'id' : '@id'}, {
'update': {'method': 'PUT'} 'update': {'method': 'PUT'}
}); });
}); });
app.factory('CertificateTemplate', function($resource){ app.factory('CertificateTemplate', function($resource){
return $resource('/api/certificate_template/:course', {}, { return $resource(BASE_API_URL + '/certificate_template/:course', {}, {
'update' : {'method' : 'PUT'}, 'update' : {'method' : 'PUT'},
}); });
}); });
...@@ -292,7 +272,7 @@ ...@@ -292,7 +272,7 @@
*/ */
app.factory('StudentSearch', ['$http', function($http){ app.factory('StudentSearch', ['$http', function($http){
return function(val, course_id) { return function(val, course_id) {
return $http.get('/api/student_search', { return $http.get(BASE_API_URL + '/student_search', {
params: { params: {
name: val, name: val,
course: course_id, course: course_id,
...@@ -325,7 +305,7 @@ ...@@ -325,7 +305,7 @@
*/ */
app.factory('UserSearch', ['$http', function($http){ app.factory('UserSearch', ['$http', function($http){
return function(val, course_id) { return function(val, course_id) {
return $http.get('/api/user_search', { return $http.get(BASE_API_URL + '/user_search', {
params: { params: {
name: val, name: val,
sensor: false sensor: false
...@@ -353,7 +333,7 @@ ...@@ -353,7 +333,7 @@
app.factory('Class', function($resource){ app.factory('Class', function($resource){
return $resource('/api/course_classes/:id', {'id' : '@id'}, { return $resource(BASE_API_URL + '/course_classes/:id', {'id' : '@id'}, {
'update': {'method': 'PUT'} 'update': {'method': 'PUT'}
}); });
}); });
......
...@@ -75,9 +75,6 @@ ...@@ -75,9 +75,6 @@
var messages = []; var messages = [];
for(var att in response.data) { for(var att in response.data) {
var message = response.data[att]; var message = response.data[att];
if(Course.fields && Course.fields[att]) {
message = Course.fields[att].label + ': ' + message;
}
messages.push(message); messages.push(message);
} }
$scope.alert.error('Encontramos alguns erros!', messages, true); $scope.alert.error('Encontramos alguns erros!', messages, true);
......
...@@ -113,10 +113,10 @@ class CourseCreateView(views.SuperuserRequiredMixin, View, ModelFormMixin): ...@@ -113,10 +113,10 @@ class CourseCreateView(views.SuperuserRequiredMixin, View, ModelFormMixin):
return super(CourseCreateView, self).form_valid(form) return super(CourseCreateView, self).form_valid(form)
def form_invalid(self, form): def form_invalid(self, form):
return HttpResponseRedirect(reverse_lazy('administration.courses')) return HttpResponseRedirect(reverse_lazy('courses_legacy:administration.courses'))
def get_success_url(self): def get_success_url(self):
return reverse_lazy('administration.edit_course', kwargs={'course_id': self.object.id}) return reverse_lazy('courses_legacy:administration.edit_course', kwargs={'course_id': self.object.id})
class ExportCourseView(views.SuperuserRequiredMixin, View): class ExportCourseView(views.SuperuserRequiredMixin, View):
...@@ -290,7 +290,7 @@ class ImportCourseView(APIView): ...@@ -290,7 +290,7 @@ class ImportCourseView(APIView):
# Save all changes in the new imported course # Save all changes in the new imported course
course_obj.save() course_obj.save()
return Response({'new_course_url': reverse_lazy('administration.edit_course', return Response({'new_course_url': reverse_lazy('courses_legacy:administration.edit_course',
kwargs={'course_id': course_obj.id}), kwargs={'course_id': course_obj.id}),
}) })
else: else:
......
...@@ -5,60 +5,6 @@ from ..activities.admin import ModelAdmin ...@@ -5,60 +5,6 @@ from ..activities.admin import ModelAdmin
from .models import * from .models import *
class LessonInline(admin.TabularInline):
model = Lesson
formfield_overrides = {
models.CharField: {'widget': Textarea(attrs={'rows': 3, 'class': 'span11'})},
}
class UnitInline(admin.TabularInline):
model = Unit
fields = ('title', 'video', 'position',)
class LessonAdmin(ModelAdmin):
list_display = ('name', 'course',)
search_fields = ('course__name',)
inlines = (UnitInline,)
class UnitAdmin(ModelAdmin):
search_fields = ('title', 'lesson__name')
list_display = ('title', 'position', 'lesson', 'video',)
list_select_related = ('lesson', 'video')
class CourseAdmin(ModelAdmin):
list_display = ('name', 'status', 'start_date',)
inlines = (LessonInline,)
class CourseProfessorAdmin(ModelAdmin):
list_display = ('user', 'course',)
class VideoAdmin(ModelAdmin):
pass
# list_display = ('name', 'youtube_id',)
class ClassAdmin(ModelAdmin):
search_fields = ('name', 'course', 'assistants')
list_display = ('name', 'course')
filter_horizontal = ('students', )
class StudentProgressAdmin(ModelAdmin):
search_fields = ('user__username', 'user__email', )
list_display = ('user', 'unit', 'complete', 'last_access')
class CourseStudentAdmin(ModelAdmin):
search_fields = ('user__username',)
list_display = ('user', 'course')
class CertficateAdmin(ModelAdmin): class CertficateAdmin(ModelAdmin):
pass pass
# list_display = ('course_student__user__username', 'course_student__course__name',) # list_display = ('course_student__user__username', 'course_student__course__name',)
...@@ -69,15 +15,7 @@ class CertficateTemplateAdmin(ModelAdmin): ...@@ -69,15 +15,7 @@ class CertficateTemplateAdmin(ModelAdmin):
# list_display = ('course_student__user__username', 'course_student__course__name',) # list_display = ('course_student__user__username', 'course_student__course__name',)
admin.site.register(Video, VideoAdmin)
admin.site.register(CourseProfessor, CourseProfessorAdmin)
admin.site.register(Course, CourseAdmin)
admin.site.register(Lesson, LessonAdmin)
admin.site.register(Unit, UnitAdmin)
admin.site.register(StudentProgress, StudentProgressAdmin)
admin.site.register(CourseStudent, CourseStudentAdmin)
admin.site.register(ProfessorMessage) admin.site.register(ProfessorMessage)
admin.site.register(Class, ClassAdmin)
admin.site.register(CourseCertification, CertficateAdmin) admin.site.register(CourseCertification, CertficateAdmin)
admin.site.register(CertificateTemplate, CertficateTemplateAdmin) admin.site.register(CertificateTemplate, CertficateTemplateAdmin)
admin.site.register(CertificationProcess) admin.site.register(CertificationProcess)
......
...@@ -448,7 +448,7 @@ class LessonSerializer(serializers.ModelSerializer): ...@@ -448,7 +448,7 @@ class LessonSerializer(serializers.ModelSerializer):
activity.unit = unit activity.unit = unit
activity.save() activity.save()
activities.append(activity) activities.append(activity)
unit.activities = activities unit.activities.set(activities)
units.append(unit) units.append(unit)
return units return units
......
...@@ -186,7 +186,7 @@ ...@@ -186,7 +186,7 @@
*/ */
app.factory('CourseDataFactory', ['$rootScope', '$q', '$resource', app.factory('CourseDataFactory', ['$rootScope', '$q', '$resource',
function($rootScope, $q, $resource) { function($rootScope, $q, $resource) {
var Course = $resource('/api/course/:courseSlug/',{'courseSlug': courseSlug}); var Course = $resource(BASE_API_URL + '/course/:courseSlug/',{'courseSlug': courseSlug});
var deferred = $q.defer(); var deferred = $q.defer();
var antiCache = { var antiCache = {
ie: (new Date()).getTime().toString(16) ie: (new Date()).getTime().toString(16)
...@@ -214,7 +214,7 @@ ...@@ -214,7 +214,7 @@
'method': 'PUT' 'method': 'PUT'
} }
}; };
var LessonList = $resource('/api/lessons/:id', {'id':'@id'}, resourceConfig); var LessonList = $resource(BASE_API_URL + '/lessons/:id', {'id':'@id'}, resourceConfig);
var deferred = $q.defer(); var deferred = $q.defer();
LessonList.query(function(lessons){ LessonList.query(function(lessons){
...@@ -241,7 +241,7 @@ ...@@ -241,7 +241,7 @@
'method': 'PUT' 'method': 'PUT'
} }
}; };
return $resource('/api/lessons/:id', {'id':'@id'}, resourceConfig); return $resource(BASE_API_URL + '/lessons/:id', {'id':'@id'}, resourceConfig);
} }
]); ]);
})(angular); })(angular);
...@@ -132,7 +132,7 @@ ...@@ -132,7 +132,7 @@
}; };
$scope.getUsers = function(val) { $scope.getUsers = function(val) {
return $http.get('/api/user_search', { return $http.get(BASE_API_URL + '/user_search', {
params: { params: {
name: val, name: val,
sensor: false sensor: false
......
(function(angular){ (function(angular){
'use strict'; 'use strict';
var app = angular.module('courses', [ var app = angular.module('admin.courses', [
'admin.courses.controllers',
'admin.courses.filters',
'ngResource', 'ngResource',
'timtec-models', 'timtec-models',
'directive.fixedBar', 'directive.fixedBar',
'django', 'django',
'ui.bootstrap', 'ui.bootstrap',
'directive.file', 'directive.file',
'header',
]); ]);
})(window.angular); })(window.angular);
(function(angular){ (function(angular){
'use strict'; 'use strict';
var app = angular.module('courses'); var app = angular.module('admin.courses.controllers', []);
app.controller('CoursesAdminController', [ app.controller('CoursesAdminController', [
'$scope', '$uibModal', '$window', 'Course', 'Lesson', 'FormUpload', '$scope', '$uibModal', '$window', 'Course', 'Lesson', 'FormUpload',
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
if (force) if (force)
$scope.fu.addField('force', true); $scope.fu.addField('force', true);
$scope.fu.sendTo('/admin/course/import/') $scope.fu.sendTo('/legacy/admin/course/import/')
.then(function(response) { .then(function(response) {
if (response.data.error) { if (response.data.error) {
if (response.data.error == 'course_started') { if (response.data.error == 'course_started') {
......
(function(angular){ (function(angular){
'use strict'; 'use strict';
var app = angular.module('courses'); var app = angular.module('admin.courses.filters', []);
app.filter('capfirst', function() { app.filter('capfirst', function() {
return function(text) { return function(text) {
......