diff --git a/VIPSWeb/settings.py b/VIPSWeb/settings.py index 6b8a5c9ded12cab5f4939e8650dc86ede4e0e162..bc667ae54363afb1ece66ce64133c15d5b344ab7 100644 --- a/VIPSWeb/settings.py +++ b/VIPSWeb/settings.py @@ -131,9 +131,11 @@ INSTALLED_APPS = ( 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', + 'tinymce', 'forecasts', 'messages', 'organisms', + 'information', 'VIPSWeb' ) diff --git a/VIPSWeb/urls.py b/VIPSWeb/urls.py index 472f81d8cd82f9e66a185dd4ffb8a97288274ef9..e0bb25f318be28ef4a2b01e8389dd678cf670d44 100644 --- a/VIPSWeb/urls.py +++ b/VIPSWeb/urls.py @@ -43,9 +43,11 @@ urlpatterns = patterns('', url(r'^forecasts/', include('forecasts.urls', namespace = "forecasts")), url(r'^messages/', include('messages.urls', namespace = "messages")), url(r'^organisms/', include('organisms.urls', namespace = "organisms")), + url(r'^information/', include('information.urls', namespace = "information")), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), + url(r'^tinymce/', include('tinymce.urls')), # Static serving of media files url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), # Enabling translation in JavaScript files diff --git a/information/admin.py b/information/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..a42af2dab89f2dbe5b2a143f027e7b7f6a937982 --- /dev/null +++ b/information/admin.py @@ -0,0 +1,38 @@ +# +# Copyright (c) 2014 Bioforsk <http://www.bioforsk.no/>. +# +# This file is part of VIPSWeb. +# VIPSWeb is free software: you can redistribute it and/or modify +# it under the terms of the Bioforsk Open Source License as published by +# Bioforsk, either version 1 of the License, or (at your option) any +# later version. +# +# VIPSWeb is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Bioforsk Open Source License for more details. +# +# You should have received a copy of the Bioforsk Open Source License +# along with VIPSWeb. If not, see <http://www.bioforsk.no/licenses/>. +# + +from django.contrib import admin +from information.models import Information, InformationLocale +# Register your models here. +class InformationLocaleInline(admin.TabularInline): + model = InformationLocale + fields = ['language_code', 'headline', 'lead_paragraph', 'body'] + """ + # This actually works, but CSS overrides the size attribute... + def formfield_for_dbfield(self, db_field, **kwargs): + field = super(InformationLocaleInline, self).formfield_for_dbfield(db_field, **kwargs) # Get the default field + if db_field.name == "language_code": # Check if it's the one you want + field.widget.attrs['size'] = "2" # Poke in the new + return field + """ + +class InformationAdmin(admin.ModelAdmin): + inlines = [ + InformationLocaleInline, + ] +admin.site.register(Information, InformationAdmin) \ No newline at end of file diff --git a/information/locale/bg/LC_MESSAGES/django.mo b/information/locale/bg/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..a0586f48938da2dbd96baba9eb0ae0f86818006d Binary files /dev/null and b/information/locale/bg/LC_MESSAGES/django.mo differ diff --git a/information/locale/bg/LC_MESSAGES/django.po b/information/locale/bg/LC_MESSAGES/django.po new file mode 100644 index 0000000000000000000000000000000000000000..060bf34a4b32ef09665289e08b5e5fd5b38b02d0 --- /dev/null +++ b/information/locale/bg/LC_MESSAGES/django.po @@ -0,0 +1,29 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-01-08 17:42+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: templates/information/index.html:3 templates/information/index.html.py:5 +msgid "Information" +msgstr "" + +#: templates/information/index.html:6 +msgid "" +"You haven't added any information pages yet. Please do so in the " +"administration GUI." +msgstr "" diff --git a/information/locale/bs/LC_MESSAGES/django.mo b/information/locale/bs/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..510758a062cecb15d791cc5e54fb1719e1dcadf2 Binary files /dev/null and b/information/locale/bs/LC_MESSAGES/django.mo differ diff --git a/information/locale/bs/LC_MESSAGES/django.po b/information/locale/bs/LC_MESSAGES/django.po new file mode 100644 index 0000000000000000000000000000000000000000..b75ef886664309cabc9fcebbbc8106c768405c19 --- /dev/null +++ b/information/locale/bs/LC_MESSAGES/django.po @@ -0,0 +1,30 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-01-08 17:42+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" + +#: templates/information/index.html:3 templates/information/index.html.py:5 +msgid "Information" +msgstr "" + +#: templates/information/index.html:6 +msgid "" +"You haven't added any information pages yet. Please do so in the " +"administration GUI." +msgstr "" diff --git a/information/locale/hr/LC_MESSAGES/django.mo b/information/locale/hr/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..8212fbf1c5dd58a2b4c1c674cf0374e52da309f6 Binary files /dev/null and b/information/locale/hr/LC_MESSAGES/django.mo differ diff --git a/information/locale/hr/LC_MESSAGES/django.po b/information/locale/hr/LC_MESSAGES/django.po new file mode 100644 index 0000000000000000000000000000000000000000..f595021a4f17ab849d38950b5dfcf1b091be7b1d --- /dev/null +++ b/information/locale/hr/LC_MESSAGES/django.po @@ -0,0 +1,30 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-01-08 17:42+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" + +#: templates/information/index.html:3 templates/information/index.html.py:5 +msgid "Information" +msgstr "" + +#: templates/information/index.html:6 +msgid "" +"You haven't added any information pages yet. Please do so in the " +"administration GUI." +msgstr "" diff --git a/information/locale/nb/LC_MESSAGES/django.mo b/information/locale/nb/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..ac7c1bb2fc2f5b5e0cc997fff3c4b2201d4182e1 Binary files /dev/null and b/information/locale/nb/LC_MESSAGES/django.mo differ diff --git a/information/locale/nb/LC_MESSAGES/django.po b/information/locale/nb/LC_MESSAGES/django.po new file mode 100644 index 0000000000000000000000000000000000000000..4766aef77f75974e46d53f17a76ebab7d86e1200 --- /dev/null +++ b/information/locale/nb/LC_MESSAGES/django.po @@ -0,0 +1,31 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-01-08 17:42+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: templates/information/index.html:3 +#: templates/information/index.html.py:5 +msgid "Information" +msgstr "Informasjon" + +#: templates/information/index.html:6 +msgid "" +"You haven't added any information pages yet. Please do so in the " +"administration GUI." +msgstr "Du har ikke lagt til noen informasjonssider ennå. Vennligst gjør dette via administrasjonsgrensesnittet." + diff --git a/information/models.py b/information/models.py new file mode 100644 index 0000000000000000000000000000000000000000..02dbdaa18808ee4a95322c846eef84f5579ce24b --- /dev/null +++ b/information/models.py @@ -0,0 +1,49 @@ +from django.db import models +from django.conf import settings +from django.utils import translation +from tinymce import models as tinymce_models + +# Create your models here. + +class Information(models.Model): + def __unicode__(self): + return InformationLocale.get_heading_with_fallback(self.id) + parent_information = models.ForeignKey('self', blank=True, null=True, related_name='children') + illustration = models.ImageField(upload_to='images/information', blank=True) + +class InformationLocale(models.Model): + information = models.ForeignKey(Information) + headline = models.CharField(max_length=200) + lead_paragraph = models.TextField() + body = tinymce_models.HTMLField() + language_code = models.CharField(max_length=2) + + @staticmethod + def get_information_locale_with_fallback(information_id, language_code=translation.get_language()): + # Try with user's preferred locale first + try: + return InformationLocale.objects.get( + information=Information.objects.get(pk=information_id), + language_code=language_code + ) + except: + # Try with site's default language + try: + return InformationLocale.objects.get( + information=Information.objects.get(pk=information_id), + language_code=settings.LANGUAGE_CODE + ) + except: + # Try with English + try: + return InformationLocale.objects.get( + information=Information.objects.get(pk=information_id), + language_code="en" + ) + except: + # Use the first and best + return InformationLocale.objects.all()[0] + + @staticmethod + def get_heading_with_fallback(information_id, language_code=translation.get_language()): + return InformationLocale.get_information_locale_with_fallback(information_id, language_code).headline \ No newline at end of file diff --git a/information/templates/information/detail.html b/information/templates/information/detail.html new file mode 100644 index 0000000000000000000000000000000000000000..b4f46c548bfded18b00967ed4110136dea45c1cb --- /dev/null +++ b/information/templates/information/detail.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% load i18n staticfiles %} +{% block title%}{{information_locale.headline}}{%endblock%} +{% block content %} +{% if information_locale.information.illustration %} +<div class="messages_illustration"><img src="{{settings.MEDIA_URL}}{{information_locale.information.illustration}}" class="img-responsive"/></div> +{% endif %} +<h1>{{information_locale.headline}}</h1> +<p class="lead">{{information_locale.lead_paragraph}}</p> +{{information_locale.body | safe }} +{% endblock %} \ No newline at end of file diff --git a/information/templates/information/index.html b/information/templates/information/index.html new file mode 100644 index 0000000000000000000000000000000000000000..997f12764c8e1b6d9f57349a0aa86cc8bed3f762 --- /dev/null +++ b/information/templates/information/index.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} +{% load i18n staticfiles %} +{% block title%}{% trans "Information" %}{%endblock%} +{% block content %} +<h1>{% trans "Information" %}</h1> +<p>{% trans "You haven't added any information pages yet. Please do so in the administration GUI." %}"</p> +{% endblock %} \ No newline at end of file diff --git a/information/tests.py b/information/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/information/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/information/urls.py b/information/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..65788392d773f8b19fb17342a71659833bc6ec4a --- /dev/null +++ b/information/urls.py @@ -0,0 +1,28 @@ +# +# Copyright (c) 2015 Bioforsk <http://www.bioforsk.no/>. +# +# This file is part of VIPSWeb. +# VIPSWeb is free software: you can redistribute it and/or modify +# it under the terms of the Bioforsk Open Source License as published by +# Bioforsk, either version 1 of the License, or (at your option) any +# later version. +# +# VIPSWeb is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Bioforsk Open Source License for more details. +# +# You should have received a copy of the Bioforsk Open Source License +# along with VIPSWeb. If not, see <http://www.bioforsk.no/licenses/>. +# + +from django.conf.urls import patterns, url + +from information import views + +urlpatterns = patterns('', + # ex: /messages/ + url(r'^$', views.index, name='index'), + # ex: /messages/5/ + url(r'^(?P<information_id>\d+)/$', views.detail, name='detail'), +) \ No newline at end of file diff --git a/information/views.py b/information/views.py new file mode 100644 index 0000000000000000000000000000000000000000..e3eae1665d3aa701fcecf233b9d116ba60f6e6e4 --- /dev/null +++ b/information/views.py @@ -0,0 +1,37 @@ +# +# Copyright (c) 2015 Bioforsk <http://www.bioforsk.no/>. +# +# This file is part of VIPSWeb. +# VIPSWeb is free software: you can redistribute it and/or modify +# it under the terms of the Bioforsk Open Source License as published by +# Bioforsk, either version 1 of the License, or (at your option) any +# later version. +# +# VIPSWeb is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Bioforsk Open Source License for more details. +# +# You should have received a copy of the Bioforsk Open Source License +# along with VIPSWeb. If not, see <http://www.bioforsk.no/licenses/>. +# + +from django.shortcuts import render +from information.models import InformationLocale, Information + + +def index(request): + # Check that root element exists + try: + root_information = Information.objects.get(parent_information=None) + return detail(request,root_information.id) + except: + # Fallback: Return an empty page + context = {} + return render(request, 'information/index.html', context) + +def detail(request, information_id): + information_locale = InformationLocale.get_information_locale_with_fallback(information_id) + + context = {'information_locale' : information_locale} + return render(request, 'information/detail.html', context) \ No newline at end of file diff --git a/messages/views.py b/messages/views.py index 254c38e1d4f114eacec0fcdc3ee047d628f5d42b..36cb0618c45b0f8f26368e2de0615be829f386a4 100644 --- a/messages/views.py +++ b/messages/views.py @@ -16,7 +16,7 @@ # along with VIPSWeb. If not, see <http://www.bioforsk.no/licenses/>. # -from django.shortcuts import render, get_object_or_404 +from django.shortcuts import render from django.utils import translation from messages.models import Message diff --git a/requirements.txt b/requirements.txt index ba09eec43ce5b7d5f17420e28e3435ac759bc235..bf385cb3250371215b5022bcadef1cc0e518e0bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,5 @@ # Read docs for how this works: http://www.pip-installer.org/en/latest/cookbook.html Django==1.6.1 PIL==1.1.7 -requests==2.0.1 \ No newline at end of file +requests==2.0.1 +django-tinymce \ No newline at end of file