i am really new with Google App Engine
I am trying to make a simple blog where the blog visitors can comment.
The entity properties are 'Title' and 'Content'
I managed to grab hold of the datastore ID by using {{post.key.id()}} and past it to another HTML page. The problem is, i am unable to display the content by the ID
For example, i want to display the BlogPost Title:-
I tried -
The title of the post is {{title.ID()}}
The content is {{content.ID()}}
I don't know the actual Syntax for it. May i know the right syntax?
Appreciate your kind help
Once you have the entity Key, you just need to use get() method to retrieve the entity content from Datastore. In Python, you would do this:
post = post.key.get()
Then you can access the post content as properties of the post object:
post_title = post.title
post_content = post.content
For more info, see the Gogle Datastore CRUD documentation (using Python NDB library). You'll find similar docs there for other languages.
Related
I'm trying to learn how to use Firebase by creating a simple social media application.
https://i.stack.imgur.com/wfeyw.png (Here is how my database is laid out)
I was able to add data to the database but I'm having trouble understanding how to retrieve data. I want to be able to retrieve all the posts from a certain user and then display each one as an item in a list.
let Posts = firebase.database().ref('Posts').child(userId);
So far thats my query and here is the code I'm using to add the posts to the database. Could someone also tell me what is the term for the Id that is being generated for each post?
firebase.database().ref('/Posts').child(userId).push({
Text: post,
Score: 0
});
I am looking to create a feature whereby a User can download any available documents related to the item from a tab on the PDP.
So far I have created a custom record called Documentation (customrecord_documentation) containing the following fields:
Related item : custrecord_documentation_related_item
Type : custrecord_documentation_type
Document : custrecord_documentation_document
Description : custrecord_documentation_description
Related Item ID : custrecord_documentation_related_item_id
The functionality works fine on the backend of NetSuite where I can assign documents to an Inventory item. The stumbling block is trying to fetch the data to the front end of the SCA webstore.
Any help on the above would be much appreciated.
I've come at this a number of ways.
One way is to create a Suitelet that returns JSON of the document names and urls. The urls can be the real Netsuite urls or they can be the urls of your suitelet where you set up the suitelet to return the doc when accessed with action=doc&id=_docid_ query params.
Add a target <div id="relatedDocs"></div> to the item_details.tpl
In your ItemDetailsView's init_Plugins add
$.getJSON('app/site/hosting/scriptlet.nl...?action=availabledoc').
then(function(data){
var asHtml = format(data); //however you like
$("#relatedDocs").html(asHtml);
});
You can also go the whole module route. If you created a third party module DocsView then you would add DocsView as a child view to ItemDetailsView.
That's a little more involved so try the option above first to see if it fits your needs. The nice thing is you can just about ignore Backbone with this approach. You can make this a little more portable by using a service.ss instead of the suitelet. You can create your own ssp app for the function so you don't have to deal with SCAs url structure.
It's been a while, but you should be able to access the JSON data from within the related Backbone View class. From there, within the return context, output the value you're wanting to the PDP. Hopefully you're extending the original class and not overwriting / altering the core code :P.
The model associated with the PDP should hold all the JSON data you're looking for. Model.get('...') sort of syntax.
I'd recommend against Suitelets for this, as that's extra execution time, and is a bit slower.
I'm sure you know, but you need to set the documents to be available as public as well.
Hope this helps, thanks.
I have a use case that I could use some advice on.
We publish multiple products, each of which has it's own subtree on the site. Generally, a piece of content gets published to just a single product, e.g. a news article gets published to product A and can be accessed at one URL.
However, sometimes we have content that we want to publish to multiple products, e.g. a single news article gets published to products A, B, and C and will be available at 3 different URLs.
With our current CMS we end up doing this by copying and pasting the content, which is a hassle for editors, especially if the content needs to be updated.
An ideal scenario would be where and editor edits the content in one place, specifies the products to publish to, and the content is served by more than one URL and with a template that is product-specific.
It seems that RoutablePageMixin could be useful here, but I'm not sure how to handle letting the editor specify the destination products and making the routing aware of that choice.
Has anyone solved a similar problem using Wagtail?
I have solved a similar problem in Wagtail, the RoutablePageMixin is the key to solving this problem.
If you have /blog/A/slug-product/, /blog/B/slug-product/, /blog/C/slug-product/ , then you can get the slug value slug-product here, then use this value to search the distinct content in your db.
class BlogPage(RoutablePageMixin, Page):
def get_posts(self):
return PostPage.objects.descendant_of(self).live()
#route(r'^(\d{4})/(\d{2})/(\d{2})/(.+)/$')
def post_by_date_slug(self, request, year, month, day, slug, *args, **kwargs):
post_page = self.get_posts().filter(slug=slug).first()
return Page.serve(post_page, request, *args, **kwargs)
As you can see, I did not use the date info of the url but the slug value to get the blog post object, you can follow the pattern here to use regex to match the url you want.
If the slug values in urls are also different, this solution might not work very well, but in most cases, this solution can work fine.
I have written a blog post talking about how to use RoutablePageMixin to make the page routable, you can check this link if you wang to get more about RoutablePageMixin.
Routable Page
Rather than thinking of your news articles as being child objects of one or more products, it might help to think of them as one big pool of news articles which are categorised by product. Your product page will then effectively be a filtered index page of news articles.
Here's how I'd model it:
If you want your news articles to exist at a canonical URL that's independent of any particular category, or you want to make use of page moderation and/or previewing, then define NewsArticle as a page model; otherwise, define it as a snippet or a ModelAdmin-managed model.
On the NewsArticle model, have an InlinePanel where editors can associate as many related products as required:
class NewsArticle(Page):
body = RichTextField()
date = models.DateField()
content_panels = Page.content_panels + [
FieldPanel('body'),
FieldPanel('date'),
InlinePanel('related_products', label="Related products"),
]
class NewsArticleRelatedProduct(Orderable):
news_article = ParentalKey(NewsArticle, related_name='related_products')
product = models.ForeignKey(ProductPage, on_delete=models.CASCADE, related_name='news_articles')
panels = [
PageChooserPanel('product'),
]
On your ProductPage model, add a method that returns a queryset of news items, filtered and sorted appropriately:
class ProductPage(Page):
# ...
def get_news_articles(self):
return self.news_articles.live().order_by('-date')
You can then loop over the news articles in your product page template, using a tag like {% for news_article in page.get_news_articles %}.
I have very recently been assigned to an EPiServer project. I'm .Net developer however, I had never had a pleasure of actually working with ES.
I have been given a task of creating a soft "integration" with SoundCloud. Our users would like to copy/paste URL to a SoundCloud song - which then I can use their API to actually get all information of the audio. (title, description, tags etc).
So what I have created so far
SoundcloudPageType (contains simple properties like title, description, duration etc.)
I have written little POC for Soundcloud API that gets me all information and deserializes it into object.
What I need now is a bridge between those two. I thought that creating something like "PageLinkReference" where you can click [...] button which would then ask you for "URL to SoundCloud audio", once person enters that I would do a REST api call to pre-populate all other properties on the page.
Now, this is just an idea. I would like to run it past you guys to see if
It is possible.
What is the best way of doing this and are there any tutorials that do something similar.
I do not want to hack and slash my way through EPiServer but to utilise what EPiServer might already provide.
I would add a short string property to the SoundcloudPageType and let the users paste into that field.
If you are using PageTypeBuilder something like this:
[PageTypeProperty(
EditCaption = "Soundcloud Url",
Type = typeof(PropertyString),
SortOrder = 2010,
UniqueValuePerLanguage = false,
Searchable = true)]
public virtual string SoundcloudUrl { get; set; }
Then you could either fetch "on request" or fetch and store (easiest on other properties you've added) in one of EPi's save events. Take a look at Joel's article of common patterns when integrating with EPi:
http://joelabrahamsson.com/episerver-integration-patterns/
You could use the oEmbed dynamic content plugin, which should support soundcloud
http://nuget.episerver.com/en/?search=oembed&sort=MostDownloads&page=1&pageSize=10
I am trying to extend the functionality of the comments in a WordPress install. I read allusion to an elusive 'custom comment type' functionality, but could not find any information. Instead, I was thinking that I would add a custom column ' to the 'comments' database table. That's the easy part. What I have no clue how to do is to customize the comments queries for saving, updating and reading the comments to reflect the existence of the new table column. I thought there would be a filter to alter the query, but I cannot find any that would do it... Any ideas?
There isn't really a custom comment type but you can easily and effectively add columns using "comment meta" which is a table of name/value pairs associated where each name/value pair is associated with a given comment using a 'meta_key' (please don't add a column to the SQL database; that's frowned upon in the WordPress developer community.)
Let's assume you wanted to let the user add their Twitter account. This is the code that would save my Twitter account to the comment identified by $comment_ID (prefixing the meta key name with an underscore is a good idea for any meta that you maintain via custom code vs that you let users select the meta key):
update_comment_meta($comment_ID,'_twitter','mikeschinkel');
Then to load the value to display in your template you just call get_comment_meta() (the third parameter means to return a single value, not an array of values):
$twitter = get_comment_meta($comment_ID,'_twitter',true);
Of course without knowing how to hook WordPress to integrate this the above functions would not be a lot of help. There are two hooks you'll need to use, the first being wp_insert_comment which will get called when WordPress saves a comment:
add_action('wp_insert_comment','yoursite_wp_insert_comment',10,2);
function yoursite_wp_insert_comment($comment_ID,$commmentdata) {
$twitter = isset($_GET['twitter']) ? $_GET['twitter'] : false;
update_comment_meta($comment_ID,'_twitter',$twitter);
}
The second one is a bit more complicated; the one that lets you add fields and modify other aspects of the comment form. The 'comment_form_defaults' hook sets the defaults for the comment and let's you add the HTML for a Twitter field (I snagged the format for the HTML from the comment_form() function found in /wp-includes/comment-template.php on line 1511 in WP v3.0.1)
add_filter('comment_form_defaults','yoursite_comment_form_defaults');
function yoursite_comment_form_defaults($defaults) {
$email = $defaults['fields']['email'];
$label = __( 'Twitter' );
$value = isset($_GET['twitter']) ? $_GET['twitter'] : false;
$defaults['fields']['twitter'] =<<<HTML
<p class="comment-form-twitter">
<label for="twitter">{$label}</label>
<input id="twitter" name="twitter" type="text" value="{$value}" size="30" />
</p>
HTML;
return $defaults;
}
And here's what it looks like in action:
This comment form extensibility is new for WordPress 3.0 so by its nature of being new in an open-source project it's probably not going to accommodate all use-cases yet (such as there was no easy way to get a remembered value for the Twitter screen name) but hopefully you'll be able to bend it enough to you will and get what you need and in future released of WordPress the comment form API will almost certainly improve.
Hope this helps.
-Mike
P.S. In future consider posting your question on StackOverflow's sister site WordPress Answers; that's where most of the WordPress enthusiasts hang out, those who can quickly answer questions like this.
I found this useful link related to the topic:
Customizing Comments in WordPress - Functionality and Appearance