GAE blobstore is killing me - image

I followed this tutorial :
https://developers.google.com/appengine/docs/python/images/usingimages
And it's killing me...I managed to make it work...however I was not able to make it suite my needs...problem is that i want to serialize my Model using json...
Why do they put the avatar = db.BlobProperty() in the model and not use a reference to that blob ?...Is there any reason whatsoever?
I could not find a decent tutorial, on how to store an image in Blob, and then store its location/ key/reference in a Model..Any suggestions?
With the code from below...i am doing exacty what is in the tutorial...how do I get the reference to that pic , and how do I store it???
pic = self.request.get('img')
pic = db.Blob(pic)
What i managed to do is to store the id of the entity in JSON, and use that id to retrieve and display the pic. And i display the pic with the following code:
class Image(webapp2.RequestHandler):
def get(self):
#product = db.get(self.request.get('img_id'))
product = MenuProduct.by_id(int(self.request.get('img_id')))
if product.small_pic:
self.response.headers['Content-Type'] = 'image/png'
self.response.out.write(product.small_pic)
else:
self.error(404)
I am guessing that all efficiency goes to hell by using this approach ...Right?
Sorry is my post sounds messy...but I am kind of tired of the "great" poor documentation related to this topic.

Rather than store the blob as a BlobProperty, you should use the separate Blobstore service and store the BlobKey in the model.

Related

Eager loading for reference

I wonder if it is possible to load reference data in the first call. In my case I want to load the patient reference in the Encounter Resource. As I know I always need the patient data I want to avoid to to do an additional call to get the patient data.
The server is HAPI FHIR and the client firely .Net API
Yes, that is possible. Your request will have to be a search, that way you can include any referenced resources.
On REST level it looks like this:
GET <hapi_server>/Encounter?_include=patient
Add any filters you have. For example if you have a specific encounter you would add &_id=<technical_id>.
With the FhirClient from the .Net api, the code looks like this:
var c = new FhirClient("<hapi_server");
var q = new SearchParams().Include("Encounter:patient");
q.Add("_id", "<technical_id>");
var result = c.Search<Encounter>(q);

How to perform star rating using django and ajax?

I want to perform a star rating in my blog application for better user experience...But couldn't perform in django using ajax...I basically don't want to use any third party application for my blog project...I want to do manually using django and ajax...
This is my blog model:
class Blog(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE,null=True,blank=True)
date = models.DateTimeField(default=datetime.now)
blog_title = models.CharField(max_length=255,unique=True)
likes = models.ManyToManyField(settings.AUTH_USER_MODEL,related_name='likes',blank=True)
description = models.TextField()
blog_image = models.ImageField(upload_to='blog_image', null=True, blank=True)
category = models.ForeignKey(categories,on_delete=models.CASCADE,related_name='blogs')
blog_views = models.IntegerField(default=0)
Any idea anyone how to perform this?
Thank you in advance
I assume that you're trying to rate the blog 1-5.
If you want to save each and every vote for the blog, you'll have to keep an additional model for the votes, something like:
class BlogStars(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE,null=True,blank=True)
blog = models.ForeignKey(Blog, on_delete=models.CASCADE)
stars = models.IntegerField(default=0)
For each and every vote, you'll save the user, the blog voted for and the amount of stars.
After that, all you need to do is to query the BlogStars:
stars = BlogStars.objects.filter(blog=my_blog).aggregate(Avg('stars'))
Saving the data using Ajax, is just making ajax calls to the backend view.
In any case, check this tutorial as an example, although it uses PHP, it'll give you a good idea.

How to access View Template Properties for Revit and compare them in Real Time?

I am trying to list the view template’s properties so we can compare them with another old template.
For example what model elements are hidden or have overrides in a given template or which Revit links have been hidden or overridden in a given template.
View Template
(https://www.google.com/search?q=view+template+revit&rlz=1C1GGRV_enUS770US770&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjLndrd2cTbAhVESq0KHX1cAPwQ_AUICygC&biw=1536&bih=824#imgrc=Q0v-pV7Nxl4kfM:)
I’m looking to devise a View Template Compare tool and access to the owner and creator of them.
public void ApplyViewTemplateToActiveView()
{
Document doc = this.ActiveUIDocument.Document;
View viewTemplate = (from v in new FilteredElementCollector(doc)
.OfClass(typeof(View))
.Cast<View>()
where v.IsTemplate == true && v.Name == "MyViewTemplate"
select v)
.First();
using (Transaction t = new Transaction(doc,"Set View Template"))
{
t.Start();
doc.ActiveView.ViewTemplateId = viewTemplate.Id;
t.Commit();
}
}
With Revit API you can access with:
GetTemplateParameterIds Method / ViewTemplateId Property
The Revit API exposes almost all the ViewTemplate properties.
For instance this method returns all the Visibility/Graphic Overrides for a specific category:
https://apidocs.co/apps/revit/2019/ed267b82-56be-6e3b-0c6d-4de7df1ed312.htm
The only thing I couldn't get for a ViewTemplate are the "includes", but all the rest seems to be there.
Update:
The list or properties "not included" can be retrieved with GetNonControlledTemplateParameterIds().
Yes, and no.
Yes, I guess you can use Forge Model Derivative API to export RVT file and then build a dashboard around the View Templates data. That's assuming that View Templates data actually gets exported when the model is translated. That data is not attached to any geometry so I would not be surprised if it was skipped. The question here is why? This is like renting a 16-wheel truck to move a duffel bag across the street.
No, if your intention is to directly interact with the RVT model. Forge can view it, but to push anything back or request changes to the model, is not available yet. Then again, I am not even sure that the view template data is available via model derivative exports.
This brings me another alternative. Why not just collect the data using Revit API, the standard way and then push it out to a Database and build on top of that? There is no reason to employ Forge for any of that.
Thanks Jeremy, I had dig into your amazing website and also some solution that Konrad post in the Dynamo Forum about this. In Revit seems pretty achievable, you filter the View that is View Template and then extracts these properties, is it correct?.
I am wondering if someone can point me in the right direction with Forge.
Some amazing guys are developing a BQL https://www.retriever.works/.
BQL(Building Query Language) is a query language for buildings, similar to how SQL is a query language for databases. It is fast and flexible. BQL helps improve efficiency for QA/QC (quality assurance and quality control), and building data extraction without leaving Revit. I am also trying these and I would like to understand if there are some works where I could start with Forge next week about this.

Component DB Query (Yii)

I'll first describe my initial problem - I have a few site global variables (such as whether I'm online/offline, the price of the item etc).. I was wondering how best to store/retrieve these as they are needed on most pages.
In the end after some guidance I've opted to store them in a DB and create a component class (in Yii) to access them from where ever: e.g. echo Yii::app()->variables->price
I'm new to Yii, and I've been searching around but cannot find out how to properly interface a DB (AR Style) connection with a component.. So far I've created a Model class and the DB with columns 'id', 'name', 'value'
Just to get the hang of it I'm writing a method: getTestValue() in my component class, but I just don't know how to go about retrieving the row with name test using Yii's ActiveRecord. Could someone point me in the right direction please? :)
Many thanks!
This should work:
function getTestValue(){
$myvalobj = YourModelClass::model()->findByAttributes(array('name'=>'test'));
if($myvalobj!==null)
return $myvalobj->value;
return null;
}

how to save and load a object in a windows phone 7 app?

is it possible in a WP7 app to save some objects which i create and then load it when the app is started again?
You'll want to look to store persistent items into IsolatedStorage. You can see an overview and an example of how to use IsolatedStorage here. There are also a range of examples on this site, showing how to save different types of objects.
Here's an example storing a string, but you should be able to store any type of object this way.
Add IsolatedStorage to your references:
using System.IO.IsolatedStorage;
In your class:
private string myString;
In the Loaded event for your page:
try
{
myString = (string)IsolatedStorageSettings.ApplicationSettings["myString"];
}
catch
{
IsolatedStorageSettings.ApplicationSettings.Add("myString", "this value is a string");
}
and later, when you want to save:
IsolatedStorageSettings.ApplicationSettings["myString"] = myString;
try after
the example code above to add this.
IsolatedStorageSettings.ApplicationSettings.save

Resources