Skip to content
Snippets Groups Projects
Commit 15129620 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Adding information app

parent ad429f68
No related branches found
No related tags found
No related merge requests found
Showing
with 300 additions and 2 deletions
...@@ -131,9 +131,11 @@ INSTALLED_APPS = ( ...@@ -131,9 +131,11 @@ INSTALLED_APPS = (
'django.contrib.admin', 'django.contrib.admin',
# Uncomment the next line to enable admin documentation: # Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs', # 'django.contrib.admindocs',
'tinymce',
'forecasts', 'forecasts',
'messages', 'messages',
'organisms', 'organisms',
'information',
'VIPSWeb' 'VIPSWeb'
) )
......
...@@ -43,9 +43,11 @@ urlpatterns = patterns('', ...@@ -43,9 +43,11 @@ urlpatterns = patterns('',
url(r'^forecasts/', include('forecasts.urls', namespace = "forecasts")), url(r'^forecasts/', include('forecasts.urls', namespace = "forecasts")),
url(r'^messages/', include('messages.urls', namespace = "messages")), url(r'^messages/', include('messages.urls', namespace = "messages")),
url(r'^organisms/', include('organisms.urls', namespace = "organisms")), url(r'^organisms/', include('organisms.urls', namespace = "organisms")),
url(r'^information/', include('information.urls', namespace = "information")),
# Uncomment the next line to enable the admin: # Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
url(r'^tinymce/', include('tinymce.urls')),
# Static serving of media files # Static serving of media files
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
# Enabling translation in JavaScript files # Enabling translation in JavaScript files
......
#
# 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
File added
# 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 ""
File added
# 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 ""
File added
# 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 ""
File added
# 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."
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
{% 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
{% 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
from django.test import TestCase
# Create your tests here.
#
# 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
#
# 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
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# along with VIPSWeb. If not, see <http://www.bioforsk.no/licenses/>. # 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 django.utils import translation
from messages.models import Message from messages.models import Message
......
...@@ -20,4 +20,5 @@ ...@@ -20,4 +20,5 @@
# Read docs for how this works: http://www.pip-installer.org/en/latest/cookbook.html # Read docs for how this works: http://www.pip-installer.org/en/latest/cookbook.html
Django==1.6.1 Django==1.6.1
PIL==1.1.7 PIL==1.1.7
requests==2.0.1 requests==2.0.1
\ No newline at end of file django-tinymce
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment