Skip to content

Commit

Permalink
Migrate to django-dropbox 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maxicecilia committed May 25, 2017
1 parent 0131624 commit 898cd36
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 56 deletions.
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
-e git://github.com/maxicecilia/[email protected]#egg=django_dropbox
-e git://github.com/maxicecilia/django_site_news.git@7d320097cedec159e396ad3d223b3919d6449c3e#egg=django_site_news-0.1.1
-e git://github.com/maxicecilia/[email protected]#egg=django_contact_us
argparse==1.2.1
django-bootstrap3==5.1.1
django-dropbox==0.0.2
django-registration-redux==1.1
django-sitesutils==0.1.2
django-sitetree==1.2.1
django-tinymce==1.5.3
Django==1.7.3
psycopg2==2.5.4
dropbox==2.2.0
ipdb==0.8
ipython==2.3.1
Pillow==2.7.0
Expand Down
6 changes: 3 additions & 3 deletions simple_classroom/apps/bibliography/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from simple_classroom.apps.downloads import STORAGE
from simple_classroom.apps.core.models import DropboxStorageMixin
from simple_classroom.apps.classroom.models import Subject


Expand All @@ -19,12 +18,13 @@ def __unicode__(self):
return u'{}'.format(self.name)


class Book(models.Model, DropboxStorageMixin):
class Book(models.Model):
author = models.CharField(_(u'Autor'), max_length=255, null=False, blank=False)
category = models.ForeignKey(GroupCategory)
edition = models.CharField(_(u'Edición'), max_length=255, null=False, blank=False)
editorial = models.CharField(_(u'Editorial'), max_length=255, null=False, blank=False)
cover_image = models.ImageField(_(u'Imagen'), upload_to='books', storage=STORAGE, null=True, blank=True)
cover_image = models.ImageField(_(u'Imagen'), upload_to='books', storage=STORAGE,
null=True, blank=True)
subject = models.ForeignKey(Subject)
title = models.CharField(_(u'Titulo'), max_length=255, null=False, blank=False)

Expand Down
26 changes: 16 additions & 10 deletions simple_classroom/apps/classroom/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from django.utils.translation import ugettext as _
from ordered_model.models import OrderedModel
from tinymce.models import HTMLField
from simple_classroom.apps.core.models import DropboxStorageMixin
from simple_classroom.apps.downloads import STORAGE
from .managers import AssignmentManager, DictationManager, EnrolledManager

Expand Down Expand Up @@ -59,12 +58,17 @@ class Dictation(models.Model):
subject = models.ForeignKey(Subject)
date_from = models.DateField(_('Desde'), null=True, blank=True)
date_to = models.DateField(_('Hasta'), null=True, blank=True)
semester = models.IntegerField(_('Semestre'), choices=SEMESTER_CHOICES, default=1, null=False, blank=False)
semester = models.IntegerField(_('Semestre'), choices=SEMESTER_CHOICES, default=1,
null=False, blank=False)
year = models.IntegerField(_(u'Año'), null=False, blank=False)
is_registration_open = models.BooleanField(_(u'Registración abierta'), default=True, null=False, blank=False)
dictated_practice_hours = models.PositiveIntegerField(_(u'Horas dictadas de práctica'), default=0, null=False, blank=False)
dictated_theory_hours = models.PositiveIntegerField(_(u'Horas dictadas de teoría'), default=0, null=False, blank=False)
last_modification_date = models.DateTimeField(_(u'Fecha de última modificación'), null=True, blank=True)
is_registration_open = models.BooleanField(_(u'Registración abierta'), default=True,
null=False, blank=False)
dictated_practice_hours = models.PositiveIntegerField(_(u'Horas dictadas de práctica'),
default=0, null=False, blank=False)
dictated_theory_hours = models.PositiveIntegerField(_(u'Horas dictadas de teoría'),
default=0, null=False, blank=False)
last_modification_date = models.DateTimeField(_(u'Fecha de última modificación'),
null=True, blank=True)

objects = DictationManager()

Expand All @@ -88,9 +92,10 @@ def save(self, *args, **kwargs):
super(Dictation, self).save(*args, **kwargs)


class TeacherProfile(OrderedModel, DropboxStorageMixin):
class TeacherProfile(OrderedModel):
abstract = HTMLField(null=True, blank=True)
avatar = models.ImageField(_(u'Avatar'), upload_to='avatar', storage=STORAGE, null=True, blank=True)
avatar = models.ImageField(_(u'Avatar'), upload_to='avatar', storage=STORAGE,
null=True, blank=True)
dictation = models.ManyToManyField(Dictation, verbose_name=_(u'Dictado'))
user = models.OneToOneField(User, verbose_name=_(u'Usuario'))

Expand Down Expand Up @@ -160,7 +165,8 @@ class Assignment(OrderedModel):
_(u'Corregido'), blank=False, null=False, default=False,
help_text=_(u'Tildar para indicar que la evaluación ya fue corregida y las notas están disponibles.'))
score_date = models.DateTimeField(_(u'Fecha de Notas'), blank=True, null=True)
assignment_type = models.IntegerField(_('Tipo'), choices=ASSIGNMENT_TYPES, default=4, null=False, blank=False)
assignment_type = models.IntegerField(_('Tipo'), choices=ASSIGNMENT_TYPES, default=4,
null=False, blank=False)
objects = AssignmentManager()

class Meta(OrderedModel.Meta):
Expand Down Expand Up @@ -229,4 +235,4 @@ def get_average(self):
average = self.assignment.score_set.exclude(value=-1).aggregate(Avg('value'))['value__avg']
return '%.2f' % average
except:
return ''
return ''
13 changes: 0 additions & 13 deletions simple_classroom/apps/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,3 @@ class ExtendedSite(models.Model):

def __unicode__(self):
return u'Extended info for {0}'.format(self.site.name)


class DropboxStorageMixin(object):
"""Simple mixin to add a method to retrieve the public URL for a dropbox stored image."""

def get_public_url(self, url):
return url.replace('www.dropbox', 'dl.dropboxusercontent')

def get_image_url(self):
try:
return self.get_public_url(self.default_image.url)
except Exception:
return ''
13 changes: 3 additions & 10 deletions simple_classroom/apps/downloads/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.db import models
from django.utils.translation import ugettext as _
from simple_classroom.apps.classroom.models import Assignment
from simple_classroom.apps.core.models import DropboxStorageMixin
from simple_classroom.apps.downloads import STORAGE


Expand All @@ -18,7 +17,7 @@ def get_upload_path(instance, filename):
instance.data.name)


class Download(models.Model, DropboxStorageMixin):
class Download(models.Model):
''' TODO: Change this name to a more specific one.'''
assignment = models.ForeignKey(Assignment)
title = models.CharField(_(u'Título'), max_length=255, blank=False, null=False)
Expand All @@ -34,13 +33,7 @@ def __unicode__(self):
return u'{}'.format(self.title)

def get_data_url(self):
try:
return self.get_public_url(self.data.url)
except:
try:
return self.data.url
except:
return ''
return self.data.url

def get_icon_path(self):
if self.title.lower() == 'evaluativo':
Expand Down Expand Up @@ -68,7 +61,7 @@ def __unicode__(self):
return u'{}'.format(self.name)


class SiteDownload(models.Model, DropboxStorageMixin):
class SiteDownload(models.Model):
''' All downloads related to the site/subject'''
SLIDE = _(u'Diapositivas')
RESOURCE = _(u'Recursos para el alumno')
Expand Down
7 changes: 1 addition & 6 deletions simple_classroom/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,15 @@
os.path.join(BASE_DIR, 'simple_classroom/static'),
)

ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value.
ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window
REGISTRATION_AUTO_LOGIN = False # Automatically log the user in.
REGISTRATION_OPEN = True

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'


# Dropbox config
DROPBOX_CONSUMER_KEY = ''
DROPBOX_CONSUMER_SECRET = ''

# Token for simple_classroom.
DROPBOX_ACCESS_TOKEN = ''
DROPBOX_ACCESS_TOKEN_SECRET = ''

# ReCaptcha Site and Secret keys.
RECAPTCHA_PRIVATE_KEY = ''
Expand Down
4 changes: 2 additions & 2 deletions simple_classroom/templates/accounts/teacher_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ <h2>{{profile.user.last_name|capfirst}}, {{profile.user.first_name|capfirst}}</h
<div class="clearfix">
<div class="col-lg-3" style="margin-bottom: 20px;">
{% if profile.avatar %}
<img class="img-responsive img-rounded pull-left" src="{{ profile.get_image_url }}" alt="avatar" />
<img class="img-responsive img-rounded pull-left" src="{{ profile.default_image.url }}" alt="avatar" />
{% else %}
<img class="img-responsive img-rounded pull-left" src="{% static "img/default_avatar.jpg" %}" alt="default_avatar"/>
{% endif %}
</div>
<div class="well well-lg col-lg-8">
{{ profile.abstract|safe }}
{{ profile.abstract|safe }}
</div>
</div>
<div class="panel panel-default">
Expand Down
2 changes: 1 addition & 1 deletion simple_classroom/templates/bibliography/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h3>{{object.category.name}}</h3>
<div class="clearfix">
<div class="col-lg-3">
{% if book.cover_image %}
<img class="img-responsive img-rounded pull-left" src="{{ book.get_image_url }}" alt="cover" />
<img class="img-responsive img-rounded pull-left" src="{{ book.default_image.url }}" alt="cover" />
{% endif %}
</div>
<div class="well well-lg col-lg-8">
Expand Down
6 changes: 3 additions & 3 deletions simple_classroom/templates/classroom/teachers.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ <h2>Docentes de {{dictation}}</h2>
{% if forloop.counter|divisibleby:2 %}
<div class="col-lg-2">
{% if teacher.avatar %}
<img class="img-responsive img-rounded pull-left" src="{{ teacher.get_image_url }}" alt="avatar" />
<img class="img-responsive img-rounded pull-left" src="{{ teacher.default_image.url }}" alt="avatar" />
{% else %}
<img class="img-responsive img-rounded pull-left" src="{% static "img/default_avatar.jpg" %}" alt="default_avatar"/>
{% endif %}
</div>
{% endif %}
<div class="well well-lg col-lg-10">
<h1>{{ teacher.user.get_full_name }} <small><a href="mailto:{{ teacher.user.email }}">{{ teacher.user.email }}</a></small></h1>
{{ teacher.abstract|safe }}
{{ teacher.abstract|safe }}
</div>
{% if not forloop.counter|divisibleby:2 %}
<div class="col-lg-2">
{% if teacher.avatar %}
<img class="img-responsive img-rounded pull-left" src="{{ teacher.get_image_url }}" alt="avatar" />
<img class="img-responsive img-rounded pull-left" src="{{ teacher.default_image.url }}" alt="avatar" />
{% else %}
<img class="img-responsive img-rounded pull-left" src="{% static "img/default_avatar.jpg" %}" alt="default_avatar"/>
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions simple_classroom/templates/downloads/per_category.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ <h2>{{object.category.name}}</h2>
{% for download in object.downloads %}
<tr>
<td>{{ download.title|default:"-" }}</td>
<td>{% if download.get_image_url %}<a href="{{ download.get_image_url }}">Descarga</a>{% endif %}</td>
<td>{% if download.default_image.url %}<a href="{{ download.default_image.url }}">Descarga</a>{% endif %}</td>
</tr>
{% endfor %}
</table>
{% endfor %}
{% endcache %}
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion simple_classroom/templates/downloads/per_dictation.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ <h1>{{ dictation }}<br/></h1>
$('#second-last-average-days').html(get_average_for_row(12));
});
</script>
{% endblock %}
{% endblock %}
6 changes: 3 additions & 3 deletions simple_classroom/templates/downloads/per_site.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="page-header">
<h1>{{ download_type }}</h1>
</div>

<table class="table table-striped table-bordered table-condensed">
<thead>
<th>Titulo</th>
Expand All @@ -13,8 +13,8 @@ <h1>{{ download_type }}</h1>
{% for object in site_downloads %}
<tr>
<td>{{ object.title|default:"-" }}</td>
<td>{% if object.get_image_url %}<a href="{{ object.get_image_url }}">Descarga</a>{% endif %}</td>
<td>{% if object.default_image.url %}<a href="{{ object.default_image.url }}">Descarga</a>{% endif %}</td>
</tr>
{% endfor %}
</table>
{% endblock %}
{% endblock %}

0 comments on commit 898cd36

Please sign in to comment.