Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #183

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions administration/static/js/edit-class/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
'directive.waiting-screen',
'directive.alertPopup',
'directive.fixedBar',
'ngSanitize',
'timtec-models',
'ui.bootstrap',
'ui.select',
'header',
]);
})(angular);
16 changes: 7 additions & 9 deletions administration/static/js/edit-class/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,25 @@

$scope.remove_item = function(index){
// removing from 'screen' list
var student_id = $scope.classe.students[index].user.id;
var student_id = $scope.classe.students_details[index].user.id;
$scope.classe.students.splice(index, 1);

// remove from real list
var index_management = $scope.classe.students_management.indexOf(student_id);
$scope.classe.students_management.splice(index_management, 1);
var index_management = $scope.classe.students.indexOf(student_id);
$scope.classe.students.splice(index_management, 1);
$scope.save();
};

$scope.on_select_student = function(model) {
$scope.classe.students.unshift(model);
$scope.classe.students_management.unshift(model.id);
$scope.classe.students_details.unshift(model);
$scope.classe.students.unshift(model.id);
$scope.asyncSelected = '';
$scope.save();
};

$scope.toggle_certificate = function (index){

var student = $scope.classe.students[index];
var student = $scope.classe.students_details[index];
if(student.certificate) {
var cc_id = student.certificate.link_hash;
var user_id = student.user.id;
Expand All @@ -68,9 +69,6 @@
$scope.save = function(){

$scope.classe.$resolved = false;
if($scope.classe.assistant) {
$scope.classe.assistant_management = $scope.classe.assistant.id;
}

$scope.classe.$update()
.then(function(){
Expand Down
10 changes: 8 additions & 2 deletions core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class VideoAdmin(ModelAdmin):


class ClassAdmin(ModelAdmin):
search_fields = ('name', 'course', 'assistant')
list_display = ('name', 'assistant', 'course')
search_fields = ('name', 'course', 'assistants')
list_display = ('name', 'course')
filter_horizontal = ('students', )


Expand All @@ -64,6 +64,11 @@ class CertficateAdmin(ModelAdmin):
# list_display = ('course_student__user__username', 'course_student__course__name',)


class CertficateTemplateAdmin(ModelAdmin):
pass
# 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)
Expand All @@ -74,5 +79,6 @@ class CertficateAdmin(ModelAdmin):
admin.site.register(ProfessorMessage)
admin.site.register(Class, ClassAdmin)
admin.site.register(CourseCertification, CertficateAdmin)
admin.site.register(CertificateTemplate, CertficateTemplateAdmin)
admin.site.register(CertificationProcess)
admin.site.register(Evaluation)
38 changes: 38 additions & 0 deletions core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,41 @@ def save(self, commit=True):
uid = self.cleaned_data['user_id']
self.instance.remove_students(get_user_model().objects.get(id=uid))
return super(RemoveStudentForm, self).save(commit=commit)


class AddStudentsForm(forms.ModelForm):
class Meta:
model = Class
fields = []

students_text = forms.CharField()

def clean_students_text(self):
data = self.cleaned_data['students_text'].strip().split()
data = [u.strip() for u in data]
return data

def save(self, commit=True):
User = get_user_model()
students = self.cleaned_data['students_text']

for student_name in students:
try:
student = User.objects.get(
Q(username=student_name) |
Q(email=student_name)
)
self.instance.add_students(student)

if self.data.get('auto_enroll', False) == "True":
# Check if the new user is already enrolled
try:
CourseStudent.objects.get(user=student, course=self.instance.course)
except CourseStudent.DoesNotExist:
CourseStudent.objects.create(user=student, course=self.instance.course)
pass

except User.DoesNotExist:
logger.info(u'student with username: %s does not exist' % student_name)

return super(AddStudentsForm, self).save(commit=commit)
15 changes: 15 additions & 0 deletions core/migrations/0020_merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0017_coursestudent_start_date'),
('core', '0019_auto_20161014_2116'),
]

operations = [
]
21 changes: 21 additions & 0 deletions core/migrations/0021_class_assistants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
from django.conf import settings


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('core', '0020_merge'),
]

operations = [
migrations.AddField(
model_name='class',
name='assistants',
field=models.ManyToManyField(related_name='professor_classes', verbose_name='Assistants', to=settings.AUTH_USER_MODEL, blank=True),
),
]
22 changes: 22 additions & 0 deletions core/migrations/0022_auto_20161125_1116.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


def migrate_assistants(apps, schema_editor):
Class = apps.get_model("core", "Class")
for class_group in Class.objects.all():
if class_group.assistant:
class_group.assistants.add(class_group.assistant)


class Migration(migrations.Migration):

dependencies = [
('core', '0021_class_assistants'),
]

operations = [
migrations.RunPython(migrate_assistants),
]
18 changes: 18 additions & 0 deletions core/migrations/0023_remove_class_assistant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0022_auto_20161125_1116'),
]

operations = [
migrations.RemoveField(
model_name='class',
name='assistant',
),
]
20 changes: 20 additions & 0 deletions core/migrations/0024_certificatetemplate_signature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import core.utils


class Migration(migrations.Migration):

dependencies = [
('core', '0023_remove_class_assistant'),
]

operations = [
migrations.AddField(
model_name='certificatetemplate',
name='signature',
field=models.ImageField(upload_to=core.utils.HashName(b'signature', b'organization_name'), null=True, verbose_name='Signature', blank=True),
),
]
27 changes: 22 additions & 5 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def __unicode__(self):

class Class(models.Model):
name = models.CharField(max_length=255)
assistant = models.ForeignKey(settings.AUTH_USER_MODEL,
verbose_name=_('Assistant'),
related_name='professor_classes', null=True,
blank=True)
assistants = models.ManyToManyField(settings.AUTH_USER_MODEL,
verbose_name=_('Assistants'),
related_name='professor_classes',
blank=True)
students = models.ManyToManyField(settings.AUTH_USER_MODEL,
related_name='classes', blank=True)
course = models.ForeignKey('Course', verbose_name=_('Course'))
Expand All @@ -63,6 +63,15 @@ def __unicode__(self):
def get_absolute_url(self):
return reverse('class', kwargs={'pk': self.id})

def add_students(self, *objs):
for obj in objs:
try:
c = Class.objects.get(course=self.course, students=obj)
c.students.remove(obj)
except Class.DoesNotExist:
pass
self.students.add(obj)

def remove_students(self, *objs):
for obj in objs:
self.students.remove(obj)
Expand Down Expand Up @@ -497,7 +506,7 @@ def new_message(self, course, subject, message, to=[]):
professor=self)

def get_current_user_classes(self):
return Class.objects.filter(course=self.course, assistant=self.user)
return Class.objects.filter(course=self.course, assistants=self.user)


class CourseAuthor(models.Model):
Expand Down Expand Up @@ -806,6 +815,8 @@ class CertificateTemplate(models.Model):
upload_to=hash_name('logo', 'organization_name'))
base_logo = models.ImageField(_('Logo'), null=True, blank=True,
upload_to=hash_name('base_logo', 'organization_name'))
signature = models.ImageField(_('Signature'), null=True, blank=True,
upload_to=hash_name('signature', 'organization_name'))
organization_name = models.CharField(_('Name'), max_length=255, blank=True, null=True)

class Meta:
Expand All @@ -829,6 +840,12 @@ def base_logo_url(self):
return self.base_logo.url
return ''

@property
def signature_url(self):
if self.signature:
return self.signature.url
return ''


class IfCertificateTemplate(CertificateTemplate):
pronatec_logo = models.BooleanField(_('Pronatec'), default=False)
Expand Down
Loading