import json
import random
import uuid
import zipfile

from django import forms
from django.conf import settings
from django.core.cache import cache
from django.db.models import Q
from django.utils.translation import ugettext

import olympia.core.logger

from olympia import amo
from olympia.lib.cache import memoize, memoize_key
from olympia.amo.utils import normalize_string
from olympia.constants.categories import CATEGORIES_BY_ID
from olympia.discovery.utils import call_recommendation_server
from olympia.translations.fields import LocaleList, LocaleValidationError


log = olympia.core.logger.getLogger('z.redis')


def generate_addon_guid():
    return '{%s}' % str(uuid.uuid4())


def clear_get_featured_ids_cache(*args, **kwargs):
    cache_key = memoize_key('addons:featured', *args, **kwargs)
    cache.delete(cache_key)


@memoize('addons:featured', timeout=60 * 10)
def get_featured_ids(app=None, lang=None, type=None, types=None):
    from olympia.addons.models import Addon
    ids = []
    is_featured = Q(collections__featuredcollection__isnull=False)
    if app:
        is_featured &= Q(collections__featuredcollection__application=app.id)