In my flask-admin index_view, I am displaying financial information for my rows.
I would like to add an extra row, "summary row", at the bottom of my index_view table which sums up all the columns.
How can I accomplish this?
There's a couple of things you need to do. Provide a custom list.html template and override the render() method for the view. In the render method inject your summary data into the kwargs and in the custom template use the summary data to output appropriate html. You could add the summary data to the end of the existing data table or add it to a separate table, as seen in the example below.
Here's a self-contained example (two files) using Flask-Admin 1.5, SQLAlchemy and SQLite. custom_list.html is taken directly from flask-admin list.html and we are manipulating the block beginning at line 68:
{% block model_list_table %}
...
{% endblock %}
Note that in the render() method the summary data is an array of dicts. Each dict has a 'title' attribute (e.g 'title: 'Page Total' plus an attribute for each of the columns summary data is required.
app.py
import random
import string
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_admin.contrib.sqla import ModelView
from flask_admin import Admin, expose
# Create application
from sqlalchemy import func
app = Flask(__name__)
# Create dummy secrey key so we can use sessions
app.config['SECRET_KEY'] = '123456790'
# Create in-memory database
app.config['DATABASE_FILE'] = 'sample_db.sqlite'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + app.config['DATABASE_FILE']
db = SQLAlchemy(app)
# Flask views
#app.route('/')
def index():
return 'Click me to get to Admin!'
class Project(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), nullable=False, unique=True)
cost = db.Column(db.Integer(), nullable=False)
def __str__(self):
return unicode(self).encode('utf-8')
def __unicode__(self):
return "Name: {name}; Cost : {cost}".format(name=self.name, cost=self.cost)
class ProjectView(ModelView):
# don't call the custom page list.html as you'll get a recursive call
list_template = 'admin/model/custom_list.html'
form_columns = ('name', 'cost')
page_size = 5
def page_cost(self, current_page):
# this should take into account any filters/search inplace
_query = self.session.query(Project).limit(self.page_size).offset(current_page * self.page_size)
return sum([p.cost for p in _query])
def total_cost(self):
# this should take into account any filters/search inplace
return self.session.query(func.sum(Project.cost)).scalar()
def render(self, template, **kwargs):
# we are only interested in the list page
if template == 'admin/model/custom_list.html':
# append a summary_data dictionary into kwargs
_current_page = kwargs['page']
kwargs['summary_data'] = [
{'title': 'Page Total', 'name': None, 'cost': self.page_cost(_current_page)},
{'title': 'Grand Total', 'name': None, 'cost': self.total_cost()},
]
return super(ProjectView, self).render(template, **kwargs)
admin = Admin(app, template_mode="bootstrap3")
admin.add_view(ProjectView(Project, db.session))
def build_sample_db():
db.drop_all()
db.create_all()
for _ in range(0, 100):
_cost = random.randrange(1, 1000)
_project = Project(
name=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)),
cost=_cost
)
db.session.add(_project)
db.session.commit()
if __name__ == '__main__':
build_sample_db()
app.run(port=5000, debug=True)
templates/admin/model/custom_list.html
{% extends 'admin/model/list.html' %}
{% block model_list_table %}
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover model-list">
<thead>
<tr>
{% block list_header scoped %}
{% if actions %}
<th class="list-checkbox-column">
<input type="checkbox" name="rowtoggle" class="action-rowtoggle" title="{{ _gettext('Select all records') }}" />
</th>
{% endif %}
{% block list_row_actions_header %}
{% if admin_view.column_display_actions %}
<th class="col-md-1"> </th>
{% endif %}
{% endblock %}
{% for c, name in list_columns %}
{% set column = loop.index0 %}
<th class="column-header col-{{c}}">
{% if admin_view.is_sortable(c) %}
{% if sort_column == column %}
<a href="{{ sort_url(column, True) }}" title="{{ _gettext('Sort by %(name)s', name=name) }}">
{{ name }}
{% if sort_desc %}
<span class="fa fa-chevron-up glyphicon glyphicon-chevron-up"></span>
{% else %}
<span class="fa fa-chevron-down glyphicon glyphicon-chevron-down"></span>
{% endif %}
</a>
{% else %}
{{ name }}
{% endif %}
{% else %}
{{ name }}
{% endif %}
{% if admin_view.column_descriptions.get(c) %}
<a class="fa fa-question-circle glyphicon glyphicon-question-sign"
title="{{ admin_view.column_descriptions[c] }}"
href="javascript:void(0)" data-role="tooltip"
></a>
{% endif %}
</th>
{% endfor %}
{% endblock %}
</tr>
</thead>
{% for row in data %}
<tr>
{% block list_row scoped %}
{% if actions %}
<td>
<input type="checkbox" name="rowid" class="action-checkbox" value="{{ get_pk_value(row) }}" title="{{ _gettext('Select record') }}" />
</td>
{% endif %}
{% block list_row_actions_column scoped %}
{% if admin_view.column_display_actions %}
<td class="list-buttons-column">
{% block list_row_actions scoped %}
{% for action in list_row_actions %}
{{ action.render_ctx(get_pk_value(row), row) }}
{% endfor %}
{% endblock %}
</td>
{%- endif -%}
{% endblock %}
{% for c, name in list_columns %}
<td class="col-{{c}}">
{% if admin_view.is_editable(c) %}
{% set form = list_forms[get_pk_value(row)] %}
{% if form.csrf_token %}
{{ form[c](pk=get_pk_value(row), display_value=get_value(row, c), csrf=form.csrf_token._value()) }}
{% else %}
{{ form[c](pk=get_pk_value(row), display_value=get_value(row, c)) }}
{% endif %}
{% else %}
{{ get_value(row, c) }}
{% endif %}
</td>
{% endfor %}
{% endblock %}
</tr>
{% else %}
<tr>
<td colspan="999">
{% block empty_list_message %}
<div class="text-center">
{{ admin_view.get_empty_list_message() }}
</div>
{% endblock %}
</td>
</tr>
{% endfor %}
</table>
</div>
<h3>Summaries</h3>
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover model-list">
<thead>
<tr>
{% if actions %}
<th class="list-checkbox-column">
</th>
{% endif %}
<th class="col-md-1"></th>
{% for c, name in list_columns %}
{% set column = loop.index0 %}
<th class="column-header col-{{c}}">
{{ name }}
</th>
{% endfor %}
</tr>
</thead>
{% for row in summary_data %}
<tr>
<td colspan="2"><strong>{{ row['title'] or ''}}</strong></td>
{% for c, name in list_columns %}
<td class="col-{{c}}">
{{ row[c] or ''}}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</div>
{% block list_pager %}
{% if num_pages is not none %}
{{ lib.pager(page, num_pages, pager_url) }}
{% else %}
{{ lib.simple_pager(page, data|length == page_size, pager_url) }}
{% endif %}
{% endblock %}
{% endblock %}
Related
So I was able to figure out how to unpack a dictionary keys and values on to a HTML template, but I am a bit confused as to how to unpack if if a dictionary value is a QuerySet. For example I passing in all the timeslots of the given user into the dictonary. How can I unpack the attributes of the TimeSlot QuerySet for each timeslot such as the start time and end time?
This is my HTML Template:
<table>
{% for key, value in user_info.items %}
{% for key2,value2 in value.items %}
<tr>
<td>{{key2}}</td>
<td>{{value2}}<td>
</tr>
{% endfor %}
<br>
{% endfor %}
</table>
My function in views.py
def check_food_availibility(request):
food = FoodAvail.objects.all()
timeslots = TimeSlot.objects.all()
users_dict = {}
for i in range(len(user_info)):
user = {
"author": None,
"food_available": None,
"description": None,
"timeslot": None
}
user["author"] = user_info[i].author.username
user["food_available"] = user_info[i].food_available
user["description"] = user_info[i].description
if TimeSlot.objects.filter(time_slot_owner=user_info[i].author):
user["timeslot"] = TimeSlot.objects.filter(time_slot_owner=user_info[i].author)
users_dict[user_info[i].author.username] = user
return render(request, "food_avail/view_food_avail.html", {"user_info": users_dict})
This is how it shows up currently:
try this
<table>
{% for key, value in user_info.items %}
{% for key2,value2 in value.items %}
<tr>
<td>{{key2}}</td>
{% if key2 == 'timeslot' %}
<td>
{% for i in value2 %}
i.start_time <-> i.end_time // just an example put your field here
{% endfor %}
</td>
{% else %}
<td>{{value2}}<td>
{% endif %}
</tr>
{% endfor %}
<br>
{% endfor %}
</table>
I am trying to get the data from a form that is made dynamically using Flask and WTForms. To do that I've created a list that gets populated when a user opens the link, but when I try to get the data from html I only get the data from the first element of the list.
Forms:
class Details_Form(FlaskForm):
preschool_groups = []
classes = []
continue_button = SubmitField('Continuă')
def appeend_group(self):
preschool_details = Preschool_Details()
self.preschool_groups.append(preschool_details)
def appeend_class(self, choices):
class_details = Classes_Details()
class_details.class_type.choices = choices
self.classes.append(class_details)
class Preschool_Details(FlaskForm):
group_name = StringField('', validators=[DataRequired()])
group_size = IntegerField('', validators=[DataRequired()])
class Classes_Details(FlaskForm):
class_name = StringField('', validators=[DataRequired()])
class_size = IntegerField('', validators=[DataRequired()])
class_type = SelectField('', validators=[DataRequired()])
Routes:
#app.route('/detalii-scoala/<school>/<groups>/<classes>', methods=['GET','POST'])
#login_required
def school_details_page(school, groups, classes):
groups = int(groups)
classes = int(classes)
details_form = Details_Form()
details_form.classes.clear()
details_form.preschool_groups.clear()
school_db_item = db.session.query(School).join(User, User.id == School.psychologist_id).filter(User.id == current_user.id).filter(School.school==school).first()
education_types = school_db_item.education_type.split(',')
for _ in range(groups):
details_form.appeend_group()
for _ in range(classes):
details_form.appeend_class(education_types)
if details_form.continue_button.data and details_form.validate_on_submit():
for preschool_details in details_form.preschool_groups:
group = Group(name=preschool_details.group_name.data, number_of_pupils=preschool_details.group_size.data, school_id=school_db_item.id)
db.session.add(group)
for class_details in details_form.classes:
print(class_details.class_name.data)
c = Classes(name=class_details.class_name.data, number_of_students=class_details.class_size.data, class_type=class_details.class_type.data, school_id=school_db_item.id)
db.session.add(c)
db.session.commit()
details_form.classes.clear()
details_form.preschool_groups.clear()
flash('Detaliile au fost inregistrate')
return redirect(url_for('session_page'))
return render_template('detalii-scoala.html', details_form=details_form)
html:
<form action="" method="post">
{{ details_form.hidden_tag() }}
<table>
{% for preschool in details_form.preschool_groups %}
<tr>
<td><p>
{{ preschool.group_name(class_="form-control") }}<br>
{% for error in preschool.group_name.errors %}
<span class="error">[{{ error }}]</span>
{% endfor %}
</p></td>
<td><p>
{{ preschool.group_size(class_="form-control") }}<br>
{% for error in preschool.group_size.errors %}
<span class="error">[{{ error }}]</span>
{% endfor %}
</p></td>
</tr>
{% endfor %}
</table>
<br>
<table>
<tr>
<td>Denumire clasă</td>
<td>Nr. elevi înscrişi</td>
<td>Ciclul</td>
</tr>
{% for class in details_form.classes %}
<tr>
<td><p>
{{ class.class_name(class_="form-control") }}<br>
{% for error in class.class_name.errors %}
<span class="error">[{{ error }}]</span>
{% endfor %}
</p></td>
<td><p>
{{ class.class_size(class_="form-control") }}<br>
{% for error in class.class_size.errors %}
<span class="error">[{{ error }}]</span>
{% endfor %}
</p></td>
<td><p>
{{ class.class_type(class_="form-control") }}<br>
{% for error in class.class_type.errors %}
<span class="error">[{{ error }}]</span>
{% endfor %}
</p></td>
</tr>
{% endfor %}
</table>
<p>{{ details_form.continue_button(class_="btn btn-primary") }}</p>
</form>
Front end works, the only problem is when I try to add the data from thee form in the database.
The problem was that HTML fields were having the same name. To solve that I used request.form.getlist('name) to create the lists
I am trying to create an Inventory Management System in which i can create/add stock through a form(WTForms) and have it displayed in a table on a separate page. Currently, i am stuck on the stated error. I have looked everywhere for an answer to no avail. I am supposed to add stock through 'createGPU.html' and be directed to 'retrieveGPU.html'
Clicking the submit button in createGPU results in jinja2.exceptions.UndefinedError: 'GPUs.GPUs object' has no attribute 'GPUName'
Main Program
from flask import Flask, render_template, request, redirect, url_for
from Forms import CreateGPUForm
import shelve, GPUs
#app.route("/createGPU", methods=['GET', 'POST'])
def createGPU():
createGPUForm = CreateGPUForm(request.form)
if request.method == 'POST' and createGPUForm.validate():
gpuDict = {}
db = shelve.open('storage.db', 'c')
try:
gpuDict = db['GPU']
except:
print('Error in retrieving GPUs from storage.db.')
gpu = GPUs.GPUs(createGPUForm.GPUName.data, createGPUForm.GPUUnitPrice.data, createGPUForm.GPUStock.data,createGPUForm.GPUSales.data)
gpuDict[gpu.get_GPUNo()] = gpu
db['GPU'] = gpuDict
db.close()
return redirect(url_for('retrieveGPU'))
return render_template('createGPU.html', form=createGPUForm)
if __name__ == '__main__':
app.run()
#app.route('/retrieveGPU')
def retrieveGPU():
gpuDict = {}
db = shelve.open('storage.db', 'r')
gpuDict = db['GPU']
db.close()
gpuList = []
for key in gpuDict:
gpu = gpuDict.get(key)
gpuList.append(gpu)
return render_template('retrieveGPU.html',gpuList=gpuList, count=len(gpuList))
createGPU
{% extends "base.html" %}
{% block title %}GPU-Assist - Add Graphics Card{% endblock %}
{% block content %}
{% from "includes/_formhelper.html" import render_field %}
<h1 class="display-4">Add Graphics Card</h1>
<form method="POST" action="">
<div class="form-group">
{{ render_field(form.GPUName, class="form-control") }}
</div>
<div class="form-group">
{{ render_field(form.GPUStock, class="form-control") }}
</div>
<div class="form-group">
{{ render_field(form.GPUUnitPrice, class="form-control") }}
</div>
<div class="form-group">
{{ render_field(form.GPUSales, class="form-control") }}
</div>
<input type="submit" value="Submit" class="btn btn-primary"/>
</form>
{% endblock %}
retrieveGPU
{% extends "base.html" %}
{% block title %}GPU-Assist - View GPU-Cart{% endblock %}
{% block content %}
<h1 class="display-4">View GPU</h1>
<div>
{% if count == 0 %}
<p>No GPU in recorded in inventory.</p>
{% elif count == 1 %}
<p>There is 1 GPU recorded in the inventory.</p>
{% else %}
<p>There are {{ count }} GPUs recorded in the inventory.</p>
{% endif %}
</div> <!--End of display number of users div-->
<div>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Stock</th>
<th>Unit Price</th>
<th>Sales</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
{% for gpu in gpuList %}
<tr>
<td>{{ gpu.GPUName() }}</td>
<td>{{ gpu.GPUStock() }}</td>
<td>{{ gpu.GPUUnitPrice() }}</td>
<td>{{ gpu.GPUSales() }}</td>
<td>Update</td>
<td>
<form action="" method="POST">
<input type="submit" value="Delete" class="btn btn-danger">
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
GPUs.py
class GPUs:
countID = 0
def __init__(self,GPUName,GPUStock,GPUUnitPrice,GPUSales):
GPUs.countID += 1
self.__GPUName = GPUName
self.__GPUStock = GPUStock
self.__GPUUnitPrice = GPUUnitPrice
self.__GPUSales = GPUSales
self.__GPUNo=GPUs.countID
'''
One obvious limitation it has is that every time you restart the web application, the countID resets to 0.
Once the countID resets, the next newly created Users’s userID will start from 1 again and overwrite any User
that previously had __userID = 1. (Must figure out an alternative)
'''
#Getter or Accessor
def get_GPUNo(self):
return self.__GPUNo
def get_GPUName(self):
return self.__GPUName
def get_GPUStock(self):
return self.__GPUStock
def get_GPUUnitPrice(self):
return self.__GPUUnitPrice
def get_GPUSales(self):
return self.__GPUSales
#Settor or Mutator
def set_GPUNo(self, GPUNo):
self.__GPUNo = GPUNo
def set_GPUName(self, GPUName):
self.__GPUName = GPUName
def set_GPUStock(self, GPUStock):
self.__GPUStock = GPUStock
def set_GPUUnitPrice(self, GPUUnitPrice):
self.__GPUUnitPrice = GPUUnitPrice
def set_GPUSales(self, GPUSales):
self.__GPUSales = GPUSales
When Jinja2 processes
<td>{{ gpu.GPUName() }}</td>
it expects that gpu will have a callable member function named GPUName. The way you've coded things up, get_GPUName is what you want instead.
The Pythonic way were be to drop the getters and setters entirely, removed the double-underscore prefixes, and have the template go directly for the named instance variable.
<td>{{ gpu.GPUName }}</td>
I want transfer page_number to url with name='onePart' from part_list.html. In my code page_number=1, but I want change it to current page of paginator depends on page. How I can do this?
P.S. sorry for my english:)
views.py:
def PartyNumView(request, page_number = 1):
all_parties = Part.objects.all()
current_page = Paginator(all_parties, 1)
try:
context = current_page.page(page_number)
except PageNotAnInteger:
context = current_page.page(1)
except EmptyPage:
context = current_page.page(current_page.num_pages)
return render_to_response('part_list.html', {'PartyNum': context})
def forOne(request, pk):
onePart = get_object_or_404(Part, pk=pk)
return render_to_response('SinglePart.html', {'onePart': onePart})
**urls.py:**
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^parties/(\d+)/$', PartyNumView),
url(r'^parties', PartyNumView),
url(r'parties/(?P<page_number>[\d]+)/(?P<pk>[\d]+)$', forOne, name='onePart'),
url(r'^main/', TemplateView.as_view(template_name='main.html')), #static html
url(r'^measures/', TemplateView.as_view(template_name='IcDesc.html')), #static html
]
A little bit of HTML code part_list.html:
{% for object in PartyNum %}
<tr>
<td>{{ forloop.counter }}</td>
<td> {{ object.Party_number }}</td>
<td>{{ object.Film }}</td>
<td>{{ object.Thick }}</td>
<td>{{ object.Critical_temperature }}</td>
<td>{{ object.R_s }}</td>
{% endfor %}
</tbody>
</table>
</table>
<div class="row" style="margin:auto">
<div class="large-3 large-offset-5 columns">
<ul class="pagination">
{% if PartyNum.has_previous %}
<li class="arrow">«</li>
{% else %}
<li class="arrow disabled">«</li>
{% endif %}
{% for page in PartyNum.paginator.page_range %}
{% if page == PartyNum.number %}
<li class="current">{{ page }}</li>
{% else %}
<li>{{ page }}</li>
{% endif %}
{% endfor %}
{% if PartyNum.has_next %}
<li class="arrow">»</li>
{% else %}
<li class="arrow disabled">»</li>
{% endif %}
</ul>
</div>
</div>
I'm begginer in django. If you help me, I will be grateful
Pagination with Function-Based Views
views.py
from django.contrib.auth.models import User
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
def index(request):
user_list = User.objects.all()
page = request.GET.get('page', 1)
paginator = Paginator(user_list, 10)
try:
users = paginator.page(page)
except PageNotAnInteger:
users = paginator.page(1)
except EmptyPage:
users = paginator.page(paginator.num_pages)
return render(request, 'core/user_list.html', { 'users': users })
user_list.html
<table class="table table-bordered">
<thead>
<tr>
<th>Username</th>
<th>First name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>{{ user.username }}</td>
<td>{{ user.first_name }}</td>
<td>{{ user.email }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if users.has_other_pages %}
<ul class="pagination">
{% if users.has_previous %}
<li>«</li>
{% else %}
<li class="disabled"><span>«</span></li>
{% endif %}
{% for i in users.paginator.page_range %}
{% if users.number == i %}
<li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
{% else %}
<li>{{ i }}</li>
{% endif %}
{% endfor %}
{% if users.has_next %}
<li>»</li>
{% else %}
<li class="disabled"><span>»</span></li>
{% endif %}
</ul>
{% endif %}
I'm writing a basic messaging function inside my app and it does what it's suppose to do. It sends, receives and sort messages in inbox and outbox, and I wanted it to show the nicknames of those who send (TO: 'nickname') and those who receive the message (FROM: 'nickname')
SOLVED
class Message(db.Model):
id = db.Column(db.Integer, primary_key = True)
body = db.Column(db.String(140))
timestamp = db.Column(db.DateTime)
for_id = db.Column(db.Integer)
**for_nickname = db.Column(db.String(140))**
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
def __repr__(self): # pragma: no cover
return '<Message %r>' % (self.body)
I just added one more field in my table for the nickname, so I can access it from the posted data. I felt that writing 2 more queries and comparing them to get this same result is too much for something like this.
Edited:
the view:
#app.route('/poraki', methods = ['GET', 'POST'])
#login_required
def poraki(page=1):
form = PostMessage()
nick = form.nickname.data
nickname = User.query.filter_by(nickname = nick).first()
if form.validate_on_submit():
m = Message(body = form.post.data,
timestamp = datetime.utcnow(),
author = g.user,
for_id = nickname.id)
db.session.add(m)
db.session.commit()
flash(gettext(u'Вашата порака е пратена!'))
return redirect(url_for('poraki'))
#inbox
sent = User.query.filter_by(nickname = g.user.nickname).first()
all_inbox = Message.query.filter_by(for_id = sent.id).order_by(Message.timestamp.desc()).paginate(page, POSTS_PER_PAGE, False)
#sent
all_sent = Message.query.filter_by(user_id = sent.id).order_by(Message.timestamp.desc()).paginate(page, POSTS_PER_PAGE, False)
return render_template('messages.html', form = form, posts1 = all_sent, posts2 = all_inbox, title = u'Пораки')
PostMessage():
class PostMessage(Form):
nickname = TextField('nickname', validators = [Required()])
post = TextField('post', validators = [Required()])
message.html template:
<td width="70px"><img src="{{post.author.avatar(70)}}" /></td>
<td>
{% autoescape false %}
{% if prateni == 1 %}
<p>{{ _('До: %(nickname)s ', nickname = '%s' % (url_for('user', nickname = post.for_id), post.for_id)) }}</p>
{% else %}
<p>{{ _('Од: %(nickname)s ', nickname = '%s' % (url_for('user', nickname = post.author.nickname), post.author.nickname)) }}</p>
{% endif %}
{% endautoescape %}
<p><strong><span id="post{{post.id}}">{{post.body}}</span></strong></p>
{% autoescape false %}
<p>{{ _('%(when)s', when = momentjs(post.timestamp).fromNow() ) }} </p>
{% endautoescape %}
<!-- {% if post.author.id == g.user.id %}
<div>{{ _('Избриши') }}</div>
{% endif %} -->
</td>
messages.html template:
<div class="well">
<form class="form-horizontal" action="" method="post" name="post">
{{form.hidden_tag()}}
<div class="control-group{% if form.errors.post %} error{% endif %}">
<label class="control-label" for="nickname">{{ _('До:') }}</label>
<div class="controls">
{{ form.nickname(size = 30, maxlength = 140) }}
{% for error in form.errors.nickname %}
<span class="help-inline">[{{error}}]</span><br>
{% endfor %}
</div>
</div>
<div class="control-group{% if form.errors.post %} error{% endif %}">
<label class="control-label" for="post">{{ _('Порака:') }}</label>
<div class="controls">
{{ form.post(cols = 64, rows = 4, class = "span4") }}
{% for error in form.errors.post %}
<span class="help-inline">[{{error}}]</span><br>
{% endfor %}
</div>
</div>
<div class="control-group">
<div class="controls">
<input class="btn btn-primary" type="submit" value="{{ _('Прати!') }}">
</div>
</div>
</form>
</div>
<table class="table">
<tr>
<td width=50%> Пратени пораки {{ proba }}
{% set prateni = 1 %}
{% for post in posts1.items %}
{% include 'message.html' %}
{% endfor %}
</td width=50%>
<td> Примени пораки
{% set prateni = 0 %}
{% for post in posts2.items %}
{% include 'message.html' %}
{% endfor %}
</td>
</tr>
</table>