<commit_before>from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django.core.urlresolvers import reverse
import logging
from myuw.dao.user import get_netid_of_current_user
from myuw.views import admin_required, set_admin_wrapper_template
from myuw.models import VisitedLink, PopularLink


PAGE_SIZE = 10
MAX_PAGE = 5


@login_required
@admin_required('MYUW_ADMIN_GROUP')
def popular_links(request, page):
    logger = logging.getLogger(__name__)
    if request.POST:
        if 'url' in request.POST and 'label' in request.POST:
            create_args = {'url': request.POST['url'],
                           'label': request.POST['label'],
                           }

            if request.POST['campus']:
                create_args['campus'] = request.POST['campus']

            if request.POST['affiliation']:
                create_args['affiliation'] = request.POST['affiliation']

            if 'pce' in request.POST and request.POST['pce'] == "pce":
                create_args['pce'] = True

            PopularLink.objects.create(**create_args)
            logger.info("popular link added.  user: %s, link: %s" %
                        (get_netid_of_current_user(), request.POST['url']))

        if 'remove_popular' in request.POST:
            for popular_id in request.POST.getlist('remove_popular'):
                link = PopularLink.objects.get(pk=popular_id)
                url = link.url
                link.delete()
                logger.error("popular link removed.  user: %s, link:  %s" %
                             (get_netid_of_current_user(), url))

    curated_popular = PopularLink.objects.all()
    existing_lookup = set()
    curated_links = []
    for link in curated_popular:
        existing_lookup.add(link.url)
    kwargs = {}
    filter_kwargs = {}
    for field in ('campus', 'affiliation', 'pce'):
        if field in request.GET:
            value = request.GET[field]
            kwargs['is_'+value] = True
            if value != 'any_%s' % field:
                filter_kwargs['is_'+value] = True
                kwargs[field] = value
        else:
            kwargs['is_any_%s' % field] = True

    all_popular = VisitedLink.get_popular(**filter_kwargs)<commit_msg>working around a model typo<commit_after>from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django.core.urlresolvers import reverse
import logging
from myuw.dao.user import get_netid_of_current_user
from myuw.views import admin_required, set_admin_wrapper_template
from myuw.models import VisitedLink, PopularLink


PAGE_SIZE = 10
MAX_PAGE = 5


@login_required
@admin_required('MYUW_ADMIN_GROUP')
def popular_links(request, page):
    logger = logging.getLogger(__name__)
    if request.POST:
        if 'url' in request.POST and 'label' in request.POST:
            create_args = {'url': request.POST['url'],
                           'label': request.POST['label'],
                           }

            if request.POST['campus']:
                create_args['campus'] = request.POST['campus']

            if request.POST['affiliation']:
                create_args['affiliation'] = request.POST['affiliation']

            if 'pce' in request.POST and request.POST['pce'] == "pce":
                create_args['pce'] = True

            PopularLink.objects.create(**create_args)
            logger.info("popular link added.  user: %s, link: %s" %
                        (get_netid_of_current_user(), request.POST['url']))

        if 'remove_popular' in request.POST:
            for popular_id in request.POST.getlist('remove_popular'):
                link = PopularLink.objects.get(pk=popular_id)
                url = link.url
                link.delete()
                logger.error("popular link removed.  user: %s, link:  %s" %
                             (get_netid_of_current_user(), url))

    curated_popular = PopularLink.objects.all()
    existing_lookup = set()
    curated_links = []
    for link in curated_popular:
        existing_lookup.add(link.url)
    kwargs = {}
    filter_kwargs = {}
    for field in ('campus', 'affiliation', 'pce'):
        if field in request.GET:
            value = request.GET[field]
            kwargs['is_'+value] = True
            if value != 'any_%s' % field:
                filter_kwargs['is_'+value] = True
                kwargs[field] = value
        else:
            kwargs['is_any_%s' % field] = True

    # typo in the original model creation.  patching here to avoid a
    # db migration
    if 'is_undergrad' in filter_kwargs:
        del filter_kwargs['is_undergrad']
        filter_kwargs['is_undegrad'] = True

    all_popular = VisitedLink.get_popular(**filter_kwargs)
{'fraction_non_alphanumeric': 0.10929305642962031, 'fraction_numerical': 0.0012586532410320957, 'mean_word_length': 2.301939058171745, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1969884', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1342, 'n_words': 310}