<commit_before>import json
import os
import urllib
import requests

from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt

from annoying.decorators import ajax_request
from urlparse import urlparse
from common.templatetags.gravatar import gravatar_for_user
from dateutil import tz
from datetime import datetime

from api.models import Domain, Page, Summary, SummaryHistory
from tags.models import Highlight, CommonTag, TagCollection
from tags.models import Tag, Vote, UserTagInfo, Comment
from accounts.models import UserProfile


'''
Get page info
'''
@login_required
@ajax_request
def page(request):
  success = False
  user = request.user
  errors = {}
  page_info = {}

  if request.GET:
    url = process_url(request.GET.get('url'))
    errors['page'] = []

    try: 
      p = Page.objects.get(url=url)
      page_info = {
        "url": url,
        "title": p.title,
        "favicon_url": p.favicon_url,
        "domain": {
          "name": p.domain.name,
          "url": p.domain.url,
        } 
      }
      success = True

    except Page.DoesNotExist:  
      errors['page'].append("Page does not exist")

  return {
    'success': success,
    'errors': errors,
    'page': page_info,
  }

'''
Get all tags associated with a page (but not highlight)
'''
@login_required
@ajax_request
def tags_by_page(request):
  '''
  Getting all tags for a page
  '''
  success = False
  errors = {}
  tags = {}
  user = request.user

  if request.GET:
    url = process_url(request.GET.get('url'))
    errors['get_tags'] = []

    if not len(errors['get_tags']):
      vts = Tag.objects.filter(page__url=url, highlight=None)

      try:
        page = Page.objects.get(url=url)

        # get relevant info for each value tag
        for vt in vts:
          vt_info = {
            'user_voted': False,
            'name': vt.common_tag.name,
            'color': vt.common_tag.color,
            'description': vt.common_tag.description,
            'is_private': vt.is_private,
            'vote_count': len(Vote.objects.filter(tag=vt)),
          }

          tags[vt.common_tag.name] = vt_info
          success = True

        if success == False:
          errors['get_tags'].append("No tags for page " + url)
      except Page.DoesNotExist:
        errors['get_tags'].append("Page " + url + " does not exist")

  return {
    'success': success,
    'errors': errors,
    'tags': tags,
  }

'''
Get all tags associated with a highlight
'''
@login_required
@ajax_request
def tags_by_highlight(request):
  success = False
  errors = {}
  tags = {}
  sorted_tags = []
  user = request.user

  if request.GET:
    highlight = request.GET.get('highlight')
    url = process_url(request.GET.get('url'))
    errors['get_tags'] = []

    if not len(errors['get_tags']):
      vts = Tag.objects.filter(highlight__id=highlight, page__url=url)

      # get relevant info for each value tag
      for vt in vts:
        vt_info = {
          'user_voted': False,
          'name': vt.common_tag.name,
          'color': vt.common_tag.color,
          'description': vt.common_tag.description,
          'is_private': vt.is_private,
          'vote_count': len(Vote.objects.filter(tag=vt)),
          'is_owner': (vt.user == user),
        }

        votes = []
        vs = Vote.objects.filter(tag=vt)

        # get vote info
        for v in vs:
          if user == v.voter:
            vt_info['user_voted'] = True
          user_profile = UserProfile.objects.get(user=v.voter)
          pic = user_profile.pic_url
          if not pic:
            pic = gravatar_for_user(v.voter)
          votes.append({
            'name': user_profile.get_full_name(),
            'pic': pic,
          })
        vt_info['votes'] = votes
        sorted_tags.append(vt_info)
        success = True

  sorted_tags = sorted(sorted_tags, key=lambda x: x["vote_count"], reverse=True)

  return {
    'success': success,<commit_msg>fix username tags highlight<commit_after>import json
import os
import urllib
import requests

from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt

from annoying.decorators import ajax_request
from urlparse import urlparse
from common.templatetags.gravatar import gravatar_for_user
from dateutil import tz
from datetime import datetime

from api.models import Domain, Page, Summary, SummaryHistory
from tags.models import Highlight, CommonTag, TagCollection
from tags.models import Tag, Vote, UserTagInfo, Comment
from accounts.models import UserProfile


'''
Get page info
'''
@login_required
@ajax_request
def page(request):
  success = False
  user = request.user
  errors = {}
  page_info = {}

  if request.GET:
    url = process_url(request.GET.get('url'))
    errors['page'] = []

    try: 
      p = Page.objects.get(url=url)
      page_info = {
        "url": url,
        "title": p.title,
        "favicon_url": p.favicon_url,
        "domain": {
          "name": p.domain.name,
          "url": p.domain.url,
        } 
      }
      success = True

    except Page.DoesNotExist:  
      errors['page'].append("Page does not exist")

  return {
    'success': success,
    'errors': errors,
    'page': page_info,
  }

'''
Get all tags associated with a page (but not highlight)
'''
@login_required
@ajax_request
def tags_by_page(request):
  '''
  Getting all tags for a page
  '''
  success = False
  errors = {}
  tags = {}
  user = request.user

  if request.GET:
    url = process_url(request.GET.get('url'))
    errors['get_tags'] = []

    if not len(errors['get_tags']):
      vts = Tag.objects.filter(page__url=url, highlight=None)

      try:
        page = Page.objects.get(url=url)

        # get relevant info for each value tag
        for vt in vts:
          vt_info = {
            'user_voted': False,
            'name': vt.common_tag.name,
            'color': vt.common_tag.color,
            'description': vt.common_tag.description,
            'is_private': vt.is_private,
            'vote_count': len(Vote.objects.filter(tag=vt)),
          }

          tags[vt.common_tag.name] = vt_info
          success = True

        if success == False:
          errors['get_tags'].append("No tags for page " + url)
      except Page.DoesNotExist:
        errors['get_tags'].append("Page " + url + " does not exist")

  return {
    'success': success,
    'errors': errors,
    'tags': tags,
  }

'''
Get all tags associated with a highlight
'''
@login_required
@ajax_request
def tags_by_highlight(request):
  success = False
  errors = {}
  tags = {}
  sorted_tags = []
  user = request.user

  if request.GET:
    highlight = request.GET.get('highlight')
    url = process_url(request.GET.get('url'))
    errors['get_tags'] = []

    if not len(errors['get_tags']):
      vts = Tag.objects.filter(highlight__id=highlight, page__url=url)

      # get relevant info for each value tag
      for vt in vts:
        vt_info = {
          'user_voted': False,
          'name': vt.common_tag.name,
          'color': vt.common_tag.color,
          'description': vt.common_tag.description,
          'is_private': vt.is_private,
          'vote_count': len(Vote.objects.filter(tag=vt)),
          'is_owner': (vt.user == user),
        }

        votes = []
        vs = Vote.objects.filter(tag=vt)

        # get vote info
        for v in vs:
          if user == v.voter:
            vt_info['user_voted'] = True
          user_profile = UserProfile.objects.get(user=v.voter)
          pic = user_profile.pic_url
          if not pic:
            pic = gravatar_for_user(v.voter)
          votes.append({
            'name': user_profile.user.username,
            'pic': 'https://%s' % pic[7:],
          })
        vt_info['votes'] = votes
        sorted_tags.append(vt_info)
        success = True

  sorted_tags = sorted(sorted_tags, key=lambda x: x["vote_count"], reverse=True)

  return {
    'success': success,
{'fraction_non_alphanumeric': 0.12058495476515058, 'fraction_numerical': 0.00012393109431156277, 'mean_word_length': 2.4769495906936667, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '1299814', 'n_tokens_mistral': 2584, 'n_tokens_neox': 2533, 'n_words': 609}