I downloaded the stripe connector for salesforce and wanted to create a customer using flow but showing invalid account id - stripe-payments

Even though I queried and got the accountRecordId .Please help the account id I gave is acct_163mW2J4BRSONYEY.
I am using the postCustomer action and passing values in the action and debugging
global class PostCustomer {
global PostCustomer() {
}
global class V1 {
#InvocableVariable(label='Stripe Account ID' required=true)
global String accountRecordId;
#InvocableVariable(label='address (PostCustomersRequestAddress)' required=false)
global stripeGC.PostCustomersRequestAddress address;
#InvocableVariable( required=false)
global Integer balance;
#InvocableVariable(label='bank_account (PostCustomerRequestBankAccount)' required=false)
global stripeGC.PostCustomerRequestBankAccount bankAccount;
#InvocableVariable(label='card (PostChargesRequestCard)' required=false)
global stripeGC.PostChargesRequestCard card;
#InvocableVariable(label='cash_balance (CashBalanceParam)' required=false)
global stripeGC.CashBalanceParam cashBalance;
global V1() {
}
}
}

Related

Update django model database with ForeignKey by using serializer

I have created a django model which includes a foreign key to a user as follows:
from authentication.models import User
from django.db import models
class Event(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
dr_notice_period = models.IntegerField(blank=True, null=True)
dr_duration = models.IntegerField(blank=True, null=True)
dr_request = models.FloatField(blank=True, null=True)
My serializers.py file is as follows:
class EventSerializer(serializers.ModelSerializer):
user = UserSerializer(many=True, read_only=True)
class Meta:
model = Event
fields = ['user', 'dr_notice_period', 'dr_duration', 'dr_request']
What I need to do is to go to a url and with a POST request to upload the data to the database, but without specifically specifying the user.
My views.py is as follows:
from rest_framework.response import Response
from rest_framework.decorators import api_view
from rest_framework import status
from vpp_optimization.serializers import EventSerializer
#api_view(['POST'])
def event(request):
serializer = EventSerializer(data=request.data)
if serializer.is_valid():
instance = serializer.save(commit=False)
instance.user = request.user
instance.save()
return Response({"status": "success", "data": serializer.data}, status=status.HTTP_200_OK)
else:
return Response({"status": "error", "data": serializer.errors}, status=status.HTTP_400_BAD_REQUEST)
As I study I thought that by using commit=False in save would solve the problem, but I am getting the following error:
'commit' is not a valid keyword argument to the 'save()' method. If you need to access data before committing to the database then inspect 'serializer.validated_data' instead. You can also pass additional keyword arguments to 'save()' if you need to set extra attributes on the saved model instance. For example: 'serializer.save(owner=request.user)'.'
Is there a better way to do what I intent to do?
You pass the user as parameter, so:
if serializer.is_valid():
instance = serializer.save(user=request.user)
return Response({'status': 'success', 'data': serializer.data}, status=status.HTTP_200_OK)
Note: It is normally better to make use of the settings.AUTH_USER_MODELĀ [Django-doc] to refer to the user model, than to use the User modelĀ [Django-doc] directly. For more information you can see the referencing the User model section of the documentation.

Django rest framework update ManyToManyField

models.py
class Game(models.Model):
name = models.CharField(max_length=255)
gamemodes = models.ManyToManyField(GameMode, related_name='gamemodes', blank=True)
class GameMode(models.Model):
name = models.CharField(max_length=255)
serializers.py
class GameModeSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
fields = ['pk', 'name']
model = GameMode
class GameSerializer(serializers.HyperlinkedModelSerializer):
gamemodes = GameModeSerializer(many=True, required=False)
class Meta:
model = Game
fields = ['pk', 'name', 'gamemodes']
def update(self, instance, validated_data):
print("Validated: ", validated_data)
Updating name works perfectly with PATCH. But how can I add a "gamemode" to the Game object in the rest framework with a PATCH request?
On the update function on the serializer, it print all values when I PATCH something, but when I submit "gamemodes" it does not appear in the variable validated_data
Best
With your current serializer setup you need to supply the dicts for gamemodes.
{
"pk": 1,
"name": "Game 1",
"gamemodes": [{"pk": 100, "name": "gamemode 100"}]
}
Alternatively you could add to your GameSerializer to also have a write only field that accepts the pks for the relationship PrimaryKeyRelatedField or SlugRelatedField if you don't want to use the internal ids.

how to convert this model into non editable model in admin of django?

I create a model but I need a non-editable model. When I visit the model it's just displaying text, not giving any option of update the record in admin panel.
model.py
class Contact(models.Model):
name = models.CharField(max_length=160)
email = models.EmailField()
subject = models.CharField(max_length=255)
message = models.TextField()
def __str__(self):
return self.subject
While searching I get information about readonly but I do not still understand how to use it.
There are two ways to do this. One, make editable=False for all the fields, then it will not be edible anywhere(modelform and adminsite):
class Contact(models.Model):
name = models.CharField(max_length=160, editable=False)
email = models.EmailField(editable=False)
subject = models.CharField(max_length=255, editable=False)
message = models.TextField(editable=False)
Two, in adminsite, use readonly_fields:
class ContactAdmin(admin.ModelAdmin):
readonly_fields = ('name', 'email', 'subject', 'message')
admin.site.register(Contact, ContactAdmin)

Use existing sql-alchemy model class as flask-restplus api.model?

I am developing a CRUD application using vue.js and vuetify as frontend (view) and python flask-resplus and sqlAlchemy as backend (controler and model).
app/main/model/person.py
from sqlalchemy import Column, Integer, String, Date
from app.main.repository.base_repository import Base
class Person(Base):
__tablename__ = 'person'
id = Column(Integer, primary_key=True)
name = Column(String)
date_of_birth = Column(Date)
def __init__(self, name=None, date_of_birth=None):
if name is not None:
self.name = name
if date_of_birth is not None:
self.date_of_birth = date_of_birth
app/main/controller/person_controller.py
from flask_restplus import Namespace, fields, Resource, cors
from flask import request
from app.main.service.person_service import PersonService
from app.main.model.person import Person
api = Namespace('persons', description='Person related operations')
persServ : PersonService = PersonService()
model = api.model('Person', {
'id': fields.Integer,
'name': fields.String,
'date_of_birth': fields.Date
})
#api.route("/persons/all")
class PersonList(Resource):
#api.marshal_with(model)
def get(self, **kwargs):
return persServ.get_persons()
# return Person(name="Test", date_of_birth=date(1984, 10, 20))
#api.route("/person/<int:id>")
class PersonReturn(Resource):
#api.marshal_with(model)
def get(self, id):
return persServ.get_person(id)
#api.route("/person/<int:id>")
class PersonUpdate(Resource):
#api.marshal_with(model)
def put(self, id):
data = request.json
#TODO marshalling currently still error
return persServ.update_person(pers=data)
#api.route("/person")
class PersonCreate(Resource):
#api.marshal_with(model)
def post(self):
data = request.json
#TODO: check why person is not correctly linked to sql alchemy when reated here, make sure that model.Person is created
# pers = Person()
# pers.name = data['name']
# persServ.create_person(pers)
return persServ.create_person_02(data['name'])
#api.route("/person/<int:id>")
class PersonDelete(Resource):
def delete(self, id):
persServ.delete_person(id)
return '', 204
Questions also after implementing a spring java backend :
1) Is it necessary to provide an api.model in person_controller.py or can I annotate properties in person.py? Could you kindly guide me to a tutorial annotating an existing object?
2) Naming conventions flask api classes: In my eyes it definitely makes sense to use PersonList and Person instead of PersonUpdate, PersonCreate to ease API documentation as described in the flask-resPlus full example: https://flask-restplus.readthedocs.io/en/stable/example.html
However, I already have an existing Person class in person.py. I am thinking about having two person classes, a Person(Resource) in person_controller.py for Post, Put and Get operations and a Person in person.py as domain specific person object. However, I do not want to cause confusion and adhere to naming and orgainization good practices. What is the suggested naming approach? Is there a good example tutorial?

make some model field conditionally visible in django

I have two field in my django model they should be editable only if user have selected 'type' as 'Dimention' otherwise they should not be visible to user.
My model is look like this code
from django.db import models
class Configuration(models.Model):
name = models.CharField(max_length=30)
user_defined_name = models.CharField(max_length=50)
FieldTypes = (('aD', 'Dimension'), ('aM', 'Measure'))
type = models.CharField(max_length=11, choices=FieldTypes)
is_key = models.BooleanField(default=False, editable=False)
unit = models.CharField(max_length=30, null=True, blank=True, editable=False)
def __str__(self):
return self.name
I know it is possible by using JavaScript but, I don't want to write html or js myself,Thus Can't use JavaScript for doing this.
A pure Django-only way to achieve this is to simply reset the fields from your ModelForm if type is not equal to Dimension. This will appear like magic/unintended behavior; so be careful of the implementation.
For example (assuming you are using the admin interface: the same is valid for a custom ModelForm View):
class ConfigurationAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
# At this point; the object already has the new values set; we will have to reset as needed
conditional_editable_fields = ['is_key', 'unit']
config_type = form.cleaned_data.get('type')
if config_type != 'aD':
for field in conditional_editable_fields:
if field in form.changed_data: # The value has been changed by the user
setattr(obj, field, form.initial.get(field)) # Set the initial value
self.message_user(request, "Cannot edit field: {}; value has been reset".format(field), messages.WARNING) # Inform the user that we reset the value
return super(ConfigurationAdmin, self).save_mode(request, obj, form, change)
I use similar approach for this.
I it works great
In My admin.py
`
fieldsets = (
(None, {
'fields': ('name', 'user_defined_name', 'type', 'is_active')
}),
('Advanced', {
'classes': ('toggle',),
'fields': ('is_kpi', 'unit'),
})
)
actions = [disable_multiple_column, activate_multiple_column]
class Media:
js = ("jquery.js", "my_code.js",)`
I use that JS file to show and hide .
`$(document).ready(function(){
show_hide();
$('#id_type').change(function(){
show_hide();
});
function show_hide(){
if ($("#id_type").val() == 'aM' ){
$(".module")[1].style.display="block"
}
else{
$(".module")[1].style.display="none"
}
}
});`
And in case use already entered values and then change Choice of type or from some other reason these hidden field still have data. I override the save Method of models.py
`
def save(self, *args, **kwargs):
if self.type != 'aM':
self.is_kpi = False
self.unit = None
super(Configuration, self).save(*args, **kwargs)
`

Resources