<commit_before>from django.shortcuts import get_object_or_404, render

# Create your views here.
from .models import *

def index(request, snippetID=None):
    """
    View function for home page of site.
    """
    page_context = {'page_title': 'W E B S C A L E'}

    # Normally the user would be determined by the session, but here we will
    # use Steve's account as an example
    example_user = User.objects.get(name='<NAME>')
    all_user_snippets = map(lambda snip: (snip.id.hex, snip.name, snip.description),
                            Snippit.objects.filter(user_id=example_user.id))
    page_context['all_user_snippets'] = all_user_snippets

    if snippetID is None:
        return render(request, 'index.html', page_context)


    snippet = Snippit.objects.get(pk=snippetID)

    page_context['snippet_id'] = snippet.id.hex
    page_context['snippet_name'] = ": {0}".format(snippet.name)
    page_context['snippet_user_id'] = snippet.user_id
    page_context['snippet_description'] = snippet.description
    page_context['snippet_text'] = snippet.program_text
    page_context['snippet_spec'] = snippet.program_spec
    page_context['snippet_result'] = snippet.synthesizer_result
    page_context['snippet_is_public'] = snippet.is_public

    return render(
        request,
        'index.html',
        page_context,
    )

def about(request):
    """
    View function for the about page.
    """
    return render(
        request,
        'synthesizer/about.html',
        context={'page_title': 'About Us'},
    )
def discussion(request, snippetID):
    """
    View function for the discussion page.
    """
    page_context = {'page_title': 'Discussion'}
    snippet = Snippit.objects.get(pk=snippetID)
    snippet_comments = list(
        map(lambda comment: (comment.user_id.name,
                             comment.text, comment.date_posted),
                            Comment.objects.filter(snippit_id=snippetID))
        )
    print(list(snippet_comments))
    page_context['snippet_id'] = snippet.id.hex
    page_context['snippet_name'] = snippet.name
    page_context['snippet_user_id'] = snippet.user_id
    page_context['snippet_description'] = snippet.description
    page_context['snippet_text'] = snippet.program_text
    page_context['snippet_result'] = snippet.synthesizer_result
    page_context['snippet_comments'] = snippet_comments

    return render(
        request,
        'synthesizer/discussion.html',
        page_context,
    )
def faq(request):
    """
    View function for the faq page.
    """
    return render(
        request,
        'synthesizer/faq.html',
        context={'page_title': 'FAQ'},
    )
def feed(request):
    """
    View function for the feed page.
    """
    snippits = Snippit.objects.all().order_by('-id')[:5]
    return render(
        request,
        'synthesizer/feed.html',
        context={'page_title': 'Activity Feed', 'snippits': snippits},
    )
def profile(request, profile_id="0"):
    """
    View function for a profile page.
    If the given profile id argument is not given, the profile of
    the current user will be shown
    """
    if profile_id == "0":
        profile_id = "d097b337df594c35a01d997bfbeaad42"  # default to steven's profile for now
    user = get_object_or_404(User, id=profile_id)<commit_msg>Only consider public snippits in feed<commit_after>from django.shortcuts import get_object_or_404, render

# Create your views here.
from .models import *

def index(request, snippetID=None):
    """
    View function for home page of site.
    """
    page_context = {'page_title': 'W E B S C A L E'}

    # Normally the user would be determined by the session, but here we will
    # use Steve's account as an example
    example_user = User.objects.get(name='<NAME>')
    all_user_snippets = map(lambda snip: (snip.id.hex, snip.name, snip.description),
                            Snippit.objects.filter(user_id=example_user.id))
    page_context['all_user_snippets'] = all_user_snippets

    if snippetID is None:
        return render(request, 'index.html', page_context)


    snippet = Snippit.objects.get(pk=snippetID)

    page_context['snippet_id'] = snippet.id.hex
    page_context['snippet_name'] = ": {0}".format(snippet.name)
    page_context['snippet_user_id'] = snippet.user_id
    page_context['snippet_description'] = snippet.description
    page_context['snippet_text'] = snippet.program_text
    page_context['snippet_spec'] = snippet.program_spec
    page_context['snippet_result'] = snippet.synthesizer_result
    page_context['snippet_is_public'] = snippet.is_public

    return render(
        request,
        'index.html',
        page_context,
    )

def about(request):
    """
    View function for the about page.
    """
    return render(
        request,
        'synthesizer/about.html',
        context={'page_title': 'About Us'},
    )
def discussion(request, snippetID):
    """
    View function for the discussion page.
    """
    page_context = {'page_title': 'Discussion'}
    snippet = Snippit.objects.get(pk=snippetID)
    snippet_comments = list(
        map(lambda comment: (comment.user_id.name,
                             comment.text, comment.date_posted),
                            Comment.objects.filter(snippit_id=snippetID))
        )
    print(list(snippet_comments))
    page_context['snippet_id'] = snippet.id.hex
    page_context['snippet_name'] = snippet.name
    page_context['snippet_user_id'] = snippet.user_id
    page_context['snippet_description'] = snippet.description
    page_context['snippet_text'] = snippet.program_text
    page_context['snippet_result'] = snippet.synthesizer_result
    page_context['snippet_comments'] = snippet_comments

    return render(
        request,
        'synthesizer/discussion.html',
        page_context,
    )
def faq(request):
    """
    View function for the faq page.
    """
    return render(
        request,
        'synthesizer/faq.html',
        context={'page_title': 'FAQ'},
    )
def feed(request):
    """
    View function for the feed page.
    """
    snippits = Snippit.objects.filter(is_public=True).order_by('-id')[:5]
    return render(
        request,
        'synthesizer/feed.html',
        context={'page_title': 'Activity Feed', 'snippits': snippits},
    )
def profile(request, profile_id="0"):
    """
    View function for a profile page.
    If the given profile id argument is not given, the profile of
    the current user will be shown
    """
    if profile_id == "0":
        profile_id = "d097b337df594c35a01d997bfbeaad42"  # default to steven's profile for now
    user = get_object_or_404(User, id=profile_id)
{'fraction_non_alphanumeric': 0.11257682506370859, 'fraction_numerical': 0.008394543546694649, 'mean_word_length': 3.0485436893203883, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, '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': '2542223', 'n_tokens_mistral': 2154, 'n_tokens_neox': 2048, 'n_words': 452}