<commit_before>from django.http import HttpResponse, Http404
from django.shortcuts import get_object_or_404
from madrona.features.models import Feature
from madrona.features import get_feature_by_uid
from models import *
from simplejson import dumps


'''
'''
def get_drawings(request):
    json = []
    
    drawings = AOI.objects.filter(user=request.user).order_by('date_created')
    for drawing in drawings:
        sharing_groups = [group.name for group in drawing.sharing_groups.all()]
        json.append({
            'id': drawing.id,
            'uid': drawing.uid,
            'name': drawing.name,
            'description': drawing.description,
            'attributes': drawing.serialize_attributes,
            'sharing_groups': sharing_groups
        })
        
    shared_drawings = AOI.objects.shared_with_user(request.user)
    for drawing in shared_drawings:
        if drawing.active and drawing not in drawings:
            username = drawing.user.username
            actual_name = drawing.user.first_name + ' ' + drawing.user.last_name
            json.append({
                'id': drawing.id,
                'uid': drawing.uid,
                'name': drawing.name,
                'description': drawing.description,
                'attributes': drawing.serialize_attributes,
                'shared': True,
                'shared_by_username': username,
                'shared_by_name': actual_name
            })
        
    return HttpResponse(dumps(json))

'''
'''
def delete_drawing(request, uid):
    try:
        drawing_obj = get_feature_by_uid(uid)
    except Feature.DoesNotExist:
        raise Http404
    
    #check permissions
    viewable, response = drawing_obj.is_viewable(request.user)
    if not viewable:
        return response
        
    drawing_obj.delete()
    
    return HttpResponse("", status=200)

'''
'''
def aoi_analysis(request, aoi_id):
    from aoi_analysis import display_aoi_analysis
    aoi_obj = get_object_or_404(AOI, pk=aoi_id)
    #check permissions
    viewable, response = aoi_obj.is_viewable(request.user)
    if not viewable:
        return response
    return display_aoi_analysis(request, aoi_obj)
    # Create your views here.

'''
'''
def wind_analysis(request, wind_id):
    from wind_analysis import display_wind_analysis
    wind_obj = get_object_or_404(WindEnergySite, pk=wind_id)
    #check permissions
    viewable, response = wind_obj.is_viewable(request.user)
    if not viewable:
        return response
    return display_wind_analysis(request, wind_obj)
    # Create your views here.
<commit_msg>fixing an issue in which shared drawings were preventing drawings from being loaded<commit_after>from django.http import HttpResponse, Http404
from django.shortcuts import get_object_or_404
from madrona.features.models import Feature
from madrona.features import get_feature_by_uid
from models import *
from simplejson import dumps


'''
'''
def get_drawings(request):
    json = []
    
    drawings = AOI.objects.filter(user=request.user).order_by('date_created')
    for drawing in drawings:
        sharing_groups = [group.name for group in drawing.sharing_groups.all()]
        json.append({
            'id': drawing.id,
            'uid': drawing.uid,
            'name': drawing.name,
            'description': drawing.description,
            'attributes': drawing.serialize_attributes,
            'sharing_groups': sharing_groups
        })
        
    shared_drawings = AOI.objects.shared_with_user(request.user)
    for drawing in shared_drawings:
        if drawing not in drawings:
            username = drawing.user.username
            actual_name = drawing.user.first_name + ' ' + drawing.user.last_name
            json.append({
                'id': drawing.id,
                'uid': drawing.uid,
                'name': drawing.name,
                'description': drawing.description,
                'attributes': drawing.serialize_attributes,
                'shared': True,
                'shared_by_username': username,
                'shared_by_name': actual_name
            })
        
    return HttpResponse(dumps(json))

'''
'''
def delete_drawing(request, uid):
    try:
        drawing_obj = get_feature_by_uid(uid)
    except Feature.DoesNotExist:
        raise Http404
    
    #check permissions
    viewable, response = drawing_obj.is_viewable(request.user)
    if not viewable:
        return response
        
    drawing_obj.delete()
    
    return HttpResponse("", status=200)

'''
'''
def aoi_analysis(request, aoi_id):
    from aoi_analysis import display_aoi_analysis
    aoi_obj = get_object_or_404(AOI, pk=aoi_id)
    #check permissions
    viewable, response = aoi_obj.is_viewable(request.user)
    if not viewable:
        return response
    return display_aoi_analysis(request, aoi_obj)
    # Create your views here.

'''
'''
def wind_analysis(request, wind_id):
    from wind_analysis import display_wind_analysis
    wind_obj = get_object_or_404(WindEnergySite, pk=wind_id)
    #check permissions
    viewable, response = wind_obj.is_viewable(request.user)
    if not viewable:
        return response
    return display_wind_analysis(request, wind_obj)
    # Create your views here.

{'fraction_non_alphanumeric': 0.08532296872108087, 'fraction_numerical': 0.006662965019433648, 'mean_word_length': 2.3606965174129355, 'pattern_counts': {'":': 0, '<': 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': '7354148', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1526, 'n_words': 344}