Ejemplo n.º 1
0
def create_title(gmac, section):
    section_name = CIRCUIT_CATEGORY_CHOICES.get_string(section.upper())
    if section_name == None:
        section_name = strings.GENERIC_SECTION_NAME
    return strings.LOCAL_CIRCUITS_TITLE % {
        'location_name' : gmac.formatted_name,
        'section_name': section_name
    }
Ejemplo n.º 2
0
Archivo: views.py Proyecto: biznixcn/WR
def set_favorite_cats(request):
    if request.method == 'POST':
        categories = request.POST.getlist('category', [])
        # retrieve user
        user = request.user
        # validate categories and trimm not valid
        valid_categories = []
        for cat in categories:
            if CIRCUIT_CATEGORY_CHOICES.has_value(int(cat)):
                valid_categories.append(cat)

        # delete all previously followed categories
        prev_cats = user.categories.all()
        for followed_cat in prev_cats:
            # Shoot remove favorite signal
            category_unfollow.send(
                sender=user,
                category_id=followed_cat.category
            )
            followed_cat.delete()


        for cat in valid_categories:
            # Create CircuitCategoryFollow object
            follow_record = CircuitCategoryFollow(
                user=user,
                category=cat
            )
            # Add favorite
            user.categories.add(follow_record)
            # Shoot follow signal
            category_follow.send(sender=user, category_id=cat)

        # redirect to user_profile
        return redirect('website.views.show_home')

    uproxy = CircuitRelatedUserProxy.from_user(request.user)
    fav_cats = uproxy.get_favorite_circuit_categories()
    non_fav_cats = uproxy.get_non_favorite_circuit_categories()
    initial = {}
    for cat in fav_cats:
        initial[cat] = True
    for cat in non_fav_cats:
        initial[cat] = False

    Form = make_categories_form()
    form = Form(initial)
    return render(request,
        'profile/cats.html',
        {
            'form': form,
            'initial': initial,
        }
    )
Ejemplo n.º 3
0
def validate_section(section=None):
    categories = [k.lower() for k in CIRCUIT_CATEGORY_CHOICES.keys()]
    home = WEBSITE_HOME_SECTION_KEY
    if section is None:
        return False
    elif section in categories:
        return True
    elif section == home:
        return True
    else:
        return False
Ejemplo n.º 4
0
def set_favorite_cats(request):
    if request.method == 'POST':
        categories = request.POST.getlist('category', [])
        # retrieve user
        user = request.user
        # validate categories and trimm not valid
        valid_categories = []
        for cat in categories:
            if CIRCUIT_CATEGORY_CHOICES.has_value(int(cat)):
                valid_categories.append(cat)

        # delete all previously followed categories
        prev_cats = user.categories.all()
        for followed_cat in prev_cats:
            # Shoot remove favorite signal
            category_unfollow.send(sender=user,
                                   category_id=followed_cat.category)
            followed_cat.delete()

        for cat in valid_categories:
            # Create CircuitCategoryFollow object
            follow_record = CircuitCategoryFollow(user=user, category=cat)
            # Add favorite
            user.categories.add(follow_record)
            # Shoot follow signal
            category_follow.send(sender=user, category_id=cat)

        # redirect to user_profile
        return redirect('website.views.show_home')

    uproxy = CircuitRelatedUserProxy.from_user(request.user)
    fav_cats = uproxy.get_favorite_circuit_categories()
    non_fav_cats = uproxy.get_non_favorite_circuit_categories()
    initial = {}
    for cat in fav_cats:
        initial[cat] = True
    for cat in non_fav_cats:
        initial[cat] = False

    Form = make_categories_form()
    form = Form(initial)
    return render(request, 'profile/cats.html', {
        'form': form,
        'initial': initial,
    })
Ejemplo n.º 5
0
def create_url(gmac, section):
    categories = [k.lower() for k in CIRCUIT_CATEGORY_CHOICES.keys()]
    home = WEBSITE_HOME_SECTION_KEY
    recommended = WEBSITE_RECOMMENDED_SECTION_KEY
    if section == home:
        return reverse(
            'home_loc', 
            kwargs={'gmac_slug':gmac.slug}
        )
    elif section == recommended:
        return reverse(
            'recommended_circuits', 
            kwargs={'gmac_slug':gmac.slug}
        )
    elif section in categories:
        return reverse(
            'circuit_category_listing_loc', 
            kwargs={'category_slug':section, 'gmac_slug':gmac.slug}
        )
    else:
        return None       
Ejemplo n.º 6
0
 def description(self):
     return CIRCUIT_CATEGORY_CHOICES.get_string(self._id)
Ejemplo n.º 7
0
 def name(self):
     return CIRCUIT_CATEGORY_CHOICES.get_string(self._id)
Ejemplo n.º 8
0
 def key(self):
     return CIRCUIT_CATEGORY_CHOICES.get_key(self._id)
Ejemplo n.º 9
0
 def __init__(self, category_id):
     try:
         category_id = int(category_id)
     except ValueError:
         category_id = CIRCUIT_CATEGORY_CHOICES.get_value(category_id)
     self._id = category_id
Ejemplo n.º 10
0
Archivo: utils.py Proyecto: biznixcn/WR
 def description(self):
     return CIRCUIT_CATEGORY_CHOICES.get_string(self._id)
Ejemplo n.º 11
0
Archivo: utils.py Proyecto: biznixcn/WR
 def name(self):
     return CIRCUIT_CATEGORY_CHOICES.get_string(self._id)
Ejemplo n.º 12
0
Archivo: utils.py Proyecto: biznixcn/WR
 def key(self):
     return CIRCUIT_CATEGORY_CHOICES.get_key(self._id)
Ejemplo n.º 13
0
Archivo: utils.py Proyecto: biznixcn/WR
 def __init__(self, category_id):
     try:
         category_id = int(category_id)
     except ValueError:
         category_id = CIRCUIT_CATEGORY_CHOICES.get_value(category_id)
     self._id = category_id
Ejemplo n.º 14
0
def circuit_category_listing(request, category_slug, gmac_slug=None):
    """
    Displays the first 10 circuits of a category
    """
    # Find GMAC
    gmacs = None
    if gmac_slug is not None:
        try:
            gmacs = GMAC.objects.filter(slug=gmac_slug)
        except GMAC.DoesNotExist:
            pass

    cpp = circuit_settings.DEFAULT_CIRCUITS_LIMIT

    try:
        category_value = CIRCUIT_CATEGORY_CHOICES.get_value(
            category_slug.upper())
    except KeyError:
        raise Http404

    categories = circuit_category_list()
    category = CircuitCategory(category_value)

    params = {}

    params['category'] = category_value

    gmac_get_short_formatted_name = None
    if gmacs is not None:
        params['pk__in'] = [c.pk for c in Circuit.filter_by_gmacs(gmacs)]
        gmac_get_short_formatted_name = gmacs[0].get_short_formatted_name()

    if request.is_ajax():
        page = request.POST.get('page', None)
        if page is not None:
            page = int(page)
        else:
            error_doc = OrderedDict()
            error_doc['error'] = 'Missing POST parameter: page'
            return HttpResponse(content=render_as_json(error_doc),
                                content_type='application/json')

        response = {'page': int(page) + 1}

        circuits = Circuit.objects.available().filter(
            **params).order_by('-modified')[page * cpp:(page + 1) * cpp]

        if circuits:
            html_response = u''

            for circuit in circuits:
                html_response += render_to_string(
                    'circuits/circuit_list_item.html', {
                        'circuit': circuit,
                        'user': request.user
                    })
            response['raw_html'] = html_response

        else:
            response['hide_button'] = True

        return HttpResponse(content=json.dumps(response),
                            content_type='application/json')

    # FIXME circuits filter should also include location of user
    circuits = Circuit.objects.available().filter(
        **params).order_by('-modified')[:cpp]

    return render(
        request,
        'circuits/categories.html',
        {
            'categories': categories,
            'category': category,
            'selected_category': category_value,
            'category_slug': category_slug,
            'is_preferred_category': category.is_followed(request.user),
            'circuits': circuits,
            'topbar_item': 'explore',
            'page_type': 'category',
            'gmacs': gmacs,
            'gmac_slug': gmac_slug,
            'STATIC_MAPS_ROOT': settings.STATIC_MAPS_ROOT,
            'GOOGLE_API_KEY': settings.GOOGLE_API_KEY,
            'gmac_get_short_formatted_name': gmac_get_short_formatted_name,
        },
    )
Ejemplo n.º 15
0
Archivo: views.py Proyecto: biznixcn/WR
def circuit_category_listing(request, category_slug, gmac_slug=None):
    """
    Displays the first 10 circuits of a category
    """
    # Find GMAC
    gmacs = None
    if gmac_slug is not None:
        try:
            gmacs = GMAC.objects.filter(slug=gmac_slug)
        except GMAC.DoesNotExist:
            pass

    cpp = circuit_settings.DEFAULT_CIRCUITS_LIMIT

    try:
        category_value = CIRCUIT_CATEGORY_CHOICES.get_value(
            category_slug.upper()
        )
    except KeyError:
        raise Http404

    categories = circuit_category_list()
    category = CircuitCategory(category_value)

    params = {}

    params['category'] = category_value

    gmac_get_short_formatted_name = None
    if gmacs is not None:
        params['pk__in'] = [ c.pk for c in Circuit.filter_by_gmacs(gmacs)]
        gmac_get_short_formatted_name = gmacs[0].get_short_formatted_name()

    if request.is_ajax():
        page = request.POST.get('page', None)
        if page is not None:
            page = int(page)
        else:
            error_doc = OrderedDict()
            error_doc['error'] = 'Missing POST parameter: page'
            return HttpResponse(
                content=render_as_json(error_doc),
                content_type='application/json'
            )

        response = {
            'page': int(page) + 1
        }

        circuits = Circuit.objects.available().filter(**params).order_by(
            '-modified'
        )[page * cpp: (page + 1) * cpp]

        if circuits:
            html_response = u''

            for circuit in circuits:
                html_response += render_to_string(
                    'circuits/circuit_list_item.html',
                    {'circuit': circuit, 'user': request.user}
                )
            response['raw_html'] = html_response

        else:
            response['hide_button'] = True

        return HttpResponse(
            content=json.dumps(response),
            content_type='application/json'
        )

    # FIXME circuits filter should also include location of user
    circuits = Circuit.objects.available().filter(**params).order_by(
        '-modified'
    )[:cpp]

    return render(request,
        'circuits/categories.html',
        {
            'categories': categories,
            'category': category,
            'selected_category': category_value,
            'category_slug': category_slug,
            'is_preferred_category': category.is_followed(request.user),
            'circuits': circuits,
            'topbar_item': 'explore',
            'page_type': 'category',
            'gmacs': gmacs,
            'gmac_slug': gmac_slug,
            'STATIC_MAPS_ROOT': settings.STATIC_MAPS_ROOT,
            'GOOGLE_API_KEY': settings.GOOGLE_API_KEY,
            'gmac_get_short_formatted_name': gmac_get_short_formatted_name,
        },
    )