DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Wagtail Admin+netlify
Taleb
Taleb

Posted on

Wagtail Admin+netlify

Netlify API Doc
https://open-api.netlify.com/

this are the three api endpoint we need
https://api.netlify.com/api/v1/sites/{site_id}/deploys
https://api.netlify.com/api/v1/sites/{site_id}/deploys/{deploy_id}
https://api.netlify.com/api/v1/deploys/{deploy_id}/cancel

Netlify Class

class Netlify(object):
    def __init__(
        self, netlify_site_name, netlify_api_key, netlify_site_id, netlify_webhook_id
    ):
...

    def start_job(self):
        url = f"https://api.netlify.com/build_hooks/{self.webhook_id}"
        requests.post(url)
        return self.list_jobs()[0]["id"]

    def stop_job(self, deploy_id):
        url = f"{self.base_url}/deploys/{deploy_id}/cancel"
        self.make_request(url, "POST")

    def get_job(self, deploy_id):
        url = f"{self.base_url}/sites/{self.site_id}/deploys/{deploy_id}"
        return self.make_request(url, action="GET")

    def list_jobs(self):
        url = f"{self.base_url}/sites/{self.site_id}/deploys"
        return self.make_request(url=url, action="GET")

Enter fullscreen mode Exit fullscreen mode

Wagtail admin view

amplify = Amplify(
        aws_access_key_id=settings.AMPLIFY_AWS_ACCESS_KEY_ID,
        aws_secret_access_key=settings.AMPLIFY_AWS_SECRET_ACCESS_KEY,
        app_id=settings.AMPLIFY_APP_ID,
        branch_name=settings.AMPLIFY_BRANCH,
    )

def netlify_jobs(request):

    job_id = request.GET.get("jobid", "")
    if job_id:
        active_job = netlify.get_job(job_id)

    jobs = netlify.list_jobs()
   ....
   render template

def start_build(request):
    jobid = netlify.start_job()
    ....


def stop_build(request, job_id):
    netlify.stop_job(job_id)
    ....
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Hi!I'm Noah!

Hey, my name is Noah and I’m the one who set up this ad!


My job is to get you to join DEV, so if you fancy doing me a favor, I’d love for you to create an account.
Β 
If you found DEV from searching around, here are a couple of our most popular articles on DEV: