Esempio n. 1
0
def myvessels(request,
              get_form=False,
              action_summary="",
              action_detail="",
              remove_summary=""):
    try:
        user = _validate_and_get_geniuser(request)
    except LoggedInButFailedGetGeniUserError:
        return _show_failed_get_geniuser_page(request)

    # get_form of None means don't show the form to acquire vessels.
    if interface.get_available_vessel_credits(user) == 0:
        get_form = None
    elif get_form is False:
        get_form = forms.gen_get_form(user)

    # shared vessels that are used by others but which belong to this user (TODO)
    shvessels = []

    # this user's used vessels
    my_vessels_raw = interface.get_acquired_vessels(user)
    my_vessels = interface.get_vessel_infodict_list(my_vessels_raw)

    # this user's number of donations, max vessels, total vessels and free credits
    my_donations = interface.get_donations(user)
    my_max_vessels = interface.get_available_vessel_credits(user)
    my_free_vessel_credits = interface.get_free_vessel_credits_amount(user)
    my_total_vessel_credits = interface.get_total_vessel_credits(user)

    for vessel in my_vessels:
        if vessel["expires_in_seconds"] <= 0:
            # We shouldn't ever get here, but just in case, let's handle it.
            vessel["expires_in"] = "Expired"
        else:
            days = vessel["expires_in_seconds"] / (3600 * 24)
            hours = vessel["expires_in_seconds"] / 3600 % 24
            minutes = vessel["expires_in_seconds"] / 60 % 60
            vessel["expires_in"] = "%dd %dh %dm" % (days, hours, minutes)

    # return the used resources page constructed from a template
    return direct_to_template(
        request, 'control/myvessels.html', {
            'username': user.username,
            'num_vessels': len(my_vessels),
            'my_vessels': my_vessels,
            'sh_vessels': shvessels,
            'get_form': get_form,
            'action_summary': action_summary,
            'action_detail': action_detail,
            'my_donations': len(my_donations),
            'my_max_vessels': my_max_vessels,
            'free_vessel_credits': my_free_vessel_credits,
            'total_vessel_credits': my_total_vessel_credits,
            'remove_summary': remove_summary
        })
Esempio n. 2
0
def myvessels(request, get_form=False, action_summary="", action_detail="", remove_summary=""):
  try:
    user = _validate_and_get_geniuser(request)
  except LoggedInButFailedGetGeniUserError:
    return _show_failed_get_geniuser_page(request)
  
  # get_form of None means don't show the form to acquire vessels.
  if interface.get_available_vessel_credits(user) == 0:
    get_form = None
  elif get_form is False:
    get_form = forms.gen_get_form(user)

  # shared vessels that are used by others but which belong to this user (TODO)
  shvessels = []

  # this user's used vessels
  my_vessels_raw = interface.get_acquired_vessels(user)
  my_vessels = interface.get_vessel_infodict_list(my_vessels_raw)
  
  # this user's number of donations, max vessels, total vessels and free credits
  my_donations = interface.get_donations(user)
  my_max_vessels = interface.get_available_vessel_credits(user)	
  my_free_vessel_credits = interface.get_free_vessel_credits_amount(user)
  my_total_vessel_credits = interface.get_total_vessel_credits(user)

  for vessel in my_vessels:
    if vessel["expires_in_seconds"] <= 0:
      # We shouldn't ever get here, but just in case, let's handle it.
      vessel["expires_in"] = "Expired"
    else:
      days = vessel["expires_in_seconds"] / (3600 * 24)
      hours = vessel["expires_in_seconds"] / 3600 % 24
      minutes = vessel["expires_in_seconds"] / 60 % 60
      vessel["expires_in"] = "%dd %dh %dm" % (days, hours, minutes)

  # return the used resources page constructed from a template
  return direct_to_template(request, 'control/myvessels.html',
                            {'username' : user.username,
                             'num_vessels' : len(my_vessels),
                             'my_vessels' : my_vessels,
                             'sh_vessels' : shvessels,
                             'get_form' : get_form,
                             'action_summary' : action_summary,
                             'action_detail' : action_detail,
                             'my_donations' : len(my_donations),
                             'my_max_vessels' : my_max_vessels, 
                             'free_vessel_credits' : my_free_vessel_credits,
                             'total_vessel_credits' : my_total_vessel_credits,
                             'remove_summary' : remove_summary})
Esempio n. 3
0
# Make sure the private key was created because we didn't provide a pubkey when
# creating the user.
privkey = interface.get_private_key(geniuser)

if privkey is None:
  testfailed("private key wasn't created")

# Delete the private key and make sure it gets deleted.
interface.delete_private_key(geniuser)

privkey = interface.get_private_key(geniuser)
if privkey is not None:
  testfailed("private key wasn't deleted: " + str(privkey))

# Make sure they don't have any donations initially.
donations = interface.get_donations(geniuser)
if len(donations) > 0:
  testfailed("The user shouldn't have any donations.")

INITIAL_DONATION_COUNT = 6

# Create a few nodes and donations by this user.
for i in range(INITIAL_DONATION_COUNT):
  node_identifier = 'testnode' + username + str(i)
  extra_vessel_name = 'v2'
  ip = '127.0.' + str(i) + '.0'
  node = maindb.create_node(node_identifier, ip, 1234, '0.1a', True, 'the owner pubkey', extra_vessel_name)
  maindb.create_donation(node, geniuser, 'some resource description text')
  # Create the vessels on these nodes.
  name = 'testvessel' + username + str(i)
  vessel = maindb.create_vessel(node, name)