コード例 #1
0
ファイル: views.py プロジェクト: NateWr/rua
def dashboard(request):
	if request.user.is_authenticated():
		roles=  request.user.profile.roles.all()
		if request.GET.get('next'):
			return redirect(request.GET.get('next'))
		elif string_any('Editor' in role.name for role in roles):
			return redirect(reverse('editor_dashboard'))
		elif string_any('Author' in role.name for role in roles):
			return redirect(reverse('author_dashboard'))
		elif string_any('Reviewer' in role.name for role in roles):
			return redirect(reverse('reviewer_dashboard'))
		else:
			return redirect(reverse('onetasker_dashboard'))
コード例 #2
0
ファイル: views.py プロジェクト: stuartjennings-up/rua
def proposal_history(request, proposal_id):

    proposal = submission_models.Proposal.objects.get(pk=proposal_id)
    history = submission_models.HistoryProposal.objects.filter(proposal = proposal).order_by('pk')
    proposal_form_id = core_models.Setting.objects.get(name='proposal_form').value

    if proposal.owner == request.user:
        viewable = True

    proposal_form = manager_forms.GeneratedForm(form=core_models.ProposalForm.objects.get(pk=proposal.form.id))
    default_fields = manager_forms.DefaultForm(initial={'title': proposal.title,'author':proposal.author,'subtitle':proposal.subtitle})

    intial_data={}
    data = {}
    if proposal.data:
        data = json.loads(proposal.data)
        for k,v in data.items():
            intial_data[k] = v[0]


    proposal_form.initial=intial_data

    roles = request.user.profile.roles.all()
    user_roles = [role.slug for role in request.user.profile.roles.all()]

    if string_any('Editor' in role.name for role in roles):
        viewable = True
        editor = True
        if proposal.requestor and not proposal.requestor == request.user and not 'press-editor' in user_roles:
            editor = False

        print editor
    else:
        editor = False

    if proposal.status == 'accepted' or proposal.status == 'declined':
        not_readonly = False
    else:
        not_readonly = True
    template = "submission/history_proposal.html"
    context = {
        'proposal_form': proposal_form,
        'default_fields': default_fields,
        'proposal':proposal,
        'not_readonly':not_readonly,
        'data':data,
        'history': history,
        'revise':True,
        'open': True,
        'editor': editor,
        'viewable':viewable,
        'core_proposal':core_models.ProposalForm.objects.get(pk=proposal_form_id),
    }

    return render(request, template, context)
コード例 #3
0
ファイル: logic.py プロジェクト: NateWr/rua
def get_onetasker_emails(submission_id,term):
    submission = get_object_or_404(models.Book, pk=submission_id)
    onetaskers = submission.onetaskers()

    results = []
    for user in onetaskers:
        user_json = {}
        name = user.first_name+' '+user.last_name
        user_json['id'] = user.id
        user_json['label'] = user.profile.full_name()
        user_json['value'] = user.email
        if not string_any(user_json['value'] for result in results) and term.lower() in name.lower():
        	    results.append(user_json)
    return results
コード例 #4
0
ファイル: views.py プロジェクト: NateWr/rua
def get_all(request, submission_id):
    submission = get_object_or_404(models.Book, pk=submission_id)
    if request.is_ajax():
        q = request.GET.get('term', '')
        onetasker_results = logic.get_onetasker_emails(submission_id,q)
        editor_results = logic.get_editor_emails(submission_id,q)
        author_results = logic.get_author_emails(submission_id,q)
        results = []
        for user in onetasker_results:
        	if not string_any(user['value'] in result['value'] for result in results):

        	   results.append(user)
        for author in author_results:
        	if not string_any(author['value'] in result['value'] for result in results):
        	    results.append(author)
        	    
        for editor in editor_results:
        	if not string_any(editor['value'] in result['value'] for result in results):
        	    results.append(editor)
        data = json.dumps(results)
    else:
        data = 'Unable to get any user'
    mimetype = 'application/json'
    return HttpResponse(data, mimetype)
コード例 #5
0
ファイル: logic.py プロジェクト: stuartjennings-up/rua
def get_proposal_emails(proposal_id,term):
	proposal = get_object_or_404(submission_models.Proposal, pk=proposal_id)

	results = []
	user_json = {}
	user = proposal.owner
	name = user.first_name+' '+user.last_name
	user_json['id'] = user.id
	user_json['label'] = user.profile.full_name()
	user_json['value'] = user.email
	if not string_any(user_json['value'] for result in results) and term.lower() in name.lower():
		results.append(user_json)
	
	if proposal.requestor:
		user_json = {}
		user = proposal.requestor
		name = user.first_name+' '+user.last_name
		user_json['id'] = user.id
		user_json['label'] = user.profile.full_name()
		user_json['value'] = user.email
		if not string_any(user_json['value'] for result in results) and term.lower() in name.lower():
			results.append(user_json)

	return results	
コード例 #6
0
ファイル: views.py プロジェクト: stuartjennings-up/rua
def proposal_view(request, proposal_id):

    proposal = submission_models.Proposal.objects.get(pk=proposal_id)
    proposal_form_id = core_models.Setting.objects.get(name='proposal_form').value
    notes = submission_models.ProposalNote.objects.filter(proposal=proposal)

    if proposal.owner == request.user:
        viewable = True

    proposal_form = manager_forms.GeneratedForm(form=core_models.ProposalForm.objects.get(pk=proposal.form.id))
    default_fields = manager_forms.DefaultForm(initial={'title': proposal.title,'author':proposal.author,'subtitle':proposal.subtitle})

    intial_data={}
    data = {}
    if proposal.data:
        data = json.loads(proposal.data)
        for k,v in data.items():
            intial_data[k] = v[0]


    proposal_form.initial=intial_data

    roles = request.user.profile.roles.all()
    user_roles = [role.slug for role in request.user.profile.roles.all()]

    if string_any('Editor' in role.name for role in roles):
        viewable = True
        editor = True
        if proposal.requestor and not proposal.requestor == request.user and not 'press-editor' in user_roles:
            editor = False

        print editor
    else:
        editor = False

    if request.POST and editor:
        proposal_form = manager_forms.GeneratedForm(request.POST, request.FILES, form=core_models.ProposalForm.objects.get(pk=proposal.form.id))
        default_fields = manager_forms.DefaultForm(request.POST)
        if proposal_form.is_valid() and default_fields.is_valid():

            proposal_data_processing(request,proposal,proposal_form_id)
            proposal = submission_models.Proposal.objects.get(form=core_models.ProposalForm.objects.get(pk=proposal.form.id),pk=proposal_id)
            history_proposal =  submission_models.HistoryProposal.objects.create(
                proposal = proposal,
                title = proposal.title,
                author = proposal.author,
                subtitle = proposal.subtitle,
                date_submitted = proposal.date_submitted,
                form = proposal.form,
                data = proposal.data,
                date_review_started = proposal.date_review_started,
                review_form = proposal.review_form,
                requestor = proposal.requestor,
                revision_due_date = proposal.revision_due_date,
                date_accepted = proposal.date_accepted,
                book_type = proposal.book_type,
                status = proposal.status,
                owner = proposal.owner,
                user_edited = request.user,
                date_edited = timezone.now(),
                version = proposal.current_version
                )
            history_proposal.save()
            proposal.status = "submission"
            defaults=default_fields.cleaned_data
            proposal.title = defaults.get("title")
            proposal.author = defaults.get("author")
            proposal.subtitle = defaults.get("subtitle")
            proposal_type=request.POST.get('proposal-type')
            proposal.current_version = proposal.current_version + 1
            if proposal_type:
                proposal.book_type = proposal_type
            proposal.requestor=request.user
            proposal.save()

            update_email_text = core_models.Setting.objects.get(group__name='email', name='proposal_update_ack').value
            log.add_proposal_log_entry(proposal=proposal,user=request.user, kind='proposal', message='Proposal "%s %s" has been updated.'%(proposal.title,proposal.subtitle), short_name='Proposal Updated')
            core_logic.send_proposal_update(proposal, email_text=update_email_text, sender=request.user, receiver=proposal.owner)
            messages.add_message(request, messages.SUCCESS, 'Proposal %s updated' % proposal.id)
            return redirect(reverse('user_dashboard'))

    if proposal.status == 'accepted' or proposal.status == 'declined':
        not_readonly = False
    else:
        not_readonly = True
    template = "submission/view_proposal.html"
    context = {
        'proposal_form': proposal_form,
        'default_fields': default_fields,
        'proposal':proposal,
        'not_readonly':not_readonly,
        'data':data,
        'revise':True,
        'editor': editor,
        'viewable':viewable,
        'notes': notes,
        'core_proposal':core_models.ProposalForm.objects.get(pk=proposal_form_id),
    }

    return render(request, template, context)
コード例 #7
0
ファイル: views.py プロジェクト: StuJ/rua-1
def proposal_history(request, proposal_id):
    proposal = submission_models.Proposal.objects.get(pk=proposal_id)
    history = submission_models.HistoryProposal.objects.filter(
        proposal=proposal).order_by('pk')
    proposal_form_id = core_models.Setting.objects.get(
        name='proposal_form').value

    if proposal.owner == request.user:
        viewable = True

    proposal_form = manager_forms.GeneratedForm(
        form=core_models.ProposalForm.objects.get(pk=proposal.form.id))
    default_fields = manager_forms.DefaultForm(
        initial={
            'title': proposal.title,
            'author': proposal.author,
            'subtitle': proposal.subtitle
        })
    intial_data = {}
    data = {}

    if proposal.data:
        data = json.loads(proposal.data)
        for k, v in data.items():
            intial_data[k] = v[0]

    proposal_form.initial = intial_data
    roles = request.user.profile.roles.all()
    user_roles = [role.slug for role in request.user.profile.roles.all()]

    if string_any('Editor' in role.name for role in roles):
        viewable = True
        _editor = True
        if (proposal.requestor and not proposal.requestor == request.user
                and not 'press-editor' in user_roles):
            _editor = False
    else:
        _editor = False

    if proposal.status == 'accepted' or proposal.status == 'declined':
        not_readonly = False
    else:
        not_readonly = True

    template = "submission/history_proposal.html"
    context = {
        'proposal_form': proposal_form,
        'default_fields': default_fields,
        'proposal': proposal,
        'not_readonly': not_readonly,
        'data': data,
        'history': history,
        'revise': True,
        'open': True,
        'editor': _editor,
        'viewable': viewable,
        'core_proposal':
        core_models.ProposalForm.objects.get(pk=proposal_form_id),
    }

    return render(request, template, context)
コード例 #8
0
ファイル: views.py プロジェクト: StuJ/rua-1
def proposal_view(request, proposal_id):
    proposal = submission_models.Proposal.objects.get(pk=proposal_id)
    proposal_form_id = core_models.Setting.objects.get(
        name='proposal_form', ).value
    notes = submission_models.ProposalNote.objects.filter(proposal=proposal)

    if proposal.owner == request.user:
        viewable = True

    proposal_form = manager_forms.GeneratedForm(
        form=core_models.ProposalForm.objects.get(pk=proposal.form.id))
    default_fields = manager_forms.DefaultForm(
        initial={
            'title': proposal.title,
            'author': proposal.author,
            'subtitle': proposal.subtitle
        })

    intial_data = {}
    data = {}

    if proposal.data:
        data = json.loads(proposal.data)
        for k, v in data.items():
            intial_data[k] = v[0]

    proposal_form.initial = intial_data
    roles = request.user.profile.roles.all()
    user_roles = [role.slug for role in request.user.profile.roles.all()]

    if string_any('Editor' in role.name for role in roles):
        viewable = True
        _editor = True
        if (proposal.requestor and not proposal.requestor == request.user
                and not 'press-editor' in user_roles):
            _editor = False
    else:
        _editor = False

    if request.POST and _editor:
        proposal_form = manager_forms.GeneratedForm(
            request.POST,
            request.FILES,
            form=core_models.ProposalForm.objects.get(pk=proposal.form.id))
        default_fields = manager_forms.DefaultForm(request.POST)

        if proposal_form.is_valid() and default_fields.is_valid():
            proposal_data_processing(request, proposal, proposal_form_id)
            proposal = submission_models.Proposal.objects.get(
                form=core_models.ProposalForm.objects.get(pk=proposal.form.id),
                pk=proposal_id,
            )
            history_proposal = submission_models.HistoryProposal.objects.create(
                proposal=proposal,
                title=proposal.title,
                author=proposal.author,
                subtitle=proposal.subtitle,
                date_submitted=proposal.date_submitted,
                form=proposal.form,
                data=proposal.data,
                date_review_started=proposal.date_review_started,
                review_form=proposal.review_form,
                requestor=proposal.requestor,
                revision_due_date=proposal.revision_due_date,
                date_accepted=proposal.date_accepted,
                book_type=proposal.book_type,
                status=proposal.status,
                owner=proposal.owner,
                user_edited=request.user,
                date_edited=timezone.now(),
                version=proposal.current_version)
            history_proposal.save()
            proposal.status = "submission"
            defaults = default_fields.cleaned_data
            proposal.title = defaults.get("title")
            proposal.author = defaults.get("author")
            proposal.subtitle = defaults.get("subtitle")
            proposal_type = request.POST.get('proposal-type')
            proposal.current_version = proposal.current_version + 1

            if proposal_type:
                proposal.book_type = proposal_type

            proposal.requestor = request.user
            proposal.save()

            update_email_text = core_models.Setting.objects.get(
                group__name='email', name='proposal_update_ack').value
            log.add_proposal_log_entry(
                proposal=proposal,
                user=request.user,
                kind='proposal',
                message='Proposal "%s %s" has been updated.' %
                (proposal.title, proposal.subtitle),
                short_name='Proposal Updated',
            )
            core_logic.send_proposal_update(
                proposal,
                email_text=update_email_text,
                sender=request.user,
                receiver=proposal.owner,
            )
            messages.add_message(
                request,
                messages.SUCCESS,
                'Proposal %s updated' % proposal.id,
            )
            return redirect(reverse('user_dashboard'))

    if proposal.status == 'accepted' or proposal.status == 'declined':
        not_readonly = False
    else:
        not_readonly = True

    template = "submission/view_proposal.html"
    context = {
        'proposal_form': proposal_form,
        'default_fields': default_fields,
        'proposal': proposal,
        'not_readonly': not_readonly,
        'data': data,
        'revise': True,
        'editor': _editor,
        'viewable': viewable,
        'notes': notes,
        'core_proposal':
        core_models.ProposalForm.objects.get(pk=proposal_form_id),
    }

    return render(request, template, context)
コード例 #9
0
ファイル: views.py プロジェクト: NateWr/rua
def proposal_revisions(request, proposal_id):

	proposal = get_object_or_404(submission_models.Proposal, pk=proposal_id, owner=request.user, status='revisions_required')

	proposal_form = manager_forms.GeneratedForm(form=core_models.ProposalForm.objects.get(pk=proposal.form.id))
	default_fields = manager_forms.DefaultForm(initial={'title': proposal.title,'author':proposal.author,'subtitle':proposal.subtitle})
	data = json.loads(proposal.data)
	intial_data={}
	for k,v in data.items():
		intial_data[k] = v[0]

	proposal_form.initial=intial_data
	if request.POST:
		proposal_form = manager_forms.GeneratedForm(request.POST, request.FILES, form=core_models.ProposalForm.objects.get(pk=proposal.form.id))
		default_fields = manager_forms.DefaultForm(request.POST)
		if proposal_form.is_valid() and default_fields.is_valid():

			save_dict = {}
			file_fields = core_models.ProposalFormElementsRelationship.objects.filter(form=core_models.ProposalForm.objects.get(pk=proposal.form.id), element__field_type='upload')
			data_fields = core_models.ProposalFormElementsRelationship.objects.filter(~Q(element__field_type='upload'), form=core_models.ProposalForm.objects.get(pk=proposal.form.id))

			for field in file_fields:
				if field.element.name in request.FILES:
					# TODO change value from string to list [value, value_type]
					save_dict[field.element.name] = [handle_proposal_file(request.FILES[field.element.name], submission, review_assignment, 'reviewer')]

			for field in data_fields:
				if field.element.name in request.POST:
					# TODO change value from string to list [value, value_type]
					save_dict[field.element.name] = [request.POST.get(field.element.name), 'text']

			messages.add_message(request, messages.SUCCESS, 'Revisions for Proposal %s submitted' % proposal.id)
		
			json_data = json.dumps(save_dict)
			proposal = submission_models.Proposal.objects.get(form=core_models.ProposalForm.objects.get(pk=proposal.form.id), owner=request.user)
			proposal.data=json_data
			proposal.status = "revisions_submitted"
			defaults=default_fields.cleaned_data
			proposal.title = defaults.get("title")
			proposal.author = defaults.get("author")
			proposal.subtitle = defaults.get("subtitle")
			proposal.save()
			users = User.objects.all()

			for available_user in users:
				roles=  available_user.profile.roles.all()
				if string_any('Editor' for role in roles):
					task.create_new_general_task(creator=request.user, assignee=available_user, text="Revisions for Proposal '%s' with id %s submitted" % (proposal.title,proposal.id))
			

			messages.add_message(request, messages.SUCCESS, 'Proposal %s submitted' % proposal.id)
			return redirect(reverse('user_dashboard'))

	template = "submission/start_proposal.html"
	context = {
		'proposal_form': proposal_form,
		'default_fields': default_fields,
		'data':data,
		'revise':True,
	}

	return render(request, template, context)