w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
XML Obtain multiple values
You can use XPath to fetch all nodes ending with _Away. Here's a code snippet that accomplishes what you want: <?php $xml = <<<XML <XMLSOCCER.COM> <Odds> <Id>1547</Id> <_10Bet_Home_Home>1.31</_10Bet_Home_Home> <_10Bet_Home_Url>http://en.10bet.com</_10Bet_Home_Url> <_10Bet_Home_Away>8.50</_10Bet_Home_Away> <_10Bet_Home_Draw>5.40</_10Bet_Home_Draw> <Bet_At_Home_Home>1.25</Bet_At_Home_Home> <Bet_At_Home_Url>http://www.bet-at-home.com/</Bet_At_Home_Url> <Bet_At_Home_Away>10.00</Bet_At_Home_Away> <Bet_At_Home_Draw>5.75</Bet_At_Home_Draw> <Bet365_Url>http://www.bet365.com/</Bet365_Url> <Bet365_Home>1.30&

Categories : PHP

Split long string to obtain multiple values/strings - google spreadsheet
Have you considered using XmlService Services? https://developers.google.com/apps-script/reference/xml-service Simple example: /* CODE FOR DEMONSTRATION PURPOSES */ function testXML() { var result = []; var document = XmlService.parse('<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="5" yahoo:created="2013-07-28T18:37:23Z" yahoo:lang="en-US"><diagnostics><publiclyCallable>true</publiclyCallable><user-time>145</user-time><service-time>141</service-time><build-version>38483</build-version></diagnostics><results><Result xmlns="urn:yahoo:cate">RED</Result><Result xmlns="urn:yahoo:cate">GREEN</Result><Result xmlns="urn:yahoo:cate">BLUE</Result>&

Categories : Google Apps Script

Why can't I use Django's field lookups in a values call?
https://docs.djangoproject.com/en/dev/ref/models/querysets/#values I think you still need to use the extra query. Field lookups Field lookups are how you specify the meat of an SQL WHERE clause. They’re specified as keyword arguments to the QuerySet methods filter(), exclude() and get(). Django thinks you are trying to look up a field on a relationship field "date" when you use the double underscore with your values query.

Categories : Django

Django, filter by multiple values
Contracts.objects.filter(band__in=bands) You might want to add a prefetch_related statement there to prefetch the gigs though, otherwise your template loop will hit the DB once per contract. contracts = Contracts.objects.filter(band__in=bands).prefetch_related()

Categories : Django

django NoReverseMatch with multiple pk values
You need to rethink your urls. Hopefully the following comments will help. In your family urls you have url(r'^(?P<pk>d+)/person/',include('person.urls',namespace='person')), Then in your person urls you have url(r'^(?P<pk>d+)/$',PersonDetailView.as_view(),name='person-detail'), This suggests a url of the form /family/<pk>/person/<pk>/. That is invalid, as you have used the named argument pk twice in the same pattern. If you rename one of your primary keys in the url pattern, for example: url(r'^(?P<person_pk>d+)/$',PersonDetailView.as_view(),name='person-detail'), Then you can use the pk_url_kwarg option in your PersonDetail view. class PersonDetailView(generic.DetailView): model=Person pk_url_kwarg = 'person_pk' Note also that you have

Categories : Django

Django unit testing; POST checkboxes with multiple values
So after trying out a couple other things, I'm basically going to say there is "technically" no answer to my question...I could not find any way to create a checkbox-type POST argument using HttpRequest. However, doing it the 'right' way with the Django test client as Hieu Nguyen suggested does allow for that capability. You just have to encapsulate the multiple options in parantheses, as: response = c.post('/success/',{ 'fname': 'A', 'lname': 'Student', 'email': 'me@name.com', 'passwd': 'password', 'conpasswd': 'password', 'class_choices': ('1','2'), })

Categories : Django

Django: passing multiple values into the dictionary of the render method
You're using the class-based view IntroView, which you don't pass in symbol_list with, as you identified. Try modifying your view as follows: class IntroView(generic.DetailView): model = Book template_name = 'books/intro.html' def get_context_data(self, **kwargs): context = super(IntroView, self).get_context_data(**kwargs) context['symbol_list'] = Symbol.objects.all().order_by('name') return context

Categories : Python

How to obtain months in right order from different years from DateField in django?
The only way to do it would be to add the year in too: dates = [(i.year, i.month) for i in MyModel.objects.values_list('date', flat=True)] That would return this list (once duplicates are removed and sorted): [(2012, 8), (2012, 12), (2013, 5)] If you wanted later, you could then get just the months by: >>> [x[1] for x in dates] [8, 12, 5] But note that there may well be duplicates in that list too (August In both 2012 and 2013 would come out as 8, for example), and you wouldn't necessarily know where the list changes from one year to the next.

Categories : Django

Obtain the symbol that a "super" call refers to in Scala
I think using of self type annotations and multiple inheritance will serve you: trait HelperTrait { def helperMethod {println("calling helperMethod of HelperTrait")} } trait PublicInterface { this: HelperTrait => def useHelperMethod { println("calling useHelperMethod of PublicInterface") helperMethod } } class ImplementationClass extends PublicInterface with HelperTrait var obj = new ImplementationClass() obj.useHelperMethod obj.helperMethod

Categories : Scala

Ajax call to php script sending values from multiple checkbox form
The method you choose is to some degree based on how you evaluate 'best'. In this case, I'd use three major criteria: Low bandwidth Clear code (semantically correct and easily understandable) Easy code (code that is easy to write, debug and maintain) Given your second code sample, it seems apparent that you're using jQuery. The first thing that I would do is replace your AJAX method with a call to $.get() or $.ajax(). This will simplify your code and make it easier to maintain. The next thing I'd do is modify things to use the checked selector, which will streamline the process of getting the list of checked values. Something like this: var checkedValue = $("input[name='size[]']:checked").map(function() { return Number(this.value); }).get(); In order for this to work, you'd nee

Categories : Javascript

Obtain field (td) values by clicking on table row
With using just plain javascript you can do this: <html> <head> <script language="javascript" type="text/javascript"> function showRow(row) { var x=row.cells; document.getElementById("firstname").value = x[0].innerHTML; document.getElementById("lastname").value = x[1].innerHTML; document.getElementById("age").value = x[2].innerHTML; document.getElementById("total").value = x[3].innerHTML; document.getElementById("discount").value = x[4].innerHTML; document.getElementById("diff").value = x[5].innerHTML; } </script> </head> <body> <table id="myTable" cellspacing="1"> <thead> <tr> <th>first name</th> <th>last name</th> <th>age</th>

Categories : Javascript

Obtain unique/unrepeated values from a List
Use a Set then a List: List<String> ret = new ArrayList<>(new HashSet<>(origList)); A Set cannot contain duplicate elements; and a HashSet is used since String implements .equals() and .hashCode(). If you want to keep the original order of elements in the initial list, replace the HashSet with a LinkedHashSet. (fill empty diamonds with String if this is not Java 7) Edit: see @zerocool's answer as to what was wrong with the original code

Categories : Java

Magento Collection, how to obtain array of values of a particular field
I haven't been in your particular situation, but I've had similar problems when I wanted to perform an action on all orders in my site - the objects are large, and if I just did a collection of all orders, it would quickly fill the available memory and die. In my case, I was working with orders, so I started looping through and only selecting one month's worth at a time - a little extra code, but it made the collection size much more manageable. Could you do something similar here? For example, if they're products, maybe filter on the product_id and do only 1,000 at a time, or for orders the date tends to work well if they're distributed somewhat evenly, and so on. Just some field that (reasonably) evenly divides them up.

Categories : Magento

Obtain and store adjacent values from a .csv file (Python)
Collect the values into a dictionary of lists; a collections.defaultdict() object is easiest: from collections import defaultdict import csv species = defaultdict(list) with open('speciesandbss.csv', 'rb') as inputfile: for row in csv.reader(inputfile): species[row[0]].append(row[1]) for name in sorted(species, key=str.lower): print '{} = {}'.format(name, species[name]) Outputs: acutata = ['0.16509', '0.16509', '0.16509'] acutocostata = ['0.03145', '0.01936', '0.01781', '0.01698', '0.01684', '0.01077'] adkinsi = ['0.16509'] Aenona = ['0.01311', '0.01311'] aequilateralis = ['0.00495', '0.00445', '0.00368', '0.00356'] agdjakendensis = ['0.00628'] Agerostrea = ['0.01764'] albertensis = ['0.00852', '0.00356', '0.00495', '0.00461', '0.00445', '0.0041'] alta = ['0.00328',

Categories : Python

Splitting a string to an array using a regex to obtain key-values pairs
An other approach with preg_match_all: $pattern = '~(?<=^:| :)S++|(?<=s)(?:[^:]+?|(?<! ):)+?(?= *+(?> :|$))~'; preg_match_all($pattern, $text, $matches); echo '<pre>' . print_r($matches[0], true); Pattern details: # capture all the first word at line begining preceded by a colon # (?<=^:| :) # lookbehind, preceded by the begining of the string # and a colon or a newline and a colon S++ # all that is not a space # capture all the content until the next line with : at first position # (?<=s) # lookbehind, preceded by a space (?: # open a non capturing group [^:]+? # all character that is not a colon, one or more times (lazy) | # OR (?<!^| ): # negative lookbehind, a

Categories : PHP

how to obtain html page including all tags and element values using javascript
Have you tried this? alert($('html').html()); It will alert the whole HTML element except the DOCTYPE.

Categories : Javascript

Obtain row height dynamically in UITableViewCell with multiple nibs
You can dequeue the cell in heightForForAtIndexPath and check it's height: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellId = @"Cell";//set cell ID here based on your view controller's logic UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellId]; return cell.bounds.size.height; } You can cache the dequeued cells in a dictionary if you're concerned about performance. There is a more detailed discussion of this approach in Retrieve custom prototype cell height from storyboard (contrary to what the title might imply, the use of storyboard is not required).

Categories : IOS

Is it possible to obtain multiple elements on a page simultaneously from a WebDriver instance?
Just adding to @acdcjunior's comment that the WebDriver class is not thread safe; I've found the following issue which I believe is related to this question: Issue 6592: IE Driver returns 404: File not found If it is the same issue you're having, then one solution is to synchronise your calls the WebDriver. I solved this by creating a SynchronizedInternetExplorerDriver.java class, which synchronises calls to the underlying WebDriver. Let me know if this helps (using this SynchronizedInternetExplorerDriver, you'll (at least) be able to rule out thread issues as the cause). Code Snippet: public class SynchronizedInternetExplorerDriver extends InternetExplorerDriver { ... @Override protected Response execute(String driverCommand, Map<String, ?> parameters) { synchr

Categories : Java

Django - admin.py for multiple apps in a single django project
@i.h4d35 I think DivinusVox is right. Try to add your new app in INSTALLED_APPS in the settings.py and it should be solved. Please check admin info from Django official website.

Categories : Python

How to cast Django form to dict where keys are field id in template and values are initial values?
If you have the auto_id set to True then you can get the id with form_object_instance.field_name.auto_id. With that in mind you can create your dict by iterating over the form object. I am just wondering why you would need to do such a processing as the form object is usually used to encapsulate such behaviors...

Categories : Django

Using multiple Django admin sites for multiple databases
@Zack4 I now have almost exactly the same code as you, but mine works. One questionable thing that I see is that--- whereas it will be deprecated in 1.7, I recall having read--- in 1.6.5 which I'm using it's still necessary to include the following in the url config: admin.autodiscover() When I omit that I get a notice that I don't have permission to change anything... not the problem identified in the question but maybe something else is being done that avoids that problem and leaves the one that you have. And what is "core.admin" in your url config? There is no Django module of that name, according to the error message that I get when I try it. Is "core" the name of your project root directory? Maybe there is a conflict with Django's use of the word "core". Finally, in my struggles

Categories : Django

Django Populating multiple forms with multiple objects
You are looking for the formsets A formset is a layer of abstraction to work with multiple forms on the same page. It can be best compared to a data grid.

Categories : Django

Display multiple rows and column values into a single row, multiple column values
Since you are using SQL Server there are several ways that you can transpose the rows of data into columns. Aggregate Function / CASE: You can use an aggregate function with a CASE expression along with row_number(). This version would require that you have a known number of values to become columns: select id, name, max(case when rn = 1 then employer end) employer1, max(case when rn = 1 then IncomeType end) IncomeType1, max(case when rn = 1 then Amount end) Amount1, max(case when rn = 2 then employer end) employer2, max(case when rn = 2 then IncomeType end) IncomeType2, max(case when rn = 2 then Amount end) Amount2, max(case when rn = 3 then employer end) employer3, max(case when rn = 3 then IncomeType end) IncomeType3, max(case when rn = 3 then Amount end) Amount3

Categories : SQL

How to call multiple actions of multiple modules from different controller and combine the output?
Action View Helper will help you to accomplish this in modules/default/views/scripts/index/index.phtml <?php echo $this->action('index', 'index', 'module1')); ?> <?php echo $this->action('index', 'index', 'module2'); ?> But action view helper have several performance and debugging issues please see these links before deciding to use it How can I speed up calls to the action() view helper? Action View Helper in Zend - Work around? Using Action Helpers To Implement Re-Usable Widgets

Categories : PHP

multiple databases and multiple models in django
In order to define specific databases used for specific models, you need to define a database router: The easiest way to use multiple databases is to set up a database routing scheme. The default routing scheme ensures that objects remain ‘sticky’ to their original database (i.e., an object retrieved from the foo database will be saved on the same database). The default routing scheme ensures that if a database isn’t specified, all queries fall back to the default database. See this snippet as an example: http://djangosnippets.org/snippets/2687/ Also see: Django multi-database routing Multiple Databases in Django Tutorial: Using Django's Multiple Database Support Database Routers in Django

Categories : Python

Django REST Framework API call using IOS.
When you use 'curl' and use the '-u myuser:mypass' you are sending the username and password in the HTTP Authorization header. I'm not sure how to do this in IOS specifically, but I would try doing a POST request with a url like: http://username:password@example.com/

Categories : IOS

Django call a function without an accessible URL?
But also say I DON'T want that function call to be accessible via any URL people can type into the browser. You could have a hidden form with pk of the object you want to delete, and have the form submit when a user clicks on the delete link. Since the form is POSTed, the delete url won't do any good if someone types it into the browsers address bar. But I think it would be a lot lot better to use an ajax link which sends a DELETE instead of GET. That would also make typing the url into the address bar useless.

Categories : Django

Jquery Object looping - How to differenciate the values and assign different task, when multiple key values are same..?
You can do this by using if condition in objetProcess as below: var objetProcess = function(){ $.each(obj, function(key, value){ if ($.type(value) === 'string') { console.log('string task'); } else if ($.type(value) === 'object') { console.log('object task'); } }) } http://jsfiddle.net/qS6H2/5/

Categories : Jquery

SQL select single distinct values from multiple columns (not combined values)
Try to use union with both columns select Department1 from tab union select Department2 from tab NOTE: union command eliminates duplicates

Categories : SQL

Does jquery UI Autocomplete support restrict typing on invalid values where supporting multiple values?
You could use this kind of snippet: { I'm using here keyup event to check, but on modern browsers, you could use input (oninput) event instead or bind onpaste event too } http://jsfiddle.net/q2SSF/ var availableTags = [ "Bird", "Son", "Happy"]; function split(val) { return val.split(/,s*/); } function checkAvailable(term) { var length = term.length, chck = false, term = term.toLowerCase(); for (var i = 0, z = availableTags.length; i < z; i++) if (availableTags[i].substring(0, length).toLowerCase() === term) return true; return false; } function extractLast(term) { return split(term).pop(); } var $autocomplete = $("#autocomplete") // don't navigate away from the field on tab when selecting an item .on("keyd

Categories : Jquery

passing multiple values to switch separating the values by commas
The comma operator evaluates all the expressions and returns the value of the rightmost one. (It doesn't make any difference that you're using it in a switch.) Your example is exactly the same as switch (m*2), but if any of the preceding expressions had side effects, those side effect would be applied before the switch statement was executed.

Categories : C

matching values (multiple if-functions) between two files and pasting the values
The most important first step is usually choosing the right data structure to hold your data. I think the easiest structure for the contents of the frequency file, for this purpose, is an array of hashes. Like this: use strict; use warnings; use English '-no_match_vars'; my ($variants_file, $frequency_file) = @ARGV; # take filename from command line open my $variants, '<', $variants_file or die "Could not open file $variants_file: $!"; open my $frequency, '<', $frequency_file or die "Could not open file $frequency_file $!"; # parse the header fields my (undef, undef, @header) = do { my $header_line = <$frequency>; chomp $header_line; split / /, $header_line; }; my @frequency_data; my $expect_pos = 1; # starting position while (<$frequency>){ chomp;

Categories : Perl

How to get multiple button values into editext then display all the values dynamically?
When a button is clicked, you can append the result of that button to the text field, say something like: public void onAddButtonClick(View v) { textField.setText(textField.getText() + "+"); }

Categories : Android

django views.py to call another python script
Whatever string you want to display in the browser, return it in the HttpResponse. You could try something like: #validation.py def validate(url1, url2): # perform validation here if valid: return "urls are valid" else: return "urls are invalid" #views.py def shortcuts_process(request): print request.POST url1 = request.POST.get('url1', '') url2 = request.POST.get('url2'. '') return HttpResponse(validate(url1, url2)) Hope that helps. For form validation, please refer to Chapter 7 in the django book (http://www.djangobook.com/en/2.0/chapter07.html)

Categories : Python

Why do I get 'internal error' from Paypal using this call in Django?
typo in "EXPRESS_CKECKOUT" instead of "EXPRESS_CHECKOUT" and third argument urllib.urlencode(data) for urllib2.Request is not required. data = {"scope":"EXPRESS_CHECKOUT", "callback":"http://www.example.com/success.html", "requestEnvelope": {"errorLanguage":"en_US"}} req = urllib2.Request("https://svcs.sandbox.paypal.com/Permissions/RequestPermissions/", simplejson.dumps(data), headers) res = urllib2.urlopen(req).read()

Categories : Python

Django object not saving even after "save" call
Try a manual commit. I don't know what else to suggest. from django.db import transaction @transaction.commit_manually def viewfunc(request): ... data.save() transaction.commit()

Categories : Python

Django, how to call a query whenever user logs in?
This is really very easy in django with its authorization feature look at the following link: http://www.djangobook.com/en/2.0/chapter14.html? if 'password' in request.POST and 'username' in request.POST: user = auth.authenticate(username=request.POST['username'], password=request.POST['password']) if user is not None and user.is_active: auth.login(request,user) #do your queries here return render(request,'htmlpage.html',{'data':data}

Categories : Django

can't call django json view with angularjs
$http.get('http://localhost:8000/myapp/myview/').success(function(data) The URL needs to drop the trailing /, then append .json. Like so: $http.get('http://localhost:8000/myapp/myview.json').success(function(data)

Categories : Django

Ajax Posts but does not call Django View
Solved by using: $.ajax({ url: '/results/', type: 'POST', data: send_data, success: function(response) { console.log("everything worked!"); $("#results").html(response); }, error: function(obj, status, err) { alert(err); console.log(err); } }); I was trying to use Django to redirect me to the render response like it ussually does. Because I'm calling from javascript to response is redriceted to javascript and the the typical django functions. This part of the function success: function(response) { $("#results").html(response); }, renders the response to my chosen results div.

Categories : Javascript

Django: How can I call a view function from template?
One option is, you can wrap the submit button with a form Something like this: <form action="{% url path.to.request_page %}" method="POST"> <input id="submit" type="button" value="Click" /> </form> (remove the onclick and method) If you want to load a specific part of the page, without page reload - you can do <input id="submit" type="button" value="Click" data_url/> and on a submit listener $(function(){ $('form').on('submit', function(e){ e.preventDefault(); $.ajax({ url: $(this).attr('action'), method: $(this).attr('method'), success: function(data){ $('#target').html(data) } }); }); });

Categories : Django



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.