Пример #1
0
 def save(self, *args, **kwargs):
     """Save latest presentation date in related talk if instance is later
     than current latest presentation date."""
     try:
         delta = self.presentation_date - self.talk.latest_presentation_date
         assert delta < datetime.timedelta(0)
     except:
         self.talk.latest_presentation_date = self.presentation_date
         self.talk.save()
     super(Presentation, self).save(*args, **kwargs)
Пример #2
0
class ShopUser(AbstractUser):
    SEX_MALE = 'male'
    SEX_FEMALE = 'female'
    SEX_CAT = 'cat'
    SEX_CHOICE = (
        {SEX_MALE: 'Мужской'},
        {SEX_FEMALE: 'Женский'},
        {SEX_CAT: 'Кот'}
    )
    avatar = models.ImageField(upload_to='users_avatars', blank=True)
    age = models.PositiveIntegerField(verbose_name = 'возраст', default=18)
    sex = models.CharField(max_length = 6, choices=SEX_CHOICE, default= SEX_CAT)

    activation_key = models.CharField(max_length=128, blank=True)
    activation_key_expires = models.DateTimeField(default = datetime.now() + datetime.timedelta(hours=12))

    def is_activation_key_expires(self):
        if datetime.now(pytz.timezone(settings.TIME_ZONE)) < self.activation_key_expires:
            return False
        else:
            return True
Пример #3
0
def user_confirm(request):
    code = request.GET.get('code', None)
    message = ''

    try:
        confirm = models.ConfirmString.objects.get(code=code)
    except:
        message = '无效的确认请求!'
        return render(request, 'login/confirm.html', locals())

    c_time = confirm.c_time
    now = datetime.datetime.now()
    if now > c_time + datetime.timedelta(settings.CONFIRM_DAYS):
        confirm.user.delete()
        message = '您的邮件已经过期!请重新注册!'
        return render(request, 'login/confirm.html', locals())
    else:
        confirm.user.has_confirmed = True
        confirm.user.save()
        confirm.delete()
        message = '感谢确认,请使用账户登录!'
        return render(request, 'login/confirm.html', locals())
 def was_published_recently(self):
     return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
Пример #5
0
 def recently_registred(self):
     return self.register_date >= timezone.now() - datetime.timedelta(
         days=1)
Пример #6
0
 def was_published_recently(self):
     now = timezone.now()
     return now - datetime.timedelta(days=1) <= self.load_time <= now