Exemplo n.º 1
0
Arquivo: models.py Projeto: C14L/dtr5
 def f_exclude_sr_li(self, li):
     # --- DEPRECATED ---
     if isinstance(li, str):
         li = sr_str_to_list(li)  # if it a string of subreddits, clean it.
     self._f_exclude_sr_li = " ".join(li)
Exemplo n.º 2
0
Arquivo: views.py Projeto: M108/dtr5
def me_search_view(request):
    """
    Save the user search settings and redirect to search results page.
    """
    txt_not_found = 'No redditors found for the search options.'

    if request.method in ["GET", "HEAD"]:
        # Find the next profile to show and redirect.
        search_results_buffer(request)
        if len(request.session['search_results_buffer']) < 1:
            messages.warning(request, txt_not_found)
            return redirect(request.POST.get('next', reverse('me_page')))
        x = {'username': request.session['search_results_buffer'][0]}
        _next = request.POST.get('next', reverse('profile_page', kwargs=x))
        return redirect(_next)

    p = request.user.profile
    p.f_sex = force_int(request.POST.get('f_sex', ''))

    if request.POST.get('f_distance', None):
        p.f_distance = force_int(request.POST.get('f_distance'), max=20000)
    if request.POST.get('f_minage', None):
        p.f_minage = force_int(request.POST.get('f_minage'), min=18)
    if request.POST.get('f_maxage', None):
        p.f_maxage = force_int(request.POST.get('f_maxage'), max=100)
    if request.POST.get('f_over_18', None):
        p.f_over_18 = bool(request.POST.get('f_over_18'))
    if request.POST.get('f_has_verified_email', None):
        p.f_has_verified_email = bool(request.POST.get('f_has_verified_email'))

    try:
        p.f_ignore_sr_li = sr_str_to_list(request.POST['f_ignore_sr_li'])
    except MultiValueDictKeyError:
        pass  # don't change the search vaue if not POSTed.
    try:
        p.f_ignore_sr_max = force_int(request.POST['f_ignore_sr_max'])
    except MultiValueDictKeyError:
        pass  # don't change the search vaue if not POSTed.
    try:
        p.f_exclude_sr_li = sr_str_to_list(request.POST['f_exclude_sr_li'])
    except MultiValueDictKeyError:
        pass  # don't change the search vaue if not POSTed.

    request.user.profile = p
    #
    # TODO: check if model is dirty and only force a search results
    # buffer refresh if the search parameters actually changed. To
    # avoid too many searches.
    #
    request.user.profile.save()
    search_results_buffer(request, force=True)
    #
    if len(request.session['search_results_buffer']) < 1:
        messages.warning(request, txt_not_found)
        return redirect(request.POST.get('next', reverse('me_page')))
    # messages.success(request, 'Search options updated.')
    if (request.session.get('view_post_signup', False)):
        return redirect(request.POST.get('next', reverse('me_page')))
    else:
        x = {'username': request.session['search_results_buffer'][0]}
        return redirect(reverse('profile_page', kwargs=x))
Exemplo n.º 3
0
Arquivo: models.py Projeto: C14L/dtr5
 def f_ignore_sr_li(self):
     # --- DEPRECATED ---
     return sr_str_to_list(self._f_ignore_sr_li)
Exemplo n.º 4
0
Arquivo: models.py Projeto: C14L/dtr5
 def f_exclude_sr_li(self):
     # --- DEPRECATED ---
     return sr_str_to_list(self._f_exclude_sr_li)
Exemplo n.º 5
0
Arquivo: models.py Projeto: M108/dtr5
 def f_exclude_sr_li(self):
     return sr_str_to_list(self._f_exclude_sr_li)
Exemplo n.º 6
0
Arquivo: models.py Projeto: M108/dtr5
 def f_exclude_sr_li(self, li):
     if isinstance(li, str):
         li = sr_str_to_list(li)  # if it a string of subreddits, clean it.
     self._f_exclude_sr_li = ' '.join(li)
Exemplo n.º 7
0
def me_search_view(request):
    """
    Save the user search settings and redirect to search results page.
    """
    txt_not_found = 'No redditors found for the search options.'

    if request.method in ["GET", "HEAD"]:
        # Find the next profile to show and redirect.
        search_results_buffer(request)

        if len(request.session['search_results_buffer']) < 1:
            messages.warning(request, txt_not_found)
            return redirect(request.POST.get('next', reverse('me_page')))

        x = {'username': request.session['search_results_buffer'][0]}
        _next = request.POST.get('next', reverse('profile_page', kwargs=x))

        return redirect(_next)

    p = request.user.profile
    p.f_sex = force_int(request.POST.get('f_sex', ''))

    if request.POST.get('f_distance', None):
        p.f_distance = force_int(request.POST.get('f_distance'), max=21000)
    if request.POST.get('f_minage', None):
        p.f_minage = force_int(request.POST.get('f_minage'), min=18)
    if request.POST.get('f_maxage', None):
        p.f_maxage = force_int(request.POST.get('f_maxage'), max=100)
    if request.POST.get('f_over_18', None):
        p.f_over_18 = bool(request.POST.get('f_over_18'))
    if request.POST.get('f_has_verified_email', None):
        p.f_has_verified_email = bool(request.POST.get('f_has_verified_email'))

    # List of subreddit names. This needs to be cleaned for appropriate
    # letter case, so its useful in raw SQL search. Since Django has no
    # case insensivity support :( we look up the correctly cased subreddit
    # names here once, and store those as the user's search settings.
    try:
        li = sr_str_to_list(request.POST['f_ignore_sr_li'])
        p.f_ignore_sr_li = normalize_sr_names(li)
    except MultiValueDictKeyError:
        pass  # don't change the search vaue if not POSTed.
    try:
        p.f_ignore_sr_max = force_int(request.POST['f_ignore_sr_max'])
    except MultiValueDictKeyError:
        pass  # don't change the search vaue if not POSTed.
    try:
        li = sr_str_to_list(request.POST['f_exclude_sr_li'])
        p.f_exclude_sr_li = normalize_sr_names(li)
    except MultiValueDictKeyError:
        pass  # don't change the search vaue if not POSTed.

    request.user.profile = p
    #
    # TODO: check if model is dirty and only force a search results
    # buffer refresh if the search parameters actually changed. To
    # avoid too many searches.
    #
    request.user.profile.save()
    search_results_buffer(request, force=True)

    if len(request.session['search_results_buffer']) < 1:
        messages.warning(request, txt_not_found)
        return redirect(request.POST.get('next', reverse('me_page')))

    # messages.success(request, 'Search options updated.')
    if (request.session.get('view_post_signup', False)):
        return redirect(request.POST.get('next', reverse('me_page')))
    else:
        # x = {'username': request.session['search_results_buffer'][0]}
        # return redirect(reverse('profile_page', kwargs=x))
        return redirect(reverse('me_results_page'))
Exemplo n.º 8
0
Arquivo: models.py Projeto: M108/dtr5
 def f_ignore_sr_li(self):
     return sr_str_to_list(self._f_ignore_sr_li)
Exemplo n.º 9
0
 def f_exclude_sr_li(self):
     return sr_str_to_list(self._f_exclude_sr_li)
Exemplo n.º 10
0
 def f_exclude_sr_li(self, li):
     if isinstance(li, str):
         li = sr_str_to_list(li)  # if it a string of subreddits, clean it.
     self._f_exclude_sr_li = ' '.join(li)
Exemplo n.º 11
0
 def f_ignore_sr_li(self):
     return sr_str_to_list(self._f_ignore_sr_li)
Exemplo n.º 12
0
def update_search_settings(request):
    """Update all posted search uptions in authuser's Profile."""
    p = request.user.profile

    if 'order_by' in request.POST:
        request.session['search_results_order'] = request.POST['order_by']

    if 'f_sex' in request.POST:
        p.f_sex = force_int(request.POST['f_sex'])

    if 'f_distance' in request.POST:
        p.f_distance = force_int(request.POST['f_distance'], min=0, max=21000)

    if 'f_minage' in request.POST:
        p.f_minage = force_int(request.POST['f_minage'], min=18, max=99)

    if 'f_maxage' in request.POST:
        p.f_maxage = force_int(request.POST['f_maxage'], min=19, max=100)

    if 'f_hide_no_pic' in request.POST:
        j = force_int(request.POST['f_hide_no_pic'])
        p.f_hide_no_pic = bool(j)

    if 'f_has_verified_email' in request.POST:
        j = force_int(request.POST['f_has_verified_email'])
        p.f_has_verified_email = bool(j)

    # TODO: needs Profile model update!
    # if 'f_is_stable' in request.POST:
    #     j = force_int(request.POST['f_is_stable'])
    #     p.f_is_stable = bool(j)

    if 'f_over_18' in request.POST:  # unused
        p.f_over_18 = bool(request.POST['f_over_18'])

    # List of subreddit names. This needs to be cleaned for appropriate
    # letter case, so its useful in raw SQL search. Since Django has no
    # case insensivity support :( we look up the correctly cased subreddit
    # names here once, and store those as the user's search settings.
    # --> REMOVE from search, use "fav subreddits" list instead.
    if 'f_ignore_sr_li' in request.POST:
        try:
            li = sr_str_to_list(request.POST['f_ignore_sr_li'])
            p.f_ignore_sr_li = normalize_sr_names(li)
        except MultiValueDictKeyError:
            pass  # don't change the search value if not POSTed.

    # --> REMOVE from search, use "fav subreddits" list instead.
    if 'f_ignore_sr_max' in request.POST:
        try:
            p.f_ignore_sr_max = force_int(request.POST['f_ignore_sr_max'],
                                          min=100, max=123456789)
        except MultiValueDictKeyError:
            pass  # don't change the search vaue if not POSTed.

    # Currently unused.
    if 'f_exclude_sr_li' in request.POST:
        try:
            li = sr_str_to_list(request.POST['f_exclude_sr_li'])
            p.f_exclude_sr_li = normalize_sr_names(li)
        except MultiValueDictKeyError:
            pass  # don't change the search value if not POSTed.

    # Find active subreddits: loop through user's subs and those that are in
    # the POST are active, all others are not.
    if 'sr-fav' in request.POST:
        posted = request.POST.getlist('sr-fav')
        li = request.user.subs.filter(sr__display_name__in=posted)
        if li:  # ignore empty fav list!
            with transaction.atomic():
                request.user.subs.all().update(is_favorite=False)
                li.update(is_favorite=True)
        else:
            messages.warning(request, 'no subreddits selected for search!')

    request.user.profile = p
    request.user.profile.save()
    return request
Exemplo n.º 13
0
 def test_sr_str_to_list(self):
     a = 'AskReddit, IamA , t:1990 ,Reddit.com dragonsfuckingcars'
     b = ['AskReddit', 'IamA', 't:1990', 'Reddit.com', 'dragonsfuckingcars']
     li = toolbox.sr_str_to_list(a)
     self.assertEqual(li, b)
Exemplo n.º 14
0
def update_search_settings(request):
    """Update all posted search uptions in authuser's Profile."""
    p = request.user.profile

    if 'order_by' in request.POST:
        request.session['search_results_order'] = request.POST['order_by']

    if 'f_sex' in request.POST:
        p.f_sex = force_int(request.POST['f_sex'])

    if 'f_distance' in request.POST:
        p.f_distance = force_int(request.POST['f_distance'], min=0, max=21000)

    if 'f_minage' in request.POST:
        p.f_minage = force_int(request.POST['f_minage'], min=18, max=99)

    if 'f_maxage' in request.POST:
        p.f_maxage = force_int(request.POST['f_maxage'], min=19, max=100)

    if 'f_hide_no_pic' in request.POST:
        j = force_int(request.POST['f_hide_no_pic'])
        p.f_hide_no_pic = bool(j)

    if 'f_has_verified_email' in request.POST:
        j = force_int(request.POST['f_has_verified_email'])
        p.f_has_verified_email = bool(j)

    # TODO: needs Profile model update!
    # if 'f_is_stable' in request.POST:
    #     j = force_int(request.POST['f_is_stable'])
    #     p.f_is_stable = bool(j)

    if 'f_over_18' in request.POST:  # unused
        p.f_over_18 = bool(request.POST['f_over_18'])

    # List of subreddit names. This needs to be cleaned for appropriate
    # letter case, so its useful in raw SQL search. Since Django has no
    # case insensivity support :( we look up the correctly cased subreddit
    # names here once, and store those as the user's search settings.
    # --> REMOVE from search, use "fav subreddits" list instead.
    if 'f_ignore_sr_li' in request.POST:
        try:
            li = sr_str_to_list(request.POST['f_ignore_sr_li'])
            p.f_ignore_sr_li = normalize_sr_names(li)
        except MultiValueDictKeyError:
            pass  # don't change the search value if not POSTed.

    # --> REMOVE from search, use "fav subreddits" list instead.
    if 'f_ignore_sr_max' in request.POST:
        try:
            p.f_ignore_sr_max = force_int(request.POST['f_ignore_sr_max'],
                                          min=100,
                                          max=123456789)
        except MultiValueDictKeyError:
            pass  # don't change the search vaue if not POSTed.

    # Currently unused.
    if 'f_exclude_sr_li' in request.POST:
        try:
            li = sr_str_to_list(request.POST['f_exclude_sr_li'])
            p.f_exclude_sr_li = normalize_sr_names(li)
        except MultiValueDictKeyError:
            pass  # don't change the search value if not POSTed.

    # Find active subreddits: loop through user's subs and those that are in
    # the POST are active, all others are not.
    if 'sr-fav' in request.POST:
        posted = request.POST.getlist('sr-fav')
        li = request.user.subs.filter(sr__display_name__in=posted)
        if li:  # ignore empty fav list!
            with transaction.atomic():
                request.user.subs.all().update(is_favorite=False)
                li.update(is_favorite=True)
        else:
            messages.warning(request, 'no subreddits selected for search!')

    request.user.profile = p
    request.user.profile.save()
    return request
Exemplo n.º 15
0
 def test_sr_str_to_list(self):
     a = 'AskReddit, IamA , t:1990 ,Reddit.com dragonsfuckingcars'
     b = ['AskReddit', 'IamA', 't:1990', 'Reddit.com', 'dragonsfuckingcars']
     li = toolbox.sr_str_to_list(a)
     self.assertEqual(li, b)