Beispiel #1
0
def dashboard_my_forms(request):
    template = loader.get_template('dashboard/my_dashboard_my_forms.html')
    # xml_data_id False if document not curated
    forms = FormData.objects(user=str(request.user.id), xml_data_id__exists=False,
                                 xml_data__exists=True).order_by('template')
    detailed_forms = []
    for form in forms:
        detailed_forms.append({'form': form, 'template_name': Template.objects().get(pk=form.template).title,
                               'user': form.user})
    user_form = UserForm(request.user)
    context = RequestContext(request, {'forms': detailed_forms,
                                       'user_form': user_form
    })
    #If the user is an admin, we get forms for other users
    if request.user.is_staff:
        #Get user name for admin
        usernames = dict((str(x.id), x.username) for x in User.objects.all())
        other_users_detailed_forms = []
        otherUsersForms = FormData.objects(user__ne=str(request.user.id), xml_data_id__exists=False,
                                                       xml_data__exists=True).order_by('template')
        for form in otherUsersForms:
            other_users_detailed_forms.append({'form': form,
                                               'template_name': Template.objects().get(pk=form.template).title,
                                               'user': form.user})
        context.update({'otherUsersForms': other_users_detailed_forms, 'usernames': usernames})

    return HttpResponse(template.render(context))
Beispiel #2
0
def dashboard_records(request):
    template = loader.get_template('dashboard/my_dashboard_my_records.html')
    query = {}
    # ispublished = request.GET.get('ispublished', None)
    #If ispublished not None, check if we want publish or unpublish records
    # if ispublished:
    #     ispublished = ispublished == 'true'
    #     query['ispublished'] = ispublished
    query['iduser'] = str(request.user.id)
    userXmlData = sorted(XMLdata.find(query), key=lambda data: data['lastmodificationdate'], reverse=True)
    #Add user_form for change owner
    owner = UserProfile.objects.get(user=User.objects.get(id=request.user.id))

    user_form = UserForm(request.user)
    context = RequestContext(request, {'XMLdatas': userXmlData,
                                       # 'ispublished': ispublished,
                                       'user_form': user_form,
                                       'myGroup': dataGroup.objects.filter(owner=owner.id),
                                       'otherGroup': owner.get_group()
    })
    #If the user is an admin, we get records for other users
    if request.user.is_staff:
        #Get user name for admin
        usernames = dict((str(x.id), x.username) for x in User.objects.all())
        query['iduser'] = {"$ne": str(request.user.id)}
        otherUsersXmlData = sorted(XMLdata.find(query), key=lambda data: data['lastmodificationdate'], reverse=True)
        context.update({'OtherUsersXMLdatas': otherUsersXmlData, 'usernames': usernames})

    return HttpResponse(template.render(context))
Beispiel #3
0
def dashboard_my_drafts(request):
    forms = FormData.objects(user=str(request.user.id), xml_data_id__exists=False, xml_data__exists=True).order_by('template') # xml_data_id False if document not curated
    detailed_forms = []
    for form in forms:
        detailed_forms.append({'form': form, 'template_name': Template.objects().get(pk=form.template).title})
    user_form = UserForm(request.user)

    return render(request, 'dashboard/my_dashboard_my_forms.html', {'forms':detailed_forms, 'user_form': user_form})
Beispiel #4
0
def dashboard_records(request):
    template = loader.get_template('dashboard/my_dashboard_my_records.html')
    query = {}
    # ispublished = request.GET.get('ispublished', None)
    #If ispublished not None, check if we want publish or unpublish records
    # if ispublished:
    #     ispublished = ispublished == 'true'
    #     query['ispublished'] = ispublished
    query['iduser'] = str(request.user.id)
    userXmlData = sorted(XMLdata.find(query), key=lambda data: data['lastmodificationdate'], reverse=True)
    # Get all the templates
    #templates_used = Template.find()
    templates_used = sorted(Template.find(query), key=lambda data: data['content'], reverse=True)
    #Add user_form for change owner
    user_form = UserForm(request.user)
    otherUsers = User.objects.all()
    #otherUXMLdatas = sorted(XMLdata.objects(user=str(userId)).distinct(field='title'), key=lambda data: data['lastmodificationdate'], reverse=True)
    idotherUsers = User.objects.only('_id')
    otherUXMLdatas = [] # sorted(XMLdata.find(query), key=lambda data: data['lastmodificationdate'], reverse=True)
    otherUsersTemplates = []
    otherUXMLd =[]
    usernames = []
#    for idotherUser in idotherUsers:
#        otherUXMLdata = Template.objects(user = str(idotherUser)).distinct(field ='title')
#        otherUXMLdatas.append(otherUXMLdata)

    #otherXMLdatas = XMLdata.objects(user = (str()))
    context = RequestContext(request, {'XMLdatas': userXmlData,
                                       # 'ispublished': ispublished,
                                       'user_form': user_form,
                                       'Templates': templates_used,
                                       'OtherUsersXMLdatas': otherUXMLdatas,
                                       'OtherUsers': otherUsers,
                                       'IdotherUsers':idotherUsers,
                                       'OtherUXMLd' : otherUXMLd,
                                       'usernames' : usernames,
                                       'totaldocs_user' : len(userXmlData),
                                       'totaldocs_other_users' : len(otherUXMLdatas)
    })
    #If the user is an admin, we get records for other users
    if request.user.is_staff:
        #Get user name for admin
        usernames = dict((str(x.id), x.username) for x in User.objects.all())
        query['iduser'] = {"$ne": str(request.user.id)}
        otherUsersXmlData = sorted(XMLdata.find(query), key=lambda data: data['lastmodificationdate'], reverse=True)
        context.update({'OtherUsersXMLdatas': otherUsersXmlData, 'usernames': usernames, 'totaldocs_other_users': len(otherUsersXmlData)})

        i = None
        for elem in context['OtherUsersXMLdatas']:
            i = context['OtherUsersXMLdatas'].index(elem)
            j = 0
            for k,v in context['usernames'].items():
                if j == i:
                    other_users.append((k,v))

    return HttpResponse(template.render(context))
Beispiel #5
0
def dashboard_otherusers_records(request):
    template = loader.get_template('dashboard/my_dashboard_otherusersrecords.html')
    query = {}
    iduser = request.GET['iduser']

    query['iduser'] = str(iduser)
    userXmlData = sorted(XMLdata.find(query), key=lambda data: data['lastmodificationdate'], reverse=True)

    templates_used = sorted(Template.find(query), key=lambda data: data['content'], reverse=True)
    user_form = UserForm(request.user)

    context = RequestContext(request, {'XMLdatass': userXmlData,
                                       # 'ispublished': ispublished,
                                       'user_formm': user_form,
                                       'Templatess': templates_used
    })

    return HttpResponse(template.render(context))
Beispiel #6
0
def dashboard_resources(request):
    template = loader.get_template('dashboard/my_dashboard_my_records.html')
    query = {}
    context = RequestContext(request, {})
    ispublished = request.GET.get('ispublished', None)
    role_name_list = request.GET.getlist('role', ['all'])

    role_name = ''
    for role in role_name_list:
        role_name += role + ','
    context.update({'roles': role_name[:-1]})

    query['iduser'] = str(request.user.id)

    if ispublished:
        ispublished = ispublished == 'true'
        query['ispublished'] = ispublished

    if not (len(role_name_list) == 1 and role_name_list[0] == 'all'):
        query['$or'] = [{
            "content.Resource.role.@xsi:type": role
        } for role in role_name_list]

    userXmlData = sorted(XMLdata.find(query),
                         key=lambda data: data['lastmodificationdate'],
                         reverse=True)
    #Add user_form for change owner
    user_form = UserForm(request.user)
    context.update({
        'XMLdatas': userXmlData,
        'ispublished': ispublished,
        'user_form': user_form
    })

    #If the user is an admin, we get records for other users
    if request.user.is_staff:
        #Get user name for admin
        usernames = dict((str(x.id), x.username) for x in User.objects.all())
        query['iduser'] = {"$ne": str(request.user.id)}
        otherUsersXmlData = sorted(
            XMLdata.find(query),
            key=lambda data: data['lastmodificationdate'],
            reverse=True)
        context.update({
            'OtherUsersXMLdatas': otherUsersXmlData,
            'usernames': usernames
        })

    #Get new version of records
    listIds = [str(x['_id']) for x in userXmlData]
    if request.user.is_staff:
        listIdsOtherUsers = [str(x['_id']) for x in otherUsersXmlData]
        listIds = list(set(listIds).union(set(listIdsOtherUsers)))

    drafts = FormData.objects(xml_data_id__in=listIds,
                              isNewVersionOfRecord=True).all()
    XMLdatasDrafts = dict()
    for draft in drafts:
        XMLdatasDrafts[draft.xml_data_id] = draft.id
    context.update({'XMLdatasDrafts': XMLdatasDrafts})

    #Add Status enum
    context.update({'Status': Status})

    return HttpResponse(template.render(context))
def dashboard_resources(request):
    template = loader.get_template('dashboard/my_dashboard_my_records.html')
    query = {}
    context = RequestContext(request, {})
    ispublished = request.GET.get('ispublished', None)
    template_name = request.GET.get('template', None)
    query['iduser'] = str(request.user.id)
    #If ispublished not None, check if we want publish or unpublish records
    if ispublished:
        ispublished = ispublished == 'true'
        query['ispublished'] = ispublished
    if template_name:
        context.update({'template': template_name})
        if template_name == 'datacollection':
            templateNamesQuery = list(
                chain(
                    Template.objects.filter(
                        title=template_name).values_list('id'),
                    Template.objects.filter(
                        title='repository').values_list('id'),
                    Template.objects.filter(
                        title='database').values_list('id'),
                    Template.objects.filter(
                        title='projectarchive').values_list('id')))
        else:
            templateNamesQuery = Template.objects.filter(
                title=template_name).values_list('id')
        templateNames = []
        for templateQuery in templateNamesQuery:
            templateNames.append(str(templateQuery))

        query['schema'] = {"$in": templateNames}

    userXmlData = sorted(XMLdata.find(query),
                         key=lambda data: data['lastmodificationdate'],
                         reverse=True)
    #Add user_form for change owner
    user_form = UserForm(request.user)
    context.update({
        'XMLdatas': userXmlData,
        'ispublished': ispublished,
        'user_form': user_form
    })

    #If the user is an admin, we get records for other users
    if request.user.is_staff:
        #Get user name for admin
        usernames = dict((str(x.id), x.username) for x in User.objects.all())
        query['iduser'] = {"$ne": str(request.user.id)}
        otherUsersXmlData = sorted(
            XMLdata.find(query),
            key=lambda data: data['lastmodificationdate'],
            reverse=True)
        context.update({
            'OtherUsersXMLdatas': otherUsersXmlData,
            'usernames': usernames
        })

    #Get new version of records
    listIds = [str(x['_id']) for x in userXmlData]
    if request.user.is_staff:
        listIdsOtherUsers = [str(x['_id']) for x in otherUsersXmlData]
        listIds = list(set(listIds).union(set(listIdsOtherUsers)))

    drafts = FormData.objects(xml_data_id__in=listIds,
                              isNewVersionOfRecord=True).all()
    XMLdatasDrafts = dict()
    for draft in drafts:
        XMLdatasDrafts[draft.xml_data_id] = draft.id
    context.update({'XMLdatasDrafts': XMLdatasDrafts})

    #Add Status enum
    context.update({'Status': Status})

    return HttpResponse(template.render(context))