Esempio n. 1
0
def settings_my_systems(request):
    profile = request.user.get_profile()
    all_categories = Category.list()

    if request.method == 'POST':
        for s in all_categories:
            val = request.POST.get('system-%d' % s.id)
            if val:
                profile.owned_systems.add(s)
            else:
                profile.owned_systems.remove(s)
        profile.save()

    owned_systems = profile.get_owned_systems()
    system_map = {}
    for s in all_categories:
        owned = False
        for os in owned_systems:
            if os.id == s.id:
                owned = True
        system_map[s.slug] = {'id': s.id, 'name': s.description, 'owned': owned}

    systems = [
        system_map['Xbox-Games'],
        system_map['Xbox-360-Games'],
        system_map['GameCube-Games'],
        system_map['Nintendo-DS-Games'],
        system_map['Nintendo-Wii-Games'],
        system_map['PlayStation-2-Games'],
        system_map['Sony-PSP-Games'],
        system_map['PlayStation-3-Games'],
    ]

    return {
        'title': 'My Systems',
        'systems': systems,
    }
def common(request):
    return {"CATALOG_CATEGORIES": Category.list_names(), "DEFAULT_REVIEWS_COUNT": settings.DEFAULT_REVIEWS_COUNT}
Esempio n. 3
0
def personalize_your_games(request):
    if not request.is_ajax():
        return redirect('index')

    profile = request.user.get_profile()
    all_categories = Category.list()

    if request.method == 'POST':
        for s in all_categories:
            val = request.POST.get('system-%d' % s.id)
            if val:
                profile.owned_systems.add(s)
            else:
                profile.owned_systems.remove(s)

        for s in Genre.objects.all():
            val = request.POST.get('genre-%d' % s.id)
            if val:
                profile.favorite_genres.add(s)
            else:
                profile.favorite_genres.remove(s)
        try:
            parental_control = int(request.POST.get('parental_control'))
            if parental_control not in [0, 1, 2, 3, 4]: parental_control = 0
        except:
            parental_control = 0
        profile.parental_control = parental_control

        try:
            parental_control_reviews = int(request.POST.get('parental_control_reviews'))
            if parental_control_reviews not in [0, 1, 2]: parental_control_reviews = 0
        except:
            parental_control_reviews = 0
        profile.parental_control_reviews = parental_control_reviews

        profile.save()
        request.session['just_did_it'] = True
        return JsonResponse({'close': 'true'})

    owned_systems = profile.get_owned_systems()
    system_map = {}
    for s in all_categories:
        owned = False
        for os in owned_systems:
            if os.id == s.id:
                owned = True
        system_map[s.slug] = {'id': s.id, 'name': s.description, 'owned': owned}

    systems = [
        system_map['Xbox-Games'],
        system_map['Xbox-360-Games'],
        system_map['GameCube-Games'],
        system_map['Nintendo-DS-Games'],
        system_map['Nintendo-Wii-Games'],
        system_map['PlayStation-2-Games'],
        system_map['Sony-PSP-Games'],
        system_map['PlayStation-3-Games'],
    ]

    my_favorite_genres = profile.get_favorite_genres()
    favorite_genres = []
    for s in Genre.objects.all().order_by('name'):
        favorite = False
        for os in my_favorite_genres:
            if os.id == s.id:
                favorite = True
        favorite_genres.append({'id': s.id, 'name': s.name, 'favorite': favorite})

    return {
        'systems': systems,
        'genres': favorite_genres,
        'parental_control': profile.parental_control,
        'parental_control_reviews': profile.parental_control_reviews,
    }