CSV Data in jekyll: how to sort and display data according to "Publication year" - github

I am trying to work on a simple workflow to sort out my publications csv to a list in my jekyll-based website.
This is my references.csv extracted from referencing software Mendeley and converted from bib to csv using online converter. I want to place this in my _data folder and make a list of publications in the page on jekyll website hosted on github. The sampe data is shown below:
"Item type","Authors","Title","Journal","Publication year","Volume","Issue","Pages","Publisher","Date published","ISSN","URLs","DOI","PMID","Abstract","Keywords"
"Book","Wilden H","PCI design handbook: Precast and prestressed concrete","","2017","","","","Precast/Prestressed Concrete Institute Wakefield, MA, USA","2017","","","","","",""
"Journal Article","Nanni A,Di Ludovico M,Parretti R","Shear strengthening of a PC bridge girder with NSM CFRP rectangular bars","Advances in Structural Engineering","2004","7","4","297-309","SAGE PublicationsSage UK: London, England","2004-11","1369-4332","https://journals.sagepub.com/doi/10.1260/1369433041653570;http://dx.doi.org/10.1260/1369433041653570","10.1260/1369433041653570","","trimmed down abstract","keyword 1"
"Journal Article","Di B,Wang J,Li H,Zheng J,Zheng Y,Song G","Investigation of Bonding Behavior of FRP and Steel Bars in Self-Compacting Concrete Structures Using Acoustic Emission Method","Sensors 2019, Vol. 19, Page 159","2019","19","1","159","Multidisciplinary Digital Publishing Institute","2019-01","1424-8220","http://dx.doi.org/10.3390/S19010159;https://www.ncbi.nlm.nih.gov/pubmed/30621189","10.3390/S19010159","30621189","To extend ","FRP,acoustic emission,bonding,compacting concrete,out test,pull,self"
"Journal Article","Crivelli D,Bland S","Structural health monitoring via acoustic emission","Reinforced Plastics","2016","60","6","390-392","Elsevier Ltd","2016-11","0034-3617","http://dx.doi.org/10.1016/j.repl.2015.05.004","10.1016/j.repl.2015.05.004","","Reinforced Plastics spoke to Dr Davide Crivelli from the Politecnico di Milano about new methods for detecting damage in composites.",""
"Journal Article","Tonelli D,Luchetta M,Rossi F,Migliorino P,Zonta D","Structural health monitoring based on acoustic emissions: Validation on a prestressed concrete bridge tested to failure","Sensors (Switzerland)","2020","20","24","1-20","Multidisciplinary Digital Publishing Institute","2020-12","1424-8220","http://dx.doi.org/10.3390/s20247272;https://www.ncbi.nlm.nih.gov/pubmed/33352961","10.3390/s20247272","33352961","very small abstract","AE"
Now, I want to make the list from these data as a citation data without getting into complexities of _includes. I want to keep it simple in a separate "Publications" page.
For example, I used the following code
{% assign cards = site.data.references | sort: 'Publication_year' | 'reverse' %}
{% for card in cards %}
<ul>
<li>{{ card.Publication year }} {{ card.Title }} {{ card.Publication }} </li>
<ul> {{ card.Authors }} {{ card.Authors }} </ul>
</ul>
{% endfor %}
In the code, when I use the heading in csv as "Year" and then sort using sort: 'Year' | 'reverse' %,it works. Maybe, there is a different way to write it for "two-worded" headings, as I think the card.Publication year won't work. i have spent a lot of time on this and I think I need to just use the code once and then just work with the csv file only.
The output I intend to only pick up the Journal Article from the Item type and prepare a list with the following information with items shown in the following:
[Publication year][title][Journal]
[Authors]
Also, I tried italisizing the text in one of the items, it should work like {{ __card.Publication year__ }} but it does not. I also read somewhere that the csv encoding doesn't allow to extract the first column due to some BOM or UTF-8 something encoding. But I want to filter using the item type.
ps I have tried to compromise with another simplified code with headings same as this, but the google scholar exported csv has ; as delimiters and while using card.Authors does not work to call the data.
I apologize I am not at all familiar with this and I am struggling with using this syntax. However, I foresee that if the code works, it will make my life easier. I would really appreciate your help. I apologize for any lack of proper jargon while explaining the problem.
Thank you in advance.
I tried to display the data from csv data file on the website but some values are missing. I cannot figure out the solution

You're on the right track but you are incorrectly referencing the CSV file column. Since "Publication year" is a two-worded heading, you need to reference it using underscores instead of spaces.
Try changing this line:
{% assign cards = site.data.references | sort: 'Publication_year' | 'reverse' %}
You can use sort_by instead of sort and provide 'Publication_year' as an argument.
{% assign cards = site.data.references | sort_by: 'Publication_year' | reverse %}
When you reference the column in the for loop, you should also use underscores:
<li>{{ card.Publication_year }} {{ card.Title }} {{ card.Journal }} </li>

Related

How to show the category name on the category listing page?

I've been using Wagtail for a while, for my basic website, but during the pandemic I've had to create online versions of all my courses -- I teach at a university -- and I've decided to do this in Wagtail. It's a much more robust solution than anything the university can provide. (I think a lot of people are in my situation.) It's been great so far, but I'm not a programmer (I teach Creative Writing!) and so I'm a bit out of my depth with a few things. Here's one thing I could use help with. I have categories (as per Kalob's tutorials), and I have category listing pages. I click on a category and I get a page showing just pages in that category. So far so good. But how would I show, on these listing pages, a header that says "Showing Pages in Category X"? Here's what I have in the models for my courses app (taken straight from Kalob's tutorial on categories):
#route(r"^category/(?P<cat_slug>[-\w]*)/$", name="category_view")
def category_view(self, request, cat_slug):
"""Find courses based on a category."""
context = self.get_context(request)
try:
# Look for the course category by its slug.
category = CourseCategory.objects.get(slug=cat_slug)
except Exception:
category = None
if category is None:
# This is an additional check.
pass
context["courses"] = (
CoursePage.objects.live().public().filter(
categories__in=[category])
)
And here's what I have in the template for these category pages:
<ul class="menu-list">
{% for cat in categories %}
<li>
<a href="{% routablepageurl page "category_view" cat.slug %}">
{{ cat.name }}
</a>
</li>
{% endfor %}
</ul>
As Intended, the above shows all categories. How would I show only the category of the selected pages, so that I could put that in the title of the page? I've tried a few things, but as I said, I'm out of my depth here and I am just guessing and googling -- so far, without success. I know a lot of the ways to not make this work.
Not sure if I am missing something, but if you want to make the current category available to your template (the one based on the slug in the URL). You can add it to the context to make it available in your template, similar to how you are adding courses.
Example
my_model.py
#route(r"^category/(?P<cat_slug>[-\w]*)/$", name="category_view")
def category_view(self, request, cat_slug):
"""Find courses based on a category."""
# ... rest of the code from above
context["courses"] = (
CoursePage.objects.live().public().filter(
categories__in=[category])
)
context["current_category"] = category
my_template.html
<h2>{{ page.title }} - {{ current_category }}

Symfony twig get data value from collection object

Hello,
when editing a form with obj-values from a collection in Symfony 4.2, i need each collection-objects ID for frontend stuff.
If I dump a collection object,
{{ dump(form.vars.data) }}
I can see something like this:
CollectionObj1 {#3341 ▼
-id: 21167
-value1: null
-value2: 74
If I now want to access to the id with
{{ dump(form.vars.data.id) }}
I get the following error:
Impossible to access an attribute ("id") on a null variable.
Can somebody tell me, how I can access to the id of the object in the collection?
Thanks very much in advance
Okay, two things I did not mention lead to the error:
My id is not called id. Due to an old database it is called someting like this: K_RESULTS_ID
I am using symfony's collection prototypes: https://symfony.com/doc/current/form/form_collections.html#allowing-new-tags-with-the-prototype and called the dump in the respective form-block
The first error was that you have to call such an id-name without underscores, it should be called like that:
{{ dump(form.vars.data.KRESULTSID) }}
The second one was, that I do have to check, if the object is not null, before fetching it. So I needed to add something like that:
{% if form.vars.data is not null %}
{% set resultId = form.vars.data.KRESULTSID%}
{% else %}
Now it works like expected.
Thanks anyway, #wp78de and sorry for not posting the full truth ;)

Symfony2 How to create specific collection widget for specific colletion in deep collection form nesting

I have little more complex problem, i have never done more than 1 nested form in an a form, which was fine to just include a custom collection widget template. (Reason: I need to re-code website based on laravel and Spaghetti code, with Spaghetti structure with tons of bugs and buggy patches, what i am fixing for a year now, and i have decided to recreate this app on my loved Symfony).
Let me write the structure:
Questionnaire (short name QN for later use)
- QN -
|_ QN Sections -
|_ QN Parts -
|_ QN Groups -
|_ QN Questions -
|_ some predefined answers
As you can see each QN can have Sections, these sections can have parts, these parts can have groups, and these groups can have questions, these questions have some conditional fields like if question type is "A,B,C" it has another nested collection form for these predefined answers,...
Problem is that for each of these collection form, i need to specify somehow a custom collection wiget template, because each of these collection form has different layout of fields, how they are displayed and handled.
Currently i have created a collection widget template that i include before QN Sections to style QN Sections, but this template is used also for his child collection form, what i need to avoid.
In a perfect world it should work like "prototype_template" => "some path", and then create javascript for each tempalte to add, remove, etc.
Here is an screenshot with some information how it looks now:
In final stage using these separate templates for each collection form, the "form builder" should look like actual web app.
If you need more informations please let me know, i will provide as much informations as i can.
To recap: I need somehow to specify for each nested collection form type to use different collection form widget template.
Thank you
Finnaly I got it.
The main collection template i have used was collection_widget block.
That was bad because it was too general. I hav renamed it to _questionnaire_questionnaireSections_widget, so the 1. level collection were themed. But after day of headake, 1000 combinations of form names i have got how to name the 2. level collection, its block name is "_questionnaire_questionnaireSections_entry_questionnaireParts_widget" what simply stand for "_mainFormTypeName_fieldNameOfFirstCLevelCollection_entry_FieldNameOfSecondLevelCollection_widget"
Than i just needed to place each template file to right place at the right moment.
edit.html.twig
{{ form_start(form) }}
{% form_theme form "::templates/collection/questionnaire/questionnaireSection.html.twig" %}
.........
{{ form_widget(form.questionnaireSections) }}
questionnaireSection.html.twig
{% block _questionnaire_questionnaireSections_widget %}
.............
{% for rows in form %}
{% form_theme form "::templates/collection/questionnaire/questionnairePart.html.twig" %}
questionnairePart.html.twig
{% block _questionnaire_questionnaireSections_entry_questionnaireParts_widget %}
So problem is solved, i have successfully themed nested collections. Thanks to myself and to symfony docs that has 0 words documentation to nested form theming, but they has some information about the "entry " part.

how to display particular fields in form Symfony 2.6

I need display particular fields in form in Symfony 2.6. I use a class Form. I have the folowing fields: name, email, message, send, recet. I need display all of them except recet .I try like this:
{{form_start(form)}}
{{ form_errors(form) }}
{{form_row(form.name)}}
{{form_row(form.email)}}
{{form_row(form.message)}}
{{form_end(form)}}
But, it's displaying all fields in form, it is not what I want. Even if i leave only {{form_start(form)}} and {{form_end(form)}} - its display all fields. Can someone help me wit this problem?
remove form_end, just close form with HTML
</form>
but then you must handle CSRF token generation by adding:
{{ form_widget(form._token) }}
{{ form_widget(form._token) }}
or try setting field you do not want to show using:
{% do form.recet.setRendered %}
but probably best way is not to add this field in the first place, rather than hiding it, by form options or event listeners depending on some criterias
A better solution is to remove the field from the form type. If you only remove it from the view, it may be interpreted as a blank submission for that field and delete existing data.
If you only use the form in one place, then just remove the field from the type. If you use it in multiple places, then you can selectively remove the field in a FormEvents::POST_SET_DATA event listener.

Symfony 2, double error

Why i have double error when i want to customize my form ?
Template:
<div>
{{ form_errors(edit_form.wiek) }}
{{ form_widget(edit_form.wiek) }}
</div>
HTML:
You probably see the error on the field level, but also on the form level. It can look like you have two errors especially if there's only one field in your form.
Dig into the customizing error output of the form cookbook for more details.
Edit
The doc gives a much better explanation :)
You can also customize the error output for just one specific field type. For example, certain errors that are more global to your form (i.e. not specific to just one field) are rendered separately, usually at the top of your form.