How to list documents from table grouped by id? - postgresql

I'm making a template to show documents by its parts (title, annotation, contenttext).
{% block header %}
<h1>{% block title %}Documents{% endblock %}</h1>
{% endblock %}
{% block content %}
{% for document in documents | groupby('documentid' %}
<div class="card mb-3">
<div class="card-header">
{{ document.annotation }}
<span class="badge badge-pill badge-primary">{{ document.title}}</span>
</div>
<div class="card-body">
<p class="card-text">{{ document.contenttext }}</p>
</div>
</div>
{% endfor %}
{% endblock %}
The table looks like that:
documentid title annotation contenttext
1 abc abc abc
1 abc abc def
2 zzz xxx yyy
3 ooo mmm fff
Two first rows have the same documentid so i want to display both 'abc' and 'def' in the same document. And then go frther.
Which construction will allow me to do that?
title|annotation|contenttext
doc1: abc | abc | abc def
doc2: zzz | xxx | yyy
doc3: ooo | mmm | fff

Related

significance of .Values.nameOverride while declaring cassandra.name in helper template

I was reviewing helm template on git repo https://github.com/helm/charts/tree/master/incubator/cassandra
for deploying cassandra in Kubernetes.
I can see in helper template file "_helpers.tpl" , "cassandra.name" has been defined as below , as I can understand whose default value set to name of the Chart , but why .Values.nameOverride used here , without any pipe (just after .Chart.Name) , what is the significant of the same ,I am confused here .
{{- define "cassandra.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
which is used in cassandra/template/configmap.yaml as below
{{- if .Values.configOverrides }}
kind: ConfigMap
apiVersion: v1
metadata:
name: {{ template "cassandra.name" . }}
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "cassandra.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
{{ toYaml .Values.configOverrides | indent 2 }}
{{- end }}
Sprig default function takes two parameters, that's why there is no pipe.
If .Values.nameOverride is empty, .Chart.Name will be used.

helm range get values outside of loop

I was looking at the helm range example they have on their docs.
yaml
favorite:
drink: coffee
food: pizza
pizzaToppings:
- mushrooms
- cheese
- peppers
- onions
helm
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
{{- with .Values.favorite }}
drink: {{ .drink | default "tea" | quote }}
food: {{ .food | upper | quote }}
{{- end }}
toppings: |-
{{- range .Values.pizzaToppings }}
- {{ . | title | quote }}
- {{ .Values.favorite.drink }}
{{- end }}
I updated it to have this line - {{ .Values.favorite.drink }} but when I run helm template I get the error
can't evaluate field Values
Is there anyway to access the top level .Values from within the range function and escape the loop?
You can also use a global variable $ that points to the root context
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
{{- with .Values.favorite }}
drink: {{ .drink | default "tea" | quote }}
food: {{ .food | upper | quote }}
{{- end }}
toppings: |-
{{- range $.Values.pizzaToppings }}
- {{ . | title | quote }}
- {{ $.Values.favorite.drink }}
{{- end }}
You can use a variable:
toppings: |-
{{- $drink := .Values.favorite.drink }}
{{- range .Values.pizzaToppings }}
- {{ . | title | quote }}
- {{ $drink }}
{{- end }}
You can assign Values to a variable as well if you prefer.
toppings: |-
{{- $val := .Values }}
{{- range .Values.pizzaToppings }}
- {{ . | title | quote }}
- {{ $val.favorite.drink }}
{{- end }}

Check if files/dirs/ used in templates exists

Given the following json:
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "something.server.fullname" . }}
data:
{{ (.Files.Glob "dashboards/*.json").AsConfig | indent 2 }}
{{ (.Files.Glob "datasources/*.json").AsConfig | indent 2 }}
How can I check if the folder exists and is not empty?
Currently, if the folder is missing or doesn't have any files, helm install will abort with this message:
Error: YAML parse error on domething/charts/grafana/templates/dashboards-configmap.yaml: error converting YAML to JSON: yaml: line 6821: could not find expected ':'
You can pull your Globs out to variables, and then move everything within if blocks, e.g.:
{{- $globdash := .Files.Glob "dashboards/*.json" }}
{{ if $globdash }}
{{- $globdata := .Files.Glob "datasources/*.json" }}
{{ if $globdata }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "something.server.fullname" . }}
data:
{{ ($globdash).AsConfig | indent 2 }}
{{ ($globdata).AsConfig | indent 2 }}
{{ end }}
{{ end }}

What is the most elegant way of describing textually a table

Here is the situation. I am working in epidemiological research and describing tables is something we have to do on a day-to-day basis. Content editing tools and their associated language all offers ways to describe a table. Here are a few example :
Latex
\begin{center}
\begin{tabular}{ c c c }
cell1 & cell2 & cell3 \\
cell4 & cell5 & cell6 \\
cell7 & cell8 & cell9
\end{tabular}
\end{center}
HTML
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Eve</td>
</tr>
</table>
Markdown
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
Some of these are clearer than others, but all of them start to look absolutely horrific once one try to modify their formating to something other than the most basic example.
My question is the following :
Given that this is one of the most fundamental tasks of text editing, what is the most elegant way/language we know to represent textually a non-trivial table and its content?

Symfony2 custom form

I have form with checkboxes loaded from database (I use entity field type). Checkboxes are regions and districts. I have following database schema:
+-----------------------------------+
| id | parent_id | name |
+-----------------------------------+
| 1 | NULL | Region |
+-----------------------------------+
| 2 | 1 | District |
+-----------------------------------+
| 3 | 1 | Another district |
+-----------------------------------+
| 4 | NULL | Another region |
+-----------------------------------+
| 5 | 4 | Next district |
+-----------------------------------+
Problem is that I need following form. How to do that?
<b>Region</b><!-- Loaded from database -->
<!-- Dictricts ordered by name -->
<input type="checkbox" id="someId" value="3"><label for="someId">Another district</label>
<input type="checkbox" id="someId" value="2"><label for="someId">District</label>
<b>Another region</b><!-- Loaded from database -->
<!-- Dictricts ordered by name -->
<input type="checkbox" id="someId" value="5"><label for="someId">Next district</label>
Thanks to this post I've solve this by custom rendering form template.
EntityType field with options :
multiple = true
expanded = true
property = 'name'
class = 'YourBundle:YourEntity'
query_builder = 'function (EntityRepository $er) {return $er->createQueryBuilder('r')
->where('r.parentId IS NOT NULL')
->orderBy('r.parentId', 'ASC')->orderBy('r.name', 'ASC');}'