How to make to display the button which I need in my template Django? - django-templates

I need:
1) If a user has created a object of the class by a form, then he sees the button which calls the webpage of the object detail.
2) If a user didn't create a object of the class, but another user did it, then he sees the button which calls this form to create a object and the user will be a author this object.
3) If a user didn't create a object of the class by a form, then he sees the button which calls this form.
If a user didn't create a object of the class, but another user did it, then he sees the button which calls this form to create a object and the user will be a author this object.
I made this:
{% if list %}
{% for i in list %}
{% if request.user == i.author %}
<a class="btn" href="{% url 'detail' i.id %}" role="button">
{{i.detail}}
</a>
{% else %}
<button type="button" class="btn" data-toggle="modal" data-target="#form">
the form button
</button>
{% endif %}
{% endfor %}
</div>
{% else %}
<button type="button" class="btn btn-primary mr-4" data-toggle="modal" data-target="#digital">
Кнопка для вызова формы
</button>
{% endif %}
But if a user created a object of the class, then he sees both button.

views.py
class MyClassCreateView(LoginRequiredMixin, CustomSuccessMessageMixin, CreateView):
model = MyClass
template_name = 'mypage.html'
form_class = MyClassForm
success_url = reverse_lazy('mypage')
success_msg = 'сохранён'
def get_context_data(self, **kwargs):
kwargs['list_mylist'] = MyClass.objects.all()
list_mylist = kwargs['list_mylist']
for i in list_mylist:
if i.author == self.request.user:
print('my_button')
kwargs['my_button'] = True
break
return super().get_context_data(**kwargs)
template
{% if my_button %}
{% for i in list_mylist %}
{% if request.user == i.author %}
<a class="btn btn-primary" href="#" role="button">
кнопка первая
</a>
{% endif %}
{% endfor %}
{% else %}
<button type="button" class="btn btn-primary mr-4" data-toggle="modal" data-target="#class">
кнопка вторая
</button><br>
{% endif %}

Related

Form Button is not working with unless condition - Shopify

Everything is showing like I expect but the send button is not working.
the button is not clickable as well
This part is for product-form.liquid
{% unless product.available %}
{%- form 'contact', id: form_id -%}
{% if form.posted_successfully? %}
<p class="accent-text">Thanks! We will notify you when this product becomes available!</p>
{% else %}
<p>Enter your email to get notified when {{ product.title }} become available.</p>
{% endif %}
<div id="notify-me-wrapper" class="clearfix">
{% if customer %}
<input type="hidden" name="contact[email]" value="{{ customer.email }}" />
{% else %}
<input style="float:left; width:180px;" required="required" type="email" name="contact[email]" placeholder="your#email.com" class="styled-input" />
{% endif %}
<input type="hidden" name="contact[body]" value="Please notify me when {{ product.title | escape }} becomes available." />
</div>
<button type="submit" class="btn">
{{ 'contact.form.send' | t }}
</button>
{% endform %}
{% endunless %}
I've checked your code on my store. there is no error in the liquid code. it may possible that some js code is being affected after page load. please check your JS files.

Admin template is ignored when deploying

I have a strange situation here using Django 3.2.8:
When deploying, only one admin template is being ignored (but not if debug == True):
This is my directory after deploying (and before, they are identical):
change_form.html is applied correctly, whilst submit_line.html is not when debug = false.
content of change_form.html:
{% extends "admin/change_form.html" %}
{% load i18n admin_urls %}
{% block inline_field_sets %}
{% for inline_admin_formset in inline_admin_formsets %}
{% include inline_admin_formset.opts.template %}
{% endfor %}
<h3>
<p>WARNING!</p>
</h3>
{% endblock %}
content of submit_line.html:
{% load i18n admin_urls %}
<div class="submit-row">
{% if show_save %}
<input type="submit" value="{% trans 'Save' %}" class="default" name="_save" />{% endif %}
{% if show_delete_link %}
{% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
<p class="deletelink-box">{% trans "Delete" %}</p>
{% endif %}
{% if show_download_zip %}
<input type="submit" value="{% trans 'zip' %}" name="_download_zip" />
{% endif %}
{% if show_save_as_new %}
<input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew" />
{% endif %}
{% if show_save_and_add_another %}
<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother" />
{% endif %}
{% if show_save_and_continue %}
<input type="submit" value="{% trans 'Save and continue editing' %}" name="_continue" />
{% endif %}
</div>
pre-deployment, with debug = True:
compares to:
Edit:
A little further digging:
When moving the logic from submit_line.html to change_form.html I get my download button, but only after setting all the buttons visibility by hand - again, this only happens when DEBUG == False:
working render_change_form from admin.py code fragment:
def render_change_form(self, request, context, *args, **kwargs):
context.update({'show_save_and_add_another': True})
context.update({'show_save_and_continue': True})
context.update({'show_save': True})
context.update({'show_delete_link': True})
if not context["original"] == None:
context.update({'show_download_zip': True})
return super().render_change_form(request, context, *args, **kwargs)
working change_form.html:
{% block submit_buttons_bottom %}
{% load i18n admin_urls %}
<div class="submit-row">
{% if show_save %}
<input type="submit" value="{% trans 'Save' %}" class="default" name="_save" />{% endif %}
{% if show_delete_link %}
{% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
<p class="deletelink-box">{% trans "Delete" %}</p>
{% endif %}
{% if show_download_zip %}
<input type="submit" value="{% trans 'zip' %}" name="_download_zip" />
{% endif %}
{% if show_save_as_new %}
<input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew" />
{% endif %}
{% if show_save_and_add_another %}
<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother" />
{% endif %}
{% if show_save_and_continue %}
<input type="submit" value="{% trans 'Save and continue editing' %}" name="_continue" />
{% endif %}
</div>
{% endblock %}
When doing the same in DEBUG == True, the context.update()'s are not needed, also django uses the correct submit_line.html template without any issues.
So ... now I know how to fix this, but I can't figure out why this is happening the way I observed it.

How can I replace a flexslider with stacked content in Shopify?

On the desktop version of our site, we have a 3 column section (the theme calls is text-adverts) with one about pickup, one about delivery, one about shipping. On mobile, it automatically converts to a flexslider with no arrows or really any way of knowing to swipe unless you watch it long enough. I'd much rather just have the 3 stacked so no users miss this critical info.
I've found the code dealing with the text-adverts on mobile but I don't know what to replace it with. Any help is much appreciated.
<div class="container d-block d-md-none">
<div class="row text-advert-section mobile-homepage-text-adverts flexslider text-adverts-alignment--{{ text-advert--alignment }}">
<ul class="slides">
{% for block in section.blocks %}
{%- assign advert_has_link = false -%}
{% if block.settings.link != blank %}
{%- assign advert_has_link = true -%}
{% endif %}
<li {{ block.shopify_attributes }}>
<div class="grid__item text-advert-section__item{% if advert_has_link %} text-advert-section__item--link{% endif %}">
{% if advert_has_link %}<a href="{{ block.settings.link }}">{% endif %}
{% if block.settings.icon != 'none' %}
<div class="text-advert-section__icon-wrapper {{ section.settings.icon-size }}">
<i data-feather="{{ block.settings.icon }}"></i>
</div>
{% endif %}
<div class="text-advert-section__text-wrapper">
{% if block.settings.heading != blank %}
<span class="text-advert-section__header type-subheading type-subheading--1">{{ block.settings.heading | escape }}</span>
{% endif %}
{% if block.settings.subheading != blank %}
<span class="text-advert-section__sub-header h6">{{ block.settings.subheading | escape }}</span>
{% endif %}
</div>
{% if advert_has_link %}</a>{% endif %}
</div>
</li>
{% endfor %}
</ul>
</div>
</div>
The flexslider is being initialised by javascript. So you need to find the script that initialises the slider. Most likely it will look something like this: $('.flexslider').flexslider({})
You should also remove the flexslider class from the div with class text-advert-section - because it shouldn't utilise any flexslider code.

Shopify Liquid Show Button If Variant Not Available

I'm trying to show a button that says "Email me when Available" if a product variant is not available. I'm trying to use the same logic as the Debut Theme does to have the button say "add to cart" or "sold out".
<div class="product-form__item product-form__item--submit{% if section.settings.enable_payment_button %} product-form__item--payment-button{% endif %}{% if product.has_only_default_variant %} product-form__item--no-variants{% endif %}">
<button type="submit" name="add" {% unless current_variant.available %}disabled="disabled"{% endunless %} class="btn product-form__cart-submit{% if section.settings.enable_payment_button %} btn--secondary-accent{% endif %}" data-add-to-cart>
<span data-add-to-cart-text>
{% unless current_variant.available %}
{{ 'products.product.sold_out' | t }}
{% else %}
{{ 'products.product.add_to_cart' | t }}
{% endunless %}
</span>
</button>
{% unless current_variant.available %}
<button class="btn BIS_trigger" data-product-data='{{ product | json | escape }}'>
Email When Available
</button>
{% endunless %}
</div>
What I can't understand is why the "unless current_variant.available" logic works in the button above, but not in part.
Our "not available" variants are set to have Shopify track inventory and the available inventory at zero. We set the available variants to not tracking inventory.
How can I make this work?

How to create third level menu (Shopify)

Can you please guide me, How to create third level menu in shopify.
Sub Dropdown Menu for (Almost) Any Shopify theme.
Thanks in advance.
In navigation:
If your Shopify backend updated then simple drag and drag upto three level
see: screenshot http://prntscr.com/hzu8n3
Or use as create new menu with same handle of sub menu.
And use below code
<div class="menuItems">
<ul class="mebItemParent">
{% for link in linklists.mobile-menu.links %}
{% if linklists[link.handle] == empty %}
<li class="">{{ link.title }}</li>
{% else %}
<li class="hasSubItem">
<div class="withtiggle">
{{ link.title }} <span class="toggleItem">+</span>
</div>
<ul>
{% for l in linklists[link.handle].links %}
{% if linklists[l.handle] == empty %}
<li class="">{{ l.title }}</li>
{% else %}
<li class="hasSubItem">
<div class="withtiggle">
{{ l.title }} <span class="toggleItem">+</span>
</div>
<ul>
{% for l2 in linklists[link.handle].links %}
<li class="">{{ l2.title }}</li>
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
</ul>
</div>