I've been searching this for days, got some progress but something stop me.
I'm trying to override the django xadmin's list_display into "Chained Select Boxes"/"Cascading dropdown list" style, like the "country state city".
i've add some select javascript into '/xadmin/views/model_list.html'
but i do not know how can i transfer the data result from my database into this javascript.
Anybody could show me? thanks in advance.
{% extends base_template %}
{% load i18n %}
{% load xadmin_tags %}
{% block extrastyle %}
<style type="text/css">
.btn-toolbar{margin-top: 0;}
#content-block.full-content{margin-left: 0;}
</style>
{% endblock %}
{% block bodyclass %}change-list{% endblock %}
{% block nav_title %}{% if brand_icon %}<i class="{{brand_icon}}"></i> {% endif %}{{brand_name}}{% endblock %}
{% block nav_toggles %}
{% include "xadmin/includes/toggle_menu.html" %}
{% if has_add_permission %}
<i class="fa fa-plus"></i>
{% endif %}
<button class="navbar-toggle pull-right" data-toggle="collapse" data-target=".content-navbar .navbar-collapse">
<i class="fa fa-filter"></i>
</button>
{% endblock %}
{% block nav_btns %}
{% if has_add_permission %}
<a href="{{add_url}}" class="btn btn-primary"><i class="fa fa-plus"></i>
{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}</a>
{% endif %}
{% endblock nav_btns %}
{% block content %}
<div class="content-toolbar btn-toolbar pull-right clearfix">
{% view_block 'top_toolbar' %}
{% block toolbar_column %}
<div class="btn-group">
<a class="dropdown-toggle btn btn-default btn-sm" data-toggle="dropdown" href="#">
<i class="fa fa-list-alt"></i> {% trans "Columns" %} <span class="caret"></span>
</a>
<ul class="dropdown-menu model_fields pull-right" role="menu" aria-labelledby="dLabel">
<li><i class="fa fa-refresh"></i> {% trans "Restore Selected" %}</li>
<li class="divider"></li>
{% for f, selected, flink in model_fields %}
<li><a href="{{flink}}">
{% if selected %}<i class="fa fa-check"></i>{% else %}<i class="fa fa-blank"></i>{% endif %}
{{f.verbose_name}}</a></li>
{% endfor %}
</ul>
</div>
{% endblock toolbar_column %}
{% block toolbar_layouts %}
<div class="btn-group layout-btns" data-toggle="buttons">
<label class="btn btn-default btn-sm layout-normal active">
<input type="radio"> <i class="fa fa-th-large"></i>
</label>
<label class="btn btn-default btn-sm layout-condensed">
<input type="radio"> <i class="fa fa-th"></i>
</label>
{% view_block 'top_layout_btns' %}
</div>
{% endblock toolbar_layouts %}
{% block toolbar_fullscreen %}
<div class="btn-group layout-btns" data-toggle="buttons-checkbox">
<button type="button" class="btn btn-default btn-sm layout-full"><i class="fa fa-expand"></i></button>
{% view_block 'top_check_btns' %}
</div>
{% endblock toolbar_fullscreen %}
{% view_block 'top_btns' %}
</div>
<ul class="pagination pagination-sm pagination-left pagination-inline">
{% view_block 'pagination' 'small' %}
</ul>
<form id="changelist-form" action="" method="post"{% view_block 'result_list_form' %}>{% csrf_token %}
{% view_block 'results_top' %}
<div class="results table-responsive">
{% if results %}
{% block results_grid %}
<div id="element_id">
<span class="FirstClass">FirstClassScene:
<select class="FirstClassScene">
{% for o in result_headers.cells %}
<option value="BeautySalon" >{{ o.field_name }}</option>
{% endfor %}
</select>
</span>
<span class="SecondClass">SecondClassScene:
<select class="SecondClassScene">
{% for o in result_headers.cells %}
<option value="hall" selected>{{ o.field_name }}</option>
{% endfor %}
</select>
</span>
<span class="ThirdClass">ThirdClassScene:
<select class="ThirdClassScene">
{% for o in result_headers.cells %}
<option value="ConsultingRoom" selected>{{ o.field_name }}</option>
{% endfor %}
</select>
</span>
</div>
<script src="jquery.cxselect.js"></script>
<script type="text/javascript" src=""></script>
<script>
$('#element_id').cxSelect({
url: 'cityData.min.json',
selects: ['FirstClassScene', 'SecondClassScene', 'ThirdClassScene'],
emptyStyle: 'none'
});
$(document).ready(function(){
var FirstClassSelect = $(".FirstClass").children("select");
var SecondClassSelect = $(".SecondClass").children("select");
FirstClassSelect.change(function(){
var FirstClassValue = $(this).val();
if( FirstClassValue != ""){
if(!FirstClassSelect.data(FirstClassValue)){
$.post("ChainSelect",{keyword:FirstClassValue,type:"top"},function(data){
if (data.length != 0){
SecondClassSelect.html("");
$("<option value=''>please choose</option>").appendTo(SecondClassSelect);
for(var i = 0;i < data.length; i++ ){
$("<option value =' " + data[i] + " '> "+ data[i] +"</option>").appendTo(SecondClassSelect);
}
SecondClassSelect.parent().show();
FirstClassSelect.next().show();
}else{
SecondClassSelect.parent().hide();
FirstClassSelect.next().hide();
}
FirstClassSelect.data(FirstClassValue,data);
},"json");
}else{
var data = FirstClassSelect.data(FirstClassValue);
if (data.length != 0){
SecondClassSelect.html("");
$("<option value=''>please choose</option>").appendTo(SecondClassSelect);
for(var i = 0;i < data.length; i++ ){
$("<option value =' " + data[i] + " '> "+ data[i] +"</option>").appendTo(SecondClassSelect);
}
SecondClassSelect.parent().show();
FirstClassSelect.next().show();
}else{
SecondClassSelect.parent().hide();
FirstClassSelect.next().hide();
}
}
}else{
SecondClassSelect.parent().hide();
FirstClassSelect.next().hide();
}
});
</script>
{% endblock %}
Related
when i am creating wagatil menu translatable page does not exist error display
{% load wagtailimages_tags cms_tags %}
{% get_menu "main" None request.user.is_authenticated as navigation %}
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto mr-5">
{% for item in navigation %}
{% get_menu item.slug item.page request.user.is_authenticated as submenu %}
<li class="{% if submenu %}dropdown {% endif %}p-2">
<div class="dropdown show">
<a href="{{ item.url }}"
{% if submenu %} class="menuitem dropdown-toggle {% if item.icon %}menuicon{% endif %}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"
{% else %} data-toggle="tooltip" title="{{ item.title }}" class="menuitem"
{% endif %}
>
{% if item.icon %}
{% image item.icon fill-30x30 class="image-menu" %}
{% else %}
{{ item.title }}
{% endif %}
</a>
{% if submenu %}
<div class="dropdown-menu">
{% for subitem in submenu %}
<a href="{{ subitem.url }}" class="dropdown-item menuitem p-2 {% if subitem.icon %}menuicon{% endif %}">
{% if subitem.icon %}
{% image subitem.icon fill-30x30 class="image-menu" %}
{% else %}
{{ subitem.title }}
{% endif %}
</a>
{% endfor %}
</div>
{% endif %}
</div>
</li>
{% endfor %}
</ul>
</div>
On the category page, the sub-category are getting repeated in refine search. I have added categories and sub-categories. I have 3 level categories i.e Phone-cases(Parent)->Apple(Sub-category)->iPhone X(Sub-category of apple).
Screenshot:
<?php
{{ header }}
<div id="product-category" class="container">
<ul class="breadcrumb">
{% for breadcrumb in breadcrumbs %}
<li>{{ breadcrumb.text }}</li>
{% endfor %}
</ul>
<div class="row">
{{ column_left }}
{% if column_left and column_right %}
{% set class = 'col-sm-6' %}
{% elseif column_left or column_right %}
{% set class = 'col-sm-9' %}
{% else %}
{% set class = 'col-sm-12' %}
{% endif %}
<div id="content" class="{{ class }}">
{{ content_top }}
<h2>{{ heading_title }}</h2>
{% if thumb or description %}
<div class="row">
{% if thumb %}<div class="col-sm-2"><img src="{{ thumb }}" alt="{{ heading_title }}" title="{{ heading_title }}" class="img-thumbnail" /></div>
{% endif %}
{% if description %}<div class="col-sm-10">{{ description }}</div>
{% endif %}</div>
<hr>
{% endif %}
{% if categories %}
<h3>{{ text_refine }}</h3>
{% if categories|length <= 5 %}
<div class="row">
<div class="col-sm-3">
<ul>
{% for category in categories %}
<li>{{ category.name }}</li>
{% endfor %}
</ul>
</div>
</div>
{% else %}
<div class="row">
{% for category in categories|batch((categories|length / 4)|round(1, 'ceil')) %}
<div class="col-sm-3">
<ul>
{% for child in category %}
<li>{{ child.name }}</li>
{% endfor %}
</ul>
</div>
{% endfor %}
</div>
<br />
{% endif %}
{% endif %}
{% if products %}
<div class="row">
<div class="col-md-2 col-sm-6 hidden-xs">
<div class="btn-group btn-group-sm">
<button type="button" id="list-view" class="btn btn-default" data-toggle="tooltip" title="{{ button_list }}"><i class="fa fa-th-list"></i></button>
<button type="button" id="grid-view" class="btn btn-default" data-toggle="tooltip" title="{{ button_grid }}"><i class="fa fa-th"></i></button>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="form-group">{{ text_compare }}
</div>
</div>
<div class="col-md-4 col-xs-6">
<div class="form-group input-group input-group-sm">
<label class="input-group-addon" for="input-sort">{{ text_sort }}</label>
<select id="input-sort" class="form-control" onchange="location = this.value;">
{% for sorts in sorts %}
{% if sorts.value == '%s-%s'|format(sort, order) %}
<option value="{{ sorts.href }}" selected="selected">{{ sorts.text }}</option>
{% else %}
<option value="{{ sorts.href }}">{{ sorts.text }}</option>
{% endif %}
{% endfor %}
</select>
</div>
</div>
<div class="col-md-3 col-xs-6">
<div class="form-group input-group input-group-sm">
<label class="input-group-addon" for="input-limit">{{ text_limit }}</label>
<select id="input-limit" class="form-control" onchange="location = this.value;">
{% for limits in limits %}
{% if limits.value == limit %}
<option value="{{ limits.href }}" selected="selected">{{ limits.text }}</option>
{% else %}
<option value="{{ limits.href }}">{{ limits.text }}</option>
{% endif %}
{% endfor %}
</select>
</div>
</div>
</div>
<div class="row">
{% for product in products %}
<div class="product-layout product-list col-xs-12">
<div class="product-thumb">
<div class="image"><img src="{{ product.thumb }}" alt="{{ product.name }}" title="{{ product.name }}" class="img-responsive" /></div>
<div>
<div class="caption">
<h4>{{ product.name }}</h4>
<p>{{ product.description }}</p>
{% if product.price %}
<p class="price">
{% if not product.special %}
{{ product.price }}
{% else %}
<span class="price-new">{{ product.special }}</span>
<span class="price-old">{{ product.price }}</span>
{% endif %}
{% if product.tax %}
<span class="price-tax">{{ text_tax }} {{ product.tax }}</span>
{% endif %}
</p>
{% endif %}
{% if product.rating %}
<div class="rating">
{% for i in 1..5 %}
{% if product.rating < i %}
<span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span>
{% else %} <span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span>
{% endif %}
{% endfor %}
</div>
{% endif %}
</div>
<div class="button-group">
<button type="button" onclick="cart.add('{{ product.product_id }}', '{{ product.minimum }}');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md">{{ button_cart }}</span></button>
<button type="button" data-toggle="tooltip" title="{{ button_wishlist }}" onclick="wishlist.add('{{ product.product_id }}');"><i class="fa fa-heart"></i></button>
<button type="button" data-toggle="tooltip" title="{{ button_compare }}" onclick="compare.add('{{ product.product_id }}');"><i class="fa fa-exchange"></i></button>
</div>
</div>
</div>
</div>
{% endfor %} </div>
<div class="row">
<div class="col-sm-12 text-left">{{ pagination }}</div>
{# <div class="col-sm-6 text-right">{{ results }}</div> #}
</div>
{% endif %}
{% if not categories and not products %}
<p>{{ text_empty }}</p>
<div class="buttons">
<div class="pull-right">{{ button_continue }}</div>
</div>
{% endif %}
{{ content_bottom }}</div>
{{ column_right }}</div>
</div>
{{ footer }}
Okay, this looks the relevant piece.
{% if categories %}
<h3>{{ text_refine }}</h3>
{% if categories|length <= 5 %}
<div class="row">
<div class="col-sm-3">
<ul>
{% for category in categories %}
<li>{{ category.name }}</li>
{% endfor %}
</ul>
</div>
</div>
{% else %}
<div class="row">
{% for category in categories|batch((categories|length / 4)|round(1, 'ceil')) %}
<div class="col-sm-3">
<ul>
{% for child in category %}
<li>{{ child.name }}</li>
{% endfor %}
</ul>
</div>
{% endfor %}</div>
<br />
{% endif %}
{% endif %}
You have the else triggering I think, as you have more than 5 categories.
As you can see, the child in that category gets printed instead of the category that you're trying to trigger. Rather remove the if/else and loop straight through the categories. Each of your children falls under multiple categories as well, therefore duplication.
{% if categories %}
<h3>{{ text_refine }}</h3>
<div class="row">
<div class="col-sm-3">
<ul>
{% for category in categories %}
<li>{{ category.name }}</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
Is probably what you want, or if you only want the first category with its children:
{% if categories %}
<h3>{{ text_refine }}</h3>
<div class="row">
<div class="col-sm-3">
<ul>
{% for child in category %}
<li>{{ child.name }}</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
doing a site and i need some help with the block tags. It seems that django doesn't render {% block home %} {%endblock home %}. Let's suppose in my block code i have this div and if i put the div inside my base.html as per below example it doesn't appear. It appears only when i put the source code inside the base.html, so is not including my tags. What should i do? PS i have the extended code in my block e.g. {% extends "base.html" %}
<div>
<H1>Aici trebuie adaugat restul</H1>
</div>
My base.html:
{% load staticfiles %}
<!--DOCTYPE html -->
<html>
<head>
<title>{% block head_title %}Advancing the Blog{% endblock head_title %}</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css' >
<link rel='stylesheet' href='{% static "css/base.css" %}' />
<style>
{% block style %}{% endblock style %}
</style>
{% block head_extra %} {% endblock head_extra %}
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
{% include "messages_display.html" %}
<div class='container'>
<ol class='breadcrumb'>
<li><a href='{% url "posts:list" %}'>Home</a></li>
{% block post_detail_link %}
{% endblock %}
<!-- {% block index %}
{% endblock %} -->
{% if not request.user.is_authenticated %}
<li class='pull-right'><a href='{% url "register" %}'>Register</a></li>
<li class='pull-right'><a href='{% url "login" %}'>Login</a></li>
{% else %}
<li class='pull-right'><a href='{% url "logout" %}'>Logout</a></li>
{% endif %}
</ol>
<div>
<H1>Aici trebuie adaugat restul</H1>
</div>
{% block home %} {%endblock home %}
{% block content %}{% endblock content %}
</div>
<!-- Latest compiled and minified JavaScript -->
<script src="http://code.jquery.com/jquery-1.12.2.min.js" integrity="sha256-lZFHibXzMHo3GGeehn1hudTAP3Sc0uKXBXAzHX1sjtk=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js'></script>
<script type="text/javascript">
$(document).ready(function(){
$(".content-markdown").each(function(){
var content = $(this).text()
var markedContent = marked(content)
$(this).html(markedContent)
})
$(".post-detail-item img").each(function(){
$(this).addClass("img-responsive");
})
var contentInput = $("#id_content");
function setContent(value){
var markedContent = marked(value)
$("#preview-content").html(markedContent)
$("#preview-content img").each(function(){
$(this).addClass("img-responsive")
})
}
setContent(contentInput.val())
contentInput.keyup(function(){
var newContent = $(this).val()
setContent(newContent)
})
var titleInput = $("#id_title");
function setTitle(value) {
$("#preview-title").text(value)
}
setTitle(titleInput.val())
titleInput.keyup(function(){
var newContent = $(this).val()
setTitle(newContent)
})
$(".comment-reply-btn").click(function(event){
event.preventDefault();
$(this).parent().next(".comment-reply").fadeToggle();
})
// preview-title
// preview-content
})
</script>
</body>
</html>
comment_thread.html
{% extends "base.html" %}
{% load urlify %}
{% load crispy_forms_tags %}
{% block head_title %}
{{ instance.title }} | {{ block.super }}
{% endblock head_title %}
<H1>TEST </H1>
{% block content %}
{{ object }}
<div class='col-sm-6 col-sm-offset-3'>
<p>{{ comment.content }}</p>
<footer>via {{ comment.user }} | {{ comment.timestamp|timesince }} ago | {% if comment.children.count > 0 %}{{ comment.children.count }} Comment{% if comment.children.count > 1 %}s{% endif %} {% endif %} {% if request.user == comment.user %}<a href='{{ comment.get_delete_url }}'>Delete</a> {% endif %}</footer>
<hr/>
<div>
{% for child_comment in comment.children %}
<blockquote>
<p>{{ child_comment.content }}</p>
<footer>via {{ child_comment.user }} | {{ child_comment.timestamp|timesince }} ago | {% if request.user == child_comment.user %}<a href='{{ child_comment.get_delete_url }}'>Delete</a>{% endif %}</footer>
</blockquote>
{% endfor %}
{% if request.user.is_authenticated %}
<form method="POST" action="."> {% csrf_token %}
{{ form|crispy }}
<input type='hidden' name='parent_id' value='{{ comment.id }}'>
<input type='submit' value='Reply' class='btn btn-default'>
</form>
{% else %}
<p>You must login to comment </p>
{% endif %}
</div>
<hr/>
</div>
{% endblock content %}
confirm_delete.html
{% extends "base.html" %}
{% load urlify %}
{% load crispy_forms_tags %}
{% block head_title %}
{{ instance.title }} | {{ block.super }}
{% endblock head_title %}
{% block content %}
<div class='col-sm-6 col-sm-offset-3'>
<h1>Confirm Delete</h1>
<form method="POST" action="."> {% csrf_token %}
<p>A re you sure you want to delete: "{{ object.content }}"?</p>
<input type='submit' value='Confirm' class='btn btn-warning'>
<a href='{{ object.get_absolute_url }}' class='btn btn-default'>Cancel</a>
</form>
</div>
<hr/>
</div>
{% endblock content %}
form.html
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<!-- {% block index_home %}
{% endblock %} -->
<div class='col-sm-6 col-sm-offset-3'>
<h1>{{ title }}</h1>
<hr/>
<form method='POST' action='' enctype='multipart/form-data'>{% csrf_token %}
{{ form|crispy }}
<input type='submit' class='btn btn-default' value='{{ title }}' />
</form>
</div>
{% endblock content %}
messages_display.html
{% if messages %}
<div class='messages'>
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{% if "html_safe" in message.tags %}{{ message|safe }}{% else %}{{ message }}{% endif %}</li>
{% endfor %}
</ul>
</div>
{% endif %}
post_detail.html
{% extends "base.html" %}
{% load urlify %}
{% load crispy_forms_tags %}
{% block head_title %}
{{ instance.title }} | {{ block.super }}
{% endblock head_title %}
{% block post_detail_link %}
<li><a href='{{ instance.get_absolute_url }}'>{{ instance.title }}</a></li>
{% endblock %}
{% block content %}
<div class='col-sm-6 col-sm-offset-3'>
{% if instance.image %}
<img src='{{ instance.image.url }}' class='img-responsive' />
{% endif %}
<h1>{{ title }} <small>{% if instance.draft %}<span style='color:red;'>Draft</span> {% endif %}{{ instance.publish }}</small></h1>
<!-- {% if instance.read_time|time:"i" <= "01" %} < 1 minute {% else %}{{ instance.read_time|time:"i" }} minutes {% endif %} -->
<p>Read time: {% if instance.read_time <= 1 %} < 1 Minute {% else %}{{ instance.read_time }} minutes {% endif %}</p>
{% if instance.user.get_full_name %}
<p>Author: {{ instance.user.get_full_name }}</p>
{% endif %}
<p><div class="fb-like" data-href="{{ request.build_absolute_uri }}" data-layout="button_count" data-action="like" data-show-faces="true" data-share="true"></div>
<hr/>
</p>
<p>
<a href="https://www.facebook.com/sharer/sharer.php?u={{ request.build_absolute_uri }}">
Facebook
</a>
<a href="https://twitter.com/home?status={{ instance.content|truncatechars:80|urlify }}%20{{ request.build_absolute_uri }}">
Twitter
</a>
<a href='https://plus.google.com/share?url={{ request.build_absolute_uri }}'>
<a href="https://www.linkedin.com/shareArticle?mini=true&url={{ request.build_absolute_uri }}&title={{ instance.title }}&summary={{ share_string }}&source={{ request.build_absolute_uri }}">
Linkedin
</a>
Reddit
</p>
<div class='row'>
<div class='col-sm-12 '>
<div class='post-detail-item'>{{ instance.get_markdown }}</div>
<hr/>
<br/>
<div>
<p class='lead'>Comments</p>
{% if request.user.is_authenticated %}
<form method="POST" action="."> {% csrf_token %}
{{ comment_form|crispy }}
<input type='submit' value='Post comment' class='btn btn-default'>
</form>
{% else %}
<p>You must login to comment </p>
{% endif %}
<hr/>
{% for comment in comments %}
<blockquote>
<p>{{ comment.content }}</p>
<footer>via {{ comment.user }} | {{ comment.timestamp|timesince }} ago | {% if comment.children.count > 0 %}{{ comment.children.count }} Comment{% if comment.children.count > 1 %}s{% endif %} | {% endif %} <a class='comment-reply-btn' href='#'>Reply</a> | <a class='' href='{{ comment.get_absolute_url }}'>Thread</a></footer>
<div class='comment-reply'>
{% for child_comment in comment.children %}
<blockquote>
<p>{{ child_comment.content }}</p>
<footer>via {{ child_comment.user }} | {{ child_comment.timestamp|timesince }} ago</footer>
</blockquote>
{% endfor %}
{% if request.user.is_authenticated %}
<form method="POST" action="."> {% csrf_token %}
{{ comment_form|crispy }}
<input type='hidden' name='parent_id' value='{{ comment.id }}'>
<input type='submit' value='Reply' class='btn btn-default'>
</form>
{% else %}
<p>You must login to comment </p>
{% endif %}
</div>
</blockquote>
<hr/>
{% endfor %}
</div>
</div>
</div>
</div>
{% endblock content %}
post_form.html
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block head_extra %}
{{ form.media }}
{% endblock head_extra %}
{% block content %}
<div class='col-sm-6'>
<h1>Preview</h1>
<hr/>
<div class='content-preview'>
<h3 id='preview-title'></h3>
<p id='preview-content'></p>
</div>
</div>
<div class='col-sm-6'>
<h1>Form</h1>
<hr/>
<form method='POST' action='' enctype='multipart/form-data'>{% csrf_token %}
{{ form|crispy }}
<input type='submit' class='btn btn-default' value='Create Post' />
</form>
</div>
{% endblock content %}
post_list.html
{% extends "base.html" %}
{% block content %}
<div class='col-sm-6 col-sm-offset-3'>
<h1>{{ title }}</h1>
<form method='GET' action='' class='row'>
<div class='col-sm-6'>
<div class='input-group'>
<input class='form-control' type='text' name='q' placeholder='Search posts' value='{{ request.GET.q }}'/>
<span class='input-group-btn'>
<!-- <input class='btn btn-default' type='submit' value='Search' /> -->
<button class='btn btn-default' type='submit'>Search <i class="fa fa-search"></i></button>
</span>
</div>
</div>
</form>
{% for obj in object_list %}
<div class="row">
<div class="col-sm-12">
<div class="thumbnail">
{% if obj.image %}
<img src='{{ obj.image.url }}' class='img-responsive' />
{% endif %}
<div class="caption post-detail-item">
{% if obj.draft %}<h3>Staff only: Draft</h3>{% endif %} {% if obj.publish > today %}<h3>Staff Only: Future Post</h3>{% endif %}
<h3><a href='{{ obj.get_absolute_url }}'>{{ obj.title }}</a> <small>{{ obj.publish }}</small></h3>
{% if obj.user.get_full_name %}<p>Author: {{ obj.user.get_full_name }}</p>{% endif %}
{{ obj.get_markdown|truncatechars_html:120 }}
<p>View</p>
</div>
</div>
</div>
<hr/>
</div>
{% endfor %}
<div class="pagination">
<span class="step-links">
{% if object_list.has_previous %}
previous
{% endif %}
<span class="current">
Page {{ object_list.number }} of {{ object_list.paginator.num_pages }}.
</span>
{% if object_list.has_next %}
next
{% endif %}
</span>
</div>
</div>
{% endblock content %}
Could you try having {% endblock home %} instead of {%endblock home %}. The lack of space can sometimes mess things up.
If this does not work, try simply have {% endblock %} instead.
Hope this helps!
I am trying to use django tinymce in my project but the font is too small. I have googled it and learned I am meant to use content_css but without proper step by step approaches as to how exactly this should be done.
I am wondering if there was another way and if there isn't, could someone give me a simple step by step approach to solving it using the content_css.
Below is the forms.py
class PostForm(forms.ModelForm):
text = forms.CharField(help_text='Enter your Post here', widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
name = forms.CharField(widget=forms.HiddenInput(), initial='User')
created_on = forms.DateTimeField(widget=forms.HiddenInput(), initial=timezone.now())
class Meta:
model = Post
fields = ('title', 'text',)
{% extends 'blog/base.html' %}
{% load staticfiles %}
{% block body_block %}
<!-- <h1>TinyMCE Quick Start Guide</h1>
<form method='post'>
<textarea id = 'mytextarea'>Hello, World!</textarea>
</form> -->
{% if post %}
<div class="single">
<div class="container">
<div class="col-md-8 single-main">
<div class="single-grid">
<h4>{{ post.title|safe }}</h4>
<img src="{% static 'images/post1.jpg' %}" alt=""/>
<p>{{ post.text|safe }}</p>
</div>
<div class="comments">
<h2><u>Comments</u></h2>
{% if comments %}
{% for comment in comments %}
<h3>~{{ comment.commenter.first_name|title}} {{comment.commenter.last_name|title }}</h3>
<ul>
<li>
{{ comment.text|safe }}
</</li><br>
</ul>
<span class="hidden-xs"style="margin-left:70%;, font-family:Arial">Published: {{ comment.created_on }}</span >
{% if comment.commenter == request.user or user.is_superuser %}
<button style="margin-left:90%;,line-height: .9;color: red;, font-family:Arial;" type="button" name="button">Delete</button>
{% endif %}
{% endfor %}
{% else %}
No comments available
{% endif %}
</div>
<div class="content-form">
<h3>Leave a comment</h3>
{% if user.is_authenticated %}
<form id="comment_form" action="{% url 'blog:detail' post.slug %}" method="post">
{% csrf_token %}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
{% for field in form.visible_fields %}
{{ field.errors }}
{{ field }}<br/><br/>
{% endfor %}
<input class="btn btn-primary" type="submit" name="submit" value="submit">
</form>
{% else %}
You must be logged in to comment
{% endif %}
</div>
<ul class="comment-list " >
<h5 class="post-author_head">Written by {{ post.author.first_name|title }} {{ post.author.last_name|title }}</h5>
<li><img src="{% static 'images/avatar.png' %}" class="img-responsive" alt="">
<div class="desc">
<p>View all posts by: {{ post.author.first_name|title }} {{ post.author.last_name|title }}</p>
</div>
<div class="clearfix"></div>
</li>
</ul>
</div>
<div class="col-md-4 side-content">
<div class="recent">
<h3>RECENT POSTS</h3>
{% if recent_posts %}
<ul>
{% for post in recent_posts %}
<li>{{post.title|title }}</li>
{% endfor %}
</ul>
{% else %}
<li>No post has been posted</li>
{% endif %}
</div>
<div class="comments">
<h3>RECENT COMMENTS</h3>
{% if recent_comments %}
<ul>
{% for comment in recent_comments %}
<li>{{comment.commenter|title}} on {{comment.post|title}}</li>
{% endfor %}
</ul>
{% else %}
<li>No comments at the moment</li>
{% endif %}
</div>
<div class="clearfix"></div>
<div class="archives">
<h3>ARCHIVES</h3>
<ul>
<li>October 2013</li>
<li>September 2013</li>
<li>August 2013</li>
<li>July 2013</li>
</ul>
</div>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</div>
</div>
{% if comment.commenter == request.user or user.is_superuser %}
<button style="margin-left:90%;,line-height: .9;color: red;, font-family:Arial;" type="button" name="button">Delete Post</button>
<button style="margin-left:90%;,line-height: .9;color: red;, font-family:Arial;" type="button" name="button">Edit Post</button>
{% endif %}
{% else %}
asadsh
{% endif %}
{% endblock %}
To add content css files to tinymce, you have to change the tinymce.init object value to include your content_css.
Search for the initialization call in your script and add a line to your object like in this example:
tinymce.init({
...
content_css: [
'//example.com/js/your-css-here.css'
],
...
});
If a content_css part is already present, just add the URL to the array, i.e.
['url 1 here', 'url 2 here', 'your new url here']
In your custom css file, you can now set your desired font size, i.e.
body { font-size: 14px; }
{% extends "account/base.html" %}
{% load url from future %}
{% load i18n %}
{% block head_title %}{% trans "Signup" %}{% endblock %}
{% block content %}
</style>
<h1><b>Free Membership</b>Sign up Today</h1>
<h1>{% trans "Sign Up" %}</h1>
<p>{% blocktrans %}Already have an account? Then please sign in.{% endblocktrans %}</p>
<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">
{% csrf_token %}
{{ form.as_p }}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<button type="submit">{% trans "Sign Up" %} »</button>
</form>
<h1><b>Free Membership</b>Sign up Today</h1>
{% endblock %}
{% block content2 %}
{% endblock %}
This is the original Code from Django All Auth.
What I want to do is bring it more to life like add some better HTML5 or CSS to it when I do it does not change?
Here's my login.html template (I'm using Bootstrap, Jquery and Font-Awesome for the icons).
{% extends "account/base.html" %} {% load i18n custom_tags account %} {% block head_title %}{% trans "Sign In" %}{% endblock %} {% block common_scripts %}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
// Load jquery straight from the cdn for this page.
$(function() {
// We need some mappings for Providers names from AllAuth to the icon class names.
$('.btn-google').addClass('btn-google-plus');
$('.btn-linkedin_oauth2').addClass('btn-linkedin');
$('.fa-linkedin_oauth2').addClass('fa-linkedin');
$('#id_login').addClass('form-control').removeAttr('autofocus').blur();
$('#id_password').addClass('form-control');
});
</script>
{% endblock %} {% block content %}
<div class="container col-md-12">
<div class="well login-well">
<div class="socialaccount_ballot">
<ul class="socialaccount_providers">
{% load socialaccount %} {% for provider in socialaccount.providers %} {% if provider.id == "openid" %} {% for brand in provider.get_brands %}
<li>
<a title="{{ brand.name }}" class="btn btn-block btn-social btn-md btn-{{ provider.id }} socialaccount_provider {{ brand.id }}" href="{% provider_login_url provider.id openid=brand.openid_url process=" login " %}">
<i class="fa fa-{{ provider.id }}"></i>Log in with {{ brand.name }}
</a>
</li>
{% endfor %} {% endif %}
<li>
<a title="{{ provider.name }}" class="btn btn-block btn-social btn-md socialaccount_provider btn-{{ provider.id }}" href="{% provider_login_url provider.id process=" login " %}">
<i class="fa fa-{{ provider.id }}"></i>Log in with {{ provider.name }}
</a>
</li>
{% endfor %}
</ul>
<hr>
<form class="django-login" method="POST" action="{% url 'login' %}">
{% csrf_token %} {% if form.non_field_errors %}
<div class="alert alert-warning">
<ul class="alert-message">
{% for error in form.non_field_errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<div class="input-group {% if form.login.errors %}has-error{% endif %}">
<span class="input-group-addon glyphicon glyphicon-envelope"></span>
{{ form.login }}
</div>
<div class="input-group {% if form.password.errors %}has-error{% endif %}">
<span class="input-group-addon glyphicon glyphicon-lock"></span>
{{ form.password }}
</div>
<div class="fieldWrapper form-inline remember text-center">
{{ form.remember }}
<label for="id_remember" class="text-muted">Remember me</label>
</div>
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />{% endif %}
<div class="btn-div pull-center">
<button class="btn btn-primary btn-block" type="submit">{% trans "Sign In" %}</button>
</div>
</form>
</div>
<hr>
<div>
<small><a class="text-muted" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a></small>
<br>
<small><a class="text-muted" href="{% url 'signup' %}">Sign up</a></small>
</div>
</div>
</div>
{% endblock %}
And how it looks:
You can put custom templates for allauth in your template directory under account folder. Django allauth would take the custom template from it and renders it.
Following is sample signup page I have created some days ago:
{% extends "base.html" %}
{% load staticfiles %}
{% load socialaccount %}
{% block extra_body %}account-bg{% endblock %}
{% block partial %}
<div class="container">
<div class="row">
<div class="account-form-container">
<div class="row">
<div class="col-md-12">
<h3>Create New Account</h3>
</div>
</div>
<div class="row">
<form class="form-horizontal signup-form" id="userSignupForm" action="{% url "account_signup" %}" method="post" role="form">
{% csrf_token %}
{% if request.GET.next %}
<input type="hidden" name="next" value="{{request.GET.next}}">
{% endif %}
{% if form.non_field_errors %}
<div class="fieldWrapper alert alert-danger">
<ul>
{% for error in form.non_field_errors %}
<li>{{ error | lower}}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<div class="col-lg-12">
<div class="form-group inner-addon left-addon {% if form.email.errors %}has-error{% endif %}">
<i class="icon-user"></i>
<input class="form-control login-field" type="text" id="id_email" name="email" placeholder="Email">
<span class="help-block">{{ form.email.errors }}</span>
</div>
<div class="form-group inner-addon left-addon {% if form.password1.errors %}has-error{% endif %}">
<i class="icon-lock"></i>
<input class="form-control login-field" type="password" id="id_password1" name="password1" placeholder="Password">
<span class="help-block">{{ form.password1.errors }}</span>
</div>
<div class="form-group inner-addon left-addon {% if form.password1.errors %}has-error{% endif %}">
<i class="icon-lock"></i>
<input class="form-control login-field" type="password" id="id_password2" name="password2" placeholder="Confirm Password">
<span class="help-block">{{ form.password1.errors }}</span>
</div>
<div class="form-group">
<div class="col-md-5">
<button type="submit" class="btn btn-complete btn-bold pull-right">Sign Up</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
I hope this would help you.