how to use FOSCommentBundle - symfony

Im new to symfony3 and I need a bit of help,I have a timeline page that contains posts and every post has a comment field so in order to do that I've installed the FOSCommentBundle following all the steps in this documentation https://github.com/FriendsOfSymfony/FOSCommentBundle/blob/master/Resources/doc/index.md and then I integrated it with the FOSUserBundle, and I did the following changes in the async.html.twig file :
<div id="fos_comment_thread">#comments</div>
<script type="text/javascript">
// thread id
var fos_comment_thread_id = 'pub';
// api base url to use for initial requests
var fos_comment_thread_api_base_url = 'localhost/Outdoors5/web/app_dev.php/threads';
// Snippet for asynchronously loading the comments
(function() {
var fos_comment_script = document.createElement('script');
fos_comment_script.async = true;
fos_comment_script.src = '{{ asset('bundles/foscomment/js/comments.js') }}';
fos_comment_script.type = 'text/javascript';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(fos_comment_script);
})();
</script>
but in the end I got very confused on how I use this ,I passed hours trying to understand and searching for tuto, but no luck.
this is my view
<section id="timeline">
{% for publication in publications %}
<div id="result"></div>
<div class="page-content page-app page-profil " >
<div class="profil-content">
<div class="row">
<div class="row">
<div class="item item-comment">
<div class="user">
<h5 class="name">{{ publication.idProfil.nom }}</h5>
<div class="clearfix">
<p class="time">{% if publication.dateCreation %}{{ publication.dateCreation|date('Y-m-d') }}{% endif %}</p>
</div>
<div class="comment">
<p class="c-primary m-b-0"><strong>{{ publication.texte }}</strong></p>
</div>
</div>
<div class="more">
<div class="row">
<div class="col-sm-4 like">
<i class="fa fa-heart"></i> Like
</div>
<div class="col-sm-4 more-comments">
<div class="comment-number">
<i class="icon-bubble"></i> Comments<span class="pull-right badge badge-dark">3</span>
</div>
</div>
<div class="col-sm-4 more-share">
<i class="icon-share"></i> Share
</div>
</div>
<div class="row comments">
<div class="col-sm-12">
<ul>
<li class="clearfix">
<div class="clearfix">
<div class="info">
<div class="name"><strong class="primary-font"></strong></div>
<div class="date"></div>
</div>
<p>
comment 1
</p>
</div>
</li>
<li></li>
</ul>
</div>
</div>
<div class="row share">
<div class="share-facebook">
<i class="fa fa-facebook"></i>
</div>
<div class="share-twitter">
<i class="fa fa-twitter"></i>
</div>
<div class="share-google">
<i class="fa fa-google-plus"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
</section>
Could you point me to the right direction?
thank you

There is no need to modify async.html.twig. You just need to add the following code in your twig view:
{% include 'FOSCommentBundle:Thread:async.html.twig' with {'id': 'foo'} %}
To sum up, after doing the following steps:
Step 1: Setting up the bundle
Step 2: Create your Comment and Thread classes
Step 3: Import FOSCommentBundle routing
Step 4: Enable comments on a page
For the FOSUserBundle integration you just have to extend the Comment class as explained in Step 6: Integration with FOSUserBundle

Related

Formatting text in an accordian in bootstrap 4

So I'm struggling to format an accordian in bootstrap 4 which I'm using alongside django
The basic issue with my formatting is illustrated in the picture below. The headline in the text is spilling over to outside the column of the accordian. I feel like this should be a simple fix but I can't figure it out. Code pasted below
<div class='col-xs-12 col-md-4'>
<h3> ATP tennis </h3>
<hr/>
<div id="accordion">
{% for obj in tennis %}
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<button class="first1 btn btn-link collapsed newwrap" data-toggle="collapse"
data-artid="{{obj.id}}" data-target="#tnis_{{ obj.id }}" aria-expanded="false"
aria-controls="tnis_{{ obj.id }}">
{{obj.headline}}
</button>
</h5>
</div>
<div id="tnis_{{ obj.id }}" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
<div class="card-body body_pad"><a href='{{obj.url}}' target="_blank" class='body_col'>
{{obj.summary}} </a><br>
<div class="rght3">
<i id="{{obj.id}}" class="likes fa fa-thumbs-up" data-artid="{{obj.id}}" style="font-size:25px;color:#6666ff;"></i>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
I feel like this should in theory be a pretty simple fix. Any help would be much appreciated. The {{obj.headline}} is the culprit that is spilling over (which sits within a button tag)

weasyprint is not rendering bootstrap4 css correctly

I'm trying to generate an invoice by first designing it as HTML and then feeding that to weasyprint to generate the pdf. I'm using Django 2.2.5 version with bootstrap 4.3.1 and weasyprint 50.
The invoice_generator(request) function calls the generate_invoice function with the request, username and template_name.
views.py:
from invoice_generator import generate_invoice
def invoice_generator(request, username):
ret_val = generate_invoice(request, username, template_name="ui/invoice.html")
return ret_val
invoice_generator.py:
from django.shortcuts import render
from commons.models import SMSUser, SMSMessages, Invoice
from commons.serializers import InvoiceSerialzer
from django.template.loader import get_template
from django.conf import settings
from django.http import HttpResponse
from weasyprint import HTML, CSS
import tempfile
from datetime import datetime, date
def generate_invoice(request, username, template_name):
user_to_invoice = SMSUser.objects.get(username=username)
user_invoice = Invoice(invoice_to=user_to_invoice)
company_to_invoice = user_to_invoice.company_name
company_tin = user_to_invoice.company_tin
account = user_to_invoice.pk
user_email = user_to_invoice.email
all_users_in_company = SMSUser.objects.filter(company_name=company_to_invoice)
user_invoice.save()
invoice_number = user_invoice.pk
paid_status = user_invoice.payment_status
all_sms_sent_by_users = {}
for user in all_users_in_company:
# TODO you can run the code at the begining of each month by doing:
# TODO x = date.today() then x = x.replace(day=1)
total_sent_by_single_user = SMSMessages.objects.filter(
sending_user=user,
delivery_status="True",
sent_date__year=datetime.now().year,
sent_date__month = 10
# sent_date__month = datetime.now().month - 2
)
all_sms_sent_by_users = {
"all_sms_sent": [
{
"user": user,
"total_sent_single_user": total_sent_by_single_user.count()
}
]
}
total_amount_sent = SMSMessages.objects.filter(
sent_date__year = datetime.now().year,
sent_date__month = 10,
# sent_date__month = datetime.now().month - 1,
sending_user__company_name=company_to_invoice
)
# TODO feed the below object to a pdf renderer and return that pdf rendered object
context_object = {
"username": user_to_invoice,
"company_name": company_to_invoice,
"account": account,
"invoice_number": invoice_number,
"tin": company_tin,
"email": user_email,
"bill_month": datetime.now().month - 1,
"all_sms_sent": all_sms_sent_by_users,
"total_amount_sent": total_amount_sent.count(),
"vat": total_amount_sent.count() * 0.70 * 0.15,
"total_price": total_amount_sent.count() * 0.70 * 1.15,
"payment_status": paid_status
}
rendered_html = get_template(template_name).render(
context_object,
request
).encode(encoding='UTF-8')
pdf_file = HTML(string=rendered_html, base_url=request.build_absolute_uri())
pdf_file.render()
pdf_container = pdf_file.write_pdf(
stylesheets=[
CSS(
'ui' + settings.STATIC_URL + 'ui/css/bootstrap.min.css'
)
]
)
response = HttpResponse(content_type='application/pdf;')
response['Content-Disposition'] = 'filename=Invoice ' + company_to_invoice + str(datetime.now().month) + '.pdf'
response['Content-Transfer-Encoding'] = 'UTF-8'
with tempfile.NamedTemporaryFile(delete=True) as pdf_writer:
pdf_writer.write(pdf_container)
pdf_writer.flush()
pdf_writer = open(pdf_writer.name, 'rb')
response.write(pdf_writer.read())
return response
and this is the ui/invoice.html:
<!DOCTYPE html>
<html lang="en">
<head>
{% load static %}
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<link rel="shortcut icon" type="image/png" href="{% static 'ui/images/favicon.ico' %}">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- bootstrap4 css -->
<link href="{% static 'ui/css/bootstrap.min.css' %}" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>sms.et | Invoice</title>
</head>
<body class="text-center d-print-block" style="background-color: #f5f5f5;">
<div class="container-fluid align-items-center align-middle">
<header>
<div class="row">
<div class="col-md-12 bg-primary">
<h1 class="font-weight-bold self-center h1 text-white">Service Invoice</h1>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6">
<h4 class="font-weight-light self-center h4"><p>Customer Name: <span class="font-weight-lighter"> {{ username.company_name }}</span></p></h4>
<h4 class="font-weight-light self-center h4"><p>Account: <span class="font-weight-lighter"> {{ account }}</span></p></h4>
<h4 class="font-weight-light self-center h4"><p>T.I.N: <span class="font-weight-lighter"> {{ tin }}</span></p></h4>
</div>
<div class="col-md-6">
<h4 class="font-weight-light self-center h4"><p>Invoice number: <span class="font-weight-lighter"> {{ invoice_number }}</span></p></h4>
<h4 class="font-weight-light self-center h4"><p>Email: <span class="font-weight-lighter"> {{ email }}</span></p></h4>
<h4 class="font-weight-light self-center h4"><p>Bill Month: <span class="font-weight-lighter"> {{ bill_month }}</span></p></h4>
<h4 class="font-weight-light self-center h4"><p>Due date: <span class="font-weight-lighter"> 5 days from this invoice</span></p></h4>
</div>
</div>
</header>
</div>
<hr class="bg-primary">
<h6 class="font-weight-lighter self-center h6"><p>Paid status: {{payment_status}}</p></h6>
<hr class="bg-primary">
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<label class="font-weight-light self-center h2">All users that sent sms:</label>
<div class="row">
<div class="col-md-4">
<!-- dict object all _sms_sent is garnered from the views and parsed accordingly as key & value of all_sms_sent.items -->
{% for key, value in all_sms_sent.items %}
<h4 class="font-weight-lighter h4">username</h4>
{% for val in value %}
<p>{{ val.user }}</p>
</div>
<div class="col-md-4">
<h4 class="font-weight-lighter h4">Company</h4>
<p>{{ val.user.company_name }}</p>
</div>
<div class="col-md-4">
<h4 class="font-weight-lighter h4">Total sent</h4>
<p>{{ val.total_sent_single_user }}</p>
{% endfor %}
{% endfor %}
</div>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-6">
<h4 class="font-weight-light self-center h4">Total sms sent in the month:</h4>
</div>
<div class="col-md-6">
<p>{{ total_amount_sent }}</p>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6">
<h4 class="font-weight-light self-center h4">Price per text:</h4>
</div>
<div class="col-md-6">
<p>0.70 Birr</p>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6">
<h4 class="font-weight-light self-center h4">V.A.T:</h4>
</div>
<div class="col-md-6">
<p>{{ vat }} Birr</p>
</div>
<br>
</div>
<br>
<div class="row">
<div class="col-md-6">
<h4 class="font-weight-light self-center h4">Total:</h4>
</div>
<div class="col-md-6">
<p>{{ total_price }} Birr</p>
</div>
</div>
</div>
</div>
</div>
<br>
<br>
<div class="container-fluid align-items-center align-middle bg-primary">
<footer>
<div class="row text-white">
<div class="col-md-4">
<h4 class="font-weight-light self-center h4"><p>Address</p></h4>
<p class="quote font-weight-light center">Ethiopia, Addis Ababa, Kirkos sub-city, woreda 02, House No. 700.</p>
</div>
<div class="col-md-4">
<img src="{% static 'ui/images/logo.jpg' %}" width="50" height="40" class="d-inline-block align-top navbar-brand" alt="">
<br>
www.sms.et
</div>
<div class="col-md-4">
<p class="quote font-weight-light center">Outstanding bill must be settled 5 days after issuance of this service invoice.</p>
<p class="quote font-weight-light center">Any questions can be forwared to us via our phone number: +251977207777</p>
</div>
</div>
</footer>
</div>
</body>
</html>
The problem is that weasyprint is not rendering the bootstrap 4 css as expected, i.e. as written above.
This is a question Bootstrap CSS is not applied in weasyprint
that comes close to my problem but the solutions described made no difference.
Just to clarify, this is how it was supposed to look like (the html version):
.
But it ended up looking like this:
and this:
Can anybody please help?
Edited to include urls.py of project and app
this is the urls.py from the project:
urlpatterns = [
# for the ui app
path('ui/', include('ui.urls')),
]
and this is the urls.py for the ui app:
from django.urls import path
from . import views
app_name = "ui"
urlpatterns = [
path('homepage/', views.homepage, name="homepage"),
path('login/', views.login_request, name="login"),
path('dashboard/<username>/', views.dashboard, name="dashboard"),
path('logout/', views.logout_request, name="logout"),
path('register/', views.register_request, name="register"),
path('ajax/dashboard_update/', views.ajax_dashboard_update, name="ajax_dashboard_update"),
path('<username>/invoice/', views.invoice_generator, name="invoice_generator"),
]

Load more for custom query wp

how can i integrate load more button that loads next 10 posts from custom query ?
I've tried with bunch of plugins, css and js ways, but can't seem to load it.
How would you load more posts on load click?
Any tip is very much appreaciated
<div class="container">
<div class="row featured-akcije">
#foreach(get_field('actions') as $action)
#php($query = new WP_Query(array('post_type' => 'condo', 'p' => $action['akcions']->ID)))
#php($query->the_post())
<div class="col-md-4 col-xl-3 action">
<div class="box-shadow-posts hoverPic">
<div class="row">
<div class="col-12 col-md-12">
<div class="row">
<div class="col-4 col-md-6 col-xl-6">
<div class="action-img">
<img src="{{ get_the_post_thumbnail_url() }}" class="img-fluid">
<p class="action">action</p>
</div>
</div>
<div class="col-8 col-md-6 pl-md-0">
<div class="row info-action">
<div class="col-md-12"><h2 class="title">
{{ the_title() }}
</h2></div>
<div class="col-md-12 price-info">
<div class="divider">
</div>
<?php if( get_field('price_off') ): ?>
<p class="price">price from <?php the_field('price_from'); ?>e</p>
<?php endif; ?>
<p class="detail"><a href="{{ the_permalink() }}"><span class="nav-border"></span><span>detail <i
class="fas fa-arrow-right"></i></span></a></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#php(wp_reset_postdata())
#endforeach
</div>
</div>
I implemented load more functionality for custom query like this:
Create wp ajax endpoint which is called be javascript on load more button click
Endpoint gets offset which post to load? For example from 11 to 20 and returns html with rendered posts
Javascript appends return html to html of the page in proper place
How to create endpoint? Here are examples for creating endpoint and calling it from javascript: https://codex.wordpress.org/AJAX_in_Plugins In endpoint you should call fetching posts like this: $query = new WP_Query(array('post_type' => 'condo', 'p' => $action['akcions']->ID)) with proper offset passed in params, render html template and return it.

WordPress alternate post styling with bootstrap col-offset using Custom Content Shortcode

I am trying to style the post in the loop in alternate styling using Custom Content Short code plugin. Some what like this.
Example image of post styling using bootstrap col-offset
This is what i'm trying
<?php start_short(); ?>
[loop type=service orderby=date order=ASC]
<div class="jumbo" style="background-image: url([field image-url]);">
<div class="blackBG row">
<div class="col-md-5 col-md-offset-7 BGdark opaque page-block-full wow fadeInRight" data-wow-duration="0.40s" data-wow-delay="0.50s">
<h1><b class="square BGsec">1</b><small>[field title]</small></h1>
<p>[content more=true more=... length=200]</p>
<a class="btn btn-default light" href="[field url]" title="DUX Technology - [field title]">Check Now <i class="fa fa-chevron-circle-right"></i></a>
</div>
</div>
</div>
[/loop]
<?php end_short(); ?>
What I want to display is:
<div class="jumbo" style="background-image: url([field image-url]);">
<div class="blackBG row">
<div class="col-md-5 col-md-offset-7 BGdark opaque page-block-full wow fadeInRight" data-wow-duration="0.40s" data-wow-delay="0.50s">
<h1><b class="square BGsec">1</b><small>[field title]</small></h1>
<p>[content more=true more=... length=200]</p>
<a class="btn btn-default light" href="[field url]" title="DUX Technology - [field title]">Check Now <i class="fa fa-chevron-circle-right"></i></a>
</div>
</div>
</div>
<div class="jumbo" style="background-image: url([field image-url]);">
<div class="blackBG row">
<div class="col-md-5 BGdark opaque page-block-full wow fadeInRight" data-wow-duration="0.40s" data-wow-delay="0.50s">
<h1><b class="square BGsec">1</b><small>[field title]</small></h1>
<p>[content more=true more=... length=200]</p>
<a class="btn btn-default light" href="[field url]" title="DUX Technology - [field title]">Check Now <i class="fa fa-chevron-circle-right"></i></a>
</div>
</div>
</div>
<div class="jumbo" style="background-image: url([field image-url]);">
<div class="blackBG row">
<div class="col-md-5 col-md-offset-7 BGdark opaque page-block-full wow fadeInRight" data-wow-duration="0.40s" data-wow-delay="0.50s">
<h1><b class="square BGsec">1</b><small>[field title]</small></h1>
<p>[content more=true more=... length=200]</p>
<a class="btn btn-default light" href="[field url]" title="DUX Technology - [field title]">Check Now <i class="fa fa-chevron-circle-right"></i></a>
</div>
</div>
</div>
How can I achieve this?
The above code was generating a loop of post in WordPress with single class of col-md-offset-7 to every post.
What I did was use jQuery even function to delete class from alternate post.
$("div.service-post:even").removeClass("col-md-offset-7");

Use watir web driver to click download icon

I am trying to use watir to download files from a web page. Trying to figure out how to click the 'download icon' and then save the file.
The files are in a table, and I want to download each file with the word 'done' in the column and then same it as the report name.
The HTML is below:
<div class="portlet" id="homeStatus">
<div class="portletHeader statusHeader">
Reports and Request Status
</div>
<div class="portletContent" id="statusContent">
<div class="status">
<div class="row-fluid boldText statusHeaderRow">
<div class="span3">Name</div>
<div class="span2">ID</div>
<div class="span3">Date</div>
<div class="span1">Status</div>
<div class="span3">Actions</div>
</div>
<div class="row-fluid statusResultsText">
<div class="span3 bold">
<span class="reportName">report2</span>
</div>
<div class="span2">429696109</div>
<div class="span3">2015-06-14 20:06:55</div>
<div class="span1">Done</div>
<div class="span3 statusResultsActions iconSize16 statusActionPad" id="374189255">
<i class="icon-download-alt mediumBlueIcon downloadIcon" id = "/decision_support/Status_retrieve_request.aspx?questionid=Q10201&applicationid=300&JobId=429696109&status=D&Extension=xls&filename=/Outbound06/q3bk06m_429696109_A14A90C6XB906X4F05X8539XDE448240CE97&reqname=report2,429696109" title="Download"></i>
</i>
<i class="icon-cog mediumBlueIcon modifydrequestIcon" id = "d_/decision_support/Report_Builder.aspx?country_cd=CA&qid=Q10201&exe_id=291&AppId=300&divid=1&JobId=429696109&reopen=true" title="Modify"></i>
</div>
</div>
<div class="row-fluid statusResultsText alternateBackground">
<div class="span3 bold">
<span class="reportName">Report Sun Jun 14 20:56:46 2015</span>
</div>
<div class="span2">429695641</div>
<div class="span3">2015-06-14 20:01:34</div>
<div class="span1">User Error</div>
<div class="span3 statusResultsActions iconSize16 statusActionPad" id="374188794">
</div>
</div>
</div>
</div>
</div>
# iterate through rows
Browser.divs.each do |row|
if row.div(:class => "span1").text == "Done"
report_name = row.span(:class => "reportName").text
row.divs.last.is.each do |i|
# move the mouse to <i> tag and click the <a> link, if <i> is an icon and <a> link is not present
Browser.driver.action.move_to(i.wd).click.perform
end
end
end

Resources