Django, Display thumbs in Admin? - django-admin

how ill show in the admin section the user picture?, i was looking the template of the admin and i can't see how...
i think that Django show the fields in the section code (change_list template), but jeje ..how? jeje
{% block result_list %}
{% if action_form and actions_on_top and cl.full_result_count %}{% admin_actions %}{% endif %}
{% result_list cl %}
{% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %}
{% endblock %}
Thanks guys :)

We use Justin Driscoll's fabulous django-photologue.
If photologue is installed properly (recommend running python manage.py plinit as part of the installation) and the media is being served correctly the following should provide you with an easy-to-use admin_thumbnail() as follows:
models.py
from photologue.models import Photo
class Entry(models.Model):
entry_photo = models.ForeignKey(Photo)
...
admin.py
def show_entry_thumbnail(item):
return item.entry_photo.admin_thumbnail()
show_entry_thumbnail.short_description = _('Entry Photo')
class ItemAdmin(admin.ModelAdmin):
list_display = (show_entry_thumbnail, ... )

There also appears to be an alternative method using sorl-thumbnail: it's mentioned here.

Related

Get all tags used by a Shopify shop in one request

When I try this URL in my browser:
https://USERNAME:PASSWORD#SHOP.myshopify.com/admin/products/tags.json
It gives me a nice list of all the tags in my shop.
I need this list, but when I try an API call with Python it says 'Not found'. Since I can do it with my browser, there must be a way to do it programmatically.
Getting all the tags by looping over all products is too long (+- 5-10 seconds), whereas this gives me everything I need instantly.
How can I make this request?
Thanks
Currently, Shopify Rest API still doesn't have an endpoint to get all tags, vendors, types. And GraphQL Admin API can only get at maximum first 250 results.
You can get all of them through Shopify liquid ( Not working with the passworded store ).
Create a new search template name: search.foo.liquid
{% layout none %}
{
"vendors" : {{shop.vendors|json}},
"types" : {{shop.types|json}},
"tags" : {% capture output %}
{% for collection in collections %}
{% if forloop.index == 1 %}""{% endif %}
{% if collection.all_tags.size > 0 %}
{% for tag in collection.all_tags %}
{% if output contains tag %}
{% else %}
,"{{tag}}"
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endcapture %}
{{ output | strip_newlines | prepend: '[' | append: ']' }}
}
Access: https://your-store.myshopify.com/search.json?view=foo in browser to view the result, Use cURL to get it in your application.
The tags aren't exposed via the REST API, but they're accessible via the GraphQL Admin API:
{
shop{
productTags(first: 100){
edges{
node
}
}
}
}
Check this for extra info

How to load index from for loop inside widget to use it in if condition

I have widget load pieces and I set for loop to load single item inside this widget and I want inside for loop to set index for each element to take advantage from it to make if condition, How I can do that?
here is my for loop inside widget:
{% for piece in data.widget._pieces %}
and I tried to set index like this but it didn't work:
{% set index = data.piece.__dotPath | replace(".", "-") %}
Using nunjucks's built-in loop object, you can conditionally check what index your loop is at and choose to do something special like
{% for piece in data.widget._pieces %}
{% if loop.index === 1 %}
... something special
{% else %}
... something normal
{% endif %}
{% endfor %}

How to get a SubString of variable using stencil templating tool for swift

I'm using the stencil template language tool for swift found here:
https://github.com/stencilproject/Stencil
Using master branch.
The Problem
given the following .json file
{
"xcassets" : "dev Sources test1"
}
I want to be able to retrieve the first word delimited by " " which is "dev".
What I've Tried
The latest version of Stencil has the Split Function. But the problem is I can't figure out how to access the first element in the resulting array, and it's not in the documentation either.
I've tried the following in the stencil file:
{{xcassets|split:" "[0]}}
{{{{xcassets|split:" "}}[0]}}
{{xcassets|split:" ".first}}
{{xcassets|split:" "}}.first}}
{{xcassets|split:" "|[0]}}
{{xcassets|split:" "|.first}}
{{xcassets|split:" "|first}}
None of which worked.
What I'm trying to avoid
I know I can do it this way, but there must be a better way.
{% for element in xcassets|split:" " %}
{% if forloop.first %}
{{ element }}
{% endif %}
{% endfor %}
Anyone have suggestions for a better tool?
I guess this is the only way:
{% for element in xcassets|split:" " %}
{% if forloop.first %}
{{ element }}
{% endif %}
{% endfor %}

October CMS how to get current locale name?

Could you tell me please how i can get current language name or somthing like this.
I want customize Locale Switcher on web site based on October CMS.
It will be greate to recevie something like
...
{{ set var = ****.getLocale();}}
...
then use it for switch($var){}
...
In twig you can access the current language with {{ activeLocale }}, the full language name with {{ activeLocaleName }} and an array with all locales available with {{ locales }}.
You could use {{ dump() }} to see all variables available on a page. If you try it you will find the locale variables right there as well.
i tried with activeLocale and also with locales array but one can not stop the loop and thus it was impossible for me to render some content conditionally. this is how i solved it, after reading the logic of plugin that how it is working, I did this in one of my partials.
==
use RainLab\Translate\Classes\Translator;
protected $translator;
function onStart()
{
$this->translator = Translator::instance();
$this['SelectedLanguage'] = $this->activeLocale = $this->translator->getLocale();
}
==
{% set CurrentLanguage = SelectedLanguage %}
now {{CurrentLanguage}} will give me code for current language so now using twig i can do some conditional rendering like this
{% if CurrentLanguage is same as('en') %}{% endif %}
{% if CurrentLanguage is same as('tr') %}{% endif %}
{% if CurrentLanguage is same as('gr') %}{% endif %}
Maybe there could be a another solution. but this one worked like charm.
Update:
Although, In case of components or elsewhere one can use session to retrieve the current language this way,
Session::get('rainlab.translate.locale')
Assuming that you use RainLab.Translate plugin?
Create a partial that uses the localePicker component and then use your custom code:
<div>{{ activeLocale }} - {{ activeLocaleName }}</div>
{% for code, name in localePicker.locales %}
<div>{{ code }} - {{ name }}</div>
{% endfor %}
And just call that partial from where you want to use it.

Can I pass a variable from a Jekyll template to an include then render data with that variable?

In foo.html (a post), I have the following:
{% assign table_name="application" %}
{% include table.html %}
This assignment appears to work fine in table.html
{% assign tableName = table_name %}
<p>table name is: {{ tableName }}</p> # renders "table name is: application"
Now, I'm trying to sort through an array of data that I have defined in config.yml by doing the following:
{% for header in site.table.tableName.headers %}
<th>{{ header }}</th>
{% endfor %}
This gives me no output whatsoever.
If I change the for statement to include the variable's content, not the variable, it works fine.
{% for header in site.table.application.headers %}
This leads me to believe that it's not a problem with my array but that it's either a shortcoming of Jekyll, a bug in Jekyll, or I'm not accurately constructing my statements.
Any idea how I could make this work?
Looks like this can be done. I had to think about it more programmatically. What seems to be happening is that Jekyll was expecting an object and I was feeding it a string.
{% assign tableName = "aStringName" %}
{% include table.html %}
so,
# in _includes/table.html
{% for header in site.table.tableName.headers %}
was being interpreted as
{% for header in site.table."aStringName".headers %}
When I switched to bracket notation for the object, it was perfect.
Final result:
{% for header in site.table[tableName].headers %}
or, as Jekyll sees it,
{% for header in site.table['aStringName'].headers %}

Resources