diff --git a/amadeus/static/css/base/amadeus.css b/amadeus/static/css/base/amadeus.css index 08835c6..194fd7c 100755 --- a/amadeus/static/css/base/amadeus.css +++ b/amadeus/static/css/base/amadeus.css @@ -968,4 +968,13 @@ li.item .notify_badge { .mural .post_make .post-field h4 { cursor: text; font-style: italic; +} + +.post_action i { + font-size: 45px; +} + +.post-button { + padding-right: inherit !important; + padding-left: inherit !important; } \ No newline at end of file diff --git a/amadeus/static/css/themes/green.css b/amadeus/static/css/themes/green.css index e1162c1..4774d52 100644 --- a/amadeus/static/css/themes/green.css +++ b/amadeus/static/css/themes/green.css @@ -504,6 +504,10 @@ a.add-row { color: #CCCCCC; } +.post_action i { + color: #1d8fe0; +} + @media(max-width: 768px) { .navbar .navbar-nav .dropdown .dropdown-menu li > a { color: #333333 !important; diff --git a/mural/forms.py b/mural/forms.py index e69de29..7bfedde 100644 --- a/mural/forms.py +++ b/mural/forms.py @@ -0,0 +1,41 @@ +# coding=utf-8 +from django import forms +from django.utils.translation import ugettext_lazy as _ +from django.utils.html import strip_tags + +from .models import GeneralPost + +class Validation(forms.ModelForm): + MAX_UPLOAD_SIZE = 5*1024*1024 + + def clean_post(self): + post = self.cleaned_data.get('post', '') + cleaned_post = strip_tags(post) + + if cleaned_post == '': + self._errors['post'] = [_('This field is required.')] + + return ValueError + + return post + + def clean_image(self): + image = self.cleaned_data.get('image', False) + + if image: + if hasattr(image, '_size'): + if image._size > self.MAX_UPLOAD_SIZE: + self._errors['image'] = [_("The image is too large. It should have less than 5MB.")] + + return ValueError + + return image + +class GeneralPostForm(Validation): + class Meta: + model = GeneralPost + fields = ['action', 'post', 'image'] + widgets = { + 'action': forms.RadioSelect, + 'post': forms.Textarea + } \ No newline at end of file diff --git a/mural/migrations/0003_auto_20170204_1625.py b/mural/migrations/0003_auto_20170204_1625.py new file mode 100644 index 0000000..5dc3f85 --- /dev/null +++ b/mural/migrations/0003_auto_20170204_1625.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-02-04 19:25 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mural', '0002_muralvisualizations'), + ] + + operations = [ + migrations.AlterField( + model_name='mural', + name='action', + field=models.CharField(choices=[('comment', 'Comment'), ('help', 'Ask for Help')], max_length=100, verbose_name='Action'), + ), + ] diff --git a/mural/models.py b/mural/models.py index 716a77d..59e7037 100644 --- a/mural/models.py +++ b/mural/models.py @@ -16,7 +16,7 @@ def validate_img_extension(value): raise ValidationError(_('File not supported.')) class Mural(KnowsChild): - action = models.CharField(_('Action'), max_length = 100, choices = (("comment", _("Comment")), ("help", _("Ask for Help"))), blank = True) + action = models.CharField(_('Action'), max_length = 100, default = "comment", choices = (("comment", _("Comment")), ("help", _("Ask for Help")))) post = models.TextField(_('Post'), blank = True) image = models.ImageField(verbose_name = _('Image'), null=True, blank = True, upload_to = 'posts/', validators = [validate_img_extension]) user = models.ForeignKey(User, verbose_name = _('User'), related_name = "post_user", null = True) diff --git a/mural/templates/mural/_form.html b/mural/templates/mural/_form.html new file mode 100644 index 0000000..3cf70d0 --- /dev/null +++ b/mural/templates/mural/_form.html @@ -0,0 +1,142 @@ +{% load static i18n %} +{% load widget_tweaks %} + + + + diff --git a/mural/templates/mural/_view.html b/mural/templates/mural/_view.html new file mode 100644 index 0000000..441d693 --- /dev/null +++ b/mural/templates/mural/_view.html @@ -0,0 +1,5 @@ +
+
+ {{ post.user }} +
+
\ No newline at end of file diff --git a/mural/templates/mural/list.html b/mural/templates/mural/list.html index 46fcb54..5834b75 100644 --- a/mural/templates/mural/list.html +++ b/mural/templates/mural/list.html @@ -29,21 +29,72 @@
-

{% trans 'Wish to make a new post?' %}

+

{% trans 'Wish to make a new post?' %}

- {% if posts.count > 0 %} - {% else %} -
- -

{% trans 'There are no posts in this mural yet.' %}

-
- {% endif %} +
+ {% for post in posts %} + {% include 'mural/_view.html' %} + {% endfor %} +
+
0 %} style="display:none" {% endif %}> + +

{% trans 'There are no posts in this mural yet.' %}

+
+ + + + {% endblock %} \ No newline at end of file diff --git a/mural/urls.py b/mural/urls.py index b5368e1..af3fb15 100644 --- a/mural/urls.py +++ b/mural/urls.py @@ -3,4 +3,6 @@ from . import views urlpatterns = [ url(r'^$', views.GeneralIndex.as_view(), name='manage_general'), + url(r'^create_gen/$', views.GeneralCreate.as_view(), name='create_general'), + url(r'^render_post/([\w_-]+)/$', views.render_gen_post, name='render_post_general'), ] \ No newline at end of file diff --git a/mural/views.py b/mural/views.py index c77e74f..489a511 100644 --- a/mural/views.py +++ b/mural/views.py @@ -2,12 +2,16 @@ from django.shortcuts import get_object_or_404, redirect, render from django.views import generic from django.contrib import messages from django.http import JsonResponse +from django.template.loader import render_to_string from django.core.urlresolvers import reverse, reverse_lazy from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.mixins import LoginRequiredMixin from django.db.models import Q, Count +from users.models import User + from .models import GeneralPost, CategoryPost, SubjectPost, MuralVisualizations +from .forms import GeneralPostForm class GeneralIndex(LoginRequiredMixin, generic.ListView): login_url = reverse_lazy("users:login") @@ -39,3 +43,53 @@ class GeneralIndex(LoginRequiredMixin, generic.ListView): context['mural_menu_active'] = 'subjects_menu_active' return context + +class GeneralCreate(LoginRequiredMixin, generic.edit.CreateView): + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + template_name = 'mural/_form.html' + form_class = GeneralPostForm + + def form_invalid(self, form): + context = super(GeneralCreate, self).form_invalid(form) + context.status_code = 400 + + return context + + def form_valid(self, form): + self.object = form.save(commit = False) + + self.object.user = self.request.user + + self.object.save() + + users = User.objects.all().exclude(id = self.request.user.id) + entries = [] + + for user in users: + entries.append(MuralVisualizations(viewed = False, user = user, post = self.object)) + + MuralVisualizations.objects.bulk_create(entries) + + return super(GeneralCreate, self).form_valid(form) + + def get_context_data(self, *args, **kwargs): + context = super(GeneralCreate, self).get_context_data(*args, **kwargs) + + context['form_url'] = reverse_lazy("mural:create_general") + + return context + + def get_success_url(self): + return reverse_lazy('mural:render_post_general', args = (self.object.id, )) + +def render_gen_post(request, post): + post = get_object_or_404(GeneralPost, id = post) + + context = {} + context['post'] = post + + html = render_to_string("mural/_view.html", context, request) + + return JsonResponse({'message': _('Your post was published successfully!'), 'view': html}) -- libgit2 0.21.2