예제 #1
0
def show(request, pulsar_id):
  pulsar_id = int( pulsar_id )
  pulsar = Pulsars.show( pulsar_ids=[pulsar_id])[0]
  t = loader.get_template('pulsars/show.html')
  c = RequestContext(request, {
    'pulsar': pulsar,
    })
  return HttpResponse(t.render(c))
예제 #2
0
def new(request):
  import os
  pulsars = Pulsars.show()
  obs_sys = ObsSystems.show()
  print "---"
  print obs_sys.__class__
  print "---"
  for key, info in obs_sys.iteritems():
    print "%s : %s" % (id, info.name)

  if request.method == 'POST':
    if request.POST['pulsar_select'] == "-1":
      request.session['flash'] = { 'type': 'error', 'message': 'You must specify a Pulsar to parse Tim-file for.' }
      return redirect('/webtoaster/toas/new')

    if request.POST['obssys_select'] == "-1":
      request.session['flash'] = { 'type': 'error', 'message': 'You must specify an Ovservation System to parse Tim-file for.' }
      return redirect('/webtoaster/toas/new')

    if not request.FILES.get('timfile'):      
      request.session['flash'] = { 'type': 'error', 'message': 'Seems you forgot to attach a Time-File to parse.' }
      return redirect('/webtoaster/toas/new')

  if request.method == 'POST' and request.FILES.get('timfile'):
    try:
      uf = request.FILES['timfile']
      temp_path = settings.TEMP_DIR
      fn = uf.name
      file_path = os.path.join( temp_path, fn )
      open( file_path, 'w' ).write( uf.read() )

      obs = obs_sys[int(request.POST['obssys_select'])]
      obs_args ={'obssystem_name':obs.name}

      load_status = Toas.upload( username=request.user.username, path=file_path, pulsar_id=request.POST['pulsar_select'], reader='tempo2', obssys=obs_args )

      request.session['flash'] = { 'type': 'success', 'message': 'Tim file was parse.'}
    except Exception as e:
      request.session['flash'] = { 'type': 'error', 'message': 'There was an error parsing Tim file. Message: %s' % str(e) }
      return redirect('/webtoaster/toas/new')
    return redirect('/webtoaster/toas')

  

  t = loader.get_template('toas/new.html')
  c = RequestContext(request, {
    'pulsars': pulsars,
    'obs_sys': obs_sys
    })
  c.update(csrf(request))
  return HttpResponse(t.render(c))
예제 #3
0
def add(request):
  users = ToasterUser.objects.all()
  if request.method == 'GET':    
    form = PulsarForm()
    aliases = list()
  elif request.method == 'POST':
    aliases = request.POST.getlist('aliases[]')
    curator_id = request.POST.get('curator_id')
    form = PulsarForm(request.POST)
    if form.is_valid():
      new_pulsar_name = form.cleaned_data['name']
      new_aliases = aliases
      try:
        response = Pulsars.add(new_pulsar_name, aliases)
        if curator_id != '':
          curator_id = int(curator_id)
          curator_response = Pulsars.update_curators(response, to_add_ids=[curator_id])
        request.session['flash'] = { 'type': 'success', 'message': 'Pulsar was succesfully added with iD: %i' % response }
        return redirect("/webtoaster/pulsars/%i/" % response)
      except Exception, e:
        request.session['flash'] = { 'type': 'error', 'message': 'Toaster produced an error: %s' %  str(e)}      
    else:
      request.session['flash'] = { 'type': 'error', 'message': 'Please verify your form' }
예제 #4
0
def master_parfile(request, pulsar_id):
  pulsar_id = int( pulsar_id )
  pulsar = Pulsars.show( pulsar_ids=[pulsar_id])[0]
  parfiles = pulsar.parfiles()
  if parfiles != []:
    parfile = parfiles[0]
  else:
    parfile=None
  print parfile.__class__
  t = loader.get_template('pulsars/master_parfile.html')
  c = RequestContext(request, {
    'parfile': parfile,
    'pulsar': pulsar,
    })
  return HttpResponse(t.render(c))
예제 #5
0
def index(request):
  page = request.GET.get('page')
  if page == None:
    page = 1
  else:
    page = int( page )

  sort_by = request.GET.get('sort_by')
  order = request.GET.get('order')

  if sort_by == None:
    sort_by = 'id'

  if order == None:
    order == 'desc'


  per_page = 10

  pulsars = Pulsars.show()

  def get_sort_method(pulsar):
    return getattr(pulsar, sort_by)

  pulsars_sorted = sorted(pulsars, key=lambda pulsar: get_sort_method(pulsar) )

  if order == 'asc':
    pulsars_sorted = list(reversed(pulsars_sorted))
  elif order == 'desc':
    pass


  pulsars_paged = Paginator(pulsars_sorted, per_page)
  pulsars_current_page = pulsars_paged.page(page)

  t = loader.get_template('pulsars/index.html')
  c = RequestContext(request, {
    'welcome_message': 'Welcome to Web-Toaster, friend!',
    'pulsars': pulsars_current_page,
    'page_range': pulsars_paged.page_range,
    'sort_by': sort_by,
    'order': order
    })
  return HttpResponse(t.render(c))