Thursday, 7 April 2016

Django, Eclipse and virtualenv setup

1. Create Virtual Environment

~ pip install virtualenv

~ virtualenv venv

2. Download & install Eclipse

3. Install PyDev

Go to Help -> Eclipse Marketplace -> Search PyDev and install it.




3. Each django virtual environment will be having new workspace and have to use virtual environment interpreter. 

Setup Python interpreter:

Eclipse -> Preferences -> PyDev -> Python Interpreter

Add new interpreter

New -> Set Interpreter Name -> Interpreter Executable(venv/bin/python)

Let's say new interpreter name is: customenv



Note: You can skip this step at this moment and add the interpreter at the time of creating a project.

4.  Create New Project -> PyDev -> PyDev Django Project

If Interpreter is not set till now, please set it now from step 3

Enter Project Name and Select Interpreter(customenv) -> Finish

5. Right Click on 

Project Name-> Properties -> PyDev - Django -> Django settings module (set project settings file e.g <project_name>.settings) -> apply -> Ok




That's it. Please let me know (comments), if you are facing any problem.

Thanks!!!!!!!! Enjoy Programming! :)


Reference Links:

http://linfiniti.com/2011/12/django-development-with-eclipse-and-pydev/

http://www.arruda.blog.br/programacao/review-eclipse-django-virtualenv/

http://lukeplant.me.uk/blog/posts/eclipse-pydev-and-virtualenv/


Wednesday, 6 January 2016

Odoo: MIGS Payment Gateway Integration


After Mollie it's time to work on MIGS Payment Gateway Integration with Odoo. I have done with development and you can contact me if need any kind of help in form of it's integration, coding problems or working structure. If you are interested in buying this module, you can contact me @: dirtyhandsphp@gmail.com.

Note: MIGS Payment Acquirer Module(Odoo 8) is also available for sale on Odoo webshop. Buy Here

Thanks!!!! Enjoy Programming :)

Thursday, 10 December 2015

Odoo: Mollie Payment Gateway Integration


Since few days I was working on Mollie Payment Gateway Integration with Odoo. Finally I have done it successfully. If anyone needs any kind of help in form of it's integration, coding problems, working structure or if you are interested in buying this module, you can contact by through comments on this post.

Update: Now Mollie Payment Acquirer Module(Odoo 8) is available for sale on Odoo webshop as well. Buy Here

Thanks!!!! Enjoy Programming :)

Saturday, 5 September 2015

Js/jQuery load alternative images synchronously?

You can find lot of links over Internet, how to load alternative images but most of them give examples of asynchronously loading not synchronously one. I was facing the same problem and it took around 4 hours for me to fix it and now it looks simple :)

Scenario 1(simple):
=======================
You have two images and want to show the 2nd one, in case 1st one is not valid.

Use following image tag:

<img src="'+src+'" onError="this.onerror=null;this.src=\'https://browshot.com/static/images/not-found.png\'" />; 

Note: Please don't forget to add this.onerror=null otherwise browser may stuck in a loop.


Scenario 1(typical):
=======================
You have three images:

1. Show image1 if valid otherwise image2.
2. If image2 is also invalid show 3rd one.

In this case we have to use above code as well as one more function for middle image.

Not working
--------------------
You can use following code in JS and looks like it will work but will not

var src = first_image_src
var image = new Image();
image.src = src;
if (image.complete) {  
}else{

src = second_image_src; 
}

<img src="'+src+'" onError="this.onerror=null;this.src=\'+third_image_sorce+'" />;

It will always show you first(if valid) or 3rd image(if 1st one not valid), not second one although valid one.

Reason: Above JS code makes an ajax GET asynchronous request to check whether the image is valid or not. It will not wait till the response comes due to it's single threaded feature.

Working solution
---------------------------
To solve above problem we have to either make an synchronous request or use asynchronous in such a way the it looks like request is synchronous one. 

Here is the code:

function getSecondImage(element, second_image_src){
    var image = new Image();
    image.src = second_image_src;
    image.onerror = function(){$(element).prop('onError',null)};  
    image.onload = function(){$(element).prop('src',second_image_src)};      
}


var img_tag = '<img src="'+src+'" onError="this.onerror=getSecondImage(this,\''+second_image_src+'\');this.src=\'+third_image_sorce+'" />';

1. It will first check whether 1st image is proper if it's fine, 1st image will be loaded.
2. If 1st image is not valid, getSecondImage method will be called.
3. getSecondImage method will check if second image is valid or not. If it's valid it will update src of the image and that image will be loaded otherwise returns null.

4. If getSecondImage returns null then third image will be shown.

That's it.

If need any mode clarification or facing issue with above code please come back to me with your valuable comments.

Thanks!!!!!!!! Enjoy Programming:)

Thursday, 27 August 2015

Laravel Unique Validation

Hi, You can find most of the things on the following link regarding unique validation in Laravel.

http://brianretterer.com/quick-tip-laravel-unique-validation/

But I would like to add one more case to make it little easy to understand:

articleName => unique:articles,article_name,{isset(article_id) : article_id : NULL },article_id,user_id,{user_id}

The query that this will give you is: 

Select count(*) as aggregate from articles where article_name = <given_article_name> and article_id <> {article_id} and user_id={user_id}

It will check unique article name per user. Multiple users can have same article name but one user can't have same article name again, only once.  

Thanks!!!!!!!!! Enjoy Programming :)