Commit 6e62e22b authored by Vasyl Bodnaruk's avatar Vasyl Bodnaruk

Add view for creating new job

parent 995e297b
...@@ -15,3 +15,6 @@ class Service: ...@@ -15,3 +15,6 @@ class Service:
Job.objects.get(job_id=i['id']).update(status='RUN') Job.objects.get(job_id=i['id']).update(status='RUN')
except: except:
pass pass
def run_job(self, job):
print("job is running")
...@@ -26,10 +26,10 @@ class JobListView(ListView): ...@@ -26,10 +26,10 @@ class JobListView(ListView):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
action = request.POST.get('action') action = request.POST.get('action')
if action == 'schedule': job_id = request.POST.get('job_id')
pass if action == 'run':
if action == 'status': print(job_id)
pass # job = Job.objects.get(pk=job_id)
if action == 'cancel': if action == 'cancel':
pass pass
if action == 'update': if action == 'update':
...@@ -44,9 +44,16 @@ class JobListView(ListView): ...@@ -44,9 +44,16 @@ class JobListView(ListView):
class NewJobCreateView(CreateView): class NewJobCreateView(CreateView):
template_name = 'new_job.html' template_name = 'new_job.html'
def __init__(self):
self.client = ScrapydAPI()
super(NewJobCreateView, self).__init__()
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
return render(request, self.template_name) spiders = Spider.objects.all()
return render(request, self.template_name, {'spiders': spiders})
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
pass name = request.POST.get('name')
spider = request.POST.get('spider')
...@@ -3,8 +3,28 @@ ...@@ -3,8 +3,28 @@
{% block content %} {% block content %}
<form name="jobs" method="post"> <form name="jobs" method="post">
{% csrf_token %} {% csrf_token %}
<button name="action" value="new">New job</button> <div>
<button name="action" value="update">Update</button> here will be pending jobs
<button name="action" value="cancel">Cancel</button> <input name="job_id" type="text">
<button name="action" value="run">Run job</button>
<button name="action" value="new">New job</button>
</div>
<section>
<div>
run jobs
<button name="action" value="cancel">Cancel</button>
</div>
<div>
finished
<button name="action" value="update">Update</button>
</div>
</section>
<div>
deleted
</div>
</form> </form>
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends 'base.html' %} {% extends 'base.html' %}
{% block content %} {% block content %}
new job <main class="pt-2 pb-5">
<div class="container">
<form class="form" method="post">
<section class="mb-5">
<h5 class="offset-1 display-5 mb-2">New job</h5>
<!-- Name -->
<div class="form-group row">
<label for="name" class="offset-1 col-2 col-form-label">Name</label>
<div class="col-6">
<input class="form-control" type="text" placeholder="Name job..." id="name" name="name">
</div>
</div>
<div class="form-group row">
<label for="spider" class="offset-1 col-2 col-form-label">Spider</label>
<div class="col-6">
<select name="spider" id="spider" class="form-control">
{% for i in spiders %}
<option value="{{ i.id }}">{{ i.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group row">
<div class="offset-5 col-2">
<a class="form-control btn btn-danger" href="/job/">Cancel</a>
</div>
<div class="col-2 pull-right">
<button type="submit" class="form-control btn btn-primary">Create</button>
</div>
</div>
</section>
</form>
</div>
</main>
{% endblock %} {% endblock %}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment