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 @@
  • {% trans 'Edit' %}
  •  {% trans 'Remove' %}
  • - + {% endif %} diff --git a/topics/urls.py b/topics/urls.py index 88bff2c..2058186 100644 --- a/topics/urls.py +++ b/topics/urls.py @@ -8,4 +8,5 @@ urlpatterns = [ url(r'^update/(?P[\w_-]+)/(?P[\w_-]+)/$', views.UpdateView.as_view(), name = 'update'), url(r'^delete/(?P[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'), url(r'^update_order/$', views.update_order, name = 'update_order'), + url(r'^update_resource_order/$', views.update_resource_order, name = 'update_resource_order'), ] diff --git a/topics/views.py b/topics/views.py index 2c69a99..cf2defb 100644 --- a/topics/views.py +++ b/topics/views.py @@ -12,7 +12,7 @@ from amadeus.permissions import has_subject_permissions from subjects.models import Subject -from .models import Topic +from .models import Topic, Resource from .forms import TopicForm class CreateView(LoginRequiredMixin, generic.edit.CreateView): @@ -149,4 +149,19 @@ def update_order(request): return JsonResponse({'message': 'ok'}) + return JsonResponse({'message': 'No data received'}) + +def update_resource_order(request): + data = request.GET.get('data', None) + + if not data is None: + data = json.loads(data) + + for t_data in data: + resource = get_object_or_404(Resource, id = t_data['resource_id']) + resource.order = t_data['resource_order'] + resource.save() + + return JsonResponse({'message': 'ok'}) + return JsonResponse({'message': 'No data received'}) \ No newline at end of file diff --git a/webpage/models.py b/webpage/models.py index b3bdf3d..07aaccf 100644 --- a/webpage/models.py +++ b/webpage/models.py @@ -12,4 +12,10 @@ class Webpage(Resource): verbose_name_plural = _('WebPages') def __str__(self): - return self.name \ No newline at end of file + return self.name + + def access_link(self): + if self.show_window: + return 'webpages:window_view' + + return 'webpages:view' diff --git a/webpage/templates/webpages/list.html b/webpage/templates/webpages/list.html index 259b84c..c190406 100644 --- a/webpage/templates/webpages/list.html +++ b/webpage/templates/webpages/list.html @@ -1,21 +1,29 @@ {% load static i18n pagination permissions_tags %} {% load django_bootstrap_breadcrumbs %} -
    +
    {% for resource in topic.resource_topic.all %}
    + + + +

    - {{ resource }} + + {{ resource }} +


    {% autoescape off %} @@ -23,4 +31,58 @@ {% endautoescape %}
    {% endfor %} -
    \ No newline at end of file +
    + \ No newline at end of file -- libgit2 0.21.2