Create custom actions in Django admin site (not list actions) - ajax

I'm new to django and I'm trying to figure out how to create custom actions inside admin site.
Let's say I want to create some sort of custom form with fancy ajax based ui.
What I would normally do in .NET/PHP/Ruby is prepare some js code and a service that will be called via ajax and return json or even html.
A more concrete example could be an auto complete box to manage a many to one relationship. What should I do to build such a system inside the django admin site? (I know there are a couple of ready to use solution for this. But I'm not interested: just for study purposes).

In this particular case (a fancier widget), ModelAdmin has several useful hooks like ModelAdmin.form and ModelAdmin.formfield_overrides.
Creating a custom Django Form Widget is more elegant, but if the widget is pure JS (like many jQuery widgets), most of the time it is not worth - just override the change_form.html admin template for the Model in question.

You can easily change the form and the template of the ModelAdmin.
So you're free to inject any CSS and JS you like. Take look at this presentation to get the basic idea.

Related

How to plug into Laravel

I can develop Laravel packages and can made custom blade, migration, model, controller, route from a package. But my question is specifically on how can I plug onto a default CRUD that was already built, from a package to modify that.
I started my PHP career from CMS like WordPress, Drupal, and then CakePHP, Laravel. Starting with procedural coding, OOP was a learning curve and is still a learning curve for mine. But scouring different platform made me understand that, the same thing can be achieved in different ways.
With WordPress plugin development experience, it's easy to extend functionality using action and filter hooks. With a core functionality like:
Fetch form data (3 fields)
hook here <---
Load form data (3 fields)
Submit form data (3 fields)
hook here <---
Save form data (3 fields)
can be easily modified from a plugin like:
Fetch form data (3 fields)
action hook <--- (hooked - added 2 fields)
Load form data (5 fields)
Submit form data (5 fields)
filter hook <--- (hooked - added data of 2 additional fields)
Save form data (5 fields)
But when in Laravel, I want to achieve a similar feature being in Laravel scope, how can I?
I understand the use of #yield('my_hook') is similar to the action hook in WordPress. But found that, if I hook multiple onto #yield it's getting overridden.
I found several packages like eventy with a similar approach of action and filter hook of WordPress, but I'm actually asking for a Laravel approach to the issue.
I came across to the Laravel Events, is that the solution to hook like an action hook in WordPress? And the filter hook, I think we can extend a model to modify its behavior. But I'm afraid, these are all the imagination, and might not be the reality. I don't have any idea on that.
Can I get some enlightenment onto this issue?
Both WordPress and Laravel are frameworks on a whole different level, so comparison might be difficult.
In Laravel you have tools to control the output (html page). #yield is an example, when you are using Blade templates.
Furthermore there are methods to hook on certain events within the execution of the framework (Laravel Events).
In Laravel you are working in a Model-View-Control setting meaning that you can/should:
Make a Model of every data-entity you are using and give it the responsibility to do it's own work. See also https://laravel.com/docs/5.8/eloquent#events for hooks
Make Controller methods for every action you want to execute from the front-end. It is a good practice to keep these methods as short as possible. e.g. max 10 lines.
Make sophisticated templates using the Blade Template engine
Hope this will help.

How to best apply an MVC architecture in dojo mobile (custom controllers)?

I'm pretty new to Dojo and I'm wondering about some best practises for building a MVC application. I know there are modules like dojox/app, but it seems like these are made for more complex applications.
It seems like the best way to go is to make custom page-level controller objects with will handle all the page logic, but I'm not quite sure how to fit this piece in the puzzle. What is the proper way to switch between views and passing through parameters through them following a MVC archtiecture.
I have an overview page with list items, each with their own ID. I want to navigate to another page passing through the corresponding item ID so I can retrieve the details for this item externally. What would be the proper way of doing this?
I could call a method on the corresponding controller (Page1 Controller or Page2 Details controller) directly using a button and passing the listID parameter directly?
Another way of doing this could be by working with transition states and addling listeners in the page controller to forward to the correct page. Although I'm not quite sure how to pass parameters in this scenario..
... any better solutions?
Can anybody shed some light on this? It doesn't seem like there is much documentation/examples on this with the latest versions of dojo (1.9).
Thanks!
I will recommend dojox/app since you are already using dojo mobile.
It's very simple to get started and can be use for simple apps or very complex apps
Take a look at this resources:
https://github.com/csantanapr/dapp-examples/tree/master/dapp-request
https://github.com/csantanapr/dapp-boilerplate
http://dojotoolkit.org/documentation/tutorials/1.9/dojox_app/contactsList/

Implementing ecommerce analytics with MVC Razor

I am implementing various analytic tracking services in an MVC3 site (Google, Coremetrics) and researching if a custom HTML helper or partial view would work better given the following details:
-Code runs multiple sites and business logic is needed to change analytic service account Ids.
-The class must accept an object with order details to render the appropriate tags.
-The code must know which view is being rendered.
The solution I am working on includes am HTML helper base class that accepts the needed objects and is inherited by each provider's individual HTML helper. These helpers will live on the common layout. Is there a better way of implementing analytics on MVC and are partial views better suited since business logic is needed?
The GA analytics tracking code is pretty simple, we also use ASP.NET MVC3 but have just dropped the necessary code directly into our 'Order Complete' view.
There's no reason why you couldn't use an HTML helper instead though. I suggest not overly complicating your object model. Just use a single helper that has parameters matching the parameters used in the JavaScript.
You should be able to find examples of eCommerce tracking code, add parameters as appropriate, done. You might want to create another overload that pulls GA ID and domain name from the web.config as in the example as well, but still accepts the order details as parameters.

Implement drag-and-drop using AJAX in CakePHP

I wish to create a drag and drop feature for adding profile picture using CakePHP. Are there any samples which I can follow or a step by step guide?
I sourced many samples online but none of them cater for CakePHP.
I basically need a simple drag n drop for users to drag their profile image and the URL of the image is reflected in the database. The user will be able to edit another profile image. What approach should I use for this?
what you want to do is mostly about front-end, the back-end is generic server handling (in this case, PHP upload handling) and has little to do with Cake. That's why you don't see a specific cake tutorial for this. So, look up jquery drag drop and ajax upload. You'll also need to understand Cake rather well (well enough to adapt those online sample code to your Cake app).
I recommend you to use jQuery UI's draggable and droppable interactions.
Integrating them in CakePHP is quite easy, just follow the manual instructions to include Javascript files in a CakePHP application.
Finally, updating the database to reflect the URL of the image can be easily done with jQuery as well, using the AJAX related methods (e.g. post).

How to create my own form in joomla

I want to create my own form that are submitted and values of that form will be stored in joomla database. How can i used the Joomla connection code to interacte with the joomla database.
If you just want to get your work done, there are some components already avaiable in Joomla Extension's website to your form's needs. CkForms is a good one, you can create simple forms with it that are automatically saved in the database (supports upload of files too).
If you want to learn how to write extensions in Joomla, you should read Joomla Official Documentation website.
Extensions in Joomla are divided in "Components", "Modules" and "Plugins". More informations about these differences can be found here and here.
What you're trying to achieve sounds a "component" to me. Downloading the CkForms and reading it's source code should get you started to Joomla's way of writing components.
EDIT: Joomla has a huge API with a lot of features. It has a database module of it's own, with insert methods and such. Reading Joomla's API website before implementing your component it's a good idea to avoid "reinventing the wheel" and it's a good practice since those methods are extensively tested by all Joomla users.
The JForm class helps you build forms.
Documentation can be found here:
joomla CMS: http://docs.joomla.org/API16:JForm
joomla API: http://api.joomla.org/11.4/Joomla-Platform/Form/JForm.html
This class provides you with ready to use form elements and form loading and/or processing methods
This class includes validation methods, date picker control, color picker, etc.
Of course, as another mentioned above, if you are building a module, component, or application, you will need to learn how to to develop a module, component or application. Of these three, the module is the easiest to implement.
The application gives you much freedom b/c you are not constrained to the CMS paradigm, front and back end complexities. However, there is little documentation about how to develop applications with Joomla framework b/c joomla as a framework is relatively new
This tutorial gets you started understanding how to use JForm to create a form in Joomla: http://www.ostraining.com/blog/how-tos/development/getting-started-with-jform/
Or you could just create add a html module to any position and then write the form in html i.e.
<form method="post" action="mycreatedpage.php"> <input type="text"/> <input type="submit">
Now just create a page that handles the code by emailing or inserting into db. I havent tried it but i think it should work.
Looks like everyone already told you almost everything I know except for the component creator. Very easy to use, and it follows Joomla standards. Will get you up and running within minutes.
I have got good working experience with Joomla RSForm Pro. It has got options for
validation
user email/admin emails on submit
file uploads
and many more
Good tutorials too. Get started with http://www.rsjoomla.com/support/documentation/view-knowledgebase/21-rsform-pro.html
Good luck!
Create View.
Create Model.
Create Table.
Create Controller ( if Needed ).
Create Form xml file.
Go here for more information:
http://docs.joomla.org/Standard_form_field_types
Take a look at the Chronoforms extension - does more than you want.
You have two options:
Use an already built custom form extension
Create your own custom form extension (or outsource it)
Now if you only want to modify the user registration form, then you can do some PHP customization to accomplish your goal.
Making forms in Joomla can be done in a couple of ways.
If you just wanted a contact us, you can just create a page with a menu item for the User contact form. This gives you a page with a Members address and contact form. So all you would need to do was add the user as the company of the websites home address and email. But the form is very basic, name, title, textarea for message.
Next up from that you could just make a Custom HTML module add add a form to it in plain HTML like +Sean said above this, you would need to code in PHP your own form process script. You would not get error in form data checking unless you also wrote it.
Next you might rather look on the Joomla Extension Directory JED for one of the good extensions for 3 and 2.5 Joomla RSForms!Pro is good, and can do all we have needed. This lets you add fields one by one and move your form around. Then can auto generate or custom the html of the form.
You can easily create your own forms with Fabrik
Chronoforms are now a days a very popular solution for custom forms in joomla. Chornoforms support twitter bootstrap also. In simple 5 steps you can create a contact form with unlimited fields and also embed various function like DB save, Email, Thanks Message, Redirection on any page. There is events and events will have particular events.
Also possibility of extension of Normal joomla registeration. It will not extend the core registration but at the time of registration you can take various information from users.
I would use Chrono Forms, they work really well and are easy to use.
Download here
Here is a full tutorial on the new Chronoforms 5 to help you get started quickly and understand most of the features available.
CLICK HERE
You can use plugin to insert external php form in content. It is easy and you don't need to make plugin etc. Please use this.
I suggest you to use breezingforms: http://crosstec.de/en/extensions/joomla-forms-download.html
It's one of the best solutions for custom form creation in joomla.

Resources