Skip to content

Commit

Permalink
Merge pull request #4746 from archesproject/4725_incorrect_prov_flag
Browse files Browse the repository at this point in the history
Deletes a new resource if first attempt to save tile to it fails. re #4725
  • Loading branch information
chiatt authored Apr 3, 2019
2 parents 89e6b93 + c66e186 commit 7f0d1d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
5 changes: 3 additions & 2 deletions arches/app/models/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ def check_for_missing_nodes(self, request):
else:
missing_nodes.append(node.name)
if missing_nodes != []:
message = _('This card requires values for the following:')
raise ValidationError(message, (', ').join(missing_nodes))
message = _('This card requires values for the following: ')
message += (', ').join(missing_nodes)
raise TileValidationError(message)

def validate(self, errors=None):
for nodeid, value in self.data.iteritems():
Expand Down
17 changes: 4 additions & 13 deletions arches/app/views/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def post(self, request):
try:
tile.save(request=request)
except TileValidationError as e:
resource_tiles = models.TileModel.objects.filter(
resourceinstance=tile.resourceinstance)
if resource_tiles.count() == 0:
Resource.objects.get(pk=tile.resourceinstance_id).delete(request.user, 'test')
return JSONResponse({'status': 'false', 'message': [e.message, _('Unable to Save. Please verify your input is valid')]}, status=500)
except Exception as e:
message = "Unable to save. A {0} has occurred. Arguments: {1!r}".format(type(e).__name__, e.args)
Expand All @@ -100,19 +104,6 @@ def post(self, request):
if accepted_provisional is not None:
provisional_editor = User.objects.get(pk=accepted_provisional_edit["user"])
tile.save(provisional_edit_log_details={"user": request.user, "action": "accept edit", "edit": accepted_provisional_edit, "provisional_editor": provisional_editor})
if tile_id == '4345f530-aa90-48cf-b4b3-92d1185ca439':
import couchdb
import json as json_json
couch = couchdb.Server(settings.COUCHDB_URL)
for project in models.MobileSurveyModel.objects.all():
db = couch['project_' + str(project.id)]
#tile = models.TileModel.objects.get(pk='4345f530-aa90-48cf-b4b3-92d1185ca439')
tile_json = json_json.loads(JSONSerializer().serialize(tile))
tile_json['_id'] = tile_json['tileid']
for row in db.view('_all_docs', include_docs=True):
if 'tileid' in row.doc and tile_json['_id'] == row.doc['_id']:
tile_json['_rev'] = row.doc['_rev']
db.save(tile_json)

if tile.provisionaledits is not None and str(request.user.id) in tile.provisionaledits:
tile.data = tile.provisionaledits[str(request.user.id)]['value']
Expand Down

0 comments on commit 7f0d1d1

Please sign in to comment.