Mysterious and weird lines after using uni-form - python

I'm using django-uni-form to display forms. I've included all the css and javascript (notably jquery) in the page. But now I get some weird looking lines. The image below show how it looks:
http://i243.photobucket.com/albums/ff176/cwalkrox/uni-form1.jpg
You can notice that for username and email address, the lines are aligned with the upper side of text inputs while for two passwords, the lines are below the password inputs. In uni-form's official website, I can't see any line in the 3 examples. Even if it gives me some lines, should it be consistent?
So the strange story doesn't stop here. The jquery can highlight the selected inputs. But the ways it highlights username, email and password are still inconsistent. The following images prove it:
i243.photobucket.com/albums/ff176/cwalkrox/uni-form2.jpg
i243.photobucket.com/albums/ff176/cwalkrox/uni-form3.jpg
So every problems seem to stem from the mysterious lines. So how this happens?
BTW, the page I show you is rendered with the form of django-registration. The rendering snippet is:
<form action="" method="post" class="uniForm">
<fieldset>
{{ form|as_uni_form }}
</fieldset>
</form>

Those lines are due to the css files included in django-uniform: uni-form.css, uni-form-generic.css and uni-form.jquery.css.
It seems weird but at least in my case (a pinax project) the forms look better without the provided css.
my 2 cents

Related

Filling an input in any website and pressing enter

I'm trying to write a small python script that will get a list of URLs (which are mostly just a search bar with some other elements), "write" something in the search bar and "press" enter.
My goal is to get to the next page, where all the search results are, and look at the new URL
The sites are different, so I can't just get the query parameter since I don't know it, and every site is different.
I was thinking about searching for the "input" part of the page (since the search bar is supposed to be the only input there), and send something to it. Then wait for the new URL.
Is that possible? Is there a smarter way?
I'm trying to avoid using something else but python for now (selenium, etc..)
I was searching every possible answer here and on the web, but nothing was possible so I was thinking about using the input part somehow...
Without selenium and similar softwares, you'll have to understand what is actually happening when you click such a button.
I'll take an example on a famous site (hint: if you read this you'll know which site I mean). In the HTML source I can see that (truncated) piece of code:
<form id="search" role="search" action=/search method="get" class="grid--cell fl-grow1 searchbar px12 js-searchbar " autocomplete="off">
<div class="ps-relative">
<input name="q"
type="text"
...
What it means is that when you submit the form, the browser would hit the URL /search (which here means https://stackoverflow.com/search), with a get request, wrapping all of the form's fields in the URL, after a ?. If I searched for the term python it would lead to http://stackoverflow.com/search?q=python.
Note that according to their content, the parameters would need to be URL-encoded.
If the form contains more input fields, you'll have to wrap them too, separating them by & signs, in such a way: param1=value1&param2=value2&...
To sum up, searching only inputs won't be sufficient, you'll have to parse the forms.
Not knowing more about your data, I cannot elaborate, but I think you might be able to do something with that.

Cannot write full HTML into the PDF

This has been pissing me off from yesterday, and I'm just out of ideas.
I'm trying to write a PDF with a subclassed pdfkit.PDFKit (let's call it MyPDFKit): it works well (I just subclassed it to add the possibility of using xvfb-run in the args). I specify that is not a problem of the class.
I was trying to convert some HTML to PDF. The template looks like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- Simplified for reading. -->
<style type="text/css">..</style>
</head>
<body>
<!-- Simplified for reading. -->
{% for obj in objs %}
<div>
<div>
<p>{{ obj.name }}</p>
</div>
<p>{{ obj.age }}</p>
</div>
{% endfor %}
</body>
</html>
With these template, and objs having near 400 instances, the output of the HTML is near 5k lines.
The problem comes when trying to splash that into the file. It could be in one of this two places:
MyPDFKit.to_pdf(..) (called from MyPDFKit.from_string(..))'s stdout has a limit size, and truncates part of the string (source code of the function is here).
f.write(..) is the one that truncates the string you pass in.
Cannot be a problem of the template or of the objects' data, because I can create PDFs correctly when getting only a certain range of then (more than 350 items in the same rendering starts leading to the problem due to HTML number of lines). For example, objs[:315] works well, but objs[:350] not.
I've tried setting the buffer size to -1, which is unlimited, but also don't work. Anyone had this issue before?
Ok, so finally, with the help of another programmer, I found the issue.
It looks like PDFKit, when processing a large amount of HTML (in number of PDF pages we're talking more than 349 more or less), sends progress bars comments to the buffer to see how it goes. Then, when it finish, also sends a done comment message.
This comments (I say comments to give they a type of data, cause I don't know really how PDF files handle comments), in programs like Adobe Reader, cannot be handle, so it detects that the file is corrupted/damage, while in programs like SumatraPDF/Edge, it just ignores then and shows the PDF nicely.
Now, how to prevent this behaviour? Passing the --quiet argument. But, for that, you'll need to subclass PDFKit (as I did with MyPDFKit), and add the args manually (line of code).
Problem solved.
EDIT
Seems that I can pass --quiet in the options kwargs, so no need of subclassing if that's only the problem (although it would be nice to have it active by default...)

Can i make google reCaptcha 2.0 only show the checkbox every time

I'm working on a voting application where people can vote as many times as they want, and i would like to have a reCaptcha checkbox in it, but rather than making people have to fill check the images thingy after a few votes, i'd rather have them just have the fill the checkbox every time.
I tried changing the security level to the lowest setting but it keeps showing the test after about two or three votes.
I know it's not a very good idea security wise, but it just doesn't feel good to have people check several images every time rather than just clicking it once which would already to some fine help holding back spambots.
I'm working on a Django application and implemented reCaptcha with Django-reCaptcha 2 .
No where in the documentation for Google's reCAPTCHA 2.0 does it state that you can do this. I would assume, based some some research into how the CAPTCHA works, that it's impossible for a user to set a checkbox only CAPTCHA.
Google's reCAPTCHA uses a variety of tests, including request tracking, page interaction tracking, scroll tracking and keystroke tracking to attempt to detect if the user on the site is human. You can read more about this here:
http://scraping.pro/no-captcha-recaptcha-challenge/
If Google can't assume with a high enough certainty that the user is human then it will display challenge to attempt to verify this.
As you stated you can lower the Security Level in the admin settings and this will lower the threshold that Google requires to verify a user as human, but if this is still not met a challenge will be presented.
In your case where it works a few times and then presents you with a challenge, this is probably because Google has detected your request count as abnormal and thus can't guarantee you reach the minimum threshold to verify you're a human. You therefore receive a challenge.
So in summary it doesn't seem like you can change this to check box only as Google still needs to be able to obtain enough data to prove the user is human.
However on the lowest Security Level setting you'd imagine most real users will only receive the checkbox.
You can also check how many challenges are being generated in the reCAPTCHA admin panel, as documented here:
https://developers.google.com/recaptcha/docs/faq
Index.html
<html>
<head>
<title>Google recapcha demo - Codeforgeek</title>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<h1>Google reCAPTHA Demo</h1>
<form id="comment_form" action="form.php" method="post">
<input type="email" placeholder="Type your email" size="40"><br><br>
<textarea name="comment" rows="8" cols="39"></textarea><br><br>
<input type="submit" name="submit" value="Post comment"><br><br>
<div class="g-recaptcha" data-sitekey="=== Your site key ==="></div>
</form>
</body>
</html>
verify.php
<?php
$email;$comment;$captcha;
if(isset($_POST['email']))
$email=$_POST['email'];
if(isset($_POST['comment']))
$comment=$_POST['comment'];
if(isset($_POST['g-recaptcha-response']))
$captcha=$_POST['g-recaptcha-response'];
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=YOUR SECRET KEY&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
if($response['success'] == false)
{
echo '<h2>You are spammer ! Get the #$%K out</h2>';
}
else
{
echo '<h2>Thanks for posting comment.</h2>';
}
?>

Django - turn field into tags with dropdown

In my form on django, I have a field called package_includes and a field called price. Right now, the content in package_includes it is simply text. So if I input "paper, glue, glitter" it will display exactly as i typed it, unable to change anything. However, I want the text to work like individual tags ->How I want tags to look
So when you click on one of the individual items (EX: "paper", "glue", or "glitter") i want it to display a drop down that allows you the option to put extra glitter for an additional $2.00 to the total.
Also, at the end of the text I want a tag that displays "Add" and this function would allow you to add items not included in this specific package. For example, you should be able to add crayons for $5, highlighter for $2.50, etc.
I am new to programming and don't fully understand how to add a function to text like this in a field in django. Thank you in advance for your help!
The answer to your question is unfortunately not a step-by-step instruction of how to go from 0 to a complete working example - only a pointer in the right direction.
What you need is achieved through CSS (producing the visual effect you want) and JavaScript (handling the drop-down functionality; it most probably has to be your own script based on jQuery). All of what you want needs to live (execute) within the Internet browser, and Django can only help there by serving the static CSS and script files, and referencing them in the actual page, when you put them in the correct template.
Here is an example of Wagtail Admin doing something similar:
If you open the page source in your browser, all you will see as HTML code for this is the following:
<div class="field-content">
<div class="input ">
<input id="id_tags" name="tags" type="text" value=""hello world", blog" /><script>initTagField("id_tags", "/admin/tag-autocomplete/");</script>
<span></span>
</div>
</div>
But if you open the page with FireBug, your browser's Development Tools, or the Web Developer extension, with visual styles applied it will decompose to something like this:
If you notice, the applied style to the form input element is display: none;. What you see is actually the styled unordered list elements right after. In order to be able to use them in your script, you need to be able to get to them/their contents from within your JS function. One strategy would be to assign an id attribute to all of the visible <li> elements. It can be something counter-based (e.g. id="shopping-cart-item-0", id="shopping-cart-item-1", etc.). Another way would be to assign an id to the <div class="input"> element, and within your function get all its DOM descendants of type <li>. Whatever works better for you. Then you could parse the label (inner text) of the list element in your script to get the type of item you are dealing with, and from then on find the discount price and apply it...
I would suggest that you start with a working example - find some app that uses taggit or similar package for Django and install it in a test application. Then you can use your browser's or preferred web development extension to play around with the CSS on them and see how different options affect the visual aspect of what you need. Once you are comfortable with that, see how you can build drop-down menus with jQuery. I believe the jQuery site has enough tutorials on the topic.

Plone : Check if a form was submitted

I'm working on a Plone template. Currently I'm implementing a search on the template. There is a form on the template which submits to the same template i.e. the same page.
I need to enable certain parts of the page to be viewed i.e. the results DIV, only when the form in the page has been submitted. I am not sure of how to check if a page has been submitted and display certain portions of the page.
I've looked at this link on using form.submitted, but it is really not helpful. I'm guessing whatever I have to do will be done in tal:condition tag.
Any help will be appreciated.
You can add an hidden field, name for example "submitedform" with value="1" and then, make a condition on :
request.get('submitedform', 0)
I found a way to make it work.
I used a tal:condition and checked for data that is inside the request object upon form submission.
To examine what is in the request object, simply put the following on your page:
<div tal:replace="structure request" />
Note: when the request object is called, it renders a readable, HTML version of the data. We use "structure" to prevent escaping the HTML.
Now, for my case, I needed to check whether my search form was submitted. So inside the DIV tag, I checked if the query string was empty or not. Below is a sample of the code:
<!-- Form has been submitted -->
<div tal:condition="python:request.environ.get('QUERY_STRING') != ''"></div>
<!-- Form has not been submitted -->
<div tal:condition="python:request.environ.get('QUERY_STRING') == ''"></div>
Note that you can use any variable you want. I simply chose to use the QUERY_STRING from the request object.
This might not be perfect, but I hope it will give direction to someone else.

Categories