示例#1
0
 def clean(self):
     User = get_user_model()
     try:
         self.apply(User.objects.all())
     except Exception as e:
         raise ValidationError('%s raised trying to apply rule: %s' %
                               (type(e).__name__, e))
示例#2
0
文件: tests.py 项目: kishan3/castcore
    def setUp(self):
        """
        Creates 20 users, half of which buy 25 credits a day,
        and the other half that does none.
        """
        self.User = get_user_model()

        start = timezone.now() - timedelta(hours=2)
        num_string = [
            'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh',
            'eighth', 'ninth', 'tenth'
        ]

        for i, name in enumerate(num_string):
            user = self.User.objects.create(username='******' %
                                            name,
                                            email='*****@*****.**' % name)
            self.User.objects.filter(id=user.id).update(date_joined=start -
                                                        timedelta(days=i))

            profile = Profile.objects.get(user=user)
            profile.credits = i * 25
            profile.save()

        for i, name in enumerate(num_string):
            user = self.User.objects.create(username='******' % name,
                                            email='*****@*****.**' % name)
            self.User.objects.filter(id=user.id).update(date_joined=start -
                                                        timedelta(days=i))
示例#3
0
 def clean(self):
     User = get_user_model()
     try:
         self.apply(User.objects.all())
     except Exception as e:
         raise ValidationError(
             '%s raised trying to apply rule: %s' % (type(e).__name__, e))
示例#4
0
    def get_urls(self):
        urls = super(DripAdmin, self).get_urls()
        my_urls = [
            path('<int:drip_id>/timeline/<int:into_past>/<int:into_future>/',
                 self.av(self.timeline),
                 name='drip_timeline'),
        ]

        User = get_user_model()
        if User._meta.get_field('id').get_internal_type() == 'UUIDField':
            my_urls += [
                path(
                    '<int:drip_id>/timeline/<int:into_past>/<int:into_future>/<uuid:user_id>/',  # noqa
                    self.av(self.view_drip_email),
                    name='view_drip_email',
                ),
            ]
        else:
            my_urls += [
                path(
                    '<int:drip_id>/timeline/<int:into_past>/<int:into_future>/<int:user_id>/',  # noqa
                    self.av(self.view_drip_email),
                    name='view_drip_email',
                ),
            ]

        return my_urls + urls
示例#5
0
 def build_extra_context(self, extra_context):
     extra_context = extra_context or {}
     User = get_user_model()
     if not self.users_fields:
         self.users_fields = json.dumps(get_simple_fields(User))
     extra_context['field_data'] = self.users_fields
     return extra_context
示例#6
0
 def clean(self):
     User = get_user_model()
     try:
         self.apply(User.objects.all())
     except Exception as e:
         raise ValidationError(
             '{type_name} raised trying to apply rule: {error}'.format(
                 type_name=type(e).__name__,
                 error=str(e),
             ))
示例#7
0
    def view_drip_email(self, request, drip_id, into_past, into_future,
                        user_id):

        drip = get_object_or_404(Drip, id=drip_id)
        User = get_user_model()
        user = get_object_or_404(User, id=user_id)

        html, mime = self.get_mime_html(drip, user)

        return HttpResponse(html, content_type=mime)
示例#8
0
    def queryset(self):
        """
        Returns a queryset of auth.User who meet the
        criteria of the drip.

        Alternatively, you could create Drips on the fly
        using a queryset builder from the admin interface...
        """
        User = get_user_model()
        return User.objects
示例#9
0
    def queryset(self):
        """
        Returns a queryset of auth.User who meet the
        criteria of the drip.

        Alternatively, you could create Drips on the fly
        using a queryset builder from the admin interface...
        """
        User = get_user_model()
        return User.objects
示例#10
0
 def clean(self):
     if self.drip.base_model:
         model = get_model( *self.drip.base_model.split('.',1))
     else:
         model = get_user_model()
     try:
         self.apply(model.objects.all())
     except Exception as e:
         raise ValidationError(
             '%s raised trying to apply rule: %s' % (type(e).__name__, e))
示例#11
0
    def setUp(self):
        self.User = get_user_model()

        self.old_msg_classes = getattr(settings, "DRIP_MESSAGE_CLASSES", None)
        self.user = self.User.objects.create(username="******", email="*****@*****.**")
        self.model_drip = Drip.objects.create(
            name="A Custom Week Ago",
            subject_template="HELLO {{ user.username }}",
            body_html_template="<h2>This</h2> is an <b>example</b> html <strong>body</strong>.",
        )
        QuerySetRule.objects.create(
            drip=self.model_drip, field_name="id", lookup_type="exact", field_value=self.user.id
        )
示例#12
0
    def queryset(self):
        """
        Returns a queryset of auth.User who meet the
        criteria of the drip.

        Alternatively, you could create Drips on the fly
        using a queryset builder from the admin interface...
        """

        if self.drip_model.base_model:
            from django.db.models.loading import get_model
            model = get_model( *self.drip_model.base_model.split('.',1))
            return model.objects
        else:
            return get_user_model().objects
示例#13
0
    def queryset(self):
        """
        Returns a queryset of auth.User who meet the
        criteria of the drip.

        Alternatively, you could create Drips on the fly
        using a queryset builder from the admin interface...
        """
        User = get_user_model()
        try:
            # Want to apply extra filter in User Model?
            # then add new queryset filter with named "can_drip_send_email" to restrict the user set
            qs = User.objects.can_drip_send_email()
        except Exception, e:
            qs = User.objects.all()
示例#14
0
    def setUp(self):
        self.User = get_user_model()

        self.old_msg_classes = getattr(settings, 'DRIP_MESSAGE_CLASSES', None)
        self.user = self.User.objects.create(username='******', email='*****@*****.**')
        self.model_drip = Drip.objects.create(
            name='A Custom Week Ago',
            subject_template='HELLO {{ user.username }}',
            body_html_template='<h2>This</h2> is an <b>example</b> html <strong>body</strong>.'
        )
        QuerySetRule.objects.create(
            drip=self.model_drip,
            field_name='id',
            lookup_type='exact',
            field_value=self.user.id,
        )
示例#15
0
文件: tests.py 项目: kishan3/castcore
    def setUp(self):
        self.User = get_user_model()

        self.old_msg_classes = getattr(settings, 'DRIP_MESSAGE_CLASSES', None)
        self.user = self.User.objects.create(username='******',
                                             email='*****@*****.**')
        self.model_drip = Drip.objects.create(
            name='A Custom Week Ago',
            subject_template='HELLO {{ user.username }}',
            body_html_template=
            '<h2>This</h2> is an <b>example</b> html <strong>body</strong>.')
        QuerySetRule.objects.create(
            drip=self.model_drip,
            field_name='id',
            lookup_type='exact',
            field_value=self.user.id,
        )
示例#16
0
    def view_drip_email(self, request, drip_id, into_past, into_future, user_id):
        from django.shortcuts import get_object_or_404
        from django.http import HttpResponse
        drip = get_object_or_404(Drip, id=drip_id)
        User = get_user_model()
        user = get_object_or_404(User, id=user_id)

        drip_message = message_class_for(drip.message_class)(drip.drip, user)
        html = ''
        mime = ''
        if drip_message.message.alternatives:
            for body, mime in drip_message.message.alternatives:
                if mime == 'text/html':
                    html = body
                    mime = 'text/html'
        else:
            html = drip_message.message.body
            mime = 'text/plain'

        return HttpResponse(html, content_type=mime)
示例#17
0
    def view_drip_email(self, request, drip_id, into_past, into_future, user_id):
        from django.shortcuts import render, get_object_or_404
        from django.http import HttpResponse
        drip = get_object_or_404(Drip, id=drip_id)
        User = get_user_model()
        user = get_object_or_404(User, id=user_id)

        drip_message = message_class_for(drip.message_class)(drip.drip, user)
        html = ''
        mime = ''
        if drip_message.message.alternatives:
            for body, mime in drip_message.message.alternatives:
                if mime == 'text/html':
                    html = body
                    mime = 'text/html'
        else:
            html = drip_message.message.body
            mime = 'text/plain'

        return HttpResponse(html, content_type=mime)
示例#18
0
    def prune(self):
        """
        Do an exclude for all Users who have a SentDrip already.
        """

        if self.drip_model.user_field:
            target_user_ids = self.get_queryset().values_list('%s__id' % self.drip_model.user_field, flat=True)
        else:
            target_user_ids = self.get_queryset().values_list('id', flat=True)

        exclude_user_ids = SentDrip.objects.filter(date__lt=conditional_now(),
                                                   drip=self.drip_model,
                                                   user__id__in=target_user_ids)\
                                           .values_list('user_id', flat=True)
        self._queryset = self.get_queryset().exclude(id__in=exclude_user_ids)


        # convert linked field back to user model
        if self.drip_model.user_field:
            self._queryset = get_user_model().objects.filter(id__in=self.get_queryset().values_list(self.drip_model.user_field, flat=True))
示例#19
0
    def setUp(self):
        """
        Creates 20 users, half of which buy 25 credits a day,
        and the other half that does none.
        """
        self.User = get_user_model()

        start = timezone.now() - timedelta(hours=2)
        num_string = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth"]

        for i, name in enumerate(num_string):
            user = self.User.objects.create(username="******" % name, email="*****@*****.**" % name)
            self.User.objects.filter(id=user.id).update(date_joined=start - timedelta(days=i))

            profile = Profile.objects.get(user=user)
            profile.credits = i * 25
            profile.save()

        for i, name in enumerate(num_string):
            user = self.User.objects.create(username="******" % name, email="*****@*****.**" % name)
            self.User.objects.filter(id=user.id).update(date_joined=start - timedelta(days=i))
示例#20
0
 def build_extra_context(self, extra_context):
     from drip.utils import get_simple_fields
     extra_context = extra_context or {}
     User = get_user_model()
     extra_context['field_data'] = json.dumps(get_simple_fields(User))
     return extra_context
示例#21
0
 def build_extra_context(self, extra_context):
     from drip.utils import get_simple_fields
     extra_context = extra_context or {}
     User = get_user_model()
     extra_context['field_data'] = json.dumps(get_simple_fields(User))
     return extra_context