Ricordisamoa has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/316559

Change subject: Get rid of fake_globals hack
......................................................................

Get rid of fake_globals hack

Replace it with __class__.__name__ hack.

Change-Id: I52e3ac904b3bca2c39f69c10ebe8f71bbe12397b
---
M app.py
M nuclides.py
A templates/cells/ElementCell.html
A templates/cells/EmptyCell.html
A templates/cells/IndicatorCell.html
A templates/cells/NuclideCell.html
A templates/cells/TableCell.html
A templates/cells/UnknownCell.html
M templates/index.html
M templates/nuclides_common.html
10 files changed, 18 insertions(+), 33 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/tools/ptable 
refs/changes/59/316559/1

diff --git a/app.py b/app.py
index a82ba52..a0a79b4 100644
--- a/app.py
+++ b/app.py
@@ -39,13 +39,6 @@
 element_provider_class = chemistry.SparqlElementProvider
 nuclide_provider_class = nuclides.SparqlNuclideProvider
 
-fake_globals = {'isinstance': isinstance}
-for key in ('EmptyCell', 'UnknownCell', 'ElementCell', 'IndicatorCell'):
-    fake_globals[key] = getattr(chemistry, key)
-
-for key in ('NoneCell', 'NuclideCell'):
-    fake_globals[key] = getattr(nuclides, key)
-
 
 @app.before_request
 def set_language():
@@ -64,7 +57,7 @@
     """Render the index page."""
     elements, table, special_series, incomplete = 
app.element_provider.get_table()
     return render_template('index.html', table=table, 
special_series=special_series,
-                           incomplete=incomplete, **fake_globals)
+                           incomplete=incomplete)
 
 
 @app.route('/nuclides')
@@ -89,8 +82,7 @@
     max_protons = max(map(lambda nuclide: nuclide.atomic_number, nuclides))
     return render_template(template_file, nuclide_list=nuclides,
                            magic_numbers=magic_numbers, 
max_neutrons=max_neutrons,
-                           max_protons=max_protons, incomplete=incomplete,
-                           **fake_globals)
+                           max_protons=max_protons, incomplete=incomplete)
 
 
 @app.route('/license')
diff --git a/nuclides.py b/nuclides.py
index 6660201..1753145 100644
--- a/nuclides.py
+++ b/nuclides.py
@@ -37,6 +37,7 @@
         lastnnum = -1
         for nuclide in self.iter_good():
             if nuclide.atomic_number is not None and nuclide.neutron_number is 
not None:
+                nuclide.__class__ = NuclideCell
                 if nuclide.atomic_number > lastanum:
                     lastanum = nuclide.atomic_number
                 if nuclide.neutron_number > lastnnum:
@@ -52,9 +53,7 @@
             if anum not in table:
                 table[anum] = {}
             for nnum in range(0, lastnnum+1):
-                if nnum in table[anum]:
-                    table[anum][nnum].__class__ = NuclideCell
-                else:
+                if nnum not in table[anum]:
                     table[anum][nnum] = NoneCell()
 
         return nuclides, table, incomplete
diff --git a/templates/cells/ElementCell.html b/templates/cells/ElementCell.html
new file mode 100644
index 0000000..1d58445
--- /dev/null
+++ b/templates/cells/ElementCell.html
@@ -0,0 +1,5 @@
+<td class="element{%- if cell.group %} group-{{ cell.group }}{% endif %}{%- if 
cell.special %} special-{{ cell.special }}{% endif %}{% for class in 
cell.classes %} {{ class }}{% endfor %}">
+       <span>{{ cell.symbol }}</span><br/>
+       <a href="{{ wd_url(cell) }}">{{ cell.label }}</a><br/>
+       {{ cell.number }}
+</td>
diff --git a/templates/cells/EmptyCell.html b/templates/cells/EmptyCell.html
new file mode 100644
index 0000000..59c437c
--- /dev/null
+++ b/templates/cells/EmptyCell.html
@@ -0,0 +1 @@
+<td class="empty"></td>
diff --git a/templates/cells/IndicatorCell.html 
b/templates/cells/IndicatorCell.html
new file mode 100644
index 0000000..a35819d
--- /dev/null
+++ b/templates/cells/IndicatorCell.html
@@ -0,0 +1,3 @@
+<td class="indicator indicator-{{ cell.index }}">
+       <span>{{ ('&#65290;' * cell.index) | safe }}</span>
+</td>
diff --git a/templates/cells/NuclideCell.html b/templates/cells/NuclideCell.html
new file mode 100644
index 0000000..7359c30
--- /dev/null
+++ b/templates/cells/NuclideCell.html
@@ -0,0 +1 @@
+<a xlink:href="{{ wd_url(nuclide) }}"><rect x="{{ nuclide.neutron_number }}" 
y="-{{ nuclide.atomic_number }}" width="1" height="1" class="nuclide {% for 
class in nuclide.classes %} {{ class }}{% endfor %}"><title>{{ nuclide.label 
}}</title></rect></a>
diff --git a/templates/cells/TableCell.html b/templates/cells/TableCell.html
new file mode 100644
index 0000000..c15040a
--- /dev/null
+++ b/templates/cells/TableCell.html
@@ -0,0 +1 @@
+<td></td>
diff --git a/templates/cells/UnknownCell.html b/templates/cells/UnknownCell.html
new file mode 100644
index 0000000..d892a3b
--- /dev/null
+++ b/templates/cells/UnknownCell.html
@@ -0,0 +1 @@
+<td class="unknown"><span>?</span></td>
diff --git a/templates/index.html b/templates/index.html
index a6a31be..275144c 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -3,23 +3,7 @@
        //www.wikidata.org/wiki/{{ element.item_id }}
 {%- endmacro -%}
 {%- macro format_cell(cell) -%}
-       {%- if isinstance(cell, EmptyCell) -%}
-               <td class="empty"></td>
-       {%- elif isinstance(cell, UnknownCell) -%}
-               <td class="unknown"><span>?</span></td>
-       {%- elif isinstance(cell, ElementCell) -%}
-               <td class="element{%- if cell.group %} group-{{ cell.group }}{% 
endif %}{%- if cell.special %} special-{{ cell.special }}{% endif %}{% for 
class in cell.classes %} {{ class }}{% endfor %}">
-                       <span>{{ cell.symbol }}</span><br/>
-                       <a href="{{ wd_url(cell) }}">{{ cell.label }}</a><br/>
-                       {{ cell.number }}
-               </td>
-       {%- elif isinstance(cell, IndicatorCell) -%}
-               <td class="indicator indicator-{{ cell.index }}">
-                       <span>{{ ('&#65290;' * cell.index) | safe }}</span>
-               </td>
-       {%- else -%}
-               <td></td>
-       {%- endif -%}
+       {%- include "cells/" ~ cell.__class__.__name__ ~ ".html" -%}
 {%- endmacro -%}
 {% block head -%}
 <link rel="stylesheet" type="text/css" href="{{ url_for('static', 
filename='table.css') }}">
diff --git a/templates/nuclides_common.html b/templates/nuclides_common.html
index f1353ab..a7b91bd 100644
--- a/templates/nuclides_common.html
+++ b/templates/nuclides_common.html
@@ -3,9 +3,7 @@
        //www.wikidata.org/wiki/{{ nuclide.item_id }}
 {%- endmacro -%}
 {%- macro format_cell(nuclide) -%}
-       {%- if isinstance(nuclide, NuclideCell) -%}
-            <a xlink:href="{{ wd_url(nuclide) }}"><rect x="{{ 
nuclide.neutron_number }}" y="-{{ nuclide.atomic_number }}" width="1" 
height="1" class="nuclide {% for class in nuclide.classes %} {{ class }}{% 
endfor %}"><title>{{ nuclide.label }}</title></rect></a>
-       {%- endif -%}
+       {%- include "cells/" ~ nuclide.__class__.__name__ ~ ".html" -%}
 {%- endmacro -%}
 {% block head -%}
 <link rel="stylesheet" type="text/css" href="{{ url_for('static', 
filename='nuclides.css') }}">

-- 
To view, visit https://gerrit.wikimedia.org/r/316559
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I52e3ac904b3bca2c39f69c10ebe8f71bbe12397b
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/ptable
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisa...@openmailbox.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to