Django fixtures for model from imported application (like django-allauth) - django

I know that is possible to create fixtures file like initial_data.json for my own model. I want to create similar file for tables which are created and used by imported django-allauth application.
I tried:
[
{
"model":"allauth.socialaccount.models.SocialApp",
"pk":1,
"fields":{
"id":"1",
"provider":"facebook",
"name":"facebook",
"client_id":"0011223344556677",
"key":"",
"secret":"012345678901234567890123456"
}
}
]
However it's ends up with error:
python manage.py syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
DeserializationError: Problem installing fixture 'initial_data.json':
Invalid model identifier: 'allauth.socialaccount.models.SocialApp'

I found here that table from model django.contrib.sites.models.Site can be populate using
[
{
"model": "sites.site",
"pk": 1,
"fields": {
"domain": "myproject.mydomain.com",
"name": "My Project"
}
}
]
So model allauth.socialaccount.models.SocialApp probably can by populated by:
[
{
"model":"socialaccount.socialapp",
"pk":1,
"fields":{
"id":"1",
"provider":"facebook",
"name":"facebook",
"client_id":"0011223344556677",
"key":"",
"secret":"012345678901234567890123456"
}
}
]

Full fixture example, tested with django-allauth 0.19 and Django 1.8:
[
{
"model": "sites.site",
"pk": 1,
"fields": {
"domain": "localhost",
"name": "localhost"
}
},
{
"model":"socialaccount.socialapp",
"pk":1,
"fields":{
"id":"1",
"provider":"facebook",
"name":"facebook",
"client_id":"0011223344556677",
"secret":"012345678901234567890123456",
"key":""
}
},
{
"model":"socialaccount.socialapp_sites",
"pk":1,
"fields":{
"id":1,
"socialapp_id":1,
"site_id":1
}
}
]

Related

Superset API Request Filters

I'm attempting to retreive a list of dashboards via the superset API which have a specific owner. I've attempted many unsuccessful ways to compose the request:
/api/v1/dashboard/?q={
"filters": [
{
"col": "owners__username",
"opr": "eq",
"value": "bi"
}
]
}
Resulted in Filter column: owners__username not allowed to filter
/api/v1/dashboard/?q={
"filters": [
{
"col": "owners",
"opr": "any",
"value": {
"col": "username",
"opr": "eq",
"value": "bi"
}
}
]
}
Result: Not a valid rison schema
/api/v1/dashboard/?q={
"filters": [
{
"col": "owners",
"opr": "any",
"value": "ADMIN0"
}
]
}
Which gives me all results
What am I missing?
Try this:
/api/v1/dashboard/?q=(filters:!((col:owners,opr:rel_m_m,value:4)))
So that filter only accepts user id's
You can get a list of supported filters on each resource by:
/api/v1/dashboard/_info?q=(keys:!(filters))

List users as non admin with custom fields

As per the documentation, I should be able to get a list of users with a custom schema as long as the field in the schema has a value of ALL_DOMAIN_USERS in the readAccessType property. That is the exact set up I have in the admin console; Moreover, when I perform a get request to the schema get endpoint for the schema in question, I get confirmation that the schema fields are set to ALL_DOMAIN_USERS in the readAccessType property.
The problem is when I perform a users list request, I don't get the custom schema in the response. The request is the following:
GET /admin/directory/v1/users?customer=my_customer&projection=full&query=franc&viewType=domain_public
HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer fakeTokena0AfH6SMD6jF2DwJbgiDZ
The response I get back is the following:
{
"nextPageToken": "tokenData",
"kind": "admin#directory#users",
"etag": "etagData",
"users": [
{
"externalIds": [
{
"type": "organization",
"value": "value"
}
],
"organizations": [
{
"department": "department",
"customType": "",
"name": "Name",
"title": "Title"
}
],
"kind": "admin#directory#user",
"name": {
"fullName": "Full Name",
"givenName": "Full",
"familyName": "Name"
},
"phones": [
{
"type": "work",
"value": "(999)999-9999"
}
],
"thumbnailPhotoUrl": "https://photolinkurl",
"primaryEmail": "user#domain.com",
"relations": [
{
"type": "manager",
"value": "user#domain.com"
}
],
"emails": [
{
"primary": true,
"address": "user#domain.com"
}
],
"etag": "etagData",
"thumbnailPhotoEtag": "photoEtagData",
"id": "xxxxxxxxxxxxxxxxxx",
"addresses": [
{
"locality": "Locality",
"region": "XX",
"formatted": "999 Some St Some State 99999",
"primary": true,
"streetAddress": "999 Some St",
"postalCode": "99999",
"type": "work"
}
]
}
]
}
However, if I perform the same request with a super admin user, I get an extra property in the response:
"customSchemas": {
"Dir": {
"fieldOne": false,
"fieldTwo": "value",
"fieldThree": value
}
}
My understanding is that I should get the custom schema with a non admin user as long as the custom schema fields are set to be visible by all domain users. This is not happening. I opened a support ticket with G Suite but the guy that provided "support", send me in this direction. I believe this is a bug or maybe I overlooked something.
I contacted G Suite support and in fact, this issue is a domain specific problem.
It took several weeks for the issue to be addressed by the support engineers at Google but it was finally resolved. The behaviour is the intended one now.

Connect LoopBack app to existing MySQL database

I have a local MySQL database mydb. It contains a table called person, with fields id (primary key, integer auto-increment) and name (text). The table contains records that I do not want to delete.
I want a LoopBack app that connects to mydb through a data source myds. The app should have a model Person (which extends PersistedModel). CRUD operations on the Person model should be reflected on the people table of mydb.
How do I build the app?
Generate an empty application with the application generator.
>lb
? What's the name of your application? myapp
? Enter name of the directory to contain the project: myapp
? Which version of LoopBack would you like to use? 3.x (current)
? What kind of application do you have in mind? empty-server
Add a new datasource:
/* /server/datasources.json */
"myds": {
"host": "localhost",
"port": 3306,
"url": "",
"database": "mydb",
"password": "password",
"name": "myds",
"user": "root",
"connector": "mysql"
}
Install loopback-connector-mysql:
> npm install loopback-connector-mysql --save
Create a model
/* /common/models/Person.json */
{
"name": "Person",
"plural": "People",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "number",
"required": true
},
"name": {
"type": "string"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
Then attach the model to the data source.
/* /server/model-config.json */
{
// ...
"Person": {
"dataSource": "myds",
"public": true
}
//...
}
The app is complete. To run the app,
> node .
Then navigate to localhost:3000/explorer in a browser. Click on the Person model, then click on the route GET /People, then click "try it out!" The app should return all rows in the person table from the database. The other CRUD operations should also function properly.
Note that the naming is very important. When we connect a model named Person and to the datasource myds, which itself connects to the database mydb, LoopBack looks for a table called Person in mydb (this may interact with case-sensitivty of table names in your MySQL installation), with exactly the properties of Person as its field names.

Ember data and mongodb state?

According to http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html
Records without an id property are not considered embedded records, model instances must have an id property to be used with Ember Data.
If thats so how would i use a model like:
{
"_id": "545b54f20dbd7015f015359a",
"comments": [
{
"msg": "what is this jelly",
"time": "1415271666",
"user": {
"id": "53fefc9ee4b07d3fe92fc077",
"username": "kfir124"
}
}
],
"files": [
{
"key": "1415271653.39af9c9fb8cc8b49dcaac5eec72614ce85.jpg",
"order": 0
}
],
"time": "1415271666",
"uploader": {
"id": "53fefc9ee4b07d3fe92fc077",
"username": "kfir124"
}
}
So uploader may be an embedded record but what about files and comments? they are both arrays of objects which do not live outside of the main model's namespace therefore they have no IDs

How would be the JSON is in this example?

$('.example-films .typeahead').typeahead([{name: 'best-picture-winners',
remote: '../data/films/queries/%QUERY.json',prefetch: '../data/films/post_1960.json',
template: '{{value}} – {{year}}',engine: Hogan}]);
how would be the JSON file written on this example.
i get this from typeahead js examples
If you view the source of the page you can see that there is an attached javascript file at http://twitter.github.io/typeahead.js/js/examples.js
Here you can view how they bound the typeahead box:
$('.example-films .typeahead').typeahead([
{
name: 'best-picture-winners',
remote: '../data/films/queries/%QUERY.json',
prefetch: '../data/films/post_1960.json',
template: '<p><strong>{{value}}</strong> – {{year}}</p>',
engine: Hogan
}
]);
And you will see that you can access prefetch JSON data to see the formatting at http://twitter.github.io/typeahead.js/data/films/post_1960.json
[
{
"year": "1961",
"value": "West Side Story",
"tokens": [
"West",
"Side",
"Story"
]
},
{
"year": "1962",
"value": "Lawrence of Arabia",
"tokens": [
"Lawrence",
"of",
"Arabia"
]
}, {
"year": "2012",
"value": "Argo",
"tokens": [
"Argo"
]
}
]