<commit_before>''' -- imports from installed packages -- '''
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response, render
from django.template import RequestContext
from mongokit import paginator
import json

try:
    from bson import ObjectId
except ImportError:  # old pymongo
    from pymongo.objectid import ObjectId
from gnowsys_ndf.ndf.models import File

''' -- imports from application folders/files -- '''
from gnowsys_ndf.settings import META_TYPE, GAPPS, MEDIA_ROOT
from gnowsys_ndf.ndf.models import node_collection
from gnowsys_ndf.ndf.views.methods import get_node_common_fields,create_grelation_list,get_execution_time, delete_grelation, create_grelation
from gnowsys_ndf.ndf.views.methods import get_node_metadata, node_thread_access, create_thread_for_node
from gnowsys_ndf.ndf.management.commands.data_entry import create_gattribute
from gnowsys_ndf.ndf.templatetags.ndf_tags import get_relation_value,get_file_obj
from gnowsys_ndf.ndf.views.methods import get_node_metadata, get_node_common_fields, create_gattribute, get_page, get_execution_time,set_all_urls,get_group_name_id
gapp_mt = node_collection.one({'_type': "MetaType", 'name': META_TYPE[0]})
GST_IMAGE = node_collection.one({'member_of': gapp_mt._id, 'name': GAPPS[3]})
image_ins = node_collection.find_one({'_type': "GSystemType", "name": "Image"})
file_gst = node_collection.find_one( { "_type" : "GSystemType","name":"File" } )

@get_execution_time
def imageDashboard(request, group_id, image_id=None,page_no=1):
    from gnowsys_ndf.settings import GSTUDIO_NO_OF_OBJS_PP
    '''
    fetching image acording to group name
    '''
    # ins_objectid  = ObjectId()
    # if ins_objectid.is_valid(group_id) is False :
    #     group_ins = node_collection.find_one({'_type': "Group", "name": group_id})
    #     auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #     if group_ins:
    #         group_id = str(group_ins._id)
    #     else :
    #         auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #         if auth :
    #             group_id = str(auth._id)
    # else :
    #     pass
    try:
        group_id = ObjectId(group_id)
    except:
        group_name, group_id = get_group_name_id(group_id)

    if image_id is None:
        image_ins = node_collection.find_one({'_type': "GSystemType", "name": "Image"})
        if image_ins:
            image_id = str(image_ins._id)

    # img_col = node_collection.find({'_type': 'File', 'member_of': {'$all': [ObjectId(image_id)]}, 'group_set': ObjectId(group_id)}).sort("last_update", -1)
    files_cur = node_collection.find({
                                        '_type': {'$in': ["GSystem"]},
                                        'member_of': file_gst._id,
                                        'group_set': {'$all': [ObjectId(group_id)]},
                                        'if_file.mime_type': {'$regex': 'image'}

                                        # 'created_by': {'$in': gstaff_users},
                            # '$or': [
                                    # {
                                    # },
                                    # {
                                    #     '$or': [
                                    #             {'access_policy': u"PUBLIC"},
                                    #             {
                                    #                 '$and': [
                                    #                         {'access_policy': u"PRIVATE"},
                                    #                         {'created_by': request.user.id}
                                    #                     ]
                                    #             }
                                    #         ],
                                    # }
                                    # {    'collection_set': {'$exists': "true", '$not': {'$size': 0} }}
                                # ]
                        },
                        {
                            'name': 1,
                            '_id': 1,
                            'fs_file_ids': 1,
                            'member_of': 1,
                            'mime_type': 1,
                            'if_file':1
                        }).sort("last_update", -1)
    # print "file count\n\n\n",files_cur.count()

    image_page_info = paginator.Paginator(files_cur, page_no, GSTUDIO_NO_OF_OBJS_PP)
    template = "ndf/ImageDashboard.html"
    already_uploaded=request.GET.getlist('var',"")
    variable = RequestContext(request, {'imageCollection': files_cur,'already_uploaded':already_uploaded,'groupid':group_id,'group_id':group_id,'image_page_info':image_page_info })
    return render_to_response(template, variable)

@get_execution_time
def getImageThumbnail(request, group_id, _id):
    '''
    this funciton can be called to get thumbnail of image throw url
    '''
    # ins_objectid = ObjectId()
    # if ins_objectid.is_valid(group_id) is False :
    #     group_ins = node_collection.find_one({'_type': "Group","name": group_id})
    #     auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #     if group_ins:
    #         group_id = str(group_ins._id)
    #     else :
    #         auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #         if auth :
    #             group_id = str(auth._id)
    # else :
    #     pass
    try:
        group_id = ObjectId(group_id)
    except:<commit_msg>limit to show images changed in editor add image<commit_after>''' -- imports from installed packages -- '''
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response, render
from django.template import RequestContext
from mongokit import paginator
import json

try:
    from bson import ObjectId
except ImportError:  # old pymongo
    from pymongo.objectid import ObjectId
from gnowsys_ndf.ndf.models import File

''' -- imports from application folders/files -- '''
from gnowsys_ndf.settings import META_TYPE, GAPPS, MEDIA_ROOT
from gnowsys_ndf.ndf.models import node_collection
from gnowsys_ndf.ndf.views.methods import get_node_common_fields,create_grelation_list,get_execution_time, delete_grelation, create_grelation
from gnowsys_ndf.ndf.views.methods import get_node_metadata, node_thread_access, create_thread_for_node
from gnowsys_ndf.ndf.management.commands.data_entry import create_gattribute
from gnowsys_ndf.ndf.templatetags.ndf_tags import get_relation_value,get_file_obj
from gnowsys_ndf.ndf.views.methods import get_node_metadata, get_node_common_fields, create_gattribute, get_page, get_execution_time,set_all_urls,get_group_name_id
gapp_mt = node_collection.one({'_type': "MetaType", 'name': META_TYPE[0]})
GST_IMAGE = node_collection.one({'member_of': gapp_mt._id, 'name': GAPPS[3]})
image_ins = node_collection.find_one({'_type': "GSystemType", "name": "Image"})
file_gst = node_collection.find_one( { "_type" : "GSystemType","name":"File" } )

@get_execution_time
def imageDashboard(request, group_id, image_id=None,page_no=1):
    from gnowsys_ndf.settings import GSTUDIO_NO_OF_OBJS_PP
    '''
    fetching image acording to group name
    '''
    # ins_objectid  = ObjectId()
    # if ins_objectid.is_valid(group_id) is False :
    #     group_ins = node_collection.find_one({'_type': "Group", "name": group_id})
    #     auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #     if group_ins:
    #         group_id = str(group_ins._id)
    #     else :
    #         auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #         if auth :
    #             group_id = str(auth._id)
    # else :
    #     pass
    try:
        group_id = ObjectId(group_id)
    except:
        group_name, group_id = get_group_name_id(group_id)

    if image_id is None:
        image_ins = node_collection.find_one({'_type': "GSystemType", "name": "Image"})
        if image_ins:
            image_id = str(image_ins._id)

    # img_col = node_collection.find({'_type': 'File', 'member_of': {'$all': [ObjectId(image_id)]}, 'group_set': ObjectId(group_id)}).sort("last_update", -1)
    files_cur = node_collection.find({
                                        '_type': {'$in': ["GSystem"]},
                                        'member_of': file_gst._id,
                                        'group_set': {'$all': [ObjectId(group_id)]},
                                        'if_file.mime_type': {'$regex': 'image'}

                                        # 'created_by': {'$in': gstaff_users},
                            # '$or': [
                                    # {
                                    # },
                                    # {
                                    #     '$or': [
                                    #             {'access_policy': u"PUBLIC"},
                                    #             {
                                    #                 '$and': [
                                    #                         {'access_policy': u"PRIVATE"},
                                    #                         {'created_by': request.user.id}
                                    #                     ]
                                    #             }
                                    #         ],
                                    # }
                                    # {    'collection_set': {'$exists': "true", '$not': {'$size': 0} }}
                                # ]
                        },
                        {
                            'name': 1,
                            '_id': 1,
                            'fs_file_ids': 1,
                            'member_of': 1,
                            'mime_type': 1,
                            'if_file':1
                        }).sort("last_update", -1)
    # print "file count\n\n\n",files_cur.count()

    # image_page_info = paginator.Paginator(files_cur, page_no, GSTUDIO_NO_OF_OBJS_PP)
    template = "ndf/ImageDashboard.html"
    already_uploaded=request.GET.getlist('var',"")
    variable = RequestContext(request, {'imageCollection': files_cur,'already_uploaded':already_uploaded,'groupid':group_id,'group_id':group_id })
    return render_to_response(template, variable)

@get_execution_time
def getImageThumbnail(request, group_id, _id):
    '''
    this funciton can be called to get thumbnail of image throw url
    '''
    # ins_objectid = ObjectId()
    # if ins_objectid.is_valid(group_id) is False :
    #     group_ins = node_collection.find_one({'_type': "Group","name": group_id})
    #     auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #     if group_ins:
    #         group_id = str(group_ins._id)
    #     else :
    #         auth = node_collection.one({'_type': 'Author', 'name': unicode(request.user.username) })
    #         if auth :
    #             group_id = str(auth._id)
    # else :
    #     pass
    try:
        group_id = ObjectId(group_id)
    except:
{'fraction_non_alphanumeric': 0.11454945054945055, 'fraction_numerical': 0.0021098901098901097, 'mean_word_length': 1.8468468468468469, 'pattern_counts': {'":': 10, '<': 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': 60, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4037695', 'n_tokens_mistral': 3368, 'n_tokens_neox': 3269, 'n_words': 605}