Changeset - ceb89e14107f
[Not reviewed]
default
0 5 0
Dennis Fink - 11 years ago 2013-11-18 23:23:51
dennis.fink@c3l.lu
updated ennstatus
5 files changed with 8 insertions and 8 deletions:
0 comments (0 inline, 0 general)
ennstatus/api/views.py
Show inline comments
 
@@ -88,20 +88,20 @@ def export(export_format, server_type):
 
            return ('No server_name specified!\n',
 
                    400, {'Content-Type': 'text/plain'})
 

	
 
    else:
 
        if server_type == 'all':
 
            current_app.logger.info('Getting all servers!')
 
            servers = list(all_servers())
 
        else:
 
            current_app.logger.info('Getting all %s!' % server_type)
 
            servers = list(all_servers_by_type(server_type.capitalize()))
 

	
 
        if export_format == 'json':
 
            response = {'enn-network': servers}
 
            response = {'enn_network': servers}
 
            current_app.logger.info('Returning as json!')
 
            return jsonify(response)
 
        else:
 
            current_app.logger.info('Returning as xml!')
 
            return (render_template('api/extract/xml/network.xml',
 
                                    servers=servers),
 
                    200, {'Content-Type': 'text/xml'})
ennstatus/donate/functions.py
Show inline comments
 
import os
 
import os.path
 
import csv
 

	
 

	
 
def load_csv(date):
 

	
 
    filename = '.'.join([date, 'csv'])
 
    path = os.path.join('donations', filename)
 

	
 
    with open(path, newline='') as csvfile:
 
    with open(path) as csvfile:
 
        csvreader = csv.reader(csvfile, delimiter=',')
 

	
 
        for row in csvreader:
 
            yield row
 

	
 

	
 
def get_choices():
 

	
 
    files = os.listdir('donations')
 

	
 
    for file in files:
 
        if not file.startswith('.') \
ennstatus/donate/views.py
Show inline comments
 
@@ -60,24 +60,24 @@ def received():
 
        if form.validate_on_submit():
 
            date = form.date.data
 
            return redirect(url_for('donate.received', date=date))
 
    else:
 
        if 'date' in request.args:
 
            date = request.args['date']
 
            if request.args['date'] in choices:
 
                current_app.logger.info('Showing date %s' % date)
 
                form.date.data = date
 
                csv_file = load_csv(date)
 
            else:
 
                current_app.logger.warn('Date %s not found' % date)
 
                return ('Date %s not found!', 500,
 
                return ('Date %s not found!' % date, 500,
 
                        {'Content-Type': 'text/plain'})
 
        else:
 
            current_app.logger.info('Showing last date %s' % choices[-1])
 
            form.date.data = choices[-1]
 
            csv_file = load_csv(choices[-1])
 
            date = choices[-1]
 

	
 
        current_app.logger.info('Return result')
 
        return render_template('donate/received.html',
 
                               form=form, csv_file=csv_file,
 
                               date=date)
ennstatus/templates/api/extract/xml/network.xml
Show inline comments
 
<?xml version="1.0" encoding="UTF-8" ?>
 
<enn-network>
 
<enn_network>
 
  {% for server in servers %}
 
    {%- include "api/extract/xml/server.xml" %}
 
  {% endfor %}
 
</enn-network>
 
</enn_network>
ennstatus/templates/donate/macros.html
Show inline comments
 
@@ -15,20 +15,20 @@
 
    <thead>
 
      <tr>
 
        <th>#</th>
 
        <th>Date</th>
 
        <th>Statement</th>
 
        <th>Amount</th>
 
      </tr>
 
    </thead>
 
    <tbody>
 
      {% for row in csv_file %}
 
        <tr>
 
          <td>{{ loop.index }}</td>
 
          <td>{{ row[0] }}</td>
 
          <td>{{ row[1] }}</td>
 
          <td>{{ colorize_numbers(row[2]) }}</td>
 
          <td>{{ row[0].decode('utf-8') }}</td>
 
          <td>{{ row[1].decode('utf-8') }}</td>
 
          <td>{{ colorize_numbers(row[2].decode('utf-8')) }}</td>
 
        </tr>
 
      {% endfor %}
 
    </tbody>
 
  </table>
 
{% endmacro %}
0 comments (0 inline, 0 general)