def submit_tag(request, image_key): if request.method == "POST": postDict = request.POST try: descriptionIn = postDict["description"] colorIn = postDict["color"] shapeIn = postDict["shape"] numPoints = int(postDict["numPoints"]) image = Pictures.objects.get(pk__exact=image_key) pointsArr = list() i = 0 while i < numPoints: pointsArr.append((postDict["point" + str(i) + "_x"], postDict["point" + str(i) + "_y"])) i += 1 tagShape = TagShape.objects.get(shape__exact=shapeIn) tagGroup = TagGroup(description=descriptionIn, color=colorIn, picture=image, shape=tagShape) tagGroup.save() for (counter, point) in enumerate(pointsArr): tagPoint = TagPoint(group=tagGroup, pointX=point[0], pointY=point[1], rank=counter + 1) tagPoint.save() return HttpResponseRedirect(reverse("mycoplasma_home.views.picture_editor", args=(image_key,))) except (KeyError): error = "Error on key" except (ObjectDoesNotExist): error = "Error on tag shape" + shapeIn else: error = "Not a Post" return HttpResponse("Error: " + error)
def doProcessRender(self, request): errorMessage = None errorTagGroups = [] tagKeys = {} if (request.method == "POST"): try: tagGroupKeys = request.POST.getlist('tagGroupKeys[]') description = request.POST['description'] points = getMultiListPost(request, 'points') color = request.POST.getlist('color[]') if (len(color) >= 3): # first check if the color exists (tagColor, created) = TagColor.objects.get_or_create(red=color[0], green=color[1], blue=color[2]) for key in tagGroupKeys: try: tagGroup = TagGroup.objects.get(pk__exact=key) if (tagGroup.picture.isPrivate and request.user == tagGroup.user) or not tagGroup.picture.isPrivate: newTag = Tag(description=description, color=tagColor, group=tagGroup, user=request.user) newTag.save() tagKeys[key] = newTag.pk for key, point in points.items(): newTagPoint = TagPoint(tag=newTag, pointX=float(point[0]), pointY=float(point[1]), rank=int(key)+1) newTagPoint.save() else: errorMessage = "Incorrect permissions for editing this image or tag group" except ObjectDoesNotExist: errorTagGroups.append(key) else: errorMessage = "Incorrect format for color" except KeyError as e: errorMessage = "Missing arguments in save for key: " + str(e) else: errorMessage = "Incorrect method for saving a tag" if (errorMessage == None and len(errorTagGroups) == 0): self.setJsonObject({ 'error' : False, 'tagKeys' : tagKeys, 'errorMessage' : errorMessage }) elif len(errorTagGroups) > 0: self.setJsonObject({ 'error' : True, 'errorMessage' : errorMessage + ' and these tag groups do not exist', 'errorTagGroups' : errorTagGroups }) else: self.setJsonObject({ 'error' : True, 'errorMessage' : errorMessage })
def submit_tag(request, image_key): if (request.method == "POST"): postDict = request.POST try: descriptionIn = postDict['description'] colorIn = postDict['color'] shapeIn = postDict['shape'] numPoints = int(postDict['numPoints']) image = Pictures.objects.get(pk__exact=image_key) pointsArr = list() i = 0 while (i < numPoints): pointsArr.append((postDict['point' + str(i) + '_x'], postDict['point' + str(i) + '_y'])) i += 1 tagShape = TagShape.objects.get(shape__exact=shapeIn) tagGroup = TagGroup(description=descriptionIn, color=colorIn, picture=image, shape=tagShape) tagGroup.save() for (counter, point) in enumerate(pointsArr): tagPoint = TagPoint(group=tagGroup, pointX=point[0], pointY=point[1], rank=counter + 1) tagPoint.save() return HttpResponseRedirect( reverse('mycoplasma_home.views.picture_editor', args=(image_key, ))) except (KeyError): error = "Error on key" except (ObjectDoesNotExist): error = "Error on tag shape" + shapeIn else: error = "Not a Post" return HttpResponse("Error: " + error)
def doProcessRender(self, request): errorMessage = None errorTagGroups = [] tagKeys = {} if (request.method == "POST"): try: tagGroupKeys = request.POST.getlist('tagGroupKeys[]') description = request.POST['description'] points = getMultiListPost(request, 'points') color = request.POST.getlist('color[]') if (len(color) >= 3): # first check if the color exists (tagColor, created) = TagColor.objects.get_or_create(red=color[0], green=color[1], blue=color[2]) for key in tagGroupKeys: try: tagGroup = TagGroup.objects.get(pk__exact=key) if (tagGroup.picture.isPrivate and request.user == tagGroup.user ) or not tagGroup.picture.isPrivate: newTag = Tag(description=description, color=tagColor, group=tagGroup, user=request.user) newTag.save() tagKeys[key] = newTag.pk for key, point in points.items(): newTagPoint = TagPoint( tag=newTag, pointX=float(point[0]), pointY=float(point[1]), rank=int(key) + 1) newTagPoint.save() else: errorMessage = "Incorrect permissions for editing this image or tag group" except ObjectDoesNotExist: errorTagGroups.append(key) else: errorMessage = "Incorrect format for color" except KeyError as e: errorMessage = "Missing arguments in save for key: " + str(e) else: errorMessage = "Incorrect method for saving a tag" if (errorMessage == None and len(errorTagGroups) == 0): self.setJsonObject({ 'error': False, 'tagKeys': tagKeys, 'errorMessage': errorMessage }) elif len(errorTagGroups) > 0: self.setJsonObject({ 'error': True, 'errorMessage': errorMessage + ' and these tag groups do not exist', 'errorTagGroups': errorTagGroups }) else: self.setJsonObject({'error': True, 'errorMessage': errorMessage})