def test_workshop_create_invalid_time(self): form_data = { 'event': '1', 'name': 'workshop name', 'date': '2018-10-32', 'start_time': '22:59', 'end_time': '23:59', 'location': 'k17 seminar room', 'repeat_workshop': 'NO' } form = WorkshopForm(data=form_data) self.assertFalse(form.is_valid())
def test_workshop_create_recurring_weekly(self): form_data = { 'event': '1', 'name': 'workshop name', 'date': '2018-11-01', 'start_time': '22:59', 'end_time': '23:59', 'location': 'k17 seminar room', 'repeat_workshop': 'WK' } form = WorkshopForm(data=form_data) form.save() self.assertTrue(len(Workshop.objects.all()) == 2)
def test_workshop_create_no_recurring(self): # noqa: D102 form_data = { 'event': '1', 'name': 'workshop name', 'date': '2018-10-31', 'start_time': '22:59', 'end_time': '23:59', 'location': 'k17 seminar room', 'repeat_workshop': 'NO' } form = WorkshopForm(data=form_data) form.save() self.assertTrue(len(Workshop.objects.all()) == 1)
def test_workshop_create_recurring_daily(self): form_data = { 'event': '1', 'name': 'workshop name', 'date': '2018-10-31', 'start_time': '22:59', 'end_time': '23:59', 'location': 'k17 seminar room', 'repeat_workshop': 'DL' } form = WorkshopForm(data=form_data) form.save() self.assertTrue(len(Workshop.objects.all()) == 9) # 8 days inclusive between 31/10 and 8/11
def edit_workshop(request, workshop_id=None): context = {} context.update(csrf(request)) instance = get_object_or_404(Workshop, id=workshop_id) form = WorkshopForm(request.POST or None, request.FILES or None, instance=instance) if form.is_valid(): print instance = form.save(commit=False) instance.save() return HttpResponseRedirect(instance.get_absolute_url()) context['instance'] = instance context['form'] = form return render(request, "edit_workshop.html", context)
def edit_proposal(request, proposal_id=None): user = request.user context = {} if user.is_authenticated(): try: proposal = Proposal.objects.get(id=proposal_id) if proposal.status == 'Edit': if proposal.proposal_type == 'ABSTRACT': form = ProposalForm(instance=proposal) else: form = WorkshopForm(instance=proposal) else: return render(request, 'cfp.html') if request.method == 'POST': if proposal.status == 'Edit': if proposal.proposal_type == 'ABSTRACT': form = ProposalForm(request.POST, request.FILES, instance=proposal) else: form = WorkshopForm(request.POST, request.FILES, instance=proposal) else: return render(request, 'cfp.html') if form.is_valid(): data = form.save(commit=False) data.user = user proposal.status = 'Resubmitted' data.save() context.update(csrf(request)) proposals = Proposal.objects.filter( user=user).order_by('status') context['proposals'] = proposals return render(request, 'view-abstracts.html', context) else: context['user'] = user context['form'] = form context['proposal'] = proposal return render(request, 'edit-proposal.html', context) context['user'] = user context['form'] = form context['proposal'] = proposal except: render(request, 'cfp.html') return render(request, 'edit-proposal.html', context)
def add_workshop(request): user = request.user context = {} context.update(csrf(request)) form = WorkshopForm(request.POST or None, request.FILES or None) if form.is_valid(): instance = form.save(commit=False) instance.save() messages.success(request, "Added Successfully") ws = Workshop.objects.all() context['ws'] = ws context['user'] = user return HttpResponseRedirect(instance.get_absolute_url()) # if request.method == 'POST': context = {} context['form'] = form return render(request, "add_workshop.html", context)
def workshop_create(request, event_id, slug): """ Render and show a workshop creation form page. The page shows a form allowing a staff member to create a new workshop for a particular event. Only staff members can access and see this page. Args: request: HTTP request header contents event_id: the ID of the event that we are making a workshop for slug: the human-readable event name in the URL Returns: HTTP response containing the workshop creation page """ if request.method == 'POST': workshop_form = WorkshopForm(request.POST, prefix='workshop_form') if workshop_form.is_valid(): workshop_form.save() return redirect('website:event_page', slug=slug, event_id=event_id) else: workshop_form = WorkshopForm(prefix='workshop_form') workshop_form['event'].initial = get_object_or_404(Event, pk=event_id) context = { 'workshop_form': workshop_form, 'event': get_object_or_404(Event, pk=event_id) } return render(request, 'website/workshop_create.html', context)
def submitcfw(request): context = {} if request.user.is_authenticated(): social_user = request.user context.update(csrf(request)) django_user = User.objects.get(username=social_user) context['user'] = django_user proposals_w = Proposal.objects.filter( user=request.user, proposal_type='WORKSHOP').count() if request.method == 'POST': form = WorkshopForm(request.POST, request.FILES) if form.is_valid(): data = form.save(commit=False) data.user = django_user data.email = social_user.email data.save() context['proposal_submit'] = True sender_name = "SciPy India 2017" sender_email = TO_EMAIL subject = "SciPy India 2017 – Workshop Proposal Submission Acknowledgment" to = (social_user.email, TO_EMAIL) message = """ Dear {0}, <br><br> Thank you for showing interest & submitting a workshop proposal at SciPy India 2017 conference for the workshop titled <b>“{1}”</b>. Reviewal of the proposals will start once the CFP closes. <br><br>You will be notified regarding comments/selection/rejection of your workshop via email. Visit this {2} link to view status of your submission. <br>Thank You ! <br><br>Regards,<br>SciPy India 2017,<br>FOSSEE - IIT Bombay. """.format( social_user.first_name, request.POST.get('title', None), 'http://scipy.in/2017/view-abstracts/', ) email = EmailMultiAlternatives( subject, '', sender_email, to, headers={"Content-type": "text/html;charset=iso-8859-1"}) email.attach_alternative(message, "text/html") email.send(fail_silently=True) return render_to_response('cfp.html', context) else: context['proposal_form'] = form context['proposals_w'] = proposals_w return render_to_response('submit-cfw.html', context) else: form = WorkshopForm() context['proposal_form'] = form context['proposals_w'] = proposals_w return render_to_response('submit-cfw.html', context) else: context['login_required'] = True return render_to_response('cfp.html', context)