Beispiel #1
0
def ChildrenList(request, boundary_id):
	''' To display the Child details according to Pagination'''
	queryset = []
	reqlist= request.GET.items()
	itemlist=[str(k[0]) for k in reqlist]
	url = '/boundary/'+boundary_id+'/child/view/'
	schools = School.objects.filter(boundary__id = boundary_id,active=2)
	studentGroups = StudentGroup.objects.filter(content_type__model="boundary",object_id = boundary_id,active=2)
        if 'count' in itemlist:
		count = request.GET['count']
	else:
		count = '0'
	if 'fieldName' in itemlist or 'searchtext' in itemlist:
		fieldName = request.GET['fieldName']
		searchtext = request.GET['searchtext']
		url+='?fieldName='+fieldName+'&searchtext='+searchtext
		queryset = getStudentSearch(request, boundary_id, fieldName,searchtext)
	else:
		studentslist=Student.objects.filter(school__isnull=False).values_list('child__id',flat=True)
		queryset=Child.objects.exclude(id__in = studentslist, boundary__id = boundary_id).order_by('firstName')
	boundary = Boundary.objects.get(pk = boundary_id)
	val=Collection(queryset,
	permitted_methods = ('GET', 'POST'),
	responder = TemplateResponder(
	paginate_by = 10,
	template_dir = 'viewtemplates',
	template_object_name = 'child',
	extra_context = {'url':url,'schools':schools,'count':count,'boundary':boundary,'studentGroups':studentGroups}
	),
	entry_class = ChoiceEntry,
	)
	return HttpResponse(val(request))
Beispiel #2
0
def filtered_json_resource(queryset):
    return Collection(
        queryset=queryset,
        permitted_methods=('GET', 'POST', 'PUT', 'DELETE'),
        expose_fields=['owner', 'version', 'subj', 'pred', 'obj'],
        form_class=SPOForm,
        receiver=JSONReceiver(),
        responder=JSONResponder())
Beispiel #3
0
def KLP_StudentGroup_View(request, studentgroup_id):
    """ To View Selected StudentGroup studentsroup/(?P<studentsroup_id>\d+)/view/?$"""
    reqlist = request.GET.items()
    itemlist = [str(k[0]) for k in reqlist]
    if 'count' in itemlist:
        count = request.GET['count']
    else:
        count = '0'
    kwrg = {'is_entry': True}
    studentgroup = StudentGroup.objects.get(id=studentgroup_id)
    url = '/studentgroup/' + studentgroup_id + '/view/'
    school = Institution.objects.get(id=studentgroup.institution.id)
    studgrpParent = school
    # Get All centers under Institution
    studentGroups = StudentGroup.objects.filter(
        institution__id=studgrpParent.id, group_type="Center", active=2)
    # Get Total Number of students
    Norecords = Student_StudentGroupRelation.objects.filter(
        student_group__id=studentgroup_id, academic=current_academic,
        active=2).count()
    # Query Child onjects
    child_list = Student_StudentGroupRelation.objects.filter(
        student_group__id=studentgroup_id,
        academic=current_academic,
        active=2,
        student__active=2).values_list('student__child', flat=True)

    students = Child.objects.filter(id__in=child_list).extra(
        select={
            'lower_firstname': 'lower(trim("firstName"))',
            'lower_midname': 'lower(trim("middleName"))',
            'lower_lastname': 'lower(trim("lastName"))'
        }).order_by('lower_firstname', 'lower_midname', 'lower_lastname')
    resp = Collection(
        students,
        permitted_methods=('GET', 'POST'),
        responder=TemplateResponder(template_dir='viewtemplates',
                                    template_object_name='students',
                                    paginate_by=20,
                                    extra_context={
                                        'studgrpParent': studgrpParent,
                                        'studentgroup': studentgroup,
                                        'url': url,
                                        'students': students,
                                        'Norecords': Norecords,
                                        'studentGroups': studentGroups,
                                        'count': count
                                    }),
    )
    return HttpResponse(resp(request))
Beispiel #4
0
def KLP_staff_list(request, institution_id):
	""" To view list of staff in school school/(?P<school_id>\d+)/staff/view/"""	
	queryset = Staff.objects.filter(institution__id = institution_id, active=2).order_by('firstName')
	url = '/institution/%s/staff/view/' %(institution_id)
	val= Collection(queryset,
	permitted_methods = ('GET', 'POST'),
	responder = TemplateResponder(
	paginate_by = 10,
	template_dir = 'viewtemplates',
	template_object_name = 'staff',
	extra_context = {'url':url,}
	),
	entry_class = ChoiceEntry,
	)
	return HttpResponse(val(request))
Beispiel #5
0
from django.conf.urls.defaults import *
from django_restapi.model_resource import Collection
from django_restapi.responder import *
from django_restapi_tests.polls.models import Poll, Choice

fixedend_poll_resource = Collection(
    queryset=Poll.objects.all(),
    responder=XMLResponder(),
)
fixedend_choice_resource = Collection(queryset=Choice.objects.all(),
                                      responder=XMLResponder())

urlpatterns = patterns('', url(r'^polls/xml/$', fixedend_poll_resource),
                       url(r'^polls/(.*)/xml/$', fixedend_poll_resource),
                       url(r'^choices/xml/$', fixedend_choice_resource),
                       url(r'^choices/(.*)/xml/$', fixedend_choice_resource))
Beispiel #6
0
from django_restapi.model_resource import Collection, Entry
from django_restapi.responder import JSONResponder
from django_restapi.authentication import HttpBasicAuthentication
from django_restapi.receiver import JSONReceiver

from library.synapse.models import Document, Keyword, Source, Publisher, Publication, Employee, Department, EmployeeDepartment
from library.synapse.api.collections import PublicationCollection, PublicationEntry, KeywordCollection, KeywordEntry

json_source_resource = Collection(queryset=Source.objects.all(),
                                  permitted_methods=('GET', 'POST', 'PUT',
                                                     'DELETE'),
                                  responder=JSONResponder(paginate_by=200),
                                  receiver=JSONReceiver(),
                                  authentication=HttpBasicAuthentication())

json_publisher_resource = Collection(queryset=Publisher.objects.all(),
                                     permitted_methods=('GET', 'POST', 'PUT',
                                                        'DELETE'),
                                     responder=JSONResponder(paginate_by=200),
                                     receiver=JSONReceiver(),
                                     authentication=HttpBasicAuthentication())

json_document_resource = Collection(queryset=Document.objects.all(),
                                    permitted_methods=('GET', 'POST', 'PUT',
                                                       'DELETE'),
                                    responder=JSONResponder(paginate_by=200),
                                    receiver=JSONReceiver(),
                                    authentication=HttpBasicAuthentication())

json_employee_resource = Collection(queryset=Employee.objects.all(),
                                    permitted_methods=('GET', 'POST', 'PUT',
Beispiel #7
0
        ##d['owner'] = User.objects
        print dir(request)
        print 'here d=', d
        return d


class JSONReceiverSetOwner(JSONReceiver):
    def get_data(self, request, method):
        d = super(JSONReceiverSetOwner, self).get_data(request, method)
        return d


fullxml_spo_resource = Collection(
    queryset=SPO.objects.all(),
    permitted_methods=('GET', 'POST', 'PUT', 'DELETE'),
    expose_fields=['owner', 'version', 'subj', 'pred', 'obj'],
    form_class=SPOForm,
    receiver=XMLReceiver(),
    responder=XMLResponder(),
)
fulljson_spo_resource = Collection(
    queryset=SPO.objects.all(),
    permitted_methods=('GET', 'POST', 'PUT', 'DELETE'),
    expose_fields=['owner', 'version', 'subj', 'pred', 'obj'],
    form_class=SPOForm,
    receiver=JSONReceiver(),
    responder=JSONResponder())


def filtered_xml_resource(queryset):
    return Collection(
        queryset=queryset,
Beispiel #8
0
 def __init__(self, *args, **kwargs):
     if 'entry_class' not in kwargs:
         kwargs['entry_class'] = PkEntry
     Collection.__init__(self, *args, **kwargs)
Beispiel #9
0
def KLP_StudentGroup_Answer_Entry(request, studentgroup_id, programme_id,
                                  assessment_id):
    """ To Show Answer Entry Form studentgroup/(?P<studentgroup_id>\d+)/programme/(?P<programme_id>\d+)/assessment/(?P<assessment_id>\d+)/view/"""
    """ This Method is used for to generate student answers grid to enter data/answers for the assessment questions """
    user = request.user  #get logged in user
    url = "/studentgroup/%s/programme/%s/assessment/%s/view/" % (
        studentgroup_id, programme_id, assessment_id)
    # Query Childs based on studentgroup relation

    students = Student_StudentGroupRelation.objects.select_related(
        "student").filter(student_group__id=studentgroup_id,
                          academic=current_academic,
                          active=2).values_list('student__child',
                                                flat=True).distinct()
    grupObj = StudentGroup.objects.filter(
        pk=studentgroup_id).only("group_type")
    schoolIdentity = grupObj.getSchoolIdentity()
    childs_list = Child.objects.filter(id__in=students).extra(
        select={
            'lower_firstname': 'lower(trim("firstName"))'
        }).order_by('lower_firstname').defer("mt")
    question_list = Question.objects.filter(assessment__id=assessment_id,
                                            active=2).defer("assessment")
    studIdList, qNamesList, qIdList, chList, rDict, childDict, counter=[], [], [], [], {}, {}, 0
    paginator = Paginator(childs_list, 20)

    page = request.GET.get('page')  #get page to show result
    try:
        page = int(page)  # If page is there convert to inr
    except (ValueError, TypeError):
        page = 1  # else default page is 1
    try:
        pagchilds_list = paginator.page(page)
    except (EmptyPage, InvalidPage):
        # If page is out of range (e.g. 9999), deliver last page of results.
        pagchilds_list = paginator.page(paginator.num_pages)

    for child in pagchilds_list.object_list:
        chDic = {}

        chId = child.id
        chList.append(chId)
        # Query for active student using child object
        student = Student.objects.filter(child=child, active=2).defer("child")
        studId = student[0].id
        # get Child and student information to show in grid.
        if child.dob:
            dOfB = child.dob.strftime("%d-%m-%Y")
        else:
            dOfB = ''
        chDic = {
            'studId': studId,
            'Gender': child.gender,
            'dob': dOfB,
            'firstName': child.firstName,
            'lastName': child.lastName
        }
        # get relations
        try:
            relObj = Relations.objects.filter(
                child=child, relation_type="Father").only("first_name")
            chDic['fName'] = relObj[0].first_name
        except:
            chDic['fName'] = ''

        try:
            relObj = Relations.objects.filter(
                child=child, relation_type="Mother").only("first_name")
            chDic['mName'] = relObj[0].first_name
        except:
            chDic['mName'] = ''

        studIdList.append(studId)
        childDict[chId] = chDic
    rDict, ansStudList = {}, []
    counter = counter + 1

    for ques in question_list:
        qNamesList.append(ques.name)
        # get Question Information
        qId = ques.id
        qIdList.append(qId)
        dataDict = {'qId': qId, 'qOrder': ques.order}
        qType = ques.questionType
        dataDict['qType'] = qType
        if qType == 2:
            # if quetion type is 2(marks) get grades to do validation while data entry
            ansIn = ques.grade
            dataDict['ansIn'] = ansIn
        else:
            # else get minmum and maximum score to do validation while data entry
            dataDict['scMin'] = ques.scoreMin
            dataDict['scMax'] = ques.scoreMax
        qDict = {}
        # Query For Answers based on question id and studens
        ansList = Answer.objects.select_related("user1").filter(
            question=ques,
            student__id__in=studIdList).defer("question").values()
        if ansList:
            for ansObj in ansList:
                # If answers is there get answer Information
                ansDict = dict(dataDict)
                dEntry = ansObj['doubleEntry']

                firstUser = ansObj['user1_id']
                studentId = ansObj['student_id']
                ansStudList.append(studentId)
                if dEntry == 2:
                    # if dEntry is 2 (doubleentry is finished) then dont show input box
                    ansDict['iBox'] = False
                else:
                    # else show input box
                    ansDict['iBox'] = True
                status = ansObj['status']
                if status == -99999:
                    # if answer status is -99999(absent) then show answer value as 'AB'.
                    ansVal = 'AB'
                elif status == -1:
                    # if answer status is -1(unknown) then show answer value as 'UK'.
                    ansVal = 'UK'
                elif qType == 2:
                    # if question type is 2(grade) then show answer grade
                    ansVal = ansObj['answerGrade']
                else:
                    # else show answer score
                    ansVal = ansObj['answerScore']
                ansDict['ansVal'] = ansVal
                ansDict['shVal'] = False
                if firstUser != user.id and dEntry == 1:
                    # if dEntry is 1, (first entry finished doubleentry is not finished) and logged in user is not match with first user who enter data, then make dE attribute true to do validation while doubleentry
                    ansDict['dE'] = True
                elif firstUser == user.id and dEntry == 1:
                    # if dEntry is 1, (first entry finished doubleentry is not finished) and logged in user is match with first user who enter data, then make shVal attribute true to show answer value in input box.
                    ansDict['shVal'] = True

                qDict[studentId] = ansDict

        rDict[qId] = qDict
    noAnsList = list(set(studIdList).difference(set(ansStudList)))
    if noAnsList:
        # If No Answers Found get only Question Information to show empty text box.
        for ques in question_list:
            qId = ques.id
            dataDict = {'qId': qId, 'qOrder': ques.order}
            qType = ques.questionType
            dataDict['qType'] = qType
            if qType == 2:
                ansIn = ques.grade
                dataDict['ansIn'] = ansIn
            else:
                dataDict['scMin'] = ques.scoreMin
                dataDict['scMax'] = ques.scoreMax
            qDict = rDict[qId]
            for stId in noAnsList:
                ansDict = dict(dataDict)
                ansDict['iBox'] = True
                ansDict['ansVal'] = ''
                qDict[stId] = ansDict

    val = Collection(
        childs_list,
        permitted_methods=('GET', 'POST'),
        responder=TemplateResponder(template_dir='prgtemplates',
                                    template_object_name='childs',
                                    paginate_by=20,
                                    extra_context={
                                        'filter_id': programme_id,
                                        'assessment_id': assessment_id,
                                        'user': user,
                                        'studentgroup_id': studentgroup_id,
                                        'question_list': question_list,
                                        'group_typ': grupObj[0].group_type,
                                        'url': url,
                                        'studIdList': studIdList,
                                        'rDict': rDict,
                                        'qNamesList': qNamesList,
                                        'chList': chList,
                                        'childDict': childDict,
                                        'rDict': rDict,
                                        'qIdList': qIdList,
                                        'schoolIdentity': schoolIdentity
                                    }),
        entry_class=ChoiceEntry,
    )
    return HttpResponse(val(request))
Beispiel #10
0
# -*- coding: utf-8 -*-

from django_restapi.model_resource import Collection
from django_restapi.responder import JSONResponder
from django_restapi.authentication import HttpDigestAuthentication, HttpBasicAuthentication
from core.types import *

xml_news_resource = Collection(
    queryset=News.objects.all(),
    permitted_methods=('GET', 'POST', 'PUT', 'DELETE'),
    responder=JSONResponder(paginate_by=10),
)

xml_page_resource = Collection(
    queryset=Page.objects.all(),
    permitted_methods=('GET', 'POST', 'PUT', 'DELETE'),
    responder=JSONResponder(paginate_by=10)  #
)

xml_photo_resource = Collection(
    queryset=Photo.objects.all(),
    permitted_methods=('GET', 'POST', 'PUT', 'DELETE'),
    responder=JSONResponder(paginate_by=10)  #
)

xml_file_resource = Collection(
    queryset=File.objects.all(),
    permitted_methods=('GET', 'POST', 'PUT', 'DELETE'),
    responder=JSONResponder(paginate_by=10)  #
)
Beispiel #11
0
 def read(self, request):
     return self.fixResponse(Collection.read(self, request))
Beispiel #12
0
 def create(self, request):
     return self.fixResponse(Collection.create(self, request))
Beispiel #13
0
def TreeClass(request):
    model = request.GET['root']
    data = request.GET['home']
    filterBy = request.GET['filter']
    secFilter = request.GET['secFilter']
    if secFilter == 'None' and filterBy != 'None':
        secFilter = GetAssementList(filterBy)
    if filterBy != 'None' and secFilter != 'None':
        seclist = [secFilter]
        secFilter = seclist
    boundaryType = request.GET['boundTyp']
    permFilter = request.GET.get('permission')
    assessmentPerm = request.GET.get('assesspermission')
    shPerm = request.GET.get('shPerm')
    userSel = request.GET.get('userSel')
    model = model.split('_')
    typ = model[0]
    logUser = request.user
    klp_UserGroups = logUser.groups.all()
    user_GroupsList = ['%s' % (usergroup.name) for usergroup in klp_UserGroups]
    if typ == "source":
        # if type is source
        if data:
            # if home is true query for boundaries
            if (logUser.is_superuser or logUser.is_staff
                    or 'AdminGroup' in user_GroupsList) and filterBy == 'None':
                # if logged in user is super user or staff or in AdminGroup and filterBy is none query all active boundary's where parent is 1 and based on boundaryType
                query = Boundary.objects.filter(
                    parent__id=1, active=2,
                    boundary_type=boundaryType).order_by("name").extra(
                        select={
                            'lower_name': 'lower(name)'
                        }).order_by("lower_name")
            else:
                if (logUser.is_superuser or logUser.is_staff
                        or 'AdminGroup' in user_GroupsList):
                    # if logged in user is super user or staff or in AdminGroup and filterBy is not none query all active SG's based on assessments
                    print secFilter, 'sssssssssssssssss'
                    studentgroup_list = Assessment_StudentGroup_Association.objects.filter(
                        assessment__id__in=secFilter,
                        active=2).values_list('student_group',
                                              flat=True).distinct()
                    # Query institutions based SG's
                    institutions_list = StudentGroup.objects.filter(
                        id__in=studentgroup_list,
                        active=2).values_list('institution__id',
                                              flat=True).distinct()
                elif filterBy == 'None':
                    # if user is not superuser and not staff and not related to admin group and filterby is none get all assigned institutions.
                    institutions_list = KLP_assignedInstitutions(logUser.id)
                else:
                    # else query for institutions based on map Sg's
                    studentgroup_list = Assessment_StudentGroup_Association.objects.filter(
                        assessment__id__in=secFilter,
                        active=2).values_list('student_group',
                                              flat=True).distinct()
                    map_institutions_list = StudentGroup.objects.filter(
                        id__in=studentgroup_list,
                        active=2).values_list('institution__id',
                                              flat=True).distinct()

                    institutions_list = list(
                        set(map_institutions_list) & set(
                            KLP_assignedAssessmentInst(logUser.id, secFilter)))
                try:
                    boundary_list = Boundary.objects.filter(
                        institution__pk__in=institutions_list,
                        active=2,
                        boundary_type=boundaryType).values_list(
                            'parent__parent__id', flat=True).distinct()
                except:
                    boundary_list = Boundary.objects.filter(
                        institution__pk__in=institutions_list,
                        active=2,
                        boundary_type=boundaryType).values_list(
                            'parent__id', flat=True).distinct()

                query = Boundary.objects.filter(
                    pk__in=boundary_list, active=2,
                    parent__id=1).distinct().extra(select={
                        'lower_name': 'lower(name)'
                    }).order_by("lower_name")

        else:
            # if data is not true query for all active programmes.
            query = Programme.objects.filter(
                active=2, programme_institution_category=boundaryType).extra(
                    select={
                        'lower_name': 'lower(name)'
                    }).order_by("-startDate", "-endDate", "lower_name")
            typ = 'programme'
    else:
        # typ is not source
        if typ == 'boundary':
            # if typ is boundary Query for sub boundaries or Institutions
            if (logUser.is_superuser or logUser.is_staff
                    or 'AdminGroup' in user_GroupsList) and filterBy == 'None':
                # if logged in user is super user or staff or in AdminGroup and filterBy is none query all active boundary's where parent is 1 and based on boundaryType
                query = Boundary.objects.filter(
                    parent__id=model[1], active=2,
                    boundary_type=boundaryType).extra(
                        select={
                            'lower_name': 'lower(name)'
                        }).order_by("lower_name")
            else:
                if (logUser.is_superuser or logUser.is_staff
                        or 'AdminGroup' in user_GroupsList):
                    # if logged in user is super user or staff or in AdminGroup and filterBy is not none query all active SG's based on assessments
                    studentgroup_list = Assessment_StudentGroup_Association.objects.filter(
                        assessment__id__in=secFilter,
                        active=2).values_list('student_group',
                                              flat=True).distinct()
                    # Query institutions based SG's
                    institutions_list = StudentGroup.objects.filter(
                        id__in=studentgroup_list,
                        active=2).values_list('institution_id',
                                              flat=True).distinct()
                elif filterBy == 'None':
                    # if user is not superuser and not staff and not related to admin group and filterby is none get all assigned institutions.
                    institutions_list = KLP_assignedInstitutions(logUser.id)
                else:
                    # else query for institutions based on map Sg's
                    studentgroup_list = Assessment_StudentGroup_Association.objects.filter(
                        assessment__id__in=secFilter,
                        active=2).values_list('student_group',
                                              flat=True).distinct()
                    map_institutions_list = StudentGroup.objects.filter(
                        id__in=studentgroup_list,
                        active=2).values_list('institution_id',
                                              flat=True).distinct()
                    institutions_list = list(
                        set(map_institutions_list) & set(
                            KLP_assignedAssessmentInst(logUser.id, secFilter)))

                parentBoundary = Boundary.objects.get(id=model[1])
                if parentBoundary.boundary_category.boundary_category in [
                        'district',
                ]:
                    # Query for Boundaries based on institutions
                    boundary_list = Boundary.objects.filter(
                        institution__pk__in=institutions_list,
                        active=2,
                        boundary_type=boundaryType).values_list(
                            'parent', flat=True).distinct()
                    query = Boundary.objects.filter(
                        parent__id=model[1],
                        pk__in=boundary_list,
                        active=2,
                        boundary_type=boundaryType).distinct().extra(
                            select={
                                'lower_name': 'lower(name)'
                            }).order_by("lower_name")
                else:
                    boundaries = Boundary.objects.filter(
                        parent__id=model[1],
                        institution__pk__in=institutions_list,
                        active=2,
                        boundary_type=boundaryType).values_list(
                            'id', flat=True).distinct()
                    query = Boundary.objects.filter(id__in=boundaries).extra(
                        select={
                            'lower_name': 'lower(name)'
                        }).order_by("lower_name")

            if not query:
                # If Query is Empty Query for Institutions under boundary
                if (logUser.is_superuser or logUser.is_staff or 'AdminGroup'
                        in user_GroupsList) and filterBy == 'None':
                    # if logged in user is super user or staff or in AdminGroup and filterBy is none query all active institutions's based on boundary
                    query = Institution.objects.filter(
                        boundary__id=model[1],
                        active=2).extra(select={
                            'lower_name': 'lower(name)'
                        }).order_by("lower_name")
                    typ = 'sch'
                else:
                    if (logUser.is_superuser or logUser.is_staff
                            or 'AdminGroup' in user_GroupsList):
                        # if logged in user is super user or staff or in AdminGroup and filterBy is not none query all active SG's based on assessments
                        studentgroup_list = Assessment_StudentGroup_Association.objects.filter(
                            assessment__id__in=secFilter,
                            active=2).values_list('student_group',
                                                  flat=True).distinct()
                        institutions_list = StudentGroup.objects.filter(
                            id__in=studentgroup_list,
                            active=2).values_list('institution_id',
                                                  flat=True).distinct()

                    elif filterBy == 'None':
                        # if user is not superuser and not staff and not related to admin group and filterby is none get all assigned institutions.
                        institutions_list = KLP_assignedInstitutions(
                            logUser.id)
                    else:
                        # else query for institutions based on map Sg's
                        studentgroup_list = Assessment_StudentGroup_Association.objects.filter(
                            assessment__id__in=secFilter,
                            active=2).values_list('student_group',
                                                  flat=True).distinct()
                        map_institutions_list = StudentGroup.objects.filter(
                            id__in=studentgroup_list,
                            active=2).values_list('institution_id',
                                                  flat=True).distinct()
                        institutions_list = list(
                            set(map_institutions_list) & set(
                                KLP_assignedAssessmentInst(
                                    logUser.id, secFilter)))

                    query = Institution.objects.filter(
                        pk__in=institutions_list,
                        boundary__id=model[1],
                        active=2).distinct().extra(select={
                            'lower_name': 'lower(name)'
                        }).order_by("lower_name")
                    typ = 'sch'

        elif typ == 'programme':
            # if typ is programme Query For active assessment based On programme id
            query = Assessment.objects.filter(programme__id=model[1], active=2)
        elif typ == 'assessment':
            # if typ is assessment Query For active Questions based On assessment id
            query = Question.objects.filter(assessment__id=model[1], active=2)
        else:
            if typ == 'institution':
                # if typ is Institution Query For active Sgs
                if filterBy != 'None':

                    studentgroup_list = Assessment_StudentGroup_Association.objects.filter(
                        assessment__id__in=secFilter,
                        active=2).values_list('student_group',
                                              flat=True).distinct()
                    query = StudentGroup.objects.filter(
                        institution__id=model[1],
                        active=2,
                        id__in=studentgroup_list).distinct().extra(
                            select={
                                'lower_class': 'lower(name)'
                            }).order_by("lower_class", "section")
                else:
                    query = StudentGroup.objects.filter(
                        institution__id=model[1],
                        active=2).extra(select={
                            'lower_class': 'lower(name)'
                        }).order_by("lower_class", "section")

    CDict = hasChild(query, typ, boundaryType, filterBy, secFilter, permFilter,
                     assessmentPerm, shPerm,
                     userSel)  # Checking for child objects
    val = Collection(
        queryset=query,
        responder=TreeResponder(CDict=CDict),
    )
    return HttpResponse(val(request), mimetype="application/json")
Beispiel #14
0
    def get_url(self):
        return reverse(self, (), {'poll_id': self.model.poll.id})


class ChoiceEntry(Entry):
    def get_url(self):
        choice_num = self.model.get_num()
        return reverse(self.collection, (), {
            'poll_id': self.model.poll.id,
            'choice_num': choice_num
        })


json_poll_resource = Collection(queryset=Poll.objects.all(),
                                permitted_methods=('GET', 'POST', 'PUT',
                                                   'DELETE'),
                                expose_fields=('id', 'question', 'pub_date'),
                                responder=JSONResponder(paginate_by=10))

json_choice_resource = ChoiceCollection(queryset=Choice.objects.all(),
                                        permitted_methods=('GET', 'POST',
                                                           'PUT', 'DELETE'),
                                        expose_fields=('id', 'poll_id',
                                                       'choice', 'votes'),
                                        responder=JSONResponder(paginate_by=5),
                                        entry_class=ChoiceEntry)

urlpatterns = patterns(
    '',
    url(r'^json/polls/(?P<poll_id>\d+)/choices/(?P<choice_num>\d+)/$',
        json_choice_resource, {'is_entry': True}),
Beispiel #15
0
from django.conf.urls.defaults import *
from django_restapi.model_resource import Collection
from django_restapi.responder import *
from django_restapi_tests.polls.models import Poll, Choice

template_poll_resource = Collection(
    queryset=Poll.objects.all(),
    permitted_methods=('GET', 'POST', 'PUT', 'DELETE'),
    expose_fields=('id', 'question', 'pub_date'),
    responder=TemplateResponder(template_dir='polls',
                                template_object_name='poll',
                                paginate_by=10))

template_choice_resource = Collection(
    queryset=Choice.objects.all(),
    permitted_methods=('GET', ),
    expose_fields=('id', 'poll_id', 'choice', 'votes'),
    responder=TemplateResponder(template_dir='polls',
                                template_object_name='choice',
                                paginate_by=5))

urlpatterns = patterns(
    '',
    url(r'^html/polls/creator/$',
        template_poll_resource.responder.create_form),
    url(r'^html/polls/(?P<pk>\d+)/editor/$',
        template_poll_resource.responder.update_form),
    url(r'^html/polls/(.*?)/?$', template_poll_resource),
    url(r'^html/choices/(.*?)/?$', template_choice_resource),
)
Beispiel #16
0
from django.conf.urls.defaults import *
from django_restapi.model_resource import Collection
from django_restapi.responder import *
from django_restapi_tests.polls.models import Poll, Choice

xml_poll_resource = Collection(queryset=Poll.objects.all(),
                               permitted_methods=('GET', 'POST', 'PUT',
                                                  'DELETE'),
                               expose_fields=('id', 'question', 'pub_date'),
                               responder=XMLResponder(paginate_by=10))

xml_choice_resource = Collection(queryset=Choice.objects.all(),
                                 permitted_methods=('GET', ),
                                 expose_fields=('id', 'poll_id', 'choice'),
                                 responder=XMLResponder(paginate_by=5))

urlpatterns = patterns('', url(r'^xml/polls/(.*?)/?$', xml_poll_resource),
                       url(r'^xml/choices/(.*?)/?$', xml_choice_resource))
Beispiel #17
0
 def __call__(self, request, *args, **kwargs):
     print "READ"
     return self.fixResponse(Collection.__call__(self, request, *args, **kwargs))
Beispiel #18
0
from django.conf.urls.defaults import *
from django_restapi.model_resource import Collection
from django_restapi.responder import *
from django_restapi.authentication import *
from django_restapi_tests.polls.models import Poll

# HTTP Basic
#
# No auth function specified
# -> django.contrib.auth.models.User is used.
# Test with username 'rest', password 'rest'.

basicauth_poll_resource = Collection(queryset=Poll.objects.all(),
                                     responder=XMLResponder(),
                                     authentication=HttpBasicAuthentication())

# HTTP Digest


def digest_authfunc(username, realm):
    """
    Exemplary authfunc for HTTP Digest. In production situations,
    the combined hashes of realm, username and password are usually
    stored in an external file/db.
    """
    hashes = {
        ('realm1', 'john'):
        '3014aff1d0d0f0038e23c1195301def3',  # Password: johnspass
        ('realm2', 'jim'):
        '5bae77fe607e161b831c8f8026a2ceb2'  # Password: jimspass
    }
Beispiel #19
0
from django.conf.urls.defaults import *
from django_restapi.model_resource import Collection
from django_restapi.responder import *
from django_restapi.receiver import *
from django_restapi_tests.polls.models import Poll

fullxml_poll_resource = Collection(
    queryset = Poll.objects.all(), 
    permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
    receiver = XMLReceiver(),
    responder = XMLResponder(),
)
fulljson_poll_resource = Collection(
    queryset = Poll.objects.all(),
    permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
    receiver = JSONReceiver(),
    responder = JSONResponder()
)

urlpatterns = patterns('',
   url(r'^fullxml/polls/(.*?)/?$', fullxml_poll_resource),
   url(r'^fulljson/polls/(.*?)/?$', fulljson_poll_resource)
)
Beispiel #20
0
from django_restapi.model_resource import Collection
from django_restapi.responder import XMLResponder
from django_restapi.resource import Resource
from django_restapi.authentication import *

from django.contrib.auth.models import User
from django.shortcuts import render_to_response, get_object_or_404

from uwcs_website.games.models import Game

#class UserEntry(Resource):
#    def read(self, request, user_id):
#        context = {'friendship':get_object_or_404(}
#        return render_to_response('xml/user.xml', context)

xml_user = Collection(queryset=User.objects.all(),
                      permitted_methods=('GET', ),
                      expose_fields=('first_name', 'last_name', 'is_staff'),
                      responder=XMLResponder(),
                      authentication=HttpBasicAuthentication())

xml_games = Collection(
    queryset=Game.objects.all(),
    permitted_methods=('GET', ),
    responder=XMLResponder(),
)
Beispiel #21
0
    def __init__(self, *args, **kwargs):
	Collection.__init__(self, CampaignFile, *args, **kwargs)
	self.receiver =  receiver.FormReceiver()
	self.permitted_methods = ('GET', 'POST', 'PUT', 'DELETE')