Commit 1528c249 authored by Bruno Martin's avatar Bruno Martin
Browse files

add legacy stuff

parent 36adede4
# Generated by Django 2.1.7 on 2019-03-07 23:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='user',
name='accepted_terms',
field=models.BooleanField(default=False, verbose_name='Accepted terms and condition'),
),
migrations.AddField(
model_name='user',
name='cpf',
field=models.CharField(blank=True, max_length=11, null=True, unique=True),
),
migrations.AddField(
model_name='user',
name='institution',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='user',
name='site',
field=models.URLField(blank=True, verbose_name='Site'),
),
migrations.AlterField(
model_name='user',
name='date_joined',
field=models.DateTimeField(auto_now_add=True, verbose_name='Date joined'),
),
migrations.AlterField(
model_name='user',
name='last_name',
field=models.CharField(blank=True, max_length=150, verbose_name='last name'),
),
]
......@@ -90,9 +90,31 @@ class User(AbstractUser):
max_length=255
)
# Legacy stuff
cpf = models.CharField(max_length=11, blank=True, null=True, unique=True)
institution = models.CharField(max_length=255, blank=True, null=True)
date_joined = models.DateTimeField(_('Date joined'), auto_now_add=True)
# picture = models.ImageField(_("Picture"), upload_to=hash_name('user-pictures', 'username'), blank=True)
site = models.URLField(_('Site'), blank=True)
accepted_terms = models.BooleanField(_('Accepted terms and condition'), default=False)
def __str__(self):
return self.username
# def __str__(self):
# if self.first_name or self.last_name:
# return self.get_full_name()
# return self.email
# def get_full_name(self):
# full_name = '%s %s' % (self.first_name, self.last_name)
# return full_name.strip()
# def get_short_name(self):
# return self.first_name
@property
def image_url(self):
if self.image:
......@@ -104,3 +126,59 @@ class User(AbstractUser):
if picture:
return picture
return "https://gravatar.com/avatar/{}?s=40&d=mm".format(hashlib.md5(self.email.encode('utf-8')).hexdigest())
def save(self, *args, **kwargs):
is_new = self.pk is None
super(AbstractTimtecUser, self).save(*args, **kwargs)
if is_new and settings.REGISTRATION_DEFAULT_GROUP_NAME:
try:
self.groups.add(Group.objects.get(name=settings.REGISTRATION_DEFAULT_GROUP_NAME))
self.save()
except Group.DoesNotExist:
pass
# def get_picture_url(self):
# if not self.picture:
# location = "/%s/%s" % (settings.STATIC_URL, 'img/avatar-default.png')
# else:
# location = "/%s/%s" % (settings.MEDIA_URL, self.picture)
# return re.sub('/+', '/', location)
# def get_picture_thumb_url(self,
# options={'size': (150, 150), 'crop': 'scale'}):
# try:
# return get_thumbnailer(self.picture).get_thumbnail(options).url
# except InvalidImageFormatError as e:
# return str(settings.STATIC_URL + 'img/avatar-default.png')
def email_user(self, subject, message, from_email=None):
send_mail(subject, message, from_email, [self.email])
def get_user_type(self):
if self.is_superuser:
return "superuser"
elif self.groups.filter(name='professors').count():
return "professors"
elif self.groups.filter(name='students').count():
return "students"
return "unidentified"
@property
def is_profile_filled(self):
from timtec.settings import ACCOUNT_REQUIRED_FIELDS as fields
for field in fields:
try:
f = getattr(self, field)
if not f:
return False
except AttributeError:
raise AttributeError(_('Invalid attribute: %s' % field))
return True
def get_certificates(self):
from core.models import CourseCertification
return CourseCertification.objects.filter(course_student__user=self)
\ No newline at end of file
......@@ -37,16 +37,13 @@ DJANGO_APPS = [
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# needed for allauth templates
'crispy_forms',
# Useful template tags:
# 'django.contrib.humanize',
'django.contrib.flatpages',
# Admin
'django.contrib.admin',
]
THIRD_PARTY_APPS = [
# needed for allauth templates
'crispy_forms',
'allauth', # registration
'allauth.account', # registration
'allauth.socialaccount', # registration
......@@ -58,19 +55,23 @@ THIRD_PARTY_APPS = [
'rest_auth',
'rest_auth.registration',
'corsheaders',
# legacy apps deps, refactor one day...
'localflavor',
]
# Apps specific for this project go here.
LOCAL_APPS = [
# custom users app
'base_django_project.users.apps.UsersConfig',
# 'ext-apps.django-courses.apps.DjangoCoursesConfig',
# 'ext-apps.django-courses-certification.apps.DjangoCoursesCertificationConfig',
# 'ext-apps.django-courses-gamification.apps.DjangoCoursesGamificationConfig',
# 'ext-apps.django-courses-learning-objects.apps.DjangoCoursesLearningObjectsConfig',
# 'ext-apps.django-courses-legacy.apps.DjangoCoursesLegacyConfig',
# 'ext-apps.django-courses-notes.apps.DjangoCoursesNotesConfig',
# 'ext-apps.django-courses-reports.apps.DjangoCoursesReportsConfig',
'courses.apps.CoursesConfig',
'courses_learning_objects.apps.CoursesLearningObjectsConfig',
'courses_certification.apps.CoursesCertificationConfig',
'courses_gamification.apps.CoursesGamificationConfig',
'courses_reports.apps.CoursesReportsConfig',
'courses_legacy.apps.CoursesLegacyConfig',
'courses_legacy.administration',
'discussion',
# 'courses_notes.apps.CoursesNotesConfig',
]
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
......@@ -278,7 +279,9 @@ REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticatedOrReadOnly',
),
'PAGE_SIZE': 20,
'DEFAULT_FILTER_BACKENDS': (
'django_filters.rest_framework.DjangoFilterBackend',
),
}
REST_AUTH_REGISTER_SERIALIZERS = {
......@@ -339,3 +342,25 @@ CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = (
'example.com',
)
# Legacy Defaults, review everything
# ------------------------------------------------------------------------------
TERMS_ACCEPTANCE_REQUIRED = True
REGISTRATION_DEFAULT_GROUP_NAME = 'students'
# ACCOUNT_ADAPTER = "accounts.adapter.TimtecAdapter"
# ACCOUNT_UNIQUE_EMAIL = True
# ACCOUNT_AUTHENTICATION_METHOD = "username_email"
# ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 7
# ACCOUNT_EMAIL_REQUIRED = True
# ACCOUNT_EMAIL_VERIFICATION = 'optional'
# ACCOUNT_EMAIL_SUBJECT_PREFIX = "[timtec] "
# ACCOUNT_SIGNUP_FORM_CLASS = 'accounts.forms.SignupForm'
ACCOUNT_REQUIRED_FIELDS = ('first_name', 'last_name', )
# SOCIALACCOUNT_EMAIL_VERIFICATION = False
CERTIFICATE_SIZE = (862, 596)
PHANTOMJS_PATH = ROOT_DIR.path('node_modules/phantomjs-prebuilt/bin/phantomjs')
YOUTUBE_API_KEY = ''
\ No newline at end of file
......@@ -10,6 +10,8 @@ from base_django_project.users.views import FacebookLogin, TwitterLogin, \
FacebookConnect, TwitterRequestToken, TwitterAccessToken, TwitterConnect
urlpatterns = [
url(r'^legacy/', include('courses_legacy.urls', namespace='courses_legacy')),
# Django Admin, use {% url 'admin:index' %}
url(settings.ADMIN_URL, admin.site.urls),
......
......@@ -51,3 +51,9 @@ markdown==3.0.1
django-crispy-forms==1.7.2
django-autoslug==1.9.4
# The above requiriments are for the django-courses-legacy package
django-braces==1.13.0
django-localflavor==2.1
# django-oauth-toolkit
......@@ -8,6 +8,7 @@
-e ext-apps/django-courses-legacy
-e ext-apps/django-courses-notes
-e ext-apps/django-courses-reports
-e ext-apps/django-discussion
coverage==4.5
django-coverage-plugin==1.6.0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment