'NoneType' object is not callable django - python-decorators

#admin.site.register(Post)
class PostAdmin(admin.ModelAdmin):
list_display = ('title', 'slug', 'author', 'publish', 'status')
list_filter = ('status', 'created', 'publish', 'author')
Please help me out because i dont know what is the problem

Related

How can I create the profile image customer attribute using data patch magento 2?

I need to create the customer profile image attribute. Anyone can please help how can I create the customer profile image attribute. I need to create the custom attribute in the custom module and I'm using the data patch file.
public function apply()
{
$this->moduleDataSetup->getConnection()->startSetup();
/** #var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY);
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
/** #var $attributeSet Set */
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(
Customer::ENTITY,
'profile_image',
[
'label' => 'Profile Image',
'input' => 'text',
'type' => 'file',
'source' => '',
'required' => true,
'position' => 333,
'visible' => true,
'system' => false,
'is_used_in_grid' => true,
'is_visible_in_grid' => true,
'is_filterable_in_grid' => true,
'is_searchable_in_grid' => false,
'backend' => ''
]
);
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'profile_image');
$attribute->addData([
'used_in_forms' => [
'adminhtml_customer',
'adminhtml_checkout',
'customer_account_create',
'customer_account_edit'
]
]);
$attribute->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId
]);
$attribute->save();
$this->moduleDataSetup->getConnection()->endSetup();
}
When I'm executing the s:up command then it's showing the "Invalid column data type file"
error. Please let me know how can I fix this.
The 'type' parameter must be one of the following:
datetime, decimal, int, text or varchar
Those options corresponds to the customer_entity_* database tables.
Also, there is no standard file 'input' field for customer attributes. You'll need to implement that field input type.

How can I assert an instance of a ResourceCollection in Laravel?

I am working with a feature test and it's returning data correctly; all things are coming back correctly; and I'm at the final portion of my test.
I am struggling to assert that I'm getting back a ResourceCollection:
$this->assertInstanceOf(ResourceCollection::class, $response);
Here is the portion of my test:
MyFeature.php
...
$http->assertStatus(200)
->assertJsonStructure([
'data' => [
'*' => [
'type', 'id', 'attributes' => [
'foo', 'bar', 'baz',
],
],
],
'links' => [
'first', 'last', 'prev', 'next',
],
'meta' => [
'current_page', 'from', 'last_page', 'path', 'per_page', 'to', 'total',
],
]);
// Everything is great up to this point...
$this->assertInstanceOf(ResourceCollection::class, $response);
The error I get back is:
Failed asserting that stdClass Object (...) is an instance of class "Illuminate\Http\Resources\Json\ResourceCollection".
I'm not sure what I should be asserting in this case. I am getting back a resource collection, what should I be using instead? Thank you for any suggestions!
EDIT
Thank you #mare96! Your suggestion lead me to another approach that seemed to work. Which is great but I'm not too sure I really understand why...
Here's my full test (including my final assertion):
public function mytest() {
$user = factory(User::class)->create();
$foo = factory(Foo::class)->create();
$http = $this->actingAs($user, 'api')
->postJson('api/v1/foo', $foo);
$http->assertStatus(200)
->assertJsonStructure([
'data' => [
'*' => [
'type', 'id', 'attributes' => [
'foo', 'bar', 'baz'
],
],
],
'links' => [
'first', 'last', 'prev', 'next',
],
'meta' => [
'current_page', 'from', 'last_page', 'path', 'per_page', 'to', 'total',
],
]);
$this->assertInstanceOf(Collection::class, $http->getOriginalContent());
}
As I said in the comment above, your content will be the instance of Collection.
You can do it like that:
$this->assertInstanceOf(Collection::class, $http->getOriginalContent());
So, you can try to debug, to make it clearer, like this: Do dd($http); you should get an instance of Illuminate\Foundation\Testing\TestResponse not the same when you do $http->dump(); right?
So you need to assert an instance of just content, not the whole response.
I hope at least I helped a little.

How to properly hydrate and extract Doctrine Entities from Zend Forms

I'm just starting out with Doctrine and was rewriting some code to use Doctrine entities in some Forms.
I have an Entity Business which has some 1:n relations with addresses, employees, emails etc. the Setup is really basic and working fine.
To add new Businesses i created a BusinessForm and Fieldsets for each of my entities. Here the constructor of the form:
public function __construct($scenario='create', $entityManager = null) {
parent::__construct('business_form');
$this->scenario = $scenario;
$this->entityManager = $entityManager;
$this->setAttribute('method', 'post');
$businessFieldset = new BusinessFieldset($this->entityManager);
$businessFieldset->setUseAsBaseFieldset(true);
$this->add($businessFieldset);
$hydrator = new DoctrineHydrator($this->entityManager, new Business());
$this->setHydrator($hydrator);
$this->addElements();
$this->addInputFilter();
}
addElements just adds a Submit and CSRF input.
And here the Controller action:
public function addAction(){
$form = new BusinessForm('create', $this->entityManager);
if ($this->getRequest()->isPost()) {
$data = $this->params()->fromPost();
$form->setData($data);
if($form->isValid()) {
// save Object
return $this->redirect()->toRoute('subcontractor', ['action'=>'index']);
}
}
return new ViewModel([
'form' => $form
]);
}
The form validates and i can get the Data from the form with $form->getData(). But i cant figure out how to get a populated Object from the form using the form's hydrator. When I use setObject(new Business()) at the start of the controller i get an error while $form->isValid() is running :
Zend\Hydrator\ArraySerializable::extract expects the provided object to implement getArrayCopy()
Isnt that the wrong hydrator being called ?
If i dont setObject() but instead use $form->bind(new Business()) after the validation i get an empty Object from $form->getObject(). If i get the data and hydrate a new Object with the form's hydrator like so : $form->getHydrator()->hydrate($data['business], new Business()) i do get the populated Object i was expecting. (Business being the name of the base fieldset)
So my question is, how to i get the result of the last call from just using $form->getObject() after the validation?
[EDIT]
The Problem seems to be with the Collections of Fieldsets used as sub-fieldsets in the businessfieldset. If i validate the form without using the collections i do get the expected Business Object from $form->getData()
Here an example how i add the collection (in the business fieldset):
$this->add([
'name' => 'emails',
'type' => 'Zend\Form\Element\Collection',
'attributes' => [
'id' => 'business_emails',
],
'options' => [
'label' => 'Emails',
'count' => 1,
'should_create_template' => true,
'template_placeholder' => '__index__',
'allow_add' => true,
'target_element' => [
'type' => 'LwsSubcontractor\Form\EmailFieldset',
],
'target_class' => 'LwsSubcontractor\Entity\Email'
],
]);
and here the EmailFieldset:
public function __construct() {
parent::__construct('email');
$this->setObject(new Email());
$this->addElements();
}
protected function addElements() {
$this->add([
'name' => 'email',
'type' => 'Zend\Form\Element\Email',
'attributes' => [
'placeholder' => 'E-Mail (z.B. email#muster-email.de)',
'class' => 'form-control',
'required' => true,
'size' => 50,
],
'options' => [
'label' => 'Email',
],
]);
}
}
If using the Collections i get the Error message from above. So after adding a hydrator to each Fieldset i was fine.
Although i was under the impression that setting the hydrator for the form would result in the used fieldsets to inherit that hydrator.Or was this because of using the fieldsets as collections and not directly ?
You have to add the hydrator to all your fieldsets, personally I use DoctrineModule\Stdlib\Hydrator\DoctrineObject for doctrine entities.
I would also look at using the init() method to initialize your forms and add elements then register and retrieve your form and fieldsets through the FormElementManager, $serviceLocator->get('FormElementManager')->get(yourFieldsetorForm::class). The form can than be injected into your controller.
I hope this helps.

Active record CONCAT select fields in a relationship not working

I have the following dataprovider. Parentgroups is related to parentchildren via one-many relationship.
I am trying the concat the ChildFirstName and ChildLastName but it is not displaying. Only ID and ParentID is displaying.
$query = Parentgroups::find();
$query->with(
[
'parents' => function( $query){
$query->select([ 'Name', 'ID' ]);
},
'parentchildren' => function ( $query ){
$query->select([ new \yii\db\Expression("CONCAT('ChildFirstName', 'ChildLastName') as childName"), 'ID', 'ParentID' ]);
}
]
);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => false,
]);
I referred to this link: https://github.com/yiisoft/yii2/issues/8276
But it didn't worked for me. Any help would be appreciated. Thanks.
You need to add childName property into your child model, so it will be populated automatically by yii. Yii2 docs about selecting extra fields

How to configure CreditCard class in Omnipay?

I've been trying to configure Omnipay in CodeIgniter all day long, I think I'm finally cracking it up, but I'm stuck at the credit card validation part. For some reason when I run my I get the error message Fatal error: Class 'CreditCard' not found in C:\xampp\htdocs\trabajo\emarket\application\controllers\inicio.php on line 37
This is my controller:
use Omnipay\Omnipay;
class Inicio extends CI_Controller {
public function index()
{
$gateway = Omnipay::create('PayPal_Pro');
$gateway->setUsername('######');
$gateway->setPassword('######');
$gateway->setSignature('#####');
$gateway->setTestMode(true);
$gateway->initialize();
$cardInput = array(
'firstName' => 'buyer',
'lastName' => 'one million',
'number' => '4032031186341789',
'company' => 'Visa',
'billingAddress1' => 'bill me here',
'billingAddress2' => 'or maybe here',
'billingPhone' => '4085873015',
'billingCity' => 'chicago',
'billingState' => 'illinois',
'billingPostCode' => '646960',
'shippingAddress1' => 'ship it here',
'shippingAddress2' => 'or ship here',
'shippingPhone' => '98789987',
'shippingCity' => 'chicago',
'shippingState' => 'illinois',
'shippingPostCode' => '989898',
);
$card = new CreditCard($cardInput);
}
}
Thanks for your time, I'd really appreciate some pointers on what I'm doing wrong.
Classes are loaded, but you need to point at those. And you are doing that with keyword use. Otherwise you could pass something like:
$gateway = Omnipay\Omnipay::create('PayPal_Pro');//not quite sure if you need backslash infront of vendor name
Or same way you could invoke CreditCard instance:
$card = new Omnipay\Common\CreditCard($cardInput);
That is reason of having keyword use.
This is good topic source.

Resources