Skip to content

Commit

Permalink
changed id appearance
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptHound committed Feb 6, 2021
1 parent 952267f commit 3b1f502
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
3 changes: 0 additions & 3 deletions djparser/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
<div class="status">
Task status is: {{ status }}
</div>
<div class="pid">
PID is: {{ pid }}
</div>
{% endblock %}
<form action='/parse/', method='get'>
<label for="pid">PID here:</label><br>
Expand Down
6 changes: 5 additions & 1 deletion main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ class ResultIdModel(models.Model):
class ResultRow(models.Model):
name = models.CharField(max_length=200)
value = models.CharField(max_length=200)
parent_id = models.ForeignKey(ResultIdModel, on_delete=models.CASCADE)
parent_id = models.ForeignKey(
ResultIdModel,
on_delete=models.CASCADE,
related_name="parent"
)
14 changes: 10 additions & 4 deletions main/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,28 @@ def create(pid: str) -> QueryDict:

@staticmethod
def get_all_pids() -> list:
return [model.pid for model in ResultIdModel.objects.all()]
return ResultIdModel.objects.values_list('id', flat=True)

@staticmethod
def get_db_pid_by_id(id: str) -> str:
return ResultIdModel.objects.get(id=id).pid

@staticmethod
def delete(pid: str) -> dict:
return ResultIdModel.objects.filter(pid=pid).delete()
return ResultIdModel.objects.filter(id=pid).delete()


class ResultRowQuery:
@staticmethod
def create(pid: ResultIdModel, **rows) -> None:
results: list = []
for k, v in rows.items():
ResultRow.objects.create(parent_id=pid, name=k, value=v)
results.append(ResultRow(parent_id=pid, name=k, value=v))
ResultRow.objects.bulk_create(results)

@staticmethod
def get_results_by_id(pid: str) -> QuerySet:
return ResultIdModel.objects.get(pid=pid).resultrow_set.all()
return ResultIdModel.objects.get(id=pid).parent.all()

@staticmethod
def delete(name: str) -> dict:
Expand Down
3 changes: 2 additions & 1 deletion main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def parse_task(url: str) -> str:

def index(request):
print(request.GET)

context = {
'status': request.GET.get('status'),
'pid': request.GET.get('pid'),
Expand All @@ -39,7 +40,7 @@ def parse(request):

if request.method == 'GET':
pid = request.GET.get('pid')
result = app.AsyncResult(pid).result
result = app.AsyncResult(PIDQuery.get_db_pid_by_id(pid)).result
ResultRowQuery.create(result)

context = {
Expand Down

0 comments on commit 3b1f502

Please sign in to comment.