Пример #1
0
def increment_user_post_count(user):
    # this should be an upsert but django no support :(
    stats = UserStats.objects.filter(user=user)
    rows = stats.update(
        post_count=F('post_count') + 1, modified=datetime.utcnow())
    if rows == 0:
        try:
            UserStats(user=user, post_count=1).save()
        except IntegrityError:
            # TODO recalculate at a later point
            logger.exception(
                "Conflict while incrementing post count for %s",
                user.username)
Пример #2
0
 def __call__(self, value):
     bucket_name, key_name = self.get_bucket_and_key(value)
     if bucket_name is None:
         raise ValidationError(self.message)
     elif bucket_name not in [settings.AWS_BUCKET_UPLOAD]:
         raise ValidationError("Invalid bucket name in URL")
     bucket = boto3.resource('s3', verify=settings.AWS_VERIFY).Bucket(bucket_name)
     key = bucket.Object(key_name)
     try:
         metadata = key.metadata
     except:
         c, v, t = sys.exc_info()
         if isinstance(v, ClientError):
             logger.exception("Invalid key URL")
             raise ValidationError, "Invalid key URL", t
         raise