Beispiel #1
0
def mygraph(request):
  profile = getProfile(request,allowDefault=False)
  if not profile: return HttpResponse( "You are not logged in!" )
  graphName = request.GET['graphName']
  if not graphName:
    return HttpResponse("You must type in a graph name.")
  action = request.GET['action']
  url = request.GET['url']
  if action == 'save':
    try:
      existingGraph = profile.mygraph_set.get(name=graphName)
      existingGraph.url = url
      existingGraph.save()
    except ObjectDoesNotExist:
      try:
        newGraph = MyGraph(profile=profile,name=graphName,url=url)
        newGraph.save()
      except:
        log.exception("Failed to create new MyGraph in /composer/mygraph/, graphName=%s" % graphName)
        return HttpResponse("Failed to save graph %s" % graphName)
    return HttpResponse("SAVED")
  elif action == 'delete':
    try:
      existingGraph = profile.mygraph_set.get(name=graphName)
      existingGraph.delete()
    except ObjectDoesNotExist:
      return HttpResponse("No such graph '%s'" % graphName)
    return HttpResponse("DELETED")
  else:
    return HttpResponse("Invalid operation '%s'" % action)
Beispiel #2
0
def _dogsave(request,graphName):
  profile = getProfile(request,allowDefault=False)
  if not profile: return stderr("You must be logged in to save graphs")
  url = request.GET.get('url')
  if not url: return stderr("No url specified!")
  try:
    existingGraph = profile.mygraph_set.get(name=graphName)
    existingGraph.url = url
    existingGraph.save()
  except ObjectDoesNotExist:
    try:
      newGraph = MyGraph(profile=profile,name=graphName,url=url)
      newGraph.save()
    except:
      log.exception("Failed to create new MyGraph in _dogsave(), graphName=%s" % graphName)
      return stderr("Failed to save graph %s" % graphName)
  return stdout("Saved graph %s" % graphName)
Beispiel #3
0
def _dogsave(request,graphName):
  profile = getProfile(request,allowDefault=False)
  if not profile: return stderr("You must be logged in to save graphs")
  url = request.GET.get('url')
  if not url: return stderr("No url specified!")
  try:
    existingGraph = profile.mygraph_set.get(name=graphName)
    existingGraph.url = url
    existingGraph.save()
  except ObjectDoesNotExist:
    try:
      newGraph = MyGraph(profile=profile,name=graphName,url=url)
      newGraph.save()
    except:
      log.exception("Failed to create new MyGraph in _dogsave(), graphName=%s" % graphName)
      return stderr("Failed to save graph %s" % graphName)
  return stdout("Saved graph %s" % graphName)
Beispiel #4
0
def save_graph(username, name, url):
    if named_graph_exists(username, name):
        print 'Graph for {0} with name {1} already exists'.format(username, name)
        return False
    if target_exists(username, url):
        print 'Graph for {0} with target {1} already exists'.format(username, extract_target_from_url(url))
        return False

    profile = profile_for_user(username)
    if profile:
        graph = MyGraph(profile=profile, name=name, url=url)

        graph.save()
        return True
    else:
        print 'Could not find profile for user {0}'.format(username)
        return False
Beispiel #5
0
def mygraph(request):
    profile = getProfile(request, allowDefault=False)

    if not profile:
        return HttpResponse("You are not logged in!")

    action = request.GET['action']
    graphName = request.GET['graphName']

    if not graphName:
        return HttpResponse("You must type in a graph name.")

    if action == 'save':
        url = request.GET['url']

        try:
            existingGraph = profile.mygraph_set.get(name=graphName)
            existingGraph.url = url
            existingGraph.save()

        except ObjectDoesNotExist:
            try:
                newGraph = MyGraph(profile=profile, name=graphName, url=url)
                newGraph.save()

            except:
                log.exception(
                    "Failed to create new MyGraph in /composer/mygraph/, graphName=%s"
                    % graphName)
                return HttpResponse("Failed to save graph %s" % graphName)

        return HttpResponse("SAVED")

    elif action == 'delete':
        try:
            existingGraph = profile.mygraph_set.get(name=graphName)
            existingGraph.delete()

        except ObjectDoesNotExist:
            return HttpResponse("No such graph '%s'" % graphName)

        return HttpResponse("DELETED")

    else:
        return HttpResponse("Invalid operation '%s'" % action)
Beispiel #6
0
def save_graph(username, name, url):
    if named_graph_exists(username, name):
        print 'Graph for {0} with name {1} already exists'.format(
            username, name)
        return False
    if target_exists(username, url):
        print 'Graph for {0} with target {1} already exists'.format(
            username, extract_target_from_url(url))
        return False

    profile = profile_for_user(username)
    if profile:
        graph = MyGraph(profile=profile, name=name, url=url)

        graph.save()
        return True
    else:
        print 'Could not find profile for user {0}'.format(username)
        return False