fix thumbnail issues + some cleanup
authorJan Szejko <janek37@gmail.com>
Thu, 16 Feb 2017 14:42:45 +0000 (15:42 +0100)
committerJan Szejko <janek37@gmail.com>
Thu, 16 Feb 2017 14:42:45 +0000 (15:42 +0100)
16 files changed:
apps/catalogue/templates/catalogue/book_delete.html
apps/catalogue/templates/catalogue/book_list/book.html
apps/catalogue/templates/catalogue/book_list/book_list.html
apps/catalogue/templates/catalogue/book_owner.html
apps/catalogue/templates/catalogue/book_schedule.html
apps/catalogue/templates/catalogue/book_text.html
apps/catalogue/templates/catalogue/finished.html
apps/catalogue/templates/catalogue/upcoming.html
apps/organizations/migrations/0010_auto_20170216_1508.py [new file with mode: 0644]
apps/organizations/models.py
apps/organizations/templates/organizations/main.html
apps/organizations/templates/organizations/snippets/card.html [new file with mode: 0644]
apps/organizations/templates/organizations/snippets/organization.html
apps/organizations/templates/organizations/snippets/user.html
apps/organizations/templates/organizations/user_card.html
redakcja/templates/main.html

index a32c344..23a41a5 100644 (file)
@@ -6,7 +6,7 @@
     {% if doc.owner_organization %}
         <a href="{% url 'organizations_main' doc.owner_organization.pk %}">{{ doc.owner_organization }}</a>
     {% else %}
-        {{ doc.owner_user.first_name }} {{ doc.owner_user.last_name }}
+        {{ doc.owner_user.get_full_name }}
     {% endif %} /
     <h1 style='margin-bottom: 1em'>{{ doc.meta.title }}</h1>
 
index fa6a14a..fd8f785 100755 (executable)
@@ -4,7 +4,7 @@
         <td><a href="{% url 'catalogue_html' book.pk %}">{{ book.meta.title }}</a></td>
         <td>
             {% if book.owner_user %}
-                {{ book.owner_user.first_name }} {{ book.owner_user.last_name }}
+                {{ book.owner_user.get_full_name }}
             {% else %}
                 <a href="{{ book.owner_organization.get_absolute_url }}">{{ book.owner_organization }}</a>
             {% endif %}
@@ -13,7 +13,7 @@
             {% endif %}
             </td>
         <td>{{ book.stage|default:"–" }}</td>
-        <td class="{% if book.is_overdue %}alert-danger{% endif %}">{% if book.assigned_to %}{{ book.assigned_to.first_name }} {{ book.assigned_to.last_name }}{% endif %}</td>
+        <td class="{% if book.is_overdue %}alert-danger{% endif %}">{% if book.assigned_to %}{{ book.assigned_to.get_full_name }}{% endif %}</td>
         <td class="{% if book.is_overdue %}alert-danger{% endif %}">{{ book.get_plan.deadline|default:"–" }}</td>
         <td>
             {% if am_owner %}
@@ -25,6 +25,3 @@
             {% endif %}
         </td>
     </tr>
-
-</div>
-</div>
index 97f0a59..7277f80 100755 (executable)
@@ -5,12 +5,12 @@
 <table class="table table-striped">
     {% autopaginate books 100 %}
     <thead>
-        <th>{% trans "Title" %}</th>
-        <th>{% trans "Owner" %}</th>
-        <th>{% trans "Stage" %}</th>
-        <th>{% trans "Assigned to" %}</th>
-        <th>{% trans "Deadline" %}</th>
-        <th></th>
+        <td>{% trans "Title" %}</td>
+        <td>{% trans "Owner" %}</td>
+        <td>{% trans "Stage" %}</td>
+        <td>{% trans "Assigned to" %}</td>
+        <td>{% trans "Deadline" %}</td>
+        <td></td>
     </thead>
     <tbody>
     {% for doc in books %}
@@ -28,6 +28,6 @@
 <select name="other-user" style="display:none;">
   {% for user in other_users %}
   <option {% if request.GET.user == user.username %}selected="selected"
-          {% endif %}value="{{ user.username }}">{{ user.first_name }} {{ user.last_name }} ({{ user.count }})</option>
+          {% endif %}value="{{ user.username }}">{{ user.get_full_name }} ({{ user.count }})</option>
   {% endfor %}
 </select>
index 1ee2433..19a31f9 100644 (file)
@@ -6,7 +6,7 @@
     {% if doc.owner_organization %}
         <a href="{% url 'organizations_main' doc.owner_organization.pk %}">{{ doc.owner_organization }}</a>
     {% else %}
-        {{ doc.owner_user.first_name }} {{ doc.owner_user.last_name }}
+        {{ doc.owner_user.get_full_name }}
     {% endif %} /
     <h1 style='margin-bottom: 1em'>{{ doc.meta.title }}</h1>
 
index 79fe1b4..d2c0d52 100644 (file)
@@ -11,7 +11,7 @@
 {% if book.owner_organization %}
     <a href="{% url 'organizations_main' book.owner_organization.pk %}">{{ book.owner_organization }}</a>
 {% else %}
-    {{ book.owner_user.first_name }} {{ book.owner_user.last_name }}
+    {{ book.owner_user.get_full_name }}
 {% endif %} /
 <h1 style="margin-bottom: 1em">{{ book.meta.title }}</h1>
 
@@ -25,9 +25,9 @@
 <form method="POST">
 <table class="table table-striped">
     <thead>
-        <th>{% trans "Stage" %}</th>
-        <th>{% trans "Person" %}</th>
-        <th>{% trans "Deadline" %}</th>
+        <td>{% trans "Stage" %}</td>
+        <td>{% trans "Person" %}</td>
+        <td>{% trans "Deadline" %}</td>
     </thead>
     <tbody>
         {% for i, sch, data in schedule %}
                         {% if u.pk == data.0 %}
                             selected="selected"
                         {% endif %}
-                        >{{ u.first_name }} {{ u.last_name }}</option>
+                        >{{ u.get_full_name }}</option>
                     {% endfor %}
                 </select>
             {% else %}
-                {{ people.0.first_name }} {{ people.0.last_name }}
+                {{ people.0.get_full_name }}
             {% endif %}
             </td>
             <td><input placeholder="YYYY-MM-DD" name="s{{ i }}-deadline" value="{{ data.1|default:'' }}" class="form-control datepicker-field"></td>
index e1e6c41..6cf5f13 100644 (file)
@@ -27,7 +27,7 @@
 {% endif %}
 
 {% else %}
-<div class="navbar-text" href="">{% trans "Resource owner" %}: {{ doc.owner_user.first_name }} {{ doc.owner_user.last_name }}</div>
+<div class="navbar-text" href="">{% trans "Resource owner" %}: {{ doc.owner_user.get_full_name }}</div>
 {% endif %}
 
 <div class="btn-group navbar-right">
index 84e7511..40153e8 100644 (file)
@@ -24,7 +24,7 @@
                 {% trans "Audience" %}: {{ doc.meta.audience }}<br>
             {% endif %}
             {% trans "Owner" %}: {{ doc.owner_organization|default:"" }}
-            {{ doc.owner_user.first_name }} {{ doc.owner_user.last_name }}<br/>
+            {{ doc.owner_user.get_full_name }}<br/>
         </div>
         </a>
     </div>
index e7177fc..a95c9b3 100644 (file)
@@ -24,7 +24,7 @@
                 {% trans "Audience" %}: {{ doc.meta.audience }}<br>
             {% endif %}
             {% trans "Owner" %}: {{ doc.owner_organization|default:"" }}
-            {{ doc.owner_user.first_name }} {{ doc.owner_user.last_name }}<br/>
+            {{ doc.owner_user.get_full_name }}<br/>
         </div>
         </a>
     </div>
diff --git a/apps/organizations/migrations/0010_auto_20170216_1508.py b/apps/organizations/migrations/0010_auto_20170216_1508.py
new file mode 100644 (file)
index 0000000..a99c3cf
--- /dev/null
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.12 on 2017-02-16 15:08
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organizations', '0009_auto_20170119_1321'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='organization',
+            name='preview_html',
+        ),
+        migrations.RemoveField(
+            model_name='organization',
+            name='preview_html_pl',
+        ),
+        migrations.RemoveField(
+            model_name='usercard',
+            name='preview_html',
+        ),
+        migrations.RemoveField(
+            model_name='usercard',
+            name='preview_html_pl',
+        ),
+    ]
index 8e04ddb..0919f76 100644 (file)
@@ -5,8 +5,6 @@ from django.core.urlresolvers import reverse
 from django.contrib.auth.models import User
 from django.db import models
 from django.utils.encoding import python_2_unicode_compatible
-from django.template.loader import render_to_string
-from django.utils import translation
 
 
 countries = [
@@ -49,26 +47,11 @@ class Card(models.Model):
     description = models.TextField(blank=True, default="")
     projects = models.TextField(blank=True, default="")
 
-    preview_html = models.TextField(blank=True, default="")
-    preview_html_pl = models.TextField(blank=True, default="")
-
     created_at = models.DateTimeField(auto_now_add=True)
 
     class Meta:
         abstract = True
 
-    def save(self, *args, **kwargs):
-        translation.activate('en')
-        self.preview_html = render_to_string(self.preview_html_template, {
-            'org': self
-        })
-        translation.activate('pl')
-        self.preview_html_pl = render_to_string(self.preview_html_template, {
-            'org': self
-        })
-        ret = super(Card, self).save(*args, **kwargs)
-        return ret
-
     def get_projects(self):
         for project_line in self.projects.strip().split('\n'):
             parts = project_line.strip().split(None, 2)
@@ -77,23 +60,13 @@ class Card(models.Model):
             url, lang, desc = (parts + [''] * 2)[:3]
             yield url, lang, desc
 
-    def get_preview_html(self):
-        lang = translation.get_language()
-        try:
-            p = getattr(self, "preview_html_%s" % lang)
-            assert p
-            return p
-        except (AssertionError, AttributeError):
-            return self.preview_html
-
 
 @python_2_unicode_compatible
 class UserCard(Card):
-    preview_html_template = 'organizations/snippets/user.html'
     user = models.OneToOneField(User, primary_key=True)
 
     def __str__(self):
-        return str(self.user)
+        return self.user.get_full_name()
 
     def get_absolute_url(self):
         return reverse('organizations_user', args=[self.user.pk])
@@ -101,20 +74,8 @@ class UserCard(Card):
 
 @python_2_unicode_compatible
 class Organization(Card):
-    preview_html_template = 'organizations/snippets/organization.html'
-
     name = models.CharField(max_length=1024)
     tags = models.ManyToManyField('catalogue.Tag', blank=True)
-    # logo = models.ImageField(upload_to='people/logo', blank=True)
-    # country = models.CharField(max_length=64, blank=True, choices=countries)
-    # www = models.URLField(blank=True)
-    # description = models.TextField(blank=True, default="")
-    # #projects = JSONField(default=[])
-    # projects = models.TextField(blank=True, default="")
-
-    # preview_html = models.TextField(blank=True, default="")
-
-    # created_at = models.DateTimeField(auto_now_add=True)
 
     def __str__(self):
         return self.name
index 2334be0..3fcf559 100644 (file)
@@ -1,6 +1,7 @@
 {% extends "catalogue/base.html" %}
 {% load i18n %}
 {% load document_list from document_list %}
+{% load thumbnail %}
 
 {% block inner_content %}
 
@@ -13,7 +14,7 @@
     <a style="float:right; margin-right: 5px" class="btn btn-default" href="{% url 'catalogue_create_missing' %}?organization={{ org.pk }}">{% trans "New resource +" %}</a>
     {% endif %}
 
-    {{ org.get_preview_html|safe }}
+    {% include "organizations/snippets/organization.html" %}
 
     {% if tab == 'members' %}
 
@@ -36,7 +37,7 @@
     {% for m in org.membership_set.all %}
         {% if am_owner or m.status != 'pending' or m.user == request.user %}
             <tr class="member-{{ m.status }}">
-                <td>{{ m.user.first_name }} {{ m.user.last_name }}</td>
+                <td>{{ m.user.get_full_name }}</td>
                 {% if am_owner %}<td>{{ m.user.email }}</td>{% endif %}
                 <td>
                     {% if m.status == 'owner' %}
diff --git a/apps/organizations/templates/organizations/snippets/card.html b/apps/organizations/templates/organizations/snippets/card.html
new file mode 100644 (file)
index 0000000..0332565
--- /dev/null
@@ -0,0 +1,39 @@
+{% load thumbnail %}
+{% load i18n %}
+{% load urlinfo %}
+
+
+{% if org.logo %}
+    <img style="margin: 2em 2em 0 0; float: left;" src="{% thumbnail org.logo '180x180' format="PNG" padding=True as th %}{{ th.url }}{% endthumbnail %}">
+{% endif %}
+
+<h1>{{ org }}</h1>
+    <table class="table table-striped" style="width: auto"><tbody>
+    {% if org.country %}<tr><th>{% trans "Country" %}:</th><td>{{ org.get_country_display }}</td></tr>{% endif %}
+    {% if org.www %}<tr><th>{% trans "WWW" %}:</th><td><a href="{{ org.www }}" target="_blank">{{ org.www }}</a></td></tr>{% endif %}
+
+    {% if org.description %}
+    <tr><th>{% trans "Description" %}:</th><td>{{ org.description }}</td></tr>
+    {% endif %}
+
+    {% for url, lang, desc in org.get_projects %}
+        {% if forloop.first %}
+            <tr><th colspan="2">{% trans "Main projects and publications" %}:</th></tr>
+        {% endif %}
+        {% urlinfo url as ui %}
+            <tr>
+                <td style="text-align: center">
+                    {% if ui.picture_url %}
+                    <a href="{{ url }}" target="_blank">
+                    {% thumbnail ui.picture_url '120x40' format="PNG" as th %}
+                        <img src="{{ th.url }}">
+                    {% endthumbnail %}
+                    </a>
+                    {% endif %}
+                </td>
+            <td>{{ desc }}<br>
+                <a href="{{ url }}" target="_blank">{{ url }}</a> {% if lang %}({{ lang }}){% endif %}
+                </td>
+        </tr>
+    {% endfor %}
+    </tbody></table>
index 0e60edc..1fe58df 100644 (file)
@@ -1,37 +1 @@
-{% load thumbnail %}
-{% load i18n %}
-{% load urlinfo %}
-
-
-{% if org.logo %}
-<img style="margin: 2em 2em 0 0; float: left;" src="{% thumbnail org.logo '180x180' format="PNG" as th %}{{ th.url }}{% endthumbnail %}">
-{% endif %}
-
-<h1>{{ org }}</h1>
-    <table class="table table-striped" style="width: auto"><tbody>
-    <tr><th>{% trans "Country" %}:</th><td>{{ org.get_country_display }}</td></tr>
-    <tr><th>{% trans "WWW" %}:</th><td><a href="{{ org.www }}" target="_blank">{{ org.www }}</a></td></tr>
-
-    {% if org.description %}
-    <tr><th>{% trans "Description" %}:</th><td>{{ org.description }}</td></tr>
-    {% endif %}
-
-    <tr><th colspan="2">{% trans "Main projects and publications" %}:</th></tr>
-    {% for url, lang, desc in org.get_projects %}
-        {% urlinfo url as ui %}
-            <tr>
-                <td style="text-align: center">
-                    {% if ui.picture_url %}
-                    <a href="{{ url }}" target="_blank">
-                    {% thumbnail ui.picture_url '120x40' format="PNG" as th %}
-                        <img src="{{ th.url }}">
-                    {% endthumbnail %}
-                    </a>
-                    {% endif %}
-                </td>
-            <td>{{ desc }}<br>
-                <a href="{{ url }}" target="_blank">{{ url }}</a> {% if lang %}({{ lang }}){% endif %}
-                </td>
-        </tr>
-    {% endfor %}
-    </tbody></table>
+{% extends "organizations/snippets/card.html" %}
\ No newline at end of file
index b8aeb47..1fe58df 100644 (file)
@@ -1,39 +1 @@
-{% load thumbnail %}
-{% load i18n %}
-{% load urlinfo %}
-
-
-{% if org.logo %}
-<img style="margin: 2em 2em 0 0; float: left;" src="{% thumbnail org.logo '180x180' format="PNG" as th %}{{ th.url }}{% endthumbnail %}">
-{% endif %}
-
-<h1>{{ org.user.first_name }} {{ org.user.last_name }}</h1>
-    <table class="table table-striped" style="width: auto"><tbody>
-    {% if org.country %}<tr><th>{% trans "Country" %}:</th><td>{{ org.get_country_display }}</td></tr>{% endif %}
-    {% if org.www %}<tr><th>{% trans "WWW" %}:</th><td><a href="{{ org.www }}" target="_blank">{{ org.www }}</a></td></tr>{% endif %}
-
-    {% if org.description %}
-    <tr><th>{% trans "Description" %}:</th><td>{{ org.description }}</td></tr>
-    {% endif %}
-
-    {% for url, lang, desc in org.get_projects %}
-        {% if forloop.first %}
-            <tr><th colspan="2">{% trans "Main projects and publications" %}:</th></tr>
-        {% endif %}
-        {% urlinfo url as ui %}
-            <tr>
-                <td style="text-align: center">
-                    {% if ui.picture_url %}
-                    <a href="{{ url }}" target="_blank">
-                    {% thumbnail ui.picture_url '120x40' format="PNG" as th %}
-                        <img src="{{ th.url }}">
-                    {% endthumbnail %}
-                    </a>
-                    {% endif %}
-                </td>
-            <td>{{ desc }}<br>
-                <a href="{{ url }}" target="_blank">{{ url }}</a> {% if lang %}({{ lang }}){% endif %}
-                </td>
-        </tr>
-    {% endfor %}
-    </tbody></table>
+{% extends "organizations/snippets/card.html" %}
\ No newline at end of file
index 513944b..421243f 100644 (file)
@@ -1,6 +1,7 @@
 {% extends "catalogue/base.html" %}
 {% load i18n %}
 {% load document_list from document_list %}
+{% load thumbnail %}
 
 {% block inner_content %}
 
@@ -8,7 +9,7 @@
     <a style="float:right" class="btn btn-default" href="{% url 'organizations_user_edit' %}">{% trans "Edit" %}</a>
     {% endif %}
 
-    {{ card.get_preview_html|safe }}
+    {% include "organizations/snippets/user.html" with org=card %}
 
     <h2>{% trans "Resources" %}</h2>
     {% document_list user=card.user.pk %}
index a6a9f41..64421c3 100644 (file)
@@ -85,7 +85,7 @@
                 {% trans "Audience" %}: {{ doc.meta.audience }}<br>
             {% endif %}
             {% trans "Owner" %}: {{ doc.owner_organization|default:"" }}
-            {{ doc.owner_user.first_name }} {{ doc.owner_user.last_name }}<br/>
+            {{ doc.owner_user.get_full_name }}<br/>
         </div>
         </a>
     </div>
                 {% trans "Audience" %}: {{ doc.meta.audience }}<br>
             {% endif %}
             {% trans "Owner" %}: {{ doc.owner_organization|default:"" }}
-            {{ doc.owner_user.first_name }} {{ doc.owner_user.last_name }}<br/>
+            {{ doc.owner_user.get_full_name }}<br/>
         </div>
         </a>
     </div>