Example #1
0
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)
Example #2
0
    def doProcessRender(self, request):
        errorMessage = ""
        if (request.method == "POST" and request.POST.has_key('name')):
            if (request.POST.has_key('imageKey')):
                name = request.POST['name']
                imageKey = request.POST['imageKey']
                image = None
                try:
                    image = Picture.objects.get(pk__exact=imageKey)
                except ObjectDoesNotExist:
                    errorMessage = "Image does not exist"

                if (image != None):
                    newTagGroup = TagGroup(user=request.user,
                                           name=name,
                                           picture=image)
                    try:
                        newTagGroup.save()
                        self.setJsonObject({
                            'error': False,
                            'tagGroup': {
                                'pk':
                                newTagGroup.pk,
                                'tags': [],
                                'name':
                                newTagGroup.name,
                                'dateCreated':
                                newTagGroup.dateCreated.strftime(
                                    "%Y-%m-%d %H:%M:%S"),
                                'lastModified':
                                newTagGroup.lastModified.strftime(
                                    "%Y-%m-%d %H:%M:%S")
                            }
                        })
                    except Exception:
                        errorMessage = "Name provided has been used"
            else:
                errorMessage = "No image key provided for the new tag group"
        else:
            errorMessage = "No name provided for a new group"

        if (errorMessage != ""):
            self.setJsonObject({'error': True, 'errorMessage': errorMessage})
Example #3
0
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)
Example #4
0
	def doProcessRender(self, request):
		errorMessage = ""
		if (request.method == "POST" and request.POST.has_key('name')):
			if (request.POST.has_key('imageKey')):
				name = request.POST['name']
				imageKey = request.POST['imageKey']
				image = None
				try:
					image = Picture.objects.get(pk__exact=imageKey)
				except ObjectDoesNotExist:
					errorMessage = "Image does not exist"
				
				if (image != None):
					newTagGroup = TagGroup(user=request.user, name=name, picture=image)
					try:
						newTagGroup.save()
						self.setJsonObject({
							'error' : False,
							'tagGroup' : {
								'pk' : newTagGroup.pk,
								'tags' : [],
								'name' : newTagGroup.name,
								'dateCreated' : newTagGroup.dateCreated.strftime("%Y-%m-%d %H:%M:%S"),
								'lastModified' : newTagGroup.lastModified.strftime("%Y-%m-%d %H:%M:%S")
							}
						})
					except Exception:
						errorMessage = "Name provided has been used"
			else:
				errorMessage = "No image key provided for the new tag group"
		else:
			errorMessage = "No name provided for a new group"
		
		if (errorMessage != ""):
			self.setJsonObject({
				'error' : True,
				'errorMessage' : errorMessage
			})