当前位置: 首页>>代码示例>>Python>>正文


Python Member.organisation方法代码示例

本文整理汇总了Python中members.models.Member.organisation方法的典型用法代码示例。如果您正苦于以下问题:Python Member.organisation方法的具体用法?Python Member.organisation怎么用?Python Member.organisation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在members.models.Member的用法示例。


在下文中一共展示了Member.organisation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upload_file

# 需要导入模块: from members.models import Member [as 别名]
# 或者: from members.models.Member import organisation [as 别名]
def upload_file(request):
    """Creates a view to upload a file and read the contents, if the uploaded file is\
    a zip file, file is first extracted and read. the file is read and updates the data\
    to database. if the corresponding group is not present, a new group is created and updated."""
    x = {}
    y = []
    s = []
    if request.method == "POST":
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            title = form.files["file"]
            filename = str(title)
            x = request.FILES
            front = filename.split(".")[0]
            if filename.endswith(".zip"):
                zipf = zipfile.ZipFile(x["file"])
                zipf.extractall(os.getcwd())
            else:
                y = x["file"].read()
            z = "" + front + ".xlsx"
            path = default_storage.save(z, ContentFile(y))
            tmp_file = os.path.join(settings.MEDIA_ROOT, path)
            if form.is_valid():
                workbook = xlrd.open_workbook(z)
                sh = workbook.sheet_by_name("Sheet1")
                for rownum in range(sh.nrows):
                    member = Member()
                    member.firstname = sh.row_values(rownum)[0]
                    member.lastname = sh.row_values(rownum)[1]
                    member.dob = sh.row_values(rownum)[2]
                    member.gender = sh.row_values(rownum)[3]
                    member.organisation = sh.row_values(rownum)[4]
                    member.email = sh.row_values(rownum)[5]
                    code = str(sh.row_values(rownum)[6])
                    group, status = Group.objects.get_or_create(group_code=code)
                    member.group = group
                    member.save()

                os.chdir(os.getcwd())
                files = glob.glob("*.xlsx")
                for filename in files:
                    os.unlink(filename)
            return HttpResponseRedirect(reverse("index"))
    else:
        form = UploadFileForm()
    return render(request, "contacts/read.html", {"form": form})
开发者ID:sreekanthkaralmanna,项目名称:Manage-Contacts,代码行数:48,代码来源:views.py

示例2: member

# 需要导入模块: from members.models import Member [as 别名]
# 或者: from members.models.Member import organisation [as 别名]
def member(request):
    """Creates a view to add members to database, if the group code exists,\
    add the user to that group or else create a new group and save."""
    members = Member.objects.all()
    groups = Group.objects.all()
    if request.method == "POST":
        form = MemberForm(request.POST)
        if form.is_valid():
            firstname = form.cleaned_data["firstname"]
            lastname = form.cleaned_data["lastname"]
            dob = form.cleaned_data["dob"]
            gender = form.cleaned_data["gender"]
            organisation = form.cleaned_data["organisation"]
            email = form.cleaned_data["email"]
            options = request.POST.getlist("group")
            new_code = request.POST["new_group"]
            name = request.POST["name"]
            description = request.POST["description"]
            try:
                member = Member()
                member.firstname = firstname
                member.lastname = lastname
                member.dob = dob
                member.gender = gender
                member.organisation = organisation
                member.email = request.POST["email"]
                grp_codes = [str(x) for x in options]
                for cd in grp_codes:
                    if cd:
                        gr = Group.objects.get(group_code=cd)
                        member.group = gr
                g, status = Group.objects.get_or_create(group_code=new_code)
                g.name = name
                g.description = description
                member.group = g
                member.save()
            except:
                pass
            return HttpResponseRedirect(reverse("index"))
    else:
        form = MemberForm()
    context = {"members": members, "groups": groups, "form": form}
    return render(request, "members/member.html", context)
开发者ID:sreekanthkaralmanna,项目名称:Manage-Contacts,代码行数:45,代码来源:views.py

示例3: done

# 需要导入模块: from members.models import Member [as 别名]
# 或者: from members.models.Member import organisation [as 别名]
  def done(self, fl, form_dict, **kwargs):
    self.request.breadcrumbs( ( 
				('registration','/reg/'),
                            ) )

    done_title = settings.TEMPLATE_CONTENT['reg']['register']['done']['title']
    done_template = settings.TEMPLATE_CONTENT['reg']['register']['done']['template']
    error_template = settings.TEMPLATE_CONTENT['reg']['register']['done']['error_template']
    email_template = settings.TEMPLATE_CONTENT['reg']['register']['done']['email_template']

    m_id = gen_member_id()

    M = lvl = O = A = U = D = Gs = None
    Us = []

    ty = None
    if self.kwargs: 
      for item in Member.MEMBER_TYPES: 
        if unicode(item[1]) == unicode(self.kwargs['type']):
          ty = int(item[0])
    else: 
      t_f = form_dict['type']
      ty = int(t_f.cleaned_data['member_type'])

    a_f = form_dict['address']
    h_f = form_dict['head']
    if a_f.is_valid() and h_f.is_valid():
      A = a_f.save()
      U = h_f.save()
      #role for hol
      Ro = Role(title="Head of List",user=U)
      Ro.save()
      #organisation
      if ty == Member.ORG:
        var = a_f.cleaned_data
        o = a_f.cleaned_data['organisation']
        O = Organisation(name=o,address=A)
        O.save()
  
        #get nb of users
        lvl = int(h_f.cleaned_data['more'])+1 #add one for head-of-list

        # delegate
        delegate = h_f.cleaned_data['delegate']
        if delegate:
          d_f = form_dict['delegate']
          if d_f.is_valid():
            D = d_f.save()
            D.save()

            #role for delegate
            Ro = Role(title="Delegate",user=D)
            Ro.save()

        #all users for ORG type
        mu_fs = form_dict['more']
        if mu_fs.is_valid():
          for u in mu_fs:
            if u.is_valid() and u.has_changed(): 
              if u.cleaned_data['email']:
                user = u.save(commit=False)
                user.username = gen_username(user.first_name,user.last_name)
                user.is_active = False
                user.password = make_password(gen_random_password())
                user.save()
                Us.append(user)


      #student
      if ty == Member.STD:
        sp_f = form_dict['student_proof']
        if sp_f.is_valid():
          M = sp_f.save(commit=False)
          M.pk=m_id
          M.type=ty

      if M == None: M = Member(pk=m_id,type=ty)

      # if of type org, add organisation to Member model
      if ty == Member.ORG: M.organisation = O

      # add address and head_of_list to Member model
      M.address=A
      M.head_of_list=U

      #set the level (number of users) for ORG type
      if lvl: M.lvl=lvl

      # add delegate if exists
      if D != None: M.delegate=D

      # add member_type if in alt mode
      M.type = ty

      # save Member model
      M.save()
      # add all Users for ORG type
      if Us != []: M.users=Us

      reg_hash_code = gen_hash(settings.REG_SALT,M.head_of_list.email,15,M.address)
#.........这里部分代码省略.........
开发者ID:psteichen,项目名称:clusil-intranet,代码行数:103,代码来源:views.py


注:本文中的members.models.Member.organisation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。