def edit_share(request):

  return_dict = {}
  try:
    user_list = samba_settings.get_user_list()
    group_list = samba_settings.get_group_list()
  
    if request.method == "GET":
      # Shd be an edit request
      if "share_id" not in request.GET:
        return_dict["error"] = "Unknown share specified"
        return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request))
      share_id = request.GET["share_id"]
      try :
        share_dict = samba_settings.load_share_info("by_id", share_id)
        valid_users_list = samba_settings.load_valid_users_list(share_dict["share_id"])
      except Exception, e:
        return_dict["error"] = "Error loading share information - %s" %e
        return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request))
  
      # Set initial form values
      initial = {}
      initial["share_id"] = share_dict["share_id"]
      initial["name"] = share_dict["name"]
      initial["path"] = share_dict["path"]
      initial["display_path"] = share_dict["display_path"]
      if share_dict["guest_ok"]:
        initial["guest_ok"] = True
      else:
        initial["guest_ok"] = False
      if share_dict["browseable"]:
        initial["browseable"] = True
      else:
        initial["browseable"] = False
      if share_dict["read_only"]:
        initial["read_only"] = True
      else:
        initial["read_only"] = False
      initial["comment"] = share_dict["comment"]
  
      if valid_users_list:
        vgl = []
        vul = []
        for u in valid_users_list:
          if u["grp"]:
            vgl.append(u["name"])
          else:
            vul.append(u["name"])
        initial["users"] = vul
        initial["groups"] = vgl
  
      form = samba_shares_forms.ShareForm(initial = initial, user_list = user_list, group_list = group_list)
  
      return_dict["form"] = form
      return django.shortcuts.render_to_response('edit_share.html', return_dict, context_instance=django.template.context.RequestContext(request))
  
    else:
def view_share(request):

    return_dict = {}
    try:
        template = 'logged_in_error.html'

        if request.method != "GET":
            return_dict[
                "error"] = "Incorrect access method. Please use the menus"

        if "index" not in request.GET or "access_mode" not in request.GET:
            return_dict["error"] = "Unknown share"

        if not "error" in return_dict:

            access_mode = request.GET["access_mode"]
            index = request.GET["index"]

            if "action" in request.GET and request.GET["action"] == "saved":
                return_dict[
                    "conf_message"] = "Information updated successfully"

            valid_users_list = None
            try:
                share = samba_settings.load_share_info(access_mode, index)
                valid_users_list = samba_settings.load_valid_users_list(
                    share["share_id"])
            except Exception, e:
                return_dict[
                    "error"] = "Error retrieving share information - %s" % e
            else:
                if not share:
                    return_dict[
                        "error"] = "Error retrieving share information for  %s" % share_name
                else:
                    return_dict["share"] = share
                    if valid_users_list:
                        return_dict["valid_users_list"] = valid_users_list
                    template = 'view_share.html'

        return django.shortcuts.render_to_response(
            template,
            return_dict,
            context_instance=django.template.context.RequestContext(request))
def view_share(request):

    return_dict = {}
    try:
        template = "logged_in_error.html"

        if request.method != "GET":
            return_dict["error"] = "Incorrect access method. Please use the menus"

        if "index" not in request.GET or "access_mode" not in request.GET:
            return_dict["error"] = "Unknown share"

        if not "error" in return_dict:

            access_mode = request.GET["access_mode"]
            index = request.GET["index"]

            if "action" in request.GET and request.GET["action"] == "saved":
                return_dict["conf_message"] = "Information updated successfully"

            valid_users_list = None
            try:
                share = samba_settings.load_share_info(access_mode, index)
                valid_users_list = samba_settings.load_valid_users_list(share["share_id"])
            except Exception, e:
                return_dict["error"] = "Error retrieving share information - %s" % e
            else:
                if not share:
                    return_dict["error"] = "Error retrieving share information for  %s" % share_name
                else:
                    return_dict["share"] = share
                    if valid_users_list:
                        return_dict["valid_users_list"] = valid_users_list
                    template = "view_share.html"

        return django.shortcuts.render_to_response(
            template, return_dict, context_instance=django.template.context.RequestContext(request)
        )
def edit_share(request):

    return_dict = {}
    try:
        user_list = samba_settings.get_user_list()
        group_list = samba_settings.get_group_list()

        if request.method == "GET":
            # Shd be an edit request
            if "share_id" not in request.GET:
                return_dict["error"] = "Unknown share specified"
                return django.shortcuts.render_to_response(
                    'logged_in_error.html',
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
            share_id = request.GET["share_id"]
            try:
                share_dict = samba_settings.load_share_info("by_id", share_id)
                valid_users_list = samba_settings.load_valid_users_list(
                    share_dict["share_id"])
            except Exception, e:
                return_dict[
                    "error"] = "Error loading share information - %s" % e
                return django.shortcuts.render_to_response(
                    'logged_in_error.html',
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))

            # Set initial form values
            initial = {}
            initial["share_id"] = share_dict["share_id"]
            initial["name"] = share_dict["name"]
            initial["path"] = share_dict["path"]
            initial["display_path"] = share_dict["display_path"]
            if share_dict["guest_ok"]:
                initial["guest_ok"] = True
            else:
                initial["guest_ok"] = False
            if share_dict["browseable"]:
                initial["browseable"] = True
            else:
                initial["browseable"] = False
            if share_dict["read_only"]:
                initial["read_only"] = True
            else:
                initial["read_only"] = False
            initial["comment"] = share_dict["comment"]

            if valid_users_list:
                vgl = []
                vul = []
                for u in valid_users_list:
                    if u["grp"]:
                        vgl.append(u["name"])
                    else:
                        vul.append(u["name"])
                initial["users"] = vul
                initial["groups"] = vgl

            form = samba_shares_forms.ShareForm(initial=initial,
                                                user_list=user_list,
                                                group_list=group_list)

            return_dict["form"] = form
            return django.shortcuts.render_to_response(
                'edit_share.html',
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))

        else: