diff --git a/amadeus/static/css/base/amadeus.css b/amadeus/static/css/base/amadeus.css index 4b7fefe..d89efd3 100755 --- a/amadeus/static/css/base/amadeus.css +++ b/amadeus/static/css/base/amadeus.css @@ -767,6 +767,8 @@ a.add-row { padding: 10px 15px; margin-bottom: -1px; border-width: 1px !important; + overflow: inherit; + cursor: pointer; } .resource_list > .list-group-item:last-child { @@ -777,4 +779,13 @@ a.add-row { .resource_list .list-group-item .list-group-item-heading { font-weight: 500; +} + +.resource_list .btn-group { + display: inline; + margin: 0px; +} + +.resource_list a:hover, .resource_list a:focus { + text-decoration: none; } \ No newline at end of file diff --git a/amadeus/static/css/themes/green.css b/amadeus/static/css/themes/green.css index 8ace8bf..0f56827 100644 --- a/amadeus/static/css/themes/green.css +++ b/amadeus/static/css/themes/green.css @@ -361,10 +361,22 @@ a.add-row { border: 1px solid #ddd; } +.resource_list > .list-group-item:hover { + background: #F5F5F5; +} + .resource_list > .list-group-item:last-child { border-bottom: 1px solid #ddd !important; } +.resource_list .category-card-items i { + color: #CCCCCC; +} + +.resource_list a { + color: inherit; +} + @media(max-width: 768px) { .navbar .navbar-nav .dropdown .dropdown-menu li > a { color: #333333 !important; diff --git a/amadeus/static/js/topics.js b/amadeus/static/js/topics.js index deede6f..e033d28 100644 --- a/amadeus/static/js/topics.js +++ b/amadeus/static/js/topics.js @@ -31,7 +31,7 @@ $('.collapse').on('hide.bs.collapse', function (e) { $("#topics-accordion").sortable({ delay: 100, distance: 5, - handle: 'i.fa-arrows', + handle: 'i.move_topic', update: function( event, ui ) { var cont = 1; var data = []; diff --git a/topics/decorators.py b/topics/decorators.py new file mode 100644 index 0000000..aa4159b --- /dev/null +++ b/topics/decorators.py @@ -0,0 +1,16 @@ +def always_as_child(fn): + """ + Tries to run child model method if relevant + should be applied on KnowsChild child class + """ + def f(self, *args, **kwargs): + child_self = self.as_child() + f_parent = getattr(self.__class__, fn.__name__) + f_child = getattr(child_self.__class__, fn.__name__) + + if f_parent != f_child: + return f_child(child_self, *args, **kwargs) + else: + return fn(self, *args, **kwargs) + + return f \ No newline at end of file diff --git a/topics/migrations/0006_resource__my_subclass.py b/topics/migrations/0006_resource__my_subclass.py new file mode 100644 index 0000000..59db12b --- /dev/null +++ b/topics/migrations/0006_resource__my_subclass.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-01-23 21:18 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topics', '0005_resource'), + ] + + operations = [ + migrations.AddField( + model_name='resource', + name='_my_subclass', + field=models.CharField(default='webpage', max_length=200), + preserve_default=False, + ), + ] diff --git a/topics/migrations/0007_auto_20170123_1911.py b/topics/migrations/0007_auto_20170123_1911.py new file mode 100644 index 0000000..64d7601 --- /dev/null +++ b/topics/migrations/0007_auto_20170123_1911.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-01-23 22:11 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('topics', '0006_resource__my_subclass'), + ] + + operations = [ + migrations.AlterModelOptions( + name='resource', + options={'ordering': ['order'], 'verbose_name': 'Resource', 'verbose_name_plural': 'Resources'}, + ), + ] diff --git a/topics/models.py b/topics/models.py index dee5f03..c59c0dd 100644 --- a/topics/models.py +++ b/topics/models.py @@ -6,6 +6,8 @@ from subjects.models import Subject, Tag from students_group.models import StudentsGroup from users.models import User +from .decorators import always_as_child + class Topic(models.Model): name = models.CharField(_('Name'), max_length = 200) slug = AutoSlugField(_("Slug"), populate_from = 'name', unique = True) @@ -25,7 +27,27 @@ class Topic(models.Model): def __str__(self): return self.name -class Resource(models.Model): +""" + Abstract model to make easier to know which kind of Resource we are dealing with +""" +class KnowsChild(models.Model): + # Make a place to store the class name of the child + _my_subclass = models.CharField(max_length=200) + + class Meta: + abstract = True + + def as_child(self): + return getattr(self, self._my_subclass) + + def save(self, *args, **kwargs): + # save what kind we are. + if not self._my_subclass: + self._my_subclass = self.__class__.__name__.lower() + + super(KnowsChild, self).save(*args, **kwargs) + +class Resource(KnowsChild): name = models.CharField(_('Name'), max_length = 200) slug = AutoSlugField(_("Slug"), populate_from = 'name', unique = True) brief_description = models.TextField(_('Brief Description'), blank = True) @@ -43,6 +65,15 @@ class Resource(models.Model): class Meta: verbose_name = _('Resource') verbose_name_plural = _('Resources') + ordering = ['order'] def __str__(self): return self.name + + """ + Method to get the appropriated view link + Must override in the child models + """ + @always_as_child + def access_link(self): + pass diff --git a/topics/templates/topics/list.html b/topics/templates/topics/list.html index 08a67bb..29c5cfb 100644 --- a/topics/templates/topics/list.html +++ b/topics/templates/topics/list.html @@ -28,7 +28,7 @@