Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of ssh://git.netcentrum.cz/projects/content/GIT…

…/ella
  • Loading branch information...
commit e645b299c367f98e88d49cdf53b2199390be932a 2 parents 0d14b10 + 868942d
Jan Seifert authored
View
BIN  ella/core/locale/cs/LC_MESSAGES/django.mo
Binary file not shown
View
2  ella/core/locale/cs/LC_MESSAGES/django.po
@@ -50,7 +50,7 @@ msgid ""
"There is already a Placement object published in\n"
" category %(category)s with the same URL referring to %(target)s.\n"
" Please change the slug or publish date."
-msgstr ""
+msgstr "Zkuste změnit slug nebo datum publikace. Publikace se shodnou URL již existuje v kategorii \"%(category)s\" pro objekt \"%(target)s\" ."
#: admin.py:189
#: newman_admin.py:197
View
44 ella/core/models/publishable.py
@@ -206,8 +206,52 @@ def delete(self):
self.publishable.publish_from = publish_from
Publishable.objects.filter(pk=self.publishable_id).update(publish_from=publish_from)
+ @staticmethod
+ def check_placement_is_unique(placement):
+ obj = placement
+ cat = None
+ if obj.pk:
+ cat = getattr(obj, 'category', None)
+ obj_slug = getattr(obj, 'slug', obj.pk)
+ # if Placement has no slug, slug from Publishable object should be considered in following checks:
+ if not obj_slug:
+ obj_slug = obj.publishable.slug
+
+ # try and find conflicting placement
+ qset = Placement.objects.filter(
+ category=obj.category,
+ slug=obj_slug,
+ static=obj.static
+ )
+ if obj.static: # allow placements that do not overlap
+ q = Q(publish_to__lt=obj.publish_from)
+ if obj.publish_to:
+ q |= Q(publish_from__gt=obj.publish_to)
+ qset = qset.exclude(q)
+ # check for same date in URL
+ if not obj.static:
+ qset = qset.filter(
+ publish_from__year=obj.publish_from.year,
+ publish_from__month=obj.publish_from.month,
+ publish_from__day=obj.publish_from.day,
+ )
+ # exclude current object from search
+ if obj.pk:
+ qset = qset.exclude(pk=obj.pk)
+ if qset:
+ plac = qset[0]
+ raise ValueError(
+ _('''There is already a Placement object published in
+ category %(category)s with the same URL referring to %(target)s.
+ Please change the slug or publish date.''') % {
+ 'category' : plac.category,
+ 'target' : plac.publishable,
+ })
+
def save(self, **kwargs):
" If Listing is created, we create HitCount object "
+ # perform validation here
+ Placement.check_placement_is_unique(self)
if not self.slug:
self.slug = self.publishable.slug
View
7 ella/core/newman_admin.py
@@ -149,6 +149,9 @@ def clean(self):
if obj.pk:
cat = getattr(obj, 'category', None)
obj_slug = getattr(obj, 'slug', obj.pk)
+ # if Placement has no slug, slug from Publishable object should be considered in following checks:
+ if not obj_slug:
+ obj_slug = self.cleaned_data['publishable'].slug
main = None
d = self.cleaned_data
@@ -164,7 +167,7 @@ def clean(self):
qset = Placement.objects.filter(
category=d['category'],
slug=d['slug'],
- publishable=obj,
+ #publishable=obj,
static=d['static']
)
if d['static']: # allow placements that do not overlap
@@ -190,7 +193,7 @@ def clean(self):
category %(category)s with the same URL referring to %(target)s.
Please change the slug or publish date.''') % {
'category' : plac.category,
- 'target' : plac.target,
+ 'target' : plac.publishable,
})
if cat and not main:
View
BIN  ella/ellaexports/locale/cs/LC_MESSAGES/django.mo
Binary file not shown
View
8 ella/ellaexports/locale/cs/LC_MESSAGES/django.po
@@ -16,6 +16,14 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
+#: templates/newman/edit_inline/exportmeta_inline.html:41
+msgid "Show additional fields"
+msgstr "Zobrazit podrobnosti"
+
+#: templates/newman/edit_inline/exportmeta_inline.html:42
+msgid "Hide additional fields"
+msgstr "Skrýt podrobnosti"
+
#: models.py:24
msgid "Category"
msgstr "Kategorie"
View
3  ella/newman/config.py
@@ -32,6 +32,9 @@
HTTP_OK = 200
HTTP_ERROR = 405
+# Newman base URL (suitable when newman_frontend_tags' tags is used)
+BASE_URL = getattr(settings, 'NEWMAN_BASE_URL', '')
+
# Maximum autosave objects hold for bound object:
AUTOSAVE_MAX_AMOUNT = getattr(settings, 'NEWMAN_AUTOSAVE_MAX_AMOUNT', 3)
View
BIN  ella/newman/locale/cs/LC_MESSAGES/djangojs.mo
Binary file not shown
View
8 ella/newman/locale/cs/LC_MESSAGES/djangojs.po
@@ -409,6 +409,14 @@ msgstr "Rychlý náhled"
msgid "Preview on site"
msgstr "Náhled na webu"
+#: templates/newman/edit_inline/exportmeta_inline.html:41
+msgid "Show additional fields"
+msgstr "Zobrazit podrobnosti"
+
+#: templates/newman/edit_inline/exportmeta_inline.html:42
+msgid "Hide additional fields"
+msgstr "Skrýt podrobnosti"
+
#~ msgid "Now"
#~ msgstr "Nyní"
#~ msgid "6am"
View
46 ella/newman/media/css/frontend-tools.css
@@ -0,0 +1,46 @@
+div.fe-admin-toolbar {
+ position: fixed;
+ top:0;
+ left:0;
+ right:0;
+ z-index:3000;
+ background-color: rgba(0,0,0,.85);
+ /*background-color: #d6d614;*/
+ color: #fff;padding: 6px;
+ font: normal normal 10px Tahoma, Verdana, sans-serif;
+ text-align: left;
+ line-height: 1.4em;
+}
+
+.fe-admin-toolbar .listings {
+ font-size: 110%;
+}
+
+.fe-admin-toolbar .listings-container {
+ float: right;
+}
+
+.fe-admin-toolbar p {
+ margin-bottom: .5em;
+}
+
+.fe-admin-toolbar .toolbar {
+ max-width: 500px;
+}
+
+.fe-admin-toolbar a {
+ color: #fff;
+ font-weight: bold;
+ margin-left: 3px;
+ margin-right: 3px;
+}
+
+div.fe-admin-toolbar strong, div.fe-admin-toolbar b { font-weight: bold; }
+button.icn { padding: 3px; }
+button.icn span {
+ padding: 3px 3px 3px 20px;
+ background: url(../ico/16/ok.png) 0 50% no-repeat;
+}
+button.icn.logout span {
+ background-image: url(../ico/16/logout.png);
+}
View
BIN  ella/newman/media/ico/64/application-exit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
2  ella/newman/templates/newman/base.html
@@ -49,7 +49,7 @@
| <a href="{% url newman:index %}django-admin/">Django admin</a>
{% endif %}
| <a class="icn eclear js-hashadr" href="/password_change/">{% trans 'Change password' %}</a>
- | <a class="icn logout" href="{% url newman:logout %}?next={% url newman:index %}" onclick="return true/*confirm('Are you sure?')*/;">{% trans 'Log out' %}</a>
+ | <a class="icn logout" href="{% url newman:logout %}?next={% url newman:index %}">{% trans 'Log out' %}</a>
</div>
</div>
{% endblock %}
View
60 ella/newman/templates/newman/tpl_tags/newman_frontend_admin.html
@@ -0,0 +1,60 @@
+{% load newman_frontend_tags %}
+<div class="fe-admin-toolbar">
+ <div class="toolbar">
+
+<p>Přihlášen/a jako admin:
+ <strong style="font-weight:bold">{{ user.get_full_name }}</strong>
+ (<a id="js-newman-logout-button" href="{% newman_frontend_logout %}"><strong>odhlásit</strong></a>)
+</p>
+
+{% if object %}
+
+ {% if placement.listing_set.count %}
+ {% comment %}
+ <div class="listings-container">
+ <ul class="listings">
+ <li><p>
+ publikováno od: <strong style="font-weight:bold">{{ object.publish_from|date:"d.m.Y H:i:s" }}</strong>
+ </p></li>
+ {% for l in placement.listing_set.all %}
+ <li><p>{{ l.publish_from|date:"d.m.Y H:i:s" }} | {{ l.category }}</p></li>
+ {% endfor %}
+ </ul>
+ </div>
+ {% endcomment %}
+
+
+ {% comment %}
+ <select>
+ <option>výčty...</option>
+ {% for l in placement.listing_set.all %}
+ <option>{{ l.publish_from|date:"d.m.Y H:i:s" }} | {{ l.category }}</option>
+ {% endfor %}
+ </select>
+ {% endcomment %}
+ {% endif %}
+
+ <p>
+ {% trans object.content_type.name %}:
+ <strong style="font-weight:bold">{{ object }}</strong>,
+ návštěv: <strong style="font-weight:bold">{{ hitcount.hits }}</strong>
+ </p>
+
+ <div style="float: right;">
+ <button onclick="location.href='{{ newman_object_url }}'"><span>Edituj</span></button>
+ </div>
+{% endif %}
+
+
+{% comment %}
+{% if positions %}
+ <a href="http://localhost:3001/#/positions/position/category/{{ category.pk }}/" title="Upravit pozice">Pozice v kategorii {{ category.title }}</a>:
+ {% for p in positions %}
+ {{ p.name }}: {{ p.target }},
+ {% endfor %}
+{% endif %}
+{% endcomment %}
+
+{# NEWMAN_MEDIA_URL #}
+ </div>
+</div>
View
69 ella/newman/templatetags/newman_frontend_tags.py
@@ -0,0 +1,69 @@
+from django import template
+from django.conf import settings
+from django.contrib.contenttypes.models import ContentType
+
+from ella.newman import config as newman_config
+from ella.core.models.publishable import HitCount
+from ella.positions.models import Position
+
+register = template.Library()
+
+def get_newman_url(obj):
+ """ Assembles edit-object url for Newman admin. """
+ ct = ContentType.objects.get_for_model(obj)
+ url = '%(base)s#/%(app)s/%(model)s/%(pk)d/' % {
+ 'base': newman_config.BASE_URL,
+ 'app': ct.app_label,
+ 'model': ct.model,
+ 'pk': obj.pk
+ }
+ return url
+
+@register.inclusion_tag('newman/tpl_tags/newman_frontend_admin.html', takes_context=True)
+def newman_frontend_admin(context):
+ user = context['user']
+ vars = {}
+
+ if not user or not user.is_staff:
+ return vars
+
+ #vars['logout_url'] = reverse('newman:logout')
+ obj = context.get('object')
+ if 'gallery' in context:
+ obj = context.get('gallery')
+ placement = context.get('placement')
+
+ vars['user'] = user
+ vars['STATIC_URL'] = context.get('STATIC_URL')
+ vars['NEWMAN_MEDIA_URL'] = context.get('NEWMAN_MEDIA_URL')
+ vars['placement'] = placement
+ vars['category'] = context.get('category')
+ vars['newman_index_url'] = newman_config.BASE_URL
+ category = vars['category']
+ if not category or not category.pk:
+ return vars
+
+ from django.db.models import Q
+ import datetime
+ now = datetime.datetime.now()
+ lookup = (Q(active_from__isnull=True) | Q(active_from__lte=now)) & (Q(active_till__isnull=True) | Q(active_till__gt=now))
+ positions = Position.objects.filter(lookup, category=category.pk, disabled=False, target_id__isnull=False)
+ #print positions.query
+ vars['positions'] = positions
+
+ if obj:
+ vars['object'] = obj
+ vars['newman_object_url'] = get_newman_url(obj)
+ vars['hitcount'] = HitCount.objects.get(placement=placement.pk)
+
+ return vars
+
+
+logout_url = newman_config.BASE_URL + 'logout/'
+class NewmanLogoutNode(template.Node):
+ def render(self, context):
+ return logout_url
+
+@register.tag
+def newman_frontend_logout(parser, token):
+ return NewmanLogoutNode()
View
34 tests/unit_project/test_core/test_placement.py
@@ -6,6 +6,7 @@
from django.contrib.redirects.models import Redirect
from ella.core.models import Placement, Category
+from ella.articles.models import Article
from unit_project.test_core import create_basic_categories, create_and_place_a_publishable
@@ -45,6 +46,39 @@ def test_url_on_other_site(self):
self.assert_equals(u'http://not-example.com/2008/1/10/articles/first-article/', p.get_absolute_url())
+ def test_duplicity(self):
+ site = Site.objects.create(
+ name='some site',
+ domain='not-example.com'
+ )
+ category = Category.objects.create(
+ title=u"再见 category",
+ description=u"example testing category, second site",
+ site=site,
+ slug=u'zai-jian-category',
+ )
+ p = Placement.objects.create(
+ publishable=self.publishable,
+ category=category,
+ publish_from=datetime(2008,1,10)
+ )
+ publishable_two = Article.objects.create(
+ title=u'First Article',
+ slug=u'first-article',
+ description=u'Some\nlonger\ntext',
+ category=category
+ )
+ raised = False
+ try:
+ p_two = Placement.objects.create(
+ publishable=publishable_two,
+ category=category,
+ publish_from=datetime(2008,1,10)
+ )
+ except ValueError:
+ raised = True #OK
+ self.assert_equals(True, raised) # ValueError should be raised as duplicity check works right way.
+
def test_default_slug(self):
self.assert_equals(self.publishable.slug, self.placement.slug)
Please sign in to comment.
Something went wrong with that request. Please try again.