i am using IBM online hyperledger composer playground at https://composer-playground.mybluemix.net
i have an if else condition, in the else part, i need to show an alert or an error message to the user if he has low balance.
i searched the internet and couldnt fine any source. below is one of the meaningful source which is talking about success component, but it doesnt show how to implement.
https://github.com/hyperledger/composer/issues/894
and
https://github.com/hyperledger/composer/issues/539
how can we generate our own message to display to the end user?
thank you.
for testing purposes in the Online Playground - you can do
1) use alert() eg working with Composer sample network and transactions here -> https://github.com/hyperledger/composer-sample-networks/blob/v0.16.x/packages/trade-network/lib/logic.js
/**
function tradeCommodity(trade) {
alert("New Trade Commodity owner is " + trade.newOwner.firstName + ' ' + trade.newOwner.lastName);
to pop up a message. alert() is a standard JS function.
2) use console.log() (and hit SHIFT-CTRL-J to open the developer console)
function tradeCommodity(trade) {
console.log("New Trade Commodity owner is " + trade.newOwner.firstName + ' ' + trade.newOwner.lastName);
Related
Two-fold issue: 1) Trying to download attachments from Outlook emails using win32 in Jupyter Notebook 2) I get notifications of different lessons and resources by phone. Then I usually, send the URL to the resource to my email to organize later on. Is there a way to use Jupyter Notebook to grab these emails and store them in an excel file? Here is the lesson I am trying to follow currently: https://towardsdatascience.com/automatic-download-email-attachment-with-python-4aa59bc66c25 . And here is my code:
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.items
message = message.GetFirst()
attachments = message.Attachments
attachment = attachments.Item(1)
attachment_name = str(attachment).lower() attachment.SaveAsFile(path + '\\' + atttachment_name)
exit
You never check that a message has attachments (message.Attachments.Count > 0) and you assume that you get a particular message from the Inbox: can either get the currently selected message (Application.ActiveExplorer.Selection collection) or you need to search for the particular message using Items.Find/FindNext or Items.Restrict. Items.GetLast will give some undetermined item.
Thirdly, the line message = message.GetFirst() was probably meant to be message = messages.GetFirst(). Still won't work, but at least it won't blow up because message variable is uninitialized.
I have a WordPress website for a client that uses a custom theme and a number of plugins in combination to create an events calendar where logged in users can purchase tickets for paid events and register for free RSVP-required events. To accomplish this, I am using the following six plugins in combination:
The Events Calendar
Events Calendar Pro
Event Tickets
Event Tickets Plus
WooCommerce
WooCommerce Stripe Gateway
The website was established in 2015. In the last 4 years, those plugins have seen extensive updates, and as a result, at a certain point the custom site I built around those plugins started experiencing deprecation issues, and attempts to upgrade caused performance failure. After consulting with support, it became necessary to pull a duplicate copy of the site onto a development server so that I could do the work to upgrade the install so all the latest versions of all of these plugins can be running and working properly.
Everything was going well with the upgrade work until I noticed that one of the plugins seems to be generating the following error in the console in Chrome:
POST https://pcapolar.codewordserver.com/wp-admin/admin-ajax.php 400 (Bad Request)
send # jquery.js?ver=1.12.4-wp:4
ajax # jquery.js?ver=1.12.4-wp:4
n.<computed> # jquery.js?ver=1.12.4-wp:4
r.length.e.checkAvailability # frontend-ticket-form.min.js?ver=4.11.1:1
r.length.e.init # frontend-ticket-form.min.js?ver=4.11.1:1
(anonymous) # frontend-ticket-form.min.js?ver=4.11.1:1
(anonymous) # frontend-ticket-form.min.js?ver=4.11.1:1
Loading the same page in Edge generated the following console error:
HTTP400: BAD REQUEST - The request could not be processed by the server due to invalid syntax
(XHR)POST - https://pcapolar.codewordserver.com/wp-admin/admin-ajax.php
The error occurs only under very specific circumstances -- when a single event page displays the frontend form for a paid ticket. The error doesn't occur when the front end paid ticket form is not output, for example when there is a registered RSVP form with no payment component, when there is no ticket component to the event, or when a user who is not an active member views an affected page such that all information about details of the event and buying tickets is excluded from the output via theme template files. Despite the console error generated, it appears that ajax works fine and all of the functionality works exactly as expected. If you weren't looking at the console, you'd never know there was a problem.
In order to rule out an issue with my custom theme or a conflict with another plugin, I activated the default Twenty Twenty theme and deactivated all other plugins except the 6 I listed that are required to use ticketed event process. The error remained present under these circumstances
After going back and forth with Modern Tribe (the plugin developers) support desk, they report the error cannot be replicated. So I tried myself to install a clean copy of WordPress with a new database, then install only those 6 plugins while running the default Twenty Twenty theme. I did this on the same server under the same cPanel account as the dev site with the error, just at different subdomains. On the clean install, the error was NOT present. But when I then pointed the clean WordPress install to a duplicate copy of the database I'm using for the dev site I'm working on, the error shows up again. From that, I can only conclude there is something going on in my database that is making this error happen, but Modern Tribe support are telling me that since the error can't be reproduced by them, there isn't anything they can do to help.
Starting over with a clean install for this site isn't really an option, there is so much data collected over the last 4 years from ticket purchase and membership transactions that we really can't lose. I need to find the faulty data and clean it, but I feel out of my depth here. Any help or suggestions on how to resolve this are welcome.
Edited to add:
I found this code in the javascript file references by the error message in the console. Am I looking in the right place?
/**
* Check tickets availability.
*
* #since 4.9
*
* #return void
*/
obj.checkAvailability = function() {
// We're checking availability for all the tickets at once.
var params = {
action : 'ticket_availability_check',
tickets : obj.getTickets(),
};
$.post(
TribeTicketOptions.ajaxurl,
params,
function( response ) {
var success = response.success;
// Bail if we don't get a successful response.
if ( ! success ) {
return;
}
// Get the tickets response with availability.
var tickets = response.data.tickets;
// Make DOM updates.
obj.updateAvailability( tickets );
}
);
// Repeat every 60 (filterable via tribe_tickets_availability_check_interval ) seconds
if ( 0 < TribeTicketOptions.availability_check_interval ) {
setTimeout( obj.checkAvailability, TribeTicketOptions.availability_check_interval );
}
}
Edited to add:
Then I ran a string search for ticket_availability and found the following. It looks like it might be related, but I'm a bit over my head in interpreting. Am I on the right track yet?
public function ticket_availability( $tickets = array() ) {
$response = array( 'html' => '' );
$tickets = tribe_get_request_var( 'tickets', array() );
// Bail if we receive no tickets
if ( empty( $tickets ) ) {
wp_send_json_error( $response );
}
/** #var Tribe__Tickets__Tickets_Handler $tickets_handler */
$tickets_handler = tribe( 'tickets.handler' );
/** #var Tribe__Tickets__Editor__Template $tickets_editor */
$tickets_editor = tribe( 'tickets.editor.template' );
// Parse the tickets and create the array for the response
foreach ( $tickets as $ticket_id ) {
$ticket = Tribe__Tickets__Tickets::load_ticket_object( $ticket_id );
if (
! $ticket instanceof Tribe__Tickets__Ticket_Object
|| empty( $ticket->ID )
) {
continue;
}
$available = $tickets_handler->get_ticket_max_purchase( $ticket->ID );
$response['tickets'][ $ticket_id ]['available'] = $available;
// If there are no more available we will send the template part HTML to update the DOM
if ( 0 === $available ) {
$response['tickets'][ $ticket_id ]['unavailable_html'] = $tickets_editor->template( 'blocks/tickets/quantity-unavailable', $ticket, false );
}
}
wp_send_json_success( $response );
}
The weird thing is that this function is filed to a folder called Blocks, which implied it works with Gutenberg, which I have disabled via the Classic Editor plugin.
StackOverflow powers that be, forgive me but this was too much to fit in a comment.
I apologize, but this is more of a debug process than a strict answer.
The admin-ajax.php file only has 3 scenarios to return a 400 error.
If the user is logged in, and the ajax function hasn't been added to the wp_ajax_{function_name} action. (line #164)
The user is NOT logged in, and the ajax function hasn't been added to the wp_ajax_nopriv_{function_name} action. (line #179)
No action was sent in the request. (line #32)
You'll need to figure out which of these is causing your error. If you're not sure how to do this, an easy way is to temporarily edit your admin-ajax.php file. Before you see this:
// Require an action parameter
if ( empty( $_REQUEST['action'] ) ) {
wp_die( '0', 400 );
}
Add in the following (again, before the above lines)
ob_start();
print( '<pre>'. print_r($_REQUEST, true) .'</pre>' );
wp_mail( 'your-email#address.com', 'Debug Results', ob_get_clean() );
This will email you (semi-nicely) formatted dump of the $_REQUEST. If there's no action, you'll know that for some reason the "front end form for a paid ticket" function isn't being added, and Modern Tribe could probably help you out with that.
If the action is set, you can add a similar line down below at line 164 or 179 and repeat the above, but with print( '<pre>'. print_r($action, true) .'</pre>' ); instead. If either of these get emailed to you when you submit the form, you'll know which ajax hook isn't being added, and again Modern Tribe could probably help you from there.
Also note, that modifying core WP files is generally bad practice and you should revert these changes when you're done debugging. (There's ways to hook into file instead, but for ease/speed of diagnostics, go ahead and temporarily edit it, as these aren't permanent changes, and it's on a development site, so you shouldn't have to worry)
Beyond the above, you'll probably need to hire a developer look at it, there's not much more that someone on Stack Overflow can do without having direct access to your database and files.
I am having the same problem and I think the problem is Tribe__Editor::should_load_blocks when the classic editor plugin is active.
To bypass this error I add this code to my theme functions.php file
add_action( 'xxx', tribe_callback( 'tickets.editor.blocks.tickets', 'register' ) );
do_action( 'xxx' );
I hope this works for you.
The advice I received from the plugin developers after a great deal of back and forth was to add the following to my theme's functions.php file:
add_filter( 'tribe_tickets_availability_check_interval', function( $interval) {
return 0;
} );
This resolves the console issue, does not generate additional errors, and does not interfere with any expected functionality in all tests performed thus far.
Wanted to update everyone that with the release of Event Tickets 4.11.4 and Event Tickets Plus 4.11.3, this issue has been completely resolved on the plugin side. So apparently this was not just an issue with my site only. Thank you to everyone who contributed.
I am learning how to use Maybe observable. I created the below example. Incase of
Maybe.just(value) I will receive the value in onSuccess callback.
In case of Maybe.just(null), I expected to receive the log from onError. However, according to the posted code, when I run the code, the App crashes and I do not receive any logs.
Would you please tell me why I am not receiving any logs from onError()?
code
Maybe.just(null)
.subscribe(
i->Log.i("TAG:", "[onSuccess]: " + i),
err->Log.e("TAG", "[ERROR] err.getMessage(): " + err.getMessage()),
() -> Log.i("TAG", "[COMPLETED]: ")
);
You can't create a Maybe doing Maybe.just(null). It will throw a NullPointerException, that's why your app crashes.
Some people suggested that the library should have the option to Create a Maybe from null in RxJava, but unfortunately that won't happen:
Closing as won't happen. Static methods returning RxJava types can live on any external class.
A workaround for doing that, is to replace this:
Maybe.just(null)
For this:
Maybe.fromCallable(() -> null)
I have a report that needs to show images from a Windows folder on the server, which is working (see here ). Now, I am wondering how to get the report to pull images of differing file types, like jpg & tif. (I am using png by default). Is there a relatively easy way to do this? The image names with file extension are not in the SQL database.
EDIT: I entered this in the Custom Code block, from Daniel's help below.
Public Function GetImage(ByRef Filename As String) As String
' Full image path used for testing if it exists
Dim ImagePath As String
ImagePath = "\\GVSSERVER1\GVSServerD\Acclamare_Images\" + Filename
' Test to see if the file exists as a gif
Try
If System.IO.File.Exists(ImagePath + ".png")
Return "file://" + ImagePath + ".png"
ElseIf System.IO.File.Exists(ImagePath + ".jpg")
Else Return "file://" + ImagePath + ".jpg"
End If
Catch ex As Exception
Return "Hit an Error"
End Try
Return "Hit the end"
End Function
When I run the report, it fetches the .jpg extension even though the image file is a png, and there isn't a jpg file for that item. Any idea on how to correct that?
EDIT 2: I wasn't having success with the updated custom code, but I could have been missing something, as I'm no expert with custom code. I found this question (see here) which is for a function. I tried it and it works, except for some reason .tif files don't display on the report. I installed Microsoft Picture Manager (from the Sharepoint exe download), but it still doesn't display the .tif files.
The good news is that this is definetely possible, however it takes a bit of custom code and server side tweaking to get ready.
General Idea: Create a code behind function that takes the name of our image and then does file existence tests to determine which file extension type actually exists on the network share.
If you right-click outside of the report area and go to properties, you will see the custom code window where you can paste the following function code.
Custom Code:
Public Function GetImage(ByRef Filename As String) As String
' Full image path used for testing if the image exists
Dim ImagePath As String
ImagePath = "\\EM-SSRS\ImageTest\" + Filename
' Test to see if the file exists as a gif
If System.IO.File.Exists(ImagePath + ".gif") THEN
Return "file://" + ImagePath + ".gif"
ElseIf System.IO.File.Exists(ImagePath + ".png") THEN
Return "file://" + ImagePath + ".png"
ElseIf System.IO.File.Exists(ImagePath + ".jpg") THEN
Return "file://" + ImagePath + ".jpg"
ElseIf System.IO.File.Exists(ImagePath + ".jpeg") THEN
Return "file://" + ImagePath + ".jpeg"
End If
Return "No Image Exists"
End Function
You will have to edit the ImagePath variable to contain the network share path for your scenario or even add another parameter to the function to make it more generic if you wish.
Once the code function is created, I would advise creating a dummy textbox expression on the report and using the following value:
=Code.GetImage("Filenmame")
Which will allow you to view the output of the function and tweak things as needed. Note that the "file:// ... " syntax may not work from within report builder or visual studio and may have to be deployed to a report server for testing.
Of course, once it looks like the function is working, add the image, make sure to set the source to external and use the same expression as for the textbox.
Server Side Changes
Upon further testing on my own environment, I've had to make two additional changes to get this to work:
Ensure that the unattended execution account is set to a domain account that has permission to the file share
Edit the SSRS config in the rssrvpolicy.config file to trust custom code and allow the execution of the File.Exists function by specifying "FullTrust"
<CodeGroup
class="UnionCodeGroup"
version="1'
PermissionSetName="FullTrust"
Name="Report_Expressions_Default_Permissions"
Description="This code group grants default permissions for code in report expressions and code element."
...
</CodeGroup>
I did restart the SSRS service after making these changes (I assume that's required, but did it as a precaution)
Note that I am not an SSRS server admin and someone else may be able to add some additional information about the custom policy change. Glancing through the MS documentation, there is a recommendation about using custom assemblies instead so take this part with a grain of salt.
I am having issues with translating client-side text in CKAN. My site is in french, so here is the problem:
- if I click on the green button "S'abonner" from the left, it should change the button to a red one and show the text "Se désabonner", but instead, it shows me "Unfollow", like in the photos:
And if I click it again it shows me "Follow" (instead of "S'abonner"). So this is a problem on the client side. Normally, when you generate text on the server side you write in the templates _('msgid present in pofile'), but, on the client side, it uses the result from the AJAX call to "/api/i18n/{language}".
I did some digging and it seems that the client-side translation uses the result from the AJAX call to "/api/i18n/fr", but all I get is a json object:
{
"": {
"domain": "ckan",
"lang": "fr",
"plural-forms": "nplurals=2; plural=(n > 1)"
}
}
But, if I look at the ckan demo website, (http://demo.ckan.org/api/i18n/fr), I get a long JSON file, that contains all the translations.
I managed to discover from where this Ajax call is done, apparently it comes from : "src/ckan/ckan/public/base/javascript/client.js", at the function:
getLocaleData: function (locale, success, error) {
var url = this.url('/api/i18n/' + (locale || ''));
return jQuery.getJSON(url).then(success, error);
}
If I replace
var url = this.url('/api/i18n/' + (locale || ''));
with
var url = this.url('http://demo.ckan.org/api/i18n/fr')
the problem is solved, because I get the translations in the json object.
My question is how I can get the right data to be generated, is there a parameter to put in production.ini? Unfortunately, the documentation in CKAN is really poor so I have no leads on this. Does anybody have a clue?
Thanks!
I suspect that you might be running an unreleased branch of CKAN (eg master), so the Javascript translations have not been built.
This is done with the following command:
paster front-end-build -c config_file.ini
Just run this command and the translations should come up fine.
On the main repository this is only done just before releases to avoid complicating the git history.
Check for instance this site running the latest master branch, but on which the front end is built every night:
http://master.ckan.org/fr/dataset/world-countries