-
Notifications
You must be signed in to change notification settings - Fork 235
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
Share Model URL fix #496
Share Model URL fix #496
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,32 +89,51 @@ def save_to_db(request): | |
net_name = request.POST.get('net_name') | ||
user_id = request.POST.get('user_id') | ||
next_layer_id = request.POST.get('nextLayerId') | ||
public_sharing = True | ||
user = None | ||
public_sharing = True | ||
if net_name == '': | ||
net_name = 'Net' | ||
try: | ||
# making model sharing public by default for now | ||
# TODO: Prvilege on Sharing | ||
if user_id: | ||
user_id = int(user_id) | ||
user = User.objects.get(id=user_id) | ||
|
||
# create a new model on share event | ||
model = Network(name=net_name, public_sharing=public_sharing, author=user) | ||
model.save() | ||
# create first version of model | ||
model_version = NetworkVersion(network=model, network_def=net) | ||
model_version.save() | ||
# create initial update for nextLayerId | ||
model_update = NetworkUpdates(network_version=model_version, | ||
updated_data=json.dumps({'nextLayerId': next_layer_id}), | ||
tag='ModelShared') | ||
model_update.save() | ||
|
||
return JsonResponse({'result': 'success', 'id': model.id}) | ||
except: | ||
return JsonResponse({'result': 'error', 'error': str(sys.exc_info()[1])}) | ||
|
||
if Network.objects.filter(name=net_name).exists(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if filter returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why there is an if statement, if this returns true then this will be executed. Else it will create a new model record. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the result is null, it will return false |
||
# Update the exising json field | ||
try: | ||
if user_id: | ||
user_id = int(user_id) | ||
user = User.objects.get(id=user_id) | ||
# load the model with the net name | ||
model = Network.objects.get(name=net_name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are using |
||
model_id = model.id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't there any better way to handle this for anonymous sessions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Answered above |
||
# update the model with network id same as model id | ||
existing_model = NetworkVersion.objects.get(network_id=model_id) | ||
existing_model.network_def = net | ||
existing_model.save() | ||
return JsonResponse({'result': 'success', 'id': model.id}) | ||
except: | ||
return JsonResponse({'result': 'error', 'error': str(sys.exc_info()[1])}) | ||
else: | ||
try: | ||
if user_id: | ||
user_id = int(user_id) | ||
user = User.objects.get(id=user_id) | ||
# create a new model on save event | ||
model = Network(name=net_name, | ||
public_sharing=public_sharing, | ||
author=user) | ||
model.save() | ||
# create first version of model | ||
model_version = NetworkVersion(network=model, | ||
network_def=net) | ||
model_version.save() | ||
# create initial update for nextLayerId | ||
model_update = NetworkUpdates(network_version=model_version, | ||
updated_data=json.dumps({'nextLayerId': next_layer_id}), | ||
tag="ModelShared") | ||
model_update.save() | ||
return JsonResponse({'result': 'success', | ||
'id': model.id}) | ||
except: | ||
return JsonResponse({'result': 'error', | ||
'error': str(sys.exc_info()[1])}) | ||
|
||
|
||
def create_network_version(network_def, updates_batch): | ||
|
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.
Why was this necessary?
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.
This was necessary because then the model would not be shared and hence the canvas will not render the comments and sharing stuff on the model.