# Path: dropbeat/exceptions.py
# class UserException(DropbeatException):
#     pass
# 
# class TrackException(DropbeatException):
#     pass
# 
# class PlaylistException(DropbeatException):
#     pass
# 
# Path: dropbeat/constants.py
# class ErrorCode:
#     """Error codes for HTTP response.
# 
#     """
#     DUPLICATED_EMAIL = '100'
#     INVALID_EMAIL = '101'
#     PASSWORD_TOO_SHORT = '102'
#     EMAIL_NOT_EXIST = '103'
#     PASSWORD_MISMATCH = '104'
#     DUPLICATED_PLAYLIST_NAME = '105'
#     TRACK_ALREADY_EXIST = '106'
#     PLAYLIST_NOT_EXIST = '107'
#     TRACK_NOT_EXIST = '108'
#     RESULT_NOT_READY = '109'
#     INVALID_ACCESS = '110'
# 
# class TrackSource(ChoiceEnum):
#     """Streaming source of track.
# 
#     """
#     youtube = 0
#     soundcloud = 1


import hashlib
import datetime
from dropbeat.exceptions import (
    UserException, TrackException, PlaylistException)
from dropbeat.constants import ErrorCode, TrackSource
from django.db import models, IntegrityError
from django.core.validators import validate_email
from django.core.exceptions import ValidationError, ObjectDoesNotExist
from django.contrib.auth.models import BaseUserManager

        try:
            user = self.model(email=email)
            user.set_password(password)
            user.save(using=self._db)
        except IntegrityError:
            raise UserException(ErrorCode.DUPLICATED_EMAIL)

        return user


class PlaylistManager(models.Manager):
    def fetch_all_uids(self, user):
        """Returns list of playlist uids.

        """
        return [x.uid for x in self.filter(user=user)]

    def fetch_playlist(self, user, uid):
        """This method only wraps django exception to ours.

        """
        try:
            return self.get(user=user, uid=uid)
        except ObjectDoesNotExist:
            raise PlaylistException(ErrorCode.PLAYLIST_NOT_EXIST)

    def create_playlist(self, user, name):
        # Hash email + current server time.
        if self.filter(user=user, name=name).exists():

# Path: dropbeat/exceptions.py
# class UserException(DropbeatException):
#     pass
# 
# class TrackException(DropbeatException):
#     pass
# 
# class PlaylistException(DropbeatException):
#     pass
# 
# Path: dropbeat/constants.py
# class ErrorCode:
#     """Error codes for HTTP response.
# 
#     """
#     DUPLICATED_EMAIL = '100'
#     INVALID_EMAIL = '101'
#     PASSWORD_TOO_SHORT = '102'
#     EMAIL_NOT_EXIST = '103'
#     PASSWORD_MISMATCH = '104'
#     DUPLICATED_PLAYLIST_NAME = '105'
#     TRACK_ALREADY_EXIST = '106'
#     PLAYLIST_NOT_EXIST = '107'
#     TRACK_NOT_EXIST = '108'
#     RESULT_NOT_READY = '109'
#     INVALID_ACCESS = '110'
# 
# class TrackSource(ChoiceEnum):
#     """Streaming source of track.
# 
#     """
#     youtube = 0
#     soundcloud = 1


# Path: dropbeat/managers.py
import hashlib
import datetime
from dropbeat.exceptions import (
    UserException, TrackException, PlaylistException)
from dropbeat.constants import ErrorCode, TrackSource
from django.db import models, IntegrityError
from django.core.validators import validate_email
from django.core.exceptions import ValidationError, ObjectDoesNotExist
from django.contrib.auth.models import BaseUserManager


        try:
            user = self.model(email=email)
            user.set_password(password)
            user.save(using=self._db)
        except IntegrityError:
            raise UserException(ErrorCode.DUPLICATED_EMAIL)

        return user


class PlaylistManager(models.Manager):
    def fetch_all_uids(self, user):
        """Returns list of playlist uids.

        """
        return [x.uid for x in self.filter(user=user)]

    def fetch_playlist(self, user, uid):
        """This method only wraps django exception to ours.

        """
        try:
            return self.get(user=user, uid=uid)
        except ObjectDoesNotExist:
            raise PlaylistException(ErrorCode.PLAYLIST_NOT_EXIST)

    def create_playlist(self, user, name):
        # Hash email + current server time.
        if self.filter(user=user, name=name).exists():

            raise PlaylistException(ErrorCode.DUPLICATED_PLAYLIST_NAME)