-
Notifications
You must be signed in to change notification settings - Fork 786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template based challenges - Backend #2925
Conversation
title = models.CharField(max_length=500) | ||
template_file = models.FileField( | ||
upload_to=RandomFileName("templates") | ||
) # stores the challenge zip file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this to # Stores the challenge config zip file
@@ -677,20 +681,78 @@ def create_challenge_using_zip_file(request, challenge_host_team_pk): | |||
""" | |||
Creates a challenge using a zip file. | |||
""" | |||
if request.data.get("is_template_challenge"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to is_challenge_template
if request.data.get("is_template_challenge"): | ||
is_template_challenge = True | ||
else: | ||
is_template_challenge = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
# All files download and extract location. | ||
BASE_LOCATION = tempfile.mkdtemp() | ||
|
||
if is_template_challenge: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
samer here
if is_template_challenge: | ||
template_id = request.data.get("templateId") | ||
try: | ||
template = ChallengeTemplate.objects.get( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you create a function like get_challenge_model
for the challenge template get too. And use that here.
challenge_phases_data_from_hosts = challenge_data_from_hosts.get( | ||
"challenge_phases" | ||
) | ||
for i in range(len(challenge_phases_data)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename i
to data
] = challenge_phases_data_from_hosts.get("challenge_phases")[ | ||
i | ||
].get( | ||
"name" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here. Use an array of field names to loop through and override values if present in request
|
||
# Mapping the dataset splits data to that in yaml_file_data | ||
dataset_splits = yaml_file_data["dataset_splits"] | ||
for i in range(len(dataset_splits)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename i
to split
challenges = ChallengeTemplate.objects.filter(**q_params).order_by("-pk") | ||
serializer = ChallengeTemplateSerializer(challenges, many=True) | ||
response_data = serializer.data | ||
return Response(response_data, status=status.HTTP_200_OK) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add newline
@@ -181,4 +181,9 @@ | |||
views.manage_worker, | |||
name="manage_worker", | |||
), | |||
url( | |||
r"^get_all_challenge_templates$", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @KhalidRmb can you please add a /
at the end of this url as we have all the api's ending with /
only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will do.
@KhalidRmb What is the plan on resolving the comments here? |
@RishabhJain2018 So, I kept this on hold until finishing the github based challenges hopefully this week. I was basically waiting for Kajol's frontend changes to continue working on the backend (since I've moved on to Github challenges) but as she's understandably occupied, I'll continue with this and the frontend after GitHub based challenges. |
sounds good, Thanks for letting me know. |
Closing on account of #2989 |
This is the backend for the template based challenges, creating a new model and serializers. Also, created a new API to fetch all template based challenges. Also, modified the challenge creation API to allow for template based challenges.
@RishabhJain2018 @deshraj @Ram81