diff --git a/amadeus/static/css/fonts/glyphicons-halflings-regular.eot b/amadeus/static/css/fonts/glyphicons-halflings-regular.eot new file mode 100755 index 0000000..b93a495 Binary files /dev/null and b/amadeus/static/css/fonts/glyphicons-halflings-regular.eot differ diff --git a/amadeus/static/css/fonts/glyphicons-halflings-regular.svg b/amadeus/static/css/fonts/glyphicons-halflings-regular.svg new file mode 100755 index 0000000..8376c0f --- /dev/null +++ b/amadeus/static/css/fonts/glyphicons-halflings-regular.svg @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/amadeus/static/css/fonts/glyphicons-halflings-regular.ttf b/amadeus/static/css/fonts/glyphicons-halflings-regular.ttf new file mode 100755 index 0000000..1413fc6 Binary files /dev/null and b/amadeus/static/css/fonts/glyphicons-halflings-regular.ttf differ diff --git a/amadeus/static/css/fonts/glyphicons-halflings-regular.woff b/amadeus/static/css/fonts/glyphicons-halflings-regular.woff new file mode 100755 index 0000000..9e61285 Binary files /dev/null and b/amadeus/static/css/fonts/glyphicons-halflings-regular.woff differ diff --git a/amadeus/static/css/fonts/glyphicons-halflings-regular.woff2 b/amadeus/static/css/fonts/glyphicons-halflings-regular.woff2 new file mode 100755 index 0000000..64539b5 Binary files /dev/null and b/amadeus/static/css/fonts/glyphicons-halflings-regular.woff2 differ diff --git a/categories/models.py b/categories/models.py index 18d9d7c..95d160a 100644 --- a/categories/models.py +++ b/categories/models.py @@ -7,7 +7,7 @@ class Category(models.Model): """Represents a Course """ category_father = models.ForeignKey('Category', related_name =_("category_parent"), on_delete = models.CASCADE) - name = models.CharField(_("Name"), max_length = 100) + name = models.CharField(_("Name"), max_length = 100, blank=False, null=False) slug = AutoSlugField(_("Slug"),populate_from='name',unique=True) description = models.CharField(_("description"), max_length = 300) visible = models.BooleanField(_("visible")) @@ -15,6 +15,7 @@ class Category(models.Model): create_date = models.DateTimeField(_('Creation Date'), auto_now_add = True) modified_date = models.DateTimeField(_('Modified Date'), auto_now_add = True) + REQUIRED_FIELDS = ['name',] class Meta: verbose_name = _('Category') verbose_name_plural = _('Categories') diff --git a/categories/templates/categories/create.html b/categories/templates/categories/create.html index 2fc6aa7..bbd0b09 100644 --- a/categories/templates/categories/create.html +++ b/categories/templates/categories/create.html @@ -1,10 +1,10 @@ -{% extends 'course/index.html' %} +{% extends 'categories/home.html' %} {% load widget_tweaks static i18n permission_tags django_bootstrap_breadcrumbs %} {% block breadcrumbs %} {{ block.super }} - {% breadcrumb 'Create Course' 'course:create' %} + {% breadcrumb 'Create Category' 'categories:create' %} {% endblock %} {% block content %} diff --git a/categories/tests/test_views.py b/categories/tests/test_views.py index a93c226..852cdaf 100644 --- a/categories/tests/test_views.py +++ b/categories/tests/test_views.py @@ -3,11 +3,14 @@ from users.models import User from django.contrib.auth.models import AnonymousUser from .. import views +from django.shortcuts import render + class Index_Test(TestCase): def setUp(self): self.factory = RequestFactory() self.user = User.objects.create(username="felipe", email="felipe.bormann@gmail.com", password="teste") + self.admin = User.objects.create_superuser('admin', email = 'admin@teste.com', password = 'teste') def test_index_get_auth(self): request = self.factory.get('categories/') @@ -26,4 +29,26 @@ class Index_Test(TestCase): response = views.IndexView.as_view()(request) - self.assertEqual(response.status_code, 302) #Which means it is been redirected to login page \ No newline at end of file + self.assertEqual(response.status_code, 302) #Which means it is been redirected to login page + + def test_create_category(self): + request = self.factory.get('categories/create') + request.user = self.admin + + response = views.CreateCategory.as_view()(request) + + self.assertEqual(response.status_code, 200) + + + rendered = render(response, template_name = 'categories/create.html') #try to render the page, this one gives us more errors + + + def test_create_category_unauth(self): + request = self.factory.get('categories/create') + + request.user = AnonymousUser() + + response = views.IndexView.as_view()(request) + + self.assertEqual(response.status_code, 302) #Which means it is been redirected to login page + \ No newline at end of file diff --git a/categories/urls.py b/categories/urls.py index c416d2f..d7398e6 100644 --- a/categories/urls.py +++ b/categories/urls.py @@ -3,5 +3,6 @@ from . import views urlpatterns = [ url(r'^$', views.IndexView.as_view(), name='index'), + url(r'^create/$', views.CreateCategory.as_view(), name='create'), ] \ No newline at end of file diff --git a/categories/views.py b/categories/views.py index e1f1303..401d072 100644 --- a/categories/views.py +++ b/categories/views.py @@ -61,9 +61,15 @@ class IndexView(LoginRequiredMixin, ListView): return context -class createCategory(HasRoleMixin, CreateView): +class CreateCategory(HasRoleMixin, CreateView): allowed_rules = ['system_admin'] login_url = reverse_lazy('users:login') form_class = CategoryForm template_name = 'categories/create.html' + success_url = reverse_lazy('courses:index') + + def form_valid(self, form): + self.object = form.save() + #TODO: Implement log calls + return super(createCategory, self).form_valid(form) diff --git a/users/migrations/0003_auto_20161222_1806.py b/users/migrations/0003_auto_20161222_1806.py new file mode 100644 index 0000000..dac5848 --- /dev/null +++ b/users/migrations/0003_auto_20161222_1806.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-12-22 21:06 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models +import re +import users.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0002_auto_20161220_1700'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='email', + field=models.EmailField(help_text='Your email address that will be used to access the platform', max_length=254, unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[\\w.@+-]+$', 32), 'Type a valid email. This fields should only contain letters, numbers and the characteres: @/./+/-/_ .', 'invalid')], verbose_name='Mail'), + ), + migrations.AlterField( + model_name='user', + name='image', + field=models.ImageField(blank=True, null=True, upload_to='users/', validators=[users.models.validate_img_extension], verbose_name='Photo'), + ), + migrations.AlterField( + model_name='user', + name='show_email', + field=models.IntegerField(blank=True, choices=[(1, 'Allow everyone to see my address'), (2, 'Only classmates can see my address'), (3, 'Nobody can see my address')], null=True, verbose_name='Show email?'), + ), + ] -- libgit2 0.21.2