I've been developing product catalog. All my needs fit perfectly with MongoDB but there is one problem:
There are categories with structure like these:
{
title:"Auto", // for h1 on page
id: 1, // for urls
level: 1, //
left: 2, // nested set implementation
right:10 //
}
When user goes to url like "www.example.com/category/1" I need to show html forms to filter shown goods. I'm pretty sure it is bad idea to store static definitions for every category on the server(about 300 categories, i'm using Django => 300 form models?)
So my idea is to store meta-information about each category in MongoDB. After some research I found out that I need 3-4 "html widgets" to construct any filter form that I need.
For example:
Range fields will look like this in HTML
<fieldset>
<legend>Price</legend>
<label for="price_from">from</label>
<input type="text" name="price_from">
<label for="price_to">to</label>
<input type="text" name="price_to">
</fieldset>
And its MongoDB JSON representation:
{
name:"price",
title:"Price",
type:"range", // "range" type - 2 inputs with initial values
categories:[1,2,5],// categories to which this so called "widget" relates
values:[
{from: 100},
{to: 500}
]
}
One more example:
Group of selects:
Its HTML version
<fieldset>
<legend>Size and color</legend>
<select name="size">
<option value="small">Small size</option>
<option value="medium">Medium size</option>
<option value="huge">Huge size</option>
</select>
<select name="color">
<option value="white">White color</option>
<option value="black">Black color</option>
<option value="purple">Purple color</option>
</select>
</fieldset>
And its MongoDB JSON version:
{
title:"Size and color",
type:"selectgroup",
categories:[2,4,6]
items:[
{
name:"size",
values:["small", "medium", "huge"]
},
{
name:"color",
values:["white", "black", "purple"]
}
]
}
So the main idea is : fetch all widgets from collection by category_id, parse them and print complete HTML form.
Pros
Easy to add any new type of widget to database
Easy to add parser for such widget to generate HTML from JSON
Each widget can relates to many categories => no duplicates
Cons
Collection of widgets has no less or more fixed structure of the document(actually i don't see real problem here)
Аll values related to widget are embedded.
Hard validation because fields are dynamic => no corresponding model on server side (right now i don't have any idea how to validate this)
My question is: does anybody know a better way of doing this? Pros of my method are cool, but cons are terrible.
Thanks for help and sorry for bad English.
If you only need 3-4 sets of form widgets to display all necessary query forms for the 300+ categories, you should use Django forms to specify the widgets. You do not need 300+ Django forms for that as you can easily use multiple forms in one page.
As a quick example, your
<fieldset>
<legend>Price</legend>
<label for="price_from">from</label>
<input type="text" name="price_from">
<label for="price_to">to</label>
<input type="text" name="price_to">
</fieldset>
would become
class PriceForm(forms.Form):
price_from = forms.IntegerField()
price_to = forms.IntegerField()
...and of course the template to embed the form into which would provide the <fieldset> and other necessary html document structure.
EDIT:
As it seems that your form labels etc. depend on the category, you still need to have some information about the forms in the category documents in mongodb. However, by using django forms you get a lot of useful functionality for free, such as input validation.
You probably can parametrize the templates in such a way that you give the category-specific values (labels etc.) to the template from mongodb, along with the necessary forms.
Technique for constructing dynamic filtered (faceted) search with Map/Reduce: http://ianwarshak.posterous.com/faceted-search-with-mongodb
I have successfully migrated the code to Python (and used it in a Django project).
Related
Here is an exemple of what I have:
forms.py
class aForm(forms.Form):
choices = [
('value1', 'choice1'),
('value2', 'choice2'),
('value3', 'choice3')
]
dropDownList = forms.ChoiceField(
choices=choices)
I want to add the attribute Disabledd to the first choice, like this:
<select>
<option selected value="value1" disabled>choice1</option>
<option selected value="value2">choice2</option>
<option selected value="value3">choice3</option>
</select>
How can I add that Disabled attribute from the forms.py file ?
After long search I didn't find the solution am looking for, but I did pass that problem with another aproch, what I did is creating a completly RAW html form from scratch where I had full power so I added the "disabled" attribute to the first option, without touching the views.py file, what I mean is am still using forms.Form and all the validations I already writen, this works by just naming your the fields in the RAW html form the same names as in the Form.
You can have a look at solution to this question. It pretty much addresses the same.
Disable Choice In ModelMultipleChoiceField CheckBoxSelectMultiple Django
I am finding it difficult to retrieve data from a web page when that data was initially passed in from the controller layer.
I am using Thymeleaf 3 and Spring boot v1. I have a webMVC controller which is passing an object to the template. The object looks something like this (pseudo-code):
public class Person{
// Nested object retrieved from various data sources
// and passed to the UI
private Address address;
private Job job;
// Form values I want to retrieve from UI
private String formValue1;
private String formValue2;
// getters/setters
}
My html page is divided into two sections. One section displays most of the Person values, while the other section includes a basic form. When the form is submitted, I want the form values plus ALL original values returned to the server.
What I'm finding is that it seems Thymeleaf will only retrieve values which are in the form, which means I have to stretch the form across both sections of the page, even though the user will only fill out one section of the page. So now the html looks as follows:
<html>
<!--header/body/etc -->
<form th:object="${person}" th:action="#{/person/id}" method="post">
<!-- Form Inputs -->
<input type="text" th:field="${person.formValue1}"/>
<input type="text" th:field="${person.formValue2}"/>
<!-- Values not used in form, but included so they will be sent back
to server -->
<input type="text" th:field="${person.address.city}" readonly="readonly"/>
<input type="text" th:field="${person.address.street}"
readonly="readonly"/>
<input type="text" th:field="${person.job.title}" readonly="readonly"/>
</form>
</html>
Additionally, it seems that Thymeleaf can only retrieve values that have the attribute th:field, but th:field is only assignable to the <input/> element (as far as I know), so any long text I have is truncated to the normal length of an input field, which is rather limited.
So I'm wondering if anyone can help with the following questions:
Can Thymeleaf return values which are not within a form (but returned when the form is submitted)
Is th:field the only option I can use for sending data back? (I've successfully displayed data with th:text, but no luck sending anything back).
Thanks.
Can Thymeleaf return values which are not within a form (but returned when the form is submitted)
This is more about how HTML forms and POST in HTTP works here. HTML form will send whole data within and Thymeleaf will bind that data to an object in your controller. So if you want all the values you should in fact wrap it all in a single form - this is a good way to go. If the case is that you don't want to display all the fields you could use hidden fields.
If you still would like to keep the data in separate forms for some reason you could try to work around it:
By using JavaScript to collect data from both forms and send it
Try to name both forms the same. I am not sure about it but it might work
I wouldn't recommend any of those anyway. Try to keep it simple.
Is th:field the only option I can use for sending data back? (I've successfully displayed data with th:text, but no luck sending anything back)
For a long text you can use textarea.
I have a newbie question in php
When I Select value from dropdown
automated that the value is output in the textbox
for example..
<select></select>
<option>John</option>
</select>
When i select john
automatic
the information of john output on a textbox
How to do this?
thanks in advance..
Sorry for my bad english
You're speaking of something that is typically done on the client side via javascript. PHP on the other hand is a server side scripting language.
If the information about John is stored in a database somewhere you would be doing an ajax call to a php function that retrieves and returns your desired information from the database. You would then use javascript to manipulate the DOM to insert the returned information into your textbox.
I hope this helps and gets you on the right path.
This question is not in php scope, you just need some Javascript to do it:
WORKING DEMO
HTML:
<select id="cbxName">
<option value="Join">John</option>
<option value="TrungDQ">TrungDQ</option>
</select>
<input id="txtName" type="text" value=""/>
Javascript:
var e = document.getElementById("cbxName");
e.onchange = function() {
var strName = e.options[e.selectedIndex].value;
document.getElementById("txtName").value = strName;
}
I am trying to pass a variable from my classic asp page to ssrs. When I put in a literal value for the parameter, such as 296, it works fine. But I want to put in a variable that is sent by the URL so that it works in different ways for different people who are logged in. So, instead of a URL that is http://servername.net/reportserver....rs:Command=Render&Agency=296 (for the agency that is number 296) I want to use a variable that I have set to the agency of the person who has logged in. Let's say the variable is pAgency. I have tried Agency=" #pAgency (I set pAgency = to the logged in person's agency) and all sorts of other combinations, and have searched the web, but find no answer for this. I've even tried session variables but, no go. You must be able to do this but...
Thanks for any help you can give. Cheers!
That is not how a rest URI works to my knowledge. You need to build the string and present it first fully formed, not define a variable on it. You could do somthing in code like (using HTML Form as a base)
In the example below there are four clear things to understand:
A. The 'action' in the form must be the webservice location of a report and do a post to self. (Or you can do an iframe element potentialy but I have not messed with that as much)
B. The 'input' element is text based but you MUST match the id and name to the name of your parameter passing in.
C. The 'select' element gives a user 'option's of save methods to output directly to common types.
D. The 'input' for a type of 'submit' ensure the form will post to itself with the data prescribed.
<!DOCTYPE HTML>
<html>
<head>
<title>SSRS Tester</title>
</head>
<body>
<form id="SSRSRender" action="http:// (reportservername)/ReportServer?/(pathtoreport)" method="post" target="_self">
<H3>Enter some detail for the report to render</H3>
My Variable 'Test': <input type="text" id="Test" name="Test">
<br/>
My outputs:
<select ID="rs:format" name="rs:format" size=1>
<option value="HTML4.0">HTML 4</option>
<option value="IMAGE">Tiff Image</option>
<option value="PDF">PDF</option>
</select>
<br/>
<input type="submit" value="Render Report">
</form>
</body>
</html>
If you want to do more types of input variables to dynamically get SSRS to render as you want outside of the SSRS landing page you need to determine if you want to use:
The service with some front end with scripting like javascript with HTML
Something more easy to control will pre built tools like 'Report Viewer' with ASP.NET or a client application in C# or VB.NET
Create the service proxy yourself in a class library and do the calls in code directly as well as the formatting
Trying to create a rest URI programatically is better done by contacting the service and using built in methods IMHO rather than trying to make a string. It may be a little more of a learning curve but it will help you in the end.
Is there any simple language similar to Markdown or one of the Wiki Markups that gets converted into HTML form elements?
For example:
name* = ___________
sex = (x) Male () Female
phones = [] Android [x] iPhone [] Blackberry
city = {BOS, (SFO), NYC}
Would get converted to:
<label>Name (required):</label><input type="text" name="name" id="name"/>
<label>Sex:</label><input type="radio" name="sex" value="Male" checked="checked"/> <input type="radio" name="sex" value="Female"/>
<label>Phones:</label><input type="check" name="phones" value="Android"/> <input type="check" name="phones" value="iPhone" checked="checked"/> <input type="check" name="phones" value="Blackberry"/>
<label>City:</label>
<select name="city">
<option value="BOS">BOS</option>
<option value="SFO" selected="selected">SFO</option>
<option value="NYC">NYC</option>
</select>
It would be simple to create one myself, but if any existing library/language supports it already, it would save me some time in implementation, documentation and maintenance. It would be preferable if the library worked either in Java (so we could run it server-side) or JavaScript (so we could run it client-side).
Update: I created a github project for this and maleldil implemented it. Feel free to try it out!
I have not been able to find a library that suits my needs, so I forked the WMD project (which SO uses for its Markdown syntax highlighting) and put the project on on Github. I didn't have time to implement it, but maleldil kindly did it himself, so try it out!
I took a swing at the problem at https://github.com/bradgessler/formdown with a slightly different syntax:
Hi _________(Name)
How are you doing today? () Good () Ok () Bad
Could I have your email address? __________#(Email)
Write a few lines that describe your mood: ____________///(Mood)
[ Submit your feelings ]
This is packaged up as the formdown gem and can be used in Rails to render forms via the .fmd file extension (e.g. app/views/users/edit.fmd.html).
Not an answer.
I think it should read
sex = () Male () Female
in order to get radio buttons, because
sex = [] Male [] Female
would result in checkboxes (meaning you could be both male and female)
If your going to implement it. Also, you would hae to require one question per line, so you would know what to group up, otherwise any two () would be linked.
I also suggest you do not try to put values inside the () or [], since its easier to search for them w/o text inside. But you might also add () as selected and [] as checked. If you use that tho, you cant have that stream of characters apear in the questions.
Just my 2 cents in case your going to implement it.
<< GET "/post.php";
label*: __|n="inputname"|v|p|i|c|l|disabled|readonly;
password: *|n|v|p|i|c;
select: { 'multi word value'= 'Option', 'value2'='Option 2', !'value1'='Option 3' }&|n|i|c;
(!)|n|v :label for previous radio; ()|n|v :label for previous;
label for checkboxes: [!]|n|v; []|n|v;
Message:____|rows|cols|c|p|v;
File: ^|size||types|i|c
#submit|v="Send Message";
#reset|v="Reset Form";
>>
<< and >> are form start and end signs
"this is a label":
* immediately after the label is for required fields
__ is text input
| attributes are separated with pipes (n="name of the field"|c="class of the field")
; is for field separation
{} select is much like an associative array.
! is for checked/selected values
:"label that comes after the value" for radios and checkboxes
____ is textarea
^ caret is for file input (up sign for upload)
#submit for buttons
.. now only if someone implemented this. :)
i came across http://www.jspwiki.org/Wiki.jsp?page=WikiFormsPlugin some time back. not sure f you can reuse the class tho.
I am working on a PHP solution that extends Michelf Markdown. Currently, basic <input> and <textarea> elements are supported.
It uses this syntax:
?{type}("label" "value" "placeholder" rows*cols){.class}
Where type can be an input type (<input type="...") or textarea which results in a textarea.
See https://github.com/rbnvrw/markdown-forms for the code and feel free to contribute.