示例#1
0
文件: views.py 项目: arthurlutz/btb
def show_profile(request, user_id):
    try:
        profile = Profile.objects.enrolled().filter(pk=user_id)[0]
    except IndexError:
        try:
            profile = Profile.objects.active_and_inactive_commenters().filter(
                    pk=user_id
            )[0]
        except IndexError:
            raise Http404
    can_edit = can_edit_profile(request.user, profile.pk)
    try:
        document = Document.objects.filter(
                author=profile.user, type="profile", 
                status="published").order_by('-modified')[0]
    except IndexError:
        document = None
    try:
        org = profile.user.organization_set.get()
    except Organization.DoesNotExist:
        org = None
    return render(request, "profiles/profile_detail.html", {
            'document': document,
            'favorites': profile.user.favorite_set.select_related(
                'document', 'comment'),
            'transcription_revisions': profile.user.transcriptionrevision_set.select_related(
                'transcription', 'transcription__document').all(),
            'comments': profile.user.comment_set.public().select_related(
                'document', 'document__author', 'document__author__profile'),
            'profile': profile,
            'org': org,
            'can_edit': can_edit,
        })
示例#2
0
def show_profile(request, user_id):
    try:
        profile = Profile.objects.enrolled().filter(pk=user_id)[0]
    except IndexError:
        try:
            profile = Profile.objects.commenters().filter(pk=user_id)[0]
        except IndexError:
            raise Http404
    can_edit = can_edit_profile(request.user, profile.pk)
    try:
        document = Document.objects.filter(
            author=profile.user, type="profile",
            status="published").order_by('-modified')[0]
    except IndexError:
        document = None
    try:
        org = profile.user.organization_set.get()
    except Organization.DoesNotExist:
        org = None
    return render(
        request, "profiles/profile_detail.html", {
            'document': document,
            'profile': profile,
            'org': org,
            'can_edit': can_edit,
        })
示例#3
0
文件: views.py 项目: Shidash/btb
def show_profile(request, user_id):
    try:
        profile = Profile.objects.enrolled().filter(pk=user_id)[0]
    except IndexError:
        try:
            profile = Profile.objects.commenters().filter(pk=user_id)[0]
        except IndexError:
            raise Http404
    can_edit = can_edit_profile(request.user, profile.pk)
    try:
        document = Document.objects.filter(
                author=profile.user, type="profile", 
                status="published").order_by('-modified')[0]
    except IndexError:
        document = None
    try:
        org = profile.user.organization_set.get()
    except Organization.DoesNotExist:
        org = None
    return render(request, "profiles/profile_detail.html", {
            'document': document,
            'profile': profile,
            'org': org,
            'can_edit': can_edit,
        })
示例#4
0
def show_profile(request, user_id):
    try:
        profile = Profile.objects.enrolled().filter(pk=user_id)[0]
    except IndexError:
        try:
            profile = Profile.objects.active_and_inactive_commenters().filter(
                    pk=user_id
            )[0]
        except IndexError:
            raise Http404
    can_edit = can_edit_profile(request.user, profile.pk)
    try:
        document = Document.objects.filter(
                author=profile.user, type="profile", 
                status="published").order_by('-modified')[0]
    except IndexError:
        document = None
    try:
        org = profile.user.organization_set.get()
    except Organization.DoesNotExist:
        org = None
    return render(request, "profiles/profile_detail.html", {
            'document': document,
            'favorites': profile.user.favorite_set.select_related(
                'document', 'comment'),
            'transcription_revisions': profile.user.transcriptionrevision_set.select_related(
                'transcription', 'transcription__document').all(),
            'comments': profile.user.comment_set.public().select_related(
                'document', 'document__author', 'document__author__profile'),
            'profile': profile,
            'org': org,
            'can_edit': can_edit,
        })
示例#5
0
文件: views.py 项目: catstar/btb
def remove_scan(request, user_id):
    if not can_edit_profile(request.user, user_id):
        raise PermissionDenied

    profile = Profile.objects.get(pk=user_id)
    docs = profile.user.documents_authored.filter(type="profile").order_by("-modified")

    if request.method == "POST":
        for doc in docs:
            doc.scan.full_delete()
        messages.success(request, "Scan removed.")
        return redirect("profiles.profile_edit", profile.pk)

    return render(request, "profiles/confirm_delete_scan.html", {"profile": profile})
示例#6
0
def remove_scan(request, user_id):
    if not can_edit_profile(request.user, user_id):
        raise PermissionDenied
   
    profile = Profile.objects.get(pk=user_id)
    docs = profile.user.documents_authored.filter(type="profile").order_by("-modified")

    if request.method == 'POST':
        for doc in docs:
            doc.scan.full_delete()
        messages.success(request, "Scan removed.")
        return redirect("profiles.profile_edit", profile.pk)

    return render(request, "profiles/confirm_delete_scan.html", {
        'profile': profile,
    })
示例#7
0
文件: views.py 项目: catstar/btb
def show_profile(request, user_id):
    try:
        profile = Profile.objects.enrolled().filter(pk=user_id)[0]
    except IndexError:
        try:
            profile = Profile.objects.active_and_inactive_commenters().filter(pk=user_id)[0]
        except IndexError:
            raise Http404
    can_edit = can_edit_profile(request.user, profile.pk)
    try:
        document = Document.objects.filter(author=profile.user, type="profile", status="published").order_by(
            "-modified"
        )[0]
    except IndexError:
        document = None
    try:
        org = profile.user.organization_set.get()
    except Organization.DoesNotExist:
        org = None
    return render(
        request,
        "profiles/profile_detail.html",
        {
            "document": document,
            "favorites": profile.user.favorite_set.select_related("document", "comment"),
            "transcription_revisions": profile.user.transcriptionrevision_set.select_related(
                "transcription", "transcription__document"
            ).all(),
            "comments": profile.user.comment_set.public().select_related(
                "document", "document__author", "document__author__profile"
            ),
            "profile": profile,
            "org": org,
            "can_edit": can_edit,
        },
    )
示例#8
0
文件: views.py 项目: arthurlutz/btb
def edit_profile(request, user_id=None):
    edit_profile = can_edit_profile(request.user, user_id)
    edit_user = can_edit_user(request.user, user_id)
    if not edit_profile and not edit_user:
        raise PermissionDenied

    user = get_object_or_404(User, pk=user_id)
    try:
        document = Document.objects.filter(type="profile", status="published",
                                           author=user).order_by('-modified')[0]
    except IndexError:
        document = None

    # XXX Could probably simplify the permissions backflips by assuming that an
    # editor using this interface either has permissions to edit both
    # profile/user, or neither.
    
    user_form = None
    profile_form = None
    scan_upload_form = None
    ProfileForm = get_profile_form(request.user)
    if request.method == 'POST':
        if edit_profile:
            profile_form = ProfileForm(request.POST, instance=user.profile)
            scan_upload_form = ProfileUploadForm(request.POST, request.FILES)
        if edit_user:
            user_form = UserFormNoEmail(request.POST, instance=user)

        if (not profile_form or profile_form.is_valid()) and \
                (not user_form or user_form.is_valid()) and \
                (not scan_upload_form or scan_upload_form.is_valid()):

            if profile_form:
                profile_form.save()
            if user_form:
                user_form.save()
            if scan_upload_form and 'file' in request.FILES:
                pdf = move_scan_file(uploaded_file=request.FILES['file'])
                scan = Scan.objects.create(
                    uploader=user, 
                    author=user,
                    pdf=pdf
                )
                task_id = process_scan_to_profile.delay(
                    scan.pk, 
                    reverse('profiles.profile_show', args=[user_id]),
                )
                return redirect('moderation.wait_for_processing', task_id=task_id)
            messages.success(request, _("Changes saved."))
            return redirect('profiles.profile_show', user_id)
    else:
        if edit_profile:
            profile_form = ProfileForm(instance=user.profile)
            scan_upload_form = ProfileUploadForm()
        if edit_user:
            user_form = UserFormNoEmail(instance=user)

    return render(request, "profiles/profile_edit.html", {
            'document': document,
            'profile_form': profile_form,
            'user_form': user_form,
            'scan_upload_form': scan_upload_form,
            'profile': user.profile,
            'can_edit_profile': edit_profile,
            'can_edit_user': edit_user,
        })
示例#9
0
def edit_profile(request, user_id=None):
    #FIXME: org permission here
    edit_profile = can_edit_profile(request.user, user_id)
    edit_user = can_edit_user(request.user, user_id)
    if not edit_profile and not edit_user:
        raise PermissionDenied

    user = get_object_or_404(User, pk=user_id)
    try:
        document = Document.objects.filter(
            type="profile", status="published",
            author=user).order_by('-modified')[0]
    except IndexError:
        document = None

    # XXX Could probably simplify the permissions backflips by assuming that an
    # editor using this interface either has permissions to edit both
    # profile/user, or neither.

    user_form = None
    profile_form = None
    scan_upload_form = None
    ProfileForm = get_profile_form(request.user)
    if request.method == 'POST':
        if edit_profile:
            profile_form = ProfileForm(request.POST, instance=user.profile)
            scan_upload_form = ProfileUploadForm(request.POST, request.FILES)
        if edit_user:
            user_form = UserFormNoEmail(request.POST, instance=user)

        if (not profile_form or profile_form.is_valid()) and \
                (not user_form or user_form.is_valid()) and \
                (not scan_upload_form or scan_upload_form.is_valid()):

            if profile_form:
                profile_form.save()
            if user_form:
                user_form.save()
            if scan_upload_form and 'file' in request.FILES:
                pdf = move_scan_file(uploaded_file=request.FILES['file'])
                scan = Scan.objects.create(uploader=user, author=user, pdf=pdf)
                task_id = process_scan_to_profile.delay(
                    scan.pk,
                    reverse('profiles.profile_show', args=[user_id]),
                )
                return redirect('moderation.wait_for_processing',
                                task_id=task_id)
            messages.success(request, _("Changes saved."))
            return redirect('profiles.profile_show', user_id)
    else:
        if edit_profile:
            profile_form = ProfileForm(instance=user.profile)
            scan_upload_form = ProfileUploadForm()
        if edit_user:
            user_form = UserFormNoEmail(instance=user)

    return render(
        request, "profiles/profile_edit.html", {
            'document': document,
            'profile_form': profile_form,
            'user_form': user_form,
            'scan_upload_form': scan_upload_form,
            'profile': user.profile,
            'can_edit_profile': edit_profile,
            'can_edit_user': edit_user,
        })