Example #1
0
def receive_book_start(request, uniqname):
    """ Just show a form for the barcode
    On submit looks up the book type, if present redirects to receive_book
    If not saves the uniqname into request.session and redirects to
    create_book_type
    """
    if not Permissions.can_process_bookswap(request.user):
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM
        return get_previous_page(request, alternate='bookswap:admin_index')
    if not BookSwapStatus.can_receive(AcademicTerm.get_current_term()):
        request.session['error_message'] = 'Book receiving not enabled'
        return get_previous_page(request, alternate='bookswap:admin_index')
    form = BookSearchForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            barcode = form.cleaned_data.get('book_barcode', '')
            book_type = BookType.objects.filter(isbn=barcode)
            if book_type.exists():
                # TODO: If multiple give choice?
                book_type = book_type[0]
                request.session['success_message'] = ('Book found, please '
                                                      'enter sale details.')
                return redirect('bookswap:receive_book',
                                uniqname=uniqname,
                                book_type_id=book_type.id)

            else:
                request.session['warning_message'] = ('Book not found, please '
                                                      'enter details.')
                request.session['uniqname'] = uniqname
                request.session['isbn'] = barcode
                return redirect('bookswap:create_book_type')

        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form':
        form,
        'subnav':
        'admin',
        'has_files':
        False,
        'submit_name':
        'Search for book by ISBN',
        'form_title':
        'Search for a book in the system',
        'help_text': ('You can search for a book by its ISBN, which is the '
                      '13 digit code scanned by the barcode.'),
        'base':
        'bookswap/base_bookswap.html',
    }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #2
0
def complete_interview_followup(request,interview_id):
    interview = get_object_or_404(InterviewShift,id=interview_id)
    if not interview.user_can_followup(request.user):
        request.session['error_message']='Only interviewers may submit evaluations and only after the interview has started'
        return get_previous_page(request,alternate='electees:view_electee_groups')
    profile=request.user.userprofile.memberprofile
    previous_followup=ElecteeInterviewFollowup.objects.filter(interview=interview, member=profile)
    prefix='followup'
    if previous_followup.exists():
        verb = 'Update' 
        form = InterviewFollowupForm(request.POST or None, prefix=prefix,instance=previous_followup[0])
    else:
        verb='Add'
        blank_form = ElecteeInterviewFollowup(interview=interview, member=profile)
        form = InterviewFollowupForm(request.POST or None,prefix=prefix,instance=blank_form)
    if request.method =='POST':
        if form.is_valid():
            form.save()
            request.session['success_message']='Electee interview followup updated successfully'
            return get_previous_page(request,alternate='electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'

    template = loader.get_template('generic_form.html')
    help_text = r'''YOUR EVALUATION HERE IS ONE OF THE MOST IMPORTANT CRITERIA PERMITTING THE ELECTEE TO CONTINUE THE ELECTING PROCESS.

**Recommend**: You are confident that the electee has demonstrated exemplary character and would be a great member of Tau Beta Pi
**Not Sure**: This should only be selected in the extreme case, in which even after the interview you  still have absolutely no idea whether or not the electee would be a good candidate.
We trust your judgment as TBP members, so please make a decision (Recommend or Not) if at all possible. Please explain this choice *in detail* so that we can better understand your decision.
**Do Not Recommend**: You are confident that the electee does not demonstrate exemplary character and would not be a good member of Tau Beta Pi. Please explain this choice *in detail* so that we can better understand your decision.

Remember the [eligibility code of the association](http://www.tbp.org/off/eligCode.cfm), particularly that "the fact that people may not have shown unselfish activity to an appreciable degree throughout their courses of study is no infallible indication that they would not if the opportunity offered."

###Submission of this form constitutes your signature that the information contained herein is an accurate representation of the interview conducted.
'''
        
    context_dict = {
        'form':form,
        'prefix':prefix,
        'has_files':False,
        'submit_name':verb+' Interview Followup',
        'form_title':verb+' Submit Interview Followup for Electee: '+','.join([unicode(user_profile) for user_profile in interview.interviewee_shift.attendees.all()])+'---'+interview.interviewee_shift.event.name[:-10],
        'help_text':help_text,
        'base':'electees/base_electees.html',
        'back_button':{'link':reverse('electees:view_electee_groups'),'text':'To Electee Resources'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #3
0
def receive_book_start(request, uniqname):
    """ Just show a form for the barcode
    On submit looks up the book type, if present redirects to receive_book
    If not saves the uniqname into request.session and redirects to
    create_book_type
    """
    if not Permissions.can_process_bookswap(request.user):
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM
        return get_previous_page(request, alternate='bookswap:admin_index')
    if not BookSwapStatus.can_receive(AcademicTerm.get_current_term()):
        request.session['error_message'] = 'Book receiving not enabled'
        return get_previous_page(request, alternate='bookswap:admin_index')
    form = BookSearchForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            barcode = form.cleaned_data.get('book_barcode','')
            book_type = BookType.objects.filter(isbn=barcode)
            if book_type.exists():
                # TODO: If multiple give choice?
                book_type = book_type[0]
                request.session['success_message'] = ('Book found, please '
                                                      'enter sale details.')
                return redirect('bookswap:receive_book',
                                uniqname=uniqname,
                                book_type_id=book_type.id)

            else:
                request.session['warning_message'] = ('Book not found, please '
                                                      'enter details.')
                request.session['uniqname'] = uniqname
                request.session['isbn'] = barcode
                return redirect('bookswap:create_book_type')

        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form': form,
        'subnav': 'admin',
        'has_files': False,
        'submit_name': 'Search for book by ISBN',
        'form_title': 'Search for a book in the system',
        'help_text': ('You can search for a book by its ISBN, which is the '
                      '13 digit code scanned by the barcode.'),
        'base': 'bookswap/base_bookswap.html',
        }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #4
0
def complete_interview_followup(request,interview_id):
    interview = get_object_or_404(InterviewShift,id=interview_id)
    if not interview.user_can_followup(request.user):
        request.session['error_message']='Only interviewers may submit evaluations and only after the interview has started'
        return get_previous_page(request,alternate='electees:view_electee_groups')
    profile=request.user.userprofile.memberprofile
    previous_followup=ElecteeInterviewFollowup.objects.filter(interview=interview, member=profile)
    prefix='followup'
    if previous_followup.exists():
        verb = 'Update' 
        form = InterviewFollowupForm(request.POST or None, prefix=prefix,instance=previous_followup[0])
    else:
        verb='Add'
        blank_form = ElecteeInterviewFollowup(interview=interview, member=profile)
        form = InterviewFollowupForm(request.POST or None,prefix=prefix,instance=blank_form)
    if request.method =='POST':
        if form.is_valid():
            form.save()
            request.session['success_message']='Electee interview followup updated successfully'
            return get_previous_page(request,alternate='electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'

    template = loader.get_template('generic_form.html')
    help_text = r'''YOUR EVALUATION HERE IS ONE OF THE MOST IMPORTANT CRITERIA PERMITTING THE ELECTEE TO CONTINUE THE ELECTING PROCESS.

**Recommend**: You are confident that the electee has demonstrated exemplary character and would be a great member of Tau Beta Pi
**Not Sure**: This should only be selected in the extreme case, in which even after the interview you  still have absolutely no idea whether or not the electee would be a good candidate.
We trust your judgment as TBP members, so please make a decision (Recommend or Not) if at all possible. Please explain this choice *in detail* so that we can better understand your decision.
**Do Not Recommend**: You are confident that the electee does not demonstrate exemplary character and would not be a good member of Tau Beta Pi. Please explain this choice *in detail* so that we can better understand your decision.

Remember the [eligibility code of the association](http://www.tbp.org/off/eligCode.cfm), particularly that "the fact that people may not have shown unselfish activity to an appreciable degree throughout their courses of study is no infallible indication that they would not if the opportunity offered."

###Submission of this form constitutes your signature that the information contained herein is an accurate representation of the interview conducted.
'''
        
    context_dict = {
        'form':form,
        'prefix':prefix,
        'has_files':False,
        'submit_name':verb+' Interview Followup',
        'form_title':verb+' Submit Interview Followup for Electee: '+','.join([unicode(user_profile) for user_profile in interview.interviewee_shift.attendees.all()])+'---'+interview.interviewee_shift.event.name[:-10],
        'help_text':help_text,
        'base':'electees/base_electees.html',
        'back_button':{'link':reverse('electees:view_electee_groups'),'text':'To Electee Resources'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
Example #5
0
def view_map(request):
    """ The view of member locations.
    """
    if (not hasattr(request.user, 'userprofile') or
       not request.user.userprofile.is_member()):
        request.session['error_message'] = ('You must be logged in and a '
                                            'member to view this.')
        return get_previous_page(
                        request,
                        alternate='member_resources:index'
        )
    members_with_location = MemberProfile.get_members().exclude(location='')
    template = loader.get_template('fora/map.html')
    member = request.user.userprofile.memberprofile
    location = (member.location if member.location
                else GeoLocation(42.26, -83.7483))
    context_dict = {
        'members': members_with_location,
        'center': location,
        'can_center_on_me': bool(member.location),
    }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #6
0
def upload_article(request):
    if not Permissions.can_upload_articles(request.user):
        raise PermissionDenied()
    if request.method == 'POST':
        form = ArticleForm(request.POST,request.FILES)
        if form.is_valid():
            form.save()
            request.session['success_message']='Article uploaded successfully'
            return get_previous_page(request,'history:cornerstone_view')
        else:
            request.session['error_message']='There were errors in your submission. Please correct the noted errors.'
    else:
        form = ArticleForm()
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form':form,
        'subnav':'cornerstone',
        'has_files':True,
        'submit_name':'Upload Printed Publication',
        'form_title':'Upload Article',
        'help_text':'Make sure to specify the type of publication.',
        'base':'history/base_history.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #7
0
def upload_article(request):
    """ Upload a printed article """
    if not Permissions.can_upload_articles(request.user):
        raise PermissionDenied()
    form = ArticleForm(request.POST or None, request.FILES or None)
    if request.method == 'POST':
        if form.is_valid():
            form.save()
            request.session['success_message'] = ('Article uploaded '
                                                  'successfully')
            return get_previous_page(request, 'history:cornerstone_view')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form': form,
        'subnav': 'cornerstone',
        'has_files': True,
        'submit_name': 'Upload Printed Publication',
        'form_title': 'Upload Article',
        'help_text': 'Make sure to specify the type of publication.',
        'base': 'history/base_history.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
Example #8
0
def upload_article(request):
    if not Permissions.can_upload_articles(request.user):
        raise PermissionDenied()
    if request.method == 'POST':
        form = ArticleForm(request.POST,request.FILES)
        if form.is_valid():
            form.save()
            request.session['success_message']='Article uploaded successfully'
            return get_previous_page(request,'history:cornerstone_view')
        else:
            request.session['error_message']='There were errors in your submission. Please correct the noted errors.'
    else:
        form = ArticleForm()
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form':form,
        'subnav':'cornerstone',
        'has_files':True,
        'submit_name':'Upload Printed Publication',
        'form_title':'Upload Article',
        'help_text':'Make sure to specify the type of publication.',
        'base':'history/base_history.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #9
0
def update_bylaws(request):
    denied_message = 'You are not authorized to update bylaws.'
    if not Permissions.can_manage_bylaws(request.user):
        request.session['error_message'] = denied_message
        return redirect('about:bylaws')
    form = GoverningDocumentForm(request.POST or None, request.FILES or None)
    if request.method == 'POST':
        if form.is_valid():
            form.save()
            request.session['success_message'] = ('Document uploaded '
                                                  'successfully')
            return get_previous_page(request, 'about:bylaws')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form': form,
        'subnav': 'bylaws',
        'has_files': True,
        'submit_name': 'Update Governing Document',
        'form_title': 'Upload New Version of Governing Document',
        'help_text': 'This will replace the existing document of this type.',
        'base': 'about/base_about.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))    
Example #10
0
def create_forum(request):
    if not Permissions.can_create_forum(request.user):
        raise PermissionDenied()

    NewForumForm = modelform_factory(Forum)
    form = NewForumForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            form.save()
            request.session['success_message'] = 'Forum successfully created'
            return get_previous_page(request, alternate='fora:index')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form': form,
        'has_files': False,
        'submit_name': 'Create new forum',
        'form_title': 'Create new forum',
        'help_text': ('A new forum should be organized around a topic or a '
                      'style of post.'),
        'base': 'fora/base_fora.html',
        'back_button': {
                    'link': reverse('fora:index'),
                    'text': 'Back to fora'
        },
    }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    return HttpResponse(template.render(context_dict, request))
Example #11
0
def hide_outreach_event(request,url_stem):
    if not request.user.is_superuser:
        request.session['error_message']='You are not authorized to edit outreach events'
        return get_previous_page(request,alternate='outreach:index')
    outreach_event = get_object_or_404(OutreachEventType,url_stem=url_stem)
    outreach_event.visible=False
    outreach_event.save()
    return redirect('outreach:index')
Example #12
0
def manage_outreach_events(request, url_stem):
    outreach_event = get_object_or_404(OutreachEventType, url_stem=url_stem)
    relevant_officers = Officer.objects.filter(
                        user__uniqname=request.user.username,
                        term=AcademicTerm.get_current_term(),
                        position__in=outreach_event.officers_can_edit.all()
    )
    if not (request.user.is_superuser or relevant_officers.exists()):
        request.session['error_message'] = ('You are not authorized to edit '
                                            'outreach events')
        return get_previous_page(request, alternate='outreach:index')
    OutreachFormSet = modelformset_factory(
                            OutreachEvent,
                            exclude=['outreach_event']
    )
    prefix = 'outreach'
    formset = OutreachFormSet(
                    request.POST or None,
                    request.FILES or None,
                    prefix=prefix,
                    queryset=OutreachEvent.objects.filter(
                                outreach_event=outreach_event
                    )
    )

    if request.method == 'POST':
        if formset.is_valid():
            instances = formset.save(commit=False)
            for instance in instances:
                instance.outreach_event = outreach_event
                instance.save()
            request.session['success_message'] = ('Outraech Events '
                                                  'successfully updated.')
            return redirect('outreach:mindset')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    context_dict = {
        'formset': formset,
        'prefix': prefix,
        'subnav': 'index',
        'has_files': True,
        'submit_name': 'Update Outreach Events',
        'back_button': {
                    'link': reverse('outreach:outreach_event',
                                    args=[url_stem]),
                    'text': 'To %s Page' % (outreach_event.title)
        },
        'form_title': 'Edit %s Events' % (outreach_event.title),
        'help_text': ('Update or add new outreach events to display in '
                      'the %s section.') % (outreach_event.title),
        'can_add_row': True,
        'base': 'outreach/base_outreach.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    template = loader.get_template('generic_formset.html')
    return HttpResponse(template.render(context))
Example #13
0
def manage_outreach_events(request, url_stem):
    outreach_event = get_object_or_404(OutreachEventType, url_stem=url_stem)
    relevant_officers = Officer.objects.filter(
        user__uniqname=request.user.username,
        term=AcademicTerm.get_current_term(),
        position__in=outreach_event.officers_can_edit.all())
    if not (request.user.is_superuser or relevant_officers.exists()):
        request.session['error_message'] = ('You are not authorized to edit '
                                            'outreach events')
        return get_previous_page(request, alternate='outreach:index')
    OutreachFormSet = modelformset_factory(OutreachEvent,
                                           exclude=['outreach_event'])
    prefix = 'outreach'
    formset = OutreachFormSet(
        request.POST or None,
        request.FILES or None,
        prefix=prefix,
        queryset=OutreachEvent.objects.filter(outreach_event=outreach_event))

    if request.method == 'POST':
        if formset.is_valid():
            instances = formset.save(commit=False)
            for instance in instances:
                instance.outreach_event = outreach_event
                instance.save()
            request.session['success_message'] = ('Outraech Events '
                                                  'successfully updated.')
            return redirect('outreach:mindset')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    context_dict = {
        'formset':
        formset,
        'prefix':
        prefix,
        'subnav':
        'index',
        'has_files':
        True,
        'submit_name':
        'Update Outreach Events',
        'back_button': {
            'link': reverse('outreach:outreach_event', args=[url_stem]),
            'text': 'To %s Page' % (outreach_event.title)
        },
        'form_title':
        'Edit %s Events' % (outreach_event.title),
        'help_text': ('Update or add new outreach events to display in '
                      'the %s section.') % (outreach_event.title),
        'can_add_row':
        True,
        'base':
        'outreach/base_outreach.html',
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    template = loader.get_template('generic_formset.html')
    return HttpResponse(template.render(context_dict, request))
Example #14
0
def update_person(request):
    """ If person exists, pre-fill information
    If person has profile but not BS profile, pre-fill some of it, and on
    submit link together
    If person has nothing, will need to create and link everything on submit 
    """
    if not Permissions.can_process_bookswap(request.user):
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM
        return get_previous_page(request, alternate='bookswap:admin_index')
    had_profile = request.session.pop('had_profile', False)
    uniqname = request.session.pop('uniqname', '')
    if had_profile:
        bsp = BookSwapPerson.objects.get(user_profile__uniqname=uniqname)
        form = BookSwapPersonForm(request.POST or None, instance=bsp)
    else:
        initial = {
            'UMID': request.session.pop('UMID', ''),
            'uniqname': uniqname,
            'barcode': request.session.pop('barcode', ''),
        }
        form = BookSwapPersonFormNoProfile(request.POST or None, initial=initial)
        
    if request.method == 'POST':
        if form.is_valid():
            bsp = form.save()
            uniqname = bsp.user_profile.uniqname
            request.session['success_message'] = ('User created/updated.')
            if BookSwapStatus.can_receive(AcademicTerm.get_current_term()):
                return redirect('bookswap:receive_book_start', uniqname=uniqname)
            elif BookSwapStatus.can_sell(AcademicTerm.get_current_term()):
                return redirect('bookswap:sell_book_start', uniqname=uniqname)
            else:
                request.session['info_message'] = ('Book Swap not open for '
                                                   'receiving or selling')
                return redirect('bookswap:admin_index')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
            request.session['had_profile'] = had_profile
            request.session['uniqname'] = uniqname
    else:
        request.session['had_profile'] = had_profile
        request.session['uniqname'] = uniqname
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form': form,
        'subnav': 'admin',
        'has_files': False,
        'submit_name': 'Create/update user',
        'form_title': 'Create/update the user information',
        'help_text': ('Please confirm that the following is correct and '
                      'update as necessary. Note that for sellers an address '
                      'is required.'),
        'base': 'bookswap/base_bookswap.html',
        }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #15
0
def create_book_type(request):
    if not Permissions.can_process_bookswap(request.user):
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM
        return get_previous_page(request, alternate='bookswap:admin_index')
    if not BookSwapStatus.can_receive(AcademicTerm.get_current_term()):
        request.session['error_message'] = 'Book receiving not enabled'
        return get_previous_page(request, alternate='bookswap:admin_index')
    isbn = request.session.get('isbn', '')
    form = BookTypeForm(request.POST or None, initial={'isbn': isbn})
    if request.method == 'POST':
        if form.is_valid():
            book_type = form.save()
            request.session['success_message'] = ('Book type created! '
                                                  'Please continue.')
            uniqname = request.session.pop('uniqname', '')
            request.session.pop('isbn', '')
            if uniqname:
                return redirect('bookswap:receive_book',
                                uniqname=uniqname,
                                book_type_id=book_type.id)
            else:
                return redirect('bookswap:create_book_type')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form':
        form,
        'subnav':
        'admin',
        'has_files':
        False,
        'submit_name':
        'Create book type',
        'form_title':
        'Create a book type',
        'help_text': ('This creates a type of book, not an individual '
                      'physical book to sell.'),
        'base':
        'bookswap/base_bookswap.html',
    }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #16
0
def view_interview_follow_up(request,follow_up_id):
    follow_up = get_object_or_404(ElecteeInterviewFollowup,id=follow_up_id)
    if not Permissions.can_see_follow_up(request.user):
        request.session['error_message']='You are not authorized to view this followup'
        return get_previous_page(request,alternate='electees:view_electee_groups')
    if not follow_up.interview.interviewee_shift.attendees.all()[0].is_electee():
        request.session['error_message']='You are not authorized to view this followup'
        return get_previous_page(request,alternate='electees:view_electee_groups')
    
    template = loader.get_template('electees/interview_followup.html')
    
    context_dict = {
        'follow_up':follow_up,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
Example #17
0
def hide_outreach_event(request, url_stem):
    if not request.user.is_superuser:
        request.session['error_message'] = ('You are not authorized to edit '
                                            'outreach events')
        return get_previous_page(request, alternate='outreach:index')
    outreach_event = get_object_or_404(OutreachEventType, url_stem=url_stem)
    outreach_event.visible = False
    outreach_event.save()
    return redirect('outreach:index')
Example #18
0
def delete_forum(request,forum_id):
    if not Permissions.can_create_forum(request.user):
        request.session['error_message']='You are not authorized to delete fora'
        return redirect('fora:index')
    forum=get_object_or_404(Forum,id=forum_id)
    if forum.forumthread_set.filter(hidden=False).exists():
        request.session['error_message']='Forum has visible threads, unable to delete'
        return get_previous_page(request,alternate='fora:index')
    forum.delete()
    return redirect('fora:index')
Example #19
0
def delete_forum(request, forum_id):
    if not Permissions.can_create_forum(request.user):
        request.session['error_message'] = ('You are not authorized to delete '
                                            'fora')
        return redirect('fora:index')
    forum = get_object_or_404(Forum, id=forum_id)
    if forum.forumthread_set.filter(hidden=False).exists():
        request.session['error_message'] = ('Forum has visible threads, '
                                            'unable to delete')
        return get_previous_page(request, alternate='fora:index')
    forum.delete()
    return redirect('fora:index')
Example #20
0
def receive_book(request, uniqname, book_type_id):
    if not Permissions.can_process_bookswap(request.user):
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM
        return get_previous_page(request, alternate='bookswap:admin_index')
    if not BookSwapStatus.can_receive(AcademicTerm.get_current_term()):
        request.session['error_message'] = 'Book receiving not enabled'
        return get_previous_page(request, alternate='bookswap:admin_index')
    book_type = get_object_or_404(BookType, id=book_type_id)
    seller = get_object_or_404(BookSwapPerson, user_profile__uniqname=uniqname)
    instance = Book(
                seller=seller,
                book_type=book_type,
                term=AcademicTerm.get_current_term()
    )
    form = ReceiveBookForm(request.POST or None, instance=instance)
    if request.method == 'POST':
        if form.is_valid():
            book = form.save()
            request.session['success_message'] = ('Book added created! '
                                                  'Please continue.')
            return redirect('bookswap:receive_book_start',
                            uniqname=uniqname)
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form': form,
        'subnav': 'admin',
        'has_files': False,
        'submit_name': 'Receive book',
        'form_title': 'Recieve a copy of: %s for %s' % (book_type.title, uniqname),
        'help_text': ('This receives a specific saleable book.'),
        'base': 'bookswap/base_bookswap.html',
        }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
    pass
Example #21
0
def hide_comment(request,comment_id):
    if not Permissions.can_create_forum(request.user):
        request.session['error_message']='You are not authorized to hide comments'
        return redirect('fora:index')
    message = get_object_or_404(ForumMessage,id=comment_id)
    message.hidden=True
    message.save()
    if not message.in_reply_to:
        thread =message.forum_thread
        thread.hidden=True
        thread.save()
        return redirect('fora:index')
    return get_previous_page(request,alternate='fora:index')
Example #22
0
def create_book_type(request):
    if not Permissions.can_process_bookswap(request.user):
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM
        return get_previous_page(request, alternate='bookswap:admin_index')
    if not BookSwapStatus.can_receive(AcademicTerm.get_current_term()):
        request.session['error_message'] = 'Book receiving not enabled'
        return get_previous_page(request, alternate='bookswap:admin_index')
    isbn = request.session.get('isbn', '')
    form = BookTypeForm(request.POST or None, initial = {'isbn': isbn})
    if request.method == 'POST':
        if form.is_valid():
            book_type = form.save()
            request.session['success_message'] = ('Book type created! '
                                                  'Please continue.')
            uniqname = request.session.pop('uniqname', '')
            request.session.pop('isbn', '')
            if uniqname:
                return redirect('bookswap:receive_book',
                                uniqname=uniqname,
                                book_type_id=book_type.id)
            else:
                return redirect('bookswap:create_book_type')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form': form,
        'subnav': 'admin',
        'has_files': False,
        'submit_name': 'Create book type',
        'form_title': 'Create a book type',
        'help_text': ('This creates a type of book, not an individual '
                      'physical book to sell.'),
        'base': 'bookswap/base_bookswap.html',
        }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #23
0
def start_transaction(request):
    """ Just a simple form to receive the barcode, uniqname, or UMID
    Looks up the buyer or seller, redirects to form to confirm information
    """
    if not Permissions.can_process_bookswap(
            request.user):  # TODO: create permission logic
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM
        return get_previous_page(request, alternate='bookswap:admin_index')
    form = StartTransactionForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            user = form.get_user()
            uniqname = ''
            if user:
                request.session['success_message'] = ('User found, please '
                                                      'confirm details.')
                request.session['had_profile'] = True
                uniqname = user.user_profile.uniqname
                request.session['uniqname'] = uniqname
            else:
                request.session['error_message'] = ('User not found, please '
                                                    'create now.')
                request.session['UMID'] = form.cleaned_data['user_UMID']
                request.session['uniqname'] = form.cleaned_data[
                    'user_uniqname']
                request.session['barcode'] = form.cleaned_data['user_barcode']
                request.session['had_profile'] = False
            return redirect('bookswap:update_person')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form':
        form,
        'subnav':
        'admin',
        'has_files':
        False,
        'submit_name':
        'Search for user',
        'form_title':
        'Search for a user in the system',
        'help_text': ('You can search for a user by UMID, uniqname, or the '
                      'barcode on their MCard.'),
        'base':
        'bookswap/base_bookswap.html',
    }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #24
0
def hide_comment(request, comment_id):
    if not Permissions.can_create_forum(request.user):
        request.session['error_message'] = ('You are not authorized to hide '
                                            'comments')
        return redirect('fora:index')
    message = get_object_or_404(ForumMessage, id=comment_id)
    message.hidden = True
    message.save()
    if not message.in_reply_to:
        thread = message.forum_thread
        thread.hidden = True
        thread.save()
        return redirect('fora:index')
    return get_previous_page(request, alternate='fora:index')
Example #25
0
def receive_book(request, uniqname, book_type_id):
    if not Permissions.can_process_bookswap(request.user):
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM
        return get_previous_page(request, alternate='bookswap:admin_index')
    if not BookSwapStatus.can_receive(AcademicTerm.get_current_term()):
        request.session['error_message'] = 'Book receiving not enabled'
        return get_previous_page(request, alternate='bookswap:admin_index')
    book_type = get_object_or_404(BookType, id=book_type_id)
    seller = get_object_or_404(BookSwapPerson, user_profile__uniqname=uniqname)
    instance = Book(seller=seller,
                    book_type=book_type,
                    term=AcademicTerm.get_current_term())
    form = ReceiveBookForm(request.POST or None, instance=instance)
    if request.method == 'POST':
        if form.is_valid():
            book = form.save()
            request.session['success_message'] = ('Book added created! '
                                                  'Please continue.')
            return redirect('bookswap:receive_book_start', uniqname=uniqname)
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form': form,
        'subnav': 'admin',
        'has_files': False,
        'submit_name': 'Receive book',
        'form_title':
        'Recieve a copy of: %s for %s' % (book_type.title, uniqname),
        'help_text': ('This receives a specific saleable book.'),
        'base': 'bookswap/base_bookswap.html',
    }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
    pass
Example #26
0
def get_article_view(request,article_id):
    request.session['current_page']=request.path
    today = date.today()
    web_articles    = WebsiteArticle.get_stories()
    if Permissions.can_post_web_article(request.user):
        NewArticleForm = modelform_factory(WebsiteArticle,form=WebArticleForm)
        if request.method == 'POST':
            form = NewArticleForm(request.POST)
            if form.is_valid():
                a=form.save()
                if Permissions.can_approve_web_article(request.user):
                    a.approved=True
                    a.save()
                    request.session['success_message']='Your webstory was posted successfully'
                else:
                    request.session['success_message']='Your webstory has been submitted and is awaiting approval'
                if hasattr(request.user,'userprofile') and request.user.userprofile.is_member():
                    a.created_by = request.user.userprofile.memberprofile
                    a.save()
                tweet_option = form.cleaned_data.pop('tweet_option','N')
                if tweet_option=='T':
                    a.tweet_story(False)
                elif tweet_option=='H':
                    a.tweet_story(True)
                return get_previous_page(request, 'history:index')
            else:
                request.session['error_message']='There were errors in your submission. Please correct the noted errors.'
        else:
            form = NewArticleForm(initial={'date_posted':today})
    else:
        form = None
    template = loader.get_template('history/publications.html')
    if not article_id:
        if web_articles:
            article_id=web_articles[0].id
        else:
            article_id=0
    context_dict = {
        'web_articles':web_articles,
        'main_id':int(article_id),
        'form':form,
        'subnav':'news',
        'event_photos': (EventPhoto.objects.all() if form else None),
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #27
0
def view_interview_pairings(request):
    if not Permissions.can_view_interview_pairings(request.user):
        request.session['error_message']='You are not authorized to view interview state'
        return get_previous_page(request,alternate='member_resources:index')
        
    interview_shifts = InterviewShift.objects.filter(term=AcademicTerm.get_current_term()).order_by('interviewer_shift__start_time')
    template = loader.get_template('electees/view_interviews.html')
    context_dict ={
        'interviews':interview_shifts,
        'subnav':'misc_reqs',
        'base':'member_resources/base_member_resources.html',
        'can_view_follow_ups':Permissions.can_see_follow_up(request.user),
        }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request,context_dict )
    return HttpResponse(template.render(context))
Example #28
0
def view_my_interview_forms(request):
    if not user_is_member(request.user) or not request.user.userprofile.memberprofile.status.name=='Active':
        request.session['error_message']='Only active members can fill out interview followups'
        return get_previous_page(request,alternate='electees:view_electee_groups')
    userprofile =request.user.userprofile
    my_interviews = InterviewShift.objects.filter(term=AcademicTerm.get_current_term(),interviewer_shift__attendees__in=[userprofile]).exclude(interviewee_shift__attendees=None)
    unpacked_interviews =[]
    for interview in my_interviews:
        unpacked_interviews.append({'interview':interview,'enabled':interview.user_can_followup(request.user),'completed':ElecteeInterviewFollowup.objects.filter(interview=interview,member=userprofile.memberprofile).exists()})
    template = loader.get_template('electees/interview_forms.html')  
    context_dict = {
        'interviews':unpacked_interviews,
        'back_button':{'link':reverse('electees:view_electee_groups'),'text':'To Electee Resources'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
Example #29
0
def manage_outreach_event_types(request):
    if not request.user.is_superuser:
        request.session['error_message'] = ('You are not authorized to edit '
                                            'outreach events types')
        return get_previous_page(request, alternate='outreach:index')
    OutreachFormSet = modelformset_factory(OutreachEventType)
    prefix = 'outreach'
    formset = OutreachFormSet(request.POST or None, prefix=prefix)
    if request.method == 'POST':
        if formset.is_valid():
            formset.save()
            request.session['success_message'] = ('Outraech event types '
                                                  'successfully updated.')
            return redirect('outreach:mindset')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    context_dict = {
        'formset':
        formset,
        'prefix':
        prefix,
        'subnav':
        'index',
        'has_files':
        False,
        'submit_name':
        'Update Outreach Event Types',
        'back_button': {
            'link': reverse('outreach:index'),
            'text': 'To Outreach Page'
        },
        'form_title':
        'Edit Outreach Events and Types',
        'help_text': ('Update or add new outreach event categories to '
                      'display in the outreach section. Make sure to add '
                      'the corresponding event category from the membership '
                      'section first if needed.'),
        'can_add_row':
        True,
        'base':
        'outreach/base_outreach.html',
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    template = loader.get_template('generic_formset.html')
    return HttpResponse(template.render(context_dict, request))
Example #30
0
def start_transaction(request):
    """ Just a simple form to receive the barcode, uniqname, or UMID
    Looks up the buyer or seller, redirects to form to confirm information
    """
    if not Permissions.can_process_bookswap(request.user): # TODO: create permission logic
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM 
        return get_previous_page(request, alternate='bookswap:admin_index')
    form = StartTransactionForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            user = form.get_user()
            uniqname = ''
            if user:
                request.session['success_message'] = ('User found, please '
                                                      'confirm details.')
                request.session['had_profile'] = True
                uniqname = user.user_profile.uniqname
                request.session['uniqname'] = uniqname
            else:
                request.session['error_message'] = ('User not found, please '
                                                    'create now.')
                request.session['UMID'] = form.cleaned_data['user_UMID']
                request.session['uniqname'] = form.cleaned_data['user_uniqname']
                request.session['barcode'] = form.cleaned_data['user_barcode']
                request.session['had_profile'] = False
            return redirect('bookswap:update_person')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form': form,
        'subnav': 'admin',
        'has_files': False,
        'submit_name': 'Search for user',
        'form_title': 'Search for a user in the system',
        'help_text': ('You can search for a user by UMID, uniqname, or the '
                      'barcode on their MCard.'),
        'base': 'bookswap/base_bookswap.html',
        }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #31
0
def add_comment(request,forum_id,reply_to_id):
    if not hasattr(request.user,'userprofile') or not request.user.userprofile.is_member():
        raise PermissionDenied()
    creator = request.user.userprofile.memberprofile
    forum=get_object_or_404(Forum,id=forum_id)
    if reply_to_id:
        op=get_object_or_404(ForumMessage,id=reply_to_id)

    AddCommentForm = modelform_factory(ForumMessage,exclude=('forum_thread','in_reply_to','creator','time_created','last_modified','score','hidden'))
    if request.method =='POST':
        form = AddCommentForm(request.POST)
        if form.is_valid():
            instance=form.save(commit=False)
            if reply_to_id:
                instance.in_reply_to=op
                instance.forum_thread=op.forum_thread
            else:
                ft = ForumThread(title=instance.title,forum=forum,creator=creator)
                ft.save()
                instance.in_reply_to=None
                instance.forum_thread=ft
            instance.creator=creator
            instance.save()
            request.session['success_message']='Comment successfully added' if reply_to_id else 'Thread successfully created'
            return get_previous_page(request,alternate='fora:index')
        else:
            request.session['warning_message']='There were errors in your submission'
    else:
        form = AddCommentForm()
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form':form,
        'has_files':False,
        'submit_name':'Add Comment' if reply_to_id else 'Add new thread',
        'form_title':'Add Comment' if reply_to_id else 'Add new thread',
        'help_text':'Post a comment to the forum.' if reply_to_id else 'Create a new thread with the original post.',
        'base':'fora/base_fora.html',
        'back_button':{'link':reverse('fora:index'),'text':'Back to fora'},
        }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request,context_dict )
    return HttpResponse(template.render(context))
Example #32
0
def view_interview_follow_up_table(request):
    if not Permissions.can_see_follow_up(request.user):
        request.session['error_message']='You are not authorized to view followups'
        return get_previous_page(request,alternate='electees:view_electee_groups')
    electees = MemberProfile.get_electees()
    electee_data = []
    num_followups=0
    for electee in electees:
        follow_ups = ElecteeInterviewFollowup.objects.filter(interview__interviewee_shift__attendees=electee)
        num_followups=follow_ups.count() if follow_ups.count()>num_followups else num_followups
        electee_data.append({'electee':electee,'followups':follow_ups})
    template = loader.get_template('electees/interview_followup_table.html')
    interviewer_headers = ['Interviewer %d'%count for count in range(1,num_followups+1)]
    context_dict = {
        'interviewer_headers':interviewer_headers,
        'electees':electee_data,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))    
Example #33
0
def manage_outreach_event_types(request):
    if not request.user.is_superuser:
        request.session['error_message'] = ('You are not authorized to edit '
                                            'outreach events types')
        return get_previous_page(request, alternate='outreach:index')
    OutreachFormSet = modelformset_factory(OutreachEventType)
    prefix = 'outreach'
    formset = OutreachFormSet(request.POST or None, prefix=prefix)
    if request.method == 'POST':
        if formset.is_valid():
            formset.save()
            request.session['success_message'] = ('Outraech event types '
                                                  'successfully updated.')
            return redirect('outreach:mindset')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    context_dict = {
        'formset': formset,
        'prefix': prefix,
        'subnav': 'index',
        'has_files': False,
        'submit_name': 'Update Outreach Event Types',
        'back_button': {
                    'link': reverse('outreach:index'),
                    'text': 'To Outreach Page'
        },
        'form_title': 'Edit Outreach Events and Types',
        'help_text': ('Update or add new outreach event categories to '
                      'display in the outreach section. Make sure to add '
                      'the corresponding event category from the membership '
                      'section first if needed.'),
        'can_add_row': True,
        'base': 'outreach/base_outreach.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    template = loader.get_template('generic_formset.html')
    return HttpResponse(template.render(context))
Example #34
0
def view_map(request):
    """ The view of member locations.
    """
    if (not hasattr(request.user, 'userprofile') or
       not request.user.userprofile.is_member()):
        request.session['error_message'] = ('You must be logged in and a '
                                            'member to view this.')
        return get_previous_page(
                        request,
                        alternate='member_resources:index'
        )
    members_with_location = MemberProfile.get_members().exclude(location='')
    template = loader.get_template('fora/map.html')
    member = request.user.userprofile.memberprofile
    location = (member.location if member.location
                else GeoLocation(42.26, -83.7483))
    context_dict = {
        'members': members_with_location,
        'center': location,
        'can_center_on_me': bool(member.location),
    }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    return HttpResponse(template.render(context_dict, request))
Example #35
0
def get_article_view(request,article_id):
    request.session['current_page']=request.path
    today = date.today()
    web_articles    = WebsiteArticle.objects.order_by('-date_posted').exclude(date_posted__gt=today)
    if Permissions.can_post_web_article(request.user):
        if request.method == 'POST':
            form = WebArticleForm(request.POST)
            if form.is_valid():
                a=form.save()
                if hasattr(request.user,'userprofile') and request.user.userprofile.is_member():
                    a.created_by = request.user.userprofile.memberprofile
                    a.save()
                request.session['success_message']='Your webstory was posted successfully'
                return get_previous_page(request, 'history:index')
            else:
                request.session['error_message']='There were errors in your submission. Please correct the noted errors.'
        else:
            form = WebArticleForm(initial={'date_posted':today})
    else:
        form = None
    template = loader.get_template('history/publications.html')
    if not article_id:
        if web_articles:
            article_id=web_articles[0].id
        else:
            article_id=0
    context_dict = {
        'web_articles':web_articles,
        'main_id':int(article_id),
        'form':form,
        'subnav':'news',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #36
0
def view_interview_follow_up_table(request):
    if not Permissions.can_see_follow_up(request.user):
        request.session['error_message']='You are not authorized to view followups'
        return get_previous_page(request,alternate='electees:view_electee_groups')
    electees = MemberProfile.get_electees()
    green_electees=[]
    yellow_electees=[]
    red_electees=[]
    blank_electees=[]
    num_followups=0
    for electee in electees:
        follow_ups = ElecteeInterviewFollowup.objects.filter(interview__interviewee_shift__attendees=electee).exclude(recommendation='X')
        num_followups=follow_ups.count() if follow_ups.count()>num_followups else num_followups
        num_red = follow_ups.filter(recommendation='N').count()
        num_yellow = follow_ups.filter(recommendation='M').count()
        if num_red:
            red_electees.append({'electee':electee,'followups':follow_ups})
        elif num_yellow:
            yellow_electees.append({'electee':electee,'followups':follow_ups})
        elif follow_ups.count():
            green_electees.append({'electee':electee,'followups':follow_ups})
        else:
            blank_electees.append({'electee':electee,'followups':follow_ups})
    template = loader.get_template('electees/interview_followup_table.html')
    interviewer_headers = ['Interviewer %d'%count for count in range(1,num_followups+1)]
    context_dict = {
        'interviewer_headers':interviewer_headers,
        'green_electees':green_electees,
        'yellow_electees':yellow_electees,
        'red_electees':red_electees,
        'blank_electees':blank_electees,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
Example #37
0
def add_comment(request, forum_id, reply_to_id):
    """ Adds a comment or creates a new thread.

    This can be viewed directly, or it can be called from create_thread.
    The latter unsurprisingly creates a thread.
    """
    if (not hasattr(request.user, 'userprofile') or
       not request.user.userprofile.is_member()):
        raise PermissionDenied()
    creator = request.user.userprofile.memberprofile
    forum = get_object_or_404(Forum, id=forum_id)
    op = None
    if reply_to_id:
        op = get_object_or_404(ForumMessage, id=reply_to_id)

    AddCommentForm = modelform_factory(
                        ForumMessage,
                        exclude=(
                            'forum_thread',
                            'in_reply_to',
                            'creator',
                            'time_created',
                            'last_modified',
                            'score',
                            'hidden'
                        )
    )
    form = AddCommentForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            instance = form.save(commit=False)
            instance.in_reply_to = op
            instance.creator = creator
            msg = 'Thread successfully created'
            if reply_to_id:
                instance.forum_thread = op.forum_thread
                msg = 'Comment successfully added'
            else:
                ft = ForumThread(
                        title=instance.title,
                        forum=forum,
                        creator=creator
                )
                ft.save()
                instance.forum_thread = ft
            instance.save()
            request.session['success_message'] = msg
            return get_previous_page(request, alternate='fora:index')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form': form,
        'has_files': False,
        'submit_name': 'Add Comment' if reply_to_id else 'Add new thread',
        'form_title': 'Add Comment' if reply_to_id else 'Add new thread',
        'help_text': ('Post a comment to the forum.' if reply_to_id
                      else 'Create a new thread with the original post.'),
        'base': 'fora/base_fora.html',
        'back_button': {
                    'link': reverse('fora:index'),
                    'text': 'Back to fora'
        },
    }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    return HttpResponse(template.render(context_dict, request))
Example #38
0
def update_person(request):
    """ If person exists, pre-fill information
    If person has profile but not BS profile, pre-fill some of it, and on
    submit link together
    If person has nothing, will need to create and link everything on submit 
    """
    if not Permissions.can_process_bookswap(request.user):
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM
        return get_previous_page(request, alternate='bookswap:admin_index')
    had_profile = request.session.pop('had_profile', False)
    uniqname = request.session.pop('uniqname', '')
    if had_profile:
        bsp = BookSwapPerson.objects.get(user_profile__uniqname=uniqname)
        form = BookSwapPersonForm(request.POST or None, instance=bsp)
    else:
        initial = {
            'UMID': request.session.pop('UMID', ''),
            'uniqname': uniqname,
            'barcode': request.session.pop('barcode', ''),
        }
        form = BookSwapPersonFormNoProfile(request.POST or None,
                                           initial=initial)

    if request.method == 'POST':
        if form.is_valid():
            bsp = form.save()
            uniqname = bsp.user_profile.uniqname
            request.session['success_message'] = ('User created/updated.')
            if BookSwapStatus.can_receive(AcademicTerm.get_current_term()):
                return redirect('bookswap:receive_book_start',
                                uniqname=uniqname)
            elif BookSwapStatus.can_sell(AcademicTerm.get_current_term()):
                return redirect('bookswap:sell_book_start', uniqname=uniqname)
            else:
                request.session['info_message'] = ('Book Swap not open for '
                                                   'receiving or selling')
                return redirect('bookswap:admin_index')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
            request.session['had_profile'] = had_profile
            request.session['uniqname'] = uniqname
    else:
        request.session['had_profile'] = had_profile
        request.session['uniqname'] = uniqname
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form':
        form,
        'subnav':
        'admin',
        'has_files':
        False,
        'submit_name':
        'Create/update user',
        'form_title':
        'Create/update the user information',
        'help_text': ('Please confirm that the following is correct and '
                      'update as necessary. Note that for sellers an address '
                      'is required.'),
        'base':
        'bookswap/base_bookswap.html',
    }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Example #39
0
def get_article_view(request, article_id):
    """ The helper view method for the index and the article view.

    This is not a url-findable method. To find article urls, use article_view.
    This also serves a form to submit new articles, provided that the user
    has the permissions to submit such a story.
    """
    request.session['current_page'] = request.path
    today = date.today()
    web_articles = WebsiteArticle.get_stories()
    if (hasattr(request.user, 'userprofile') and
       request.user.userprofile.is_member()):
        profile = request.user.userprofile.memberprofile
    else:
        profile = None
    can_post = Permissions.can_post_web_article(request.user)
    NewArticleForm = modelform_factory(WebsiteArticle, form=WebArticleForm)
    form = NewArticleForm(request.POST or None,
                          initial={'date_posted': today})
    if can_post and request.method == 'POST':
        if form.is_valid():
            a = form.save()
            if Permissions.can_approve_web_article(request.user):
                a.approved = True
                a.save()
                request.session['success_message'] = ('Your webstory was '
                                                      'posted')
            else:
                request.session['success_message'] = ('Your webstory has '
                                                      'been submitted and '
                                                      'is awaiting '
                                                      'approval')
            if profile:
                a.created_by = profile
                a.save()
            tweet_option = form.cleaned_data.pop('tweet_option', 'N')
            if tweet_option == 'T':
                a.tweet_story(False)
            elif tweet_option == 'H':
                a.tweet_story(True)
            return get_previous_page(request, 'history:index')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    elif not can_post:
        form = None
    template = loader.get_template('history/publications.html')
    if not article_id:
        if web_articles:
            article_id = web_articles[0].id
        else:
            article_id = 0
    context_dict = {
        'web_articles': web_articles,
        'main_id': int(article_id),
        'form': form,
        'subnav': 'news',
        'event_photos': (EventPhoto.objects.all() if form else None),
        'needs_social_media': True,
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))