Commits (22)
......@@ -2,6 +2,8 @@
'use strict';
var app = angular.module('courses', [
'courses.controller',
'courses.filters',
'ngResource',
'timtec-models',
'directive.fixedBar',
......
(function(angular){
'use strict';
var app = angular.module('courses');
var app = angular.module('courses.controller', []);
app.controller('CoursesAdminController', [
'$scope', '$uibModal', '$window', 'Course', 'Lesson', 'FormUpload',
......
(function(angular){
'use strict';
var app = angular.module('courses');
var app = angular.module('courses.filters');
app.filter('capfirst', function() {
return function(text) {
......
......@@ -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
......@@ -102,7 +87,7 @@
*/
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': {
'method': 'PUT'
}
......@@ -116,7 +101,7 @@
*/
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': {
'method': 'PUT'
}
......@@ -128,8 +113,8 @@
* Provide a Course class. The property Class.fields contains the
* list of fields that reflects Course model in Django
*/
app.factory('Course', ['$resource', 'getRestOptions', function($resource, getRestOptions) {
var Course = $resource('/api/course/:id', {'id':'@id'});
app.factory('Course', ['$resource', function($resource) {
var Course = $resource(BASE_API_URL + '/api/course/:id', {'id':'@id'});
Course.prototype.isDraft = function() { return this.status === 'draft'; };
Course.prototype.isListed = function() { return this.status === 'listed'; };
......@@ -149,11 +134,6 @@
return this.$save();
};
getRestOptions('/api/course').success(function(data) {
Course.fields = angular.copy(data.actions.POST);
});
return Course;
}]);
......@@ -175,7 +155,7 @@
'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() {
var name = this.name;
if(!name && (this.first_name || this.last_name)) {
......@@ -194,7 +174,7 @@
var resourceConfig = {
'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() {
return (this.units || []).reduce(function(c, u){
return u.video ? c + 1 : c;
......@@ -217,7 +197,7 @@
*/
app.factory('SimpleLesson', ['$resource', function($resource){
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() {
return (this.units || []).reduce(function(c, u){
return u.video ? c + 1 : c;
......@@ -235,19 +215,19 @@
}]);
app.factory('CourseStudent', function($resource){
return $resource('/api/course_student/:id',
return $resource(BASE_API_URL + '/course_student/:id',
{'id' : '@id'},
{'update': {'method': 'PUT'} });
});
app.factory('CertificationProcess', function($resource){
return $resource('/api/certification_process/:certificateId',
return $resource(BASE_API_URL + '/certification_process/:certificateId',
{'certificateId' : '@id'},
{'update': {'method': 'PUT'} });
});
app.factory('CourseCertification', function($resource){
return $resource('/api/course_certification/:link_hash',
return $resource(BASE_API_URL + '/course_certification/:link_hash',
{'link_hash' : '@id' },
{'update': {'method': 'PUT'} });
});
......@@ -256,13 +236,13 @@
* Basic model class to Evaluation
*/
app.factory('Evaluation', function($resource){
return $resource('/api/evaluation/:id', {'id' : '@id'}, {
return $resource(BASE_API_URL + '/evaluation/:id', {'id' : '@id'}, {
'update': {'method': 'PUT'}
});
});
app.factory('CertificateTemplate', function($resource){
return $resource('/api/certificate_template/:course', {}, {
return $resource(BASE_API_URL + '/certificate_template/:course', {}, {
'update' : {'method' : 'PUT'},
});
});
......@@ -292,7 +272,7 @@
*/
app.factory('StudentSearch', ['$http', function($http){
return function(val, course_id) {
return $http.get('/api/student_search', {
return $http.get(BASE_API_URL + '/student_search', {
params: {
name: val,
course: course_id,
......@@ -325,7 +305,7 @@
*/
app.factory('UserSearch', ['$http', function($http){
return function(val, course_id) {
return $http.get('/api/user_search', {
return $http.get(BASE_API_URL + '/user_search', {
params: {
name: val,
sensor: false
......@@ -353,7 +333,7 @@
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'}
});
});
......
......@@ -75,9 +75,6 @@
var messages = [];
for(var att in response.data) {
var message = response.data[att];
if(Course.fields && Course.fields[att]) {
message = Course.fields[att].label + ': ' + message;
}
messages.push(message);
}
$scope.alert.error('Encontramos alguns erros!', messages, true);
......
......@@ -113,10 +113,10 @@ class CourseCreateView(views.SuperuserRequiredMixin, View, ModelFormMixin):
return super(CourseCreateView, self).form_valid(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):
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):
......@@ -290,7 +290,7 @@ class ImportCourseView(APIView):
# Save all changes in the new imported course
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}),
})
else:
......
......@@ -5,60 +5,6 @@ from ..activities.admin import ModelAdmin
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):
pass
# list_display = ('course_student__user__username', 'course_student__course__name',)
......@@ -69,15 +15,7 @@ class CertficateTemplateAdmin(ModelAdmin):
# 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(Class, ClassAdmin)
admin.site.register(CourseCertification, CertficateAdmin)
admin.site.register(CertificateTemplate, CertficateTemplateAdmin)
admin.site.register(CertificationProcess)
......
......@@ -448,7 +448,7 @@ class LessonSerializer(serializers.ModelSerializer):
activity.unit = unit
activity.save()
activities.append(activity)
unit.activities = activities
unit.activities.set(activities)
units.append(unit)
return units
......
......@@ -186,7 +186,7 @@
*/
app.factory('CourseDataFactory', ['$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 antiCache = {
ie: (new Date()).getTime().toString(16)
......@@ -214,7 +214,7 @@
'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();
LessonList.query(function(lessons){
......@@ -241,7 +241,7 @@
'method': 'PUT'
}
};
return $resource('/api/lessons/:id', {'id':'@id'}, resourceConfig);
return $resource(BASE_API_URL + '/lessons/:id', {'id':'@id'}, resourceConfig);
}
]);
})(angular);
......@@ -132,7 +132,7 @@
};
$scope.getUsers = function(val) {
return $http.get('/api/user_search', {
return $http.get(BASE_API_URL + '/user_search', {
params: {
name: val,
sensor: false
......
(function(angular){
'use strict';
var app = angular.module('courses', [
var app = angular.module('admin.courses', [
'admin.courses.controllers',
'admin.courses.filters',
'ngResource',
'timtec-models',
'directive.fixedBar',
'django',
'ui.bootstrap',
'directive.file',
'header',
]);
})(window.angular);
(function(angular){
'use strict';
var app = angular.module('courses');
var app = angular.module('admin.courses.controllers', []);
app.controller('CoursesAdminController', [
'$scope', '$uibModal', '$window', 'Course', 'Lesson', 'FormUpload',
......@@ -50,7 +50,7 @@
if (force)
$scope.fu.addField('force', true);
$scope.fu.sendTo('/admin/course/import/')
$scope.fu.sendTo('/legacy/admin/course/import/')
.then(function(response) {
if (response.data.error) {
if (response.data.error == 'course_started') {
......
(function(angular){
'use strict';
var app = angular.module('courses');
var app = angular.module('admin.courses.filters', []);
app.filter('capfirst', function() {
return function(text) {
......