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


Python Group.creator方法代码示例

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


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

示例1: register

# 需要导入模块: from tendenci.apps.user_groups.models import Group [as 别名]
# 或者: from tendenci.apps.user_groups.models.Group import creator [as 别名]

#.........这里部分代码省略.........
    ``form``
        The registration form.

    Any extra variables supplied in the ``extra_context`` argument
    (see above).

    **Template:**

    registration/registration_form.html or ``template_name`` keyword
    argument.

    """
    # check if this site allows self registration, if not, redirect to login page
    allow_self_registration = get_setting('module', 'users', 'selfregistration')
    if not allow_self_registration:
        return HttpResponseRedirect(reverse('auth_login'))

    form_params = {}
    if request.session.get('form_params', None):
        form_params = request.session.pop('form_params')

    if request.method == 'POST':
        form = form_class(data=request.POST, files=request.FILES, **form_params)
        if form.is_valid():
            # This is for including a link in the reg email back to the event viewed
            event = None
            if event_id: # the user signed up via an event
                from tendenci.apps.events.models import Event
                event = get_object_or_404(Event, pk=event_id)

            new_user = form.save(profile_callback=profile_callback, event=event)
            # success_url needs to be dynamically generated here; setting a
            # a default value using reverse() will cause circular-import
            # problems with the default URLConf for this application, which
            # imports this file.

            # add to the default group(s)
            default_user_groups =[g.strip() for g in (get_setting('module', 'users', 'defaultusergroup')).split(',')]
            if default_user_groups:
                from tendenci.apps.user_groups.models import Group, GroupMembership
                from django.db.models import Q
                for group_name in default_user_groups:
                    groups = Group.objects.filter(Q(name=group_name) | Q(label=group_name)).filter(allow_self_add=1, status=1, status_detail='active')
                    if groups:
                        group = groups[0]
                    else:
                        # group doesnot exist, so create the group
                        group = Group()
                        group.name  = group_name
                        group.label = group_name
                        group.type = 'distribution'
                        group.show_as_option = 1
                        group.allow_self_add = 1
                        group.allow_self_remove = 1
                        group.creator = new_user
                        group.creator_username = new_user.username
                        group.owner =  new_user
                        group.owner_username = new_user.username
                        try:
                            group.save()
                        except:
                            group = None

                    if group:
                        gm = GroupMembership()
                        gm.group = group
                        gm.member = new_user
                        gm.creator_id = new_user.id
                        gm.creator_username = new_user.username
                        gm.owner_id =  new_user.id
                        gm.owner_username = new_user.username
                        gm.save()


            EventLog.objects.log(instance=new_user)

            return HttpResponseRedirect(success_url or reverse('registration_complete'))
        elif form.similar_email_found:
            messages.add_message(
                request, messages.INFO,
                _(u"An account already exists for the email %(email)s." % {
                    'email': request.POST.get('email_0') or request.POST.get('email_1')}))

            querystring = 'registration=True'
            return HttpResponseRedirect(reverse('auth_password_reset')+ "?%s" % querystring)

    else:
        allow_same_email = request.GET.get('registration_approved', False)
        form_params = {'allow_same_email' : allow_same_email }
        request.session['form_params'] = form_params
        form = form_class(**form_params)

    if extra_context is None:
        extra_context = {}
    context = RequestContext(request)
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value
    return render_to_response(template_name,
                              { 'form': form },
                              context_instance=context)
开发者ID:BIGGANI,项目名称:tendenci,代码行数:104,代码来源:views.py

示例2: save_model

# 需要导入模块: from tendenci.apps.user_groups.models import Group [as 别名]
# 或者: from tendenci.apps.user_groups.models.Group import creator [as 别名]
    def save_model(self, request, object, form, change):
        instance = form.save(commit=False)

        # save the expiration method fields
        type_exp_method = form.cleaned_data["type_exp_method"]
        type_exp_method_list = type_exp_method.split(",")
        for i, field in enumerate(form.type_exp_method_fields):
            if field == "fixed_option2_can_rollover":
                if type_exp_method_list[i] == "":
                    type_exp_method_list[i] = ""
            else:
                if type_exp_method_list[i] == "":
                    type_exp_method_list[i] = "0"

            setattr(instance, field, type_exp_method_list[i])

        if not change:
            instance.creator = request.user
            instance.creator_username = request.user.username
            instance.owner = request.user
            instance.owner_username = request.user.username

            # create a group for this type
            group = Group()
            group.name = "Membership: %s" % instance.name
            group.slug = slugify(group.name)
            # just in case, check if this slug already exists in group.
            # if it does, make a unique slug
            tmp_groups = Group.objects.filter(slug__istartswith=group.slug)
            if tmp_groups:
                t_list = [g.slug[len(group.slug) :] for g in tmp_groups]
                num = 1
                while str(num) in t_list:
                    num += 1
                group.slug = "%s%s" % (group.slug, str(num))
                # group name is also a unique field
                group.name = "%s%s" % (group.name, str(num))

            group.label = instance.name
            group.type = "system_generated"
            group.email_recipient = request.user.email
            group.show_as_option = 0
            group.allow_self_add = 0
            group.allow_self_remove = 0
            group.description = "Auto-generated with the membership type. Used for membership only"
            group.notes = "Auto-generated with the membership type. Used for membership only"
            # group.use_for_membership = 1
            group.creator = request.user
            group.creator_username = request.user.username
            group.owner = request.user
            group.owner_username = request.user.username

            group.save()

            instance.group = group

        # save the object
        instance.save()

        # form.save_m2m()

        return instance
开发者ID:simonqiang,项目名称:tendenci,代码行数:64,代码来源:admin.py

示例3: authenticate

# 需要导入模块: from tendenci.apps.user_groups.models import Group [as 别名]
# 或者: from tendenci.apps.user_groups.models.Group import creator [as 别名]
    def authenticate(self, *args, **kwargs):
        """Authenticate user using social credentials

        Authentication is made if this is the correct backend, backend
        verification is made by kwargs inspection for current backend
        name presence.
        """
        # Validate backend and arguments. Require that the Social Auth
        # response be passed in as a keyword argument, to make sure we
        # don't match the username/password calling conventions of
        # authenticate.
        if not (self.name and kwargs.get(self.name) and 'response' in kwargs):
            return None

        response = kwargs.get('response')
        request = kwargs.get('request')
        details = self.get_user_details(response)
        uid = self.get_user_id(details, response)
        is_new = False
        try:
            social_user = UserSocialAuth.objects.select_related('user')\
                                                .get(provider=self.name,
                                                     uid=uid)
        except UserSocialAuth.DoesNotExist:
            user = kwargs.get('user')
            if user is None:  # new user
                if not CREATE_USERS:
                    return None

                email = details.get('email')
                if email and ASSOCIATE_BY_MAIL:
                    # try to associate accounts registered with the same email
                    # address, only if it's a single object. ValueError is
                    # raised if multiple objects are returned
                    try:
                        user = User.objects.get(email=email)
                    except MultipleObjectsReturned:
                        raise ValueError('Not unique email address supplied')
                    except User.DoesNotExist:
                        user = None
                if not user:
                    username = self.username(details)
                    user = User.objects.create_user(username=username,
                                                    email=email)
                    is_new = True
                    default_user_groups =[g.strip() for g in (get_setting('module', 'users', 'defaultusergroup')).split(',')]
                    if default_user_groups:
                        from tendenci.apps.user_groups.models import Group, GroupMembership
                        from django.db.models import Q
                        for group_name in default_user_groups:
                            groups = Group.objects.filter(Q(name=group_name) | Q(label=group_name)).filter(allow_self_add=1, status=1, status_detail='active')
                            if groups:
                                group = groups[0]
                            else:
                                # group doesnot exist, so create the group
                                group = Group()
                                group.name  = group_name
                                group.label = group_name
                                group.type = 'distribution'
                                group.show_as_option = 1
                                group.allow_self_add = 1
                                group.allow_self_remove = 1
                                group.creator = user
                                group.creator_username = user.username
                                group.owner =  user
                                group.owner_username = user.username
                                try:
                                    group.save()
                                except:
                                    group = None
                                
                            if group:
                                gm = GroupMembership()
                                gm.group = group
                                gm.member = user
                                gm.creator_id = user.id
                                gm.creator_username = user.username
                                gm.owner_id =  user.id
                                gm.owner_username = user.username
                                gm.save()
                    log_defaults = {
                        'event_id' : 121000,
                        'event_data': '%s (%d) self added by form' % (user._meta.object_name, user.pk),
                        'description': '%s self added' % user._meta.object_name,
                        'user': user,
                        'request': request,
                        'instance': user,
                    }
                    EventLog.objects.log(**log_defaults)
            social_user = self.associate_auth(user, uid, response, details)
        else:
            # This account was registered to another user, so we raise an
            # error in such case and the view should decide what to do on
            # at this moment, merging account is not an option because that
            # would imply update user references on other apps, that's too
            # much intrusive
            if 'user' in kwargs and kwargs['user'] != social_user.user:
                raise ValueError('Account already in use.', social_user)
            user = social_user.user

#.........这里部分代码省略.........
开发者ID:a2call,项目名称:tendenci,代码行数:103,代码来源:__init__.py


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