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))
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))
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))
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
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
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), ))
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)
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
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))
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 )
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
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()
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, )
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, )
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)
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)
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))
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))
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