def edit_company(request, company_name):
	print 'edit company view'
	form_data = request.POST

	user = User.objects.get(username=request.user.username)
	company = request.user.company_set.filter(name=company_name).first()

	if form_data:
		if user and company: 
			if company.application_deadline != form_data.get('app_deadline'):

				title = str(company.name) + ' Deadline'
				if company.application_deadline:
					old_evt = request.user.events.filter(name=title).first()
					request.user.events.delete(old_evt)
					request.user.owned_events.delete(old_evt)
					old_evt.delete()
			
				evt = jam_event(
					name=title,
					event_type='Application Deadline',
					description='',
					companies=company_name,
					start_time='12:00',
					end_time='13:00',
					event_date=form_data.get('app_deadline'),
					creator=request.user
				)
				evt.save()

				request.user.events.add(evt)
				request.user.owned_events.add(evt)

			company.name=form_data.get('company_name')
			company.application_deadline=form_data.get('app_deadline')
			company.notes=form_data.get('notes')

			company.save()
			redirect_link = '../../../companies/' + company.name

			return HttpResponseRedirect(redirect_link)

		else:
			company = Company(user=request.user.username,
							  company_name=form_data.get('company_name'),
							  application_deadline=form_data.get('app_deadline'),
							  notes=form_data.get('notes')
							  )
			company.save()
			redirect_link = '../../../companies/' + company.name
			return HttpResponseRedirect(redirect_link)

	app_deadline = company.application_deadline
	app_deadline = str(app_deadline)
	datetime.strptime(app_deadline, "%Y-%m-%d")

	context = {'company_name': company_name, 'application_deadline': app_deadline, 'notes': company.notes, "controlled_channels": request.user.controlledChannels}

	return render(request, 'jam/companies/company_page_edit.html', context)
Esempio n. 2
0
def read_from_file(user, input_file):
	print "in read_from_file"
	for line in input_file:
		company_info = line.split(',')
		company_name = company_info[0]
		company_deadline = company_info[1].strip()

		company = Company(name=company_name,
						  application_deadline=company_deadline,
						  user=user)
		company.save()
Esempio n. 3
0
def read_from_file(user, input_file):
    print "in read_from_file"
    for line in input_file:
        company_info = line.split(',')
        company_name = company_info[0]
        company_deadline = company_info[1].strip()

        company = Company(name=company_name,
                          application_deadline=company_deadline,
                          user=user)
        company.save()
Esempio n. 4
0
def read_from_file(user, input_file):
    for line in input_file:
        if len(line) > 0:
            company_info = line.split(',')
            company_name = company_info[0]
            company_deadline = company_info[1].strip()

            stripped_deadline = company_deadline.replace("-", "")
            stripped_deadline.replace('/', "")
            if len(stripped_deadline) < 8:
                continue
            elif stripped_deadline.isdigit():
                is_valid_date(company_deadline)
            else:
                continue

            company = Company(name=company_name,
                              application_deadline=company_deadline,
                              user=user)
            company.save()
    return True
def read_from_file(user, input_file):
	for line in input_file:
		if len(line) > 0:
			company_info = line.split(',')
			company_name = company_info[0]
			company_deadline = company_info[1].strip()

			stripped_deadline = company_deadline.replace("-", "")
			stripped_deadline.replace('/', "")
			if len(stripped_deadline) < 8: 
				continue
			elif stripped_deadline.isdigit():
				is_valid_date(company_deadline)
			else:
				continue


			company = Company(name=company_name,
						  application_deadline=company_deadline,
						  user=user)
			company.save()
	return True
def new_company(request):
	#START OF CODE RELEVANT TO IMPORT
	if request.method == "POST" and request.FILES:
		print "in new company upload multiple"
		form = UploadFileForm(request.FILES)
		read_from_file(request.user, request.FILES['filep'])
		context = {'username': request.user.username}

		#return render(request, 'jam/companies/companies.html', context)
		return companies(request,'all')
	elif request.method == "POST":
		form_data = request.POST

		# check whether we've got a valid date. if invalid, we need them to fix their form errors!
		application_deadline = form_data.get('deadline')
		validity = is_valid_date(application_deadline)
		if(validity!=None):
			# return bad request if the deadline is still invalid somehow (but very unlikely!)
			response={}
			response["error"] = validity
			print "got here"
			return HttpResponseBadRequest(json.dumps(response),content_type="application/json")

			#probs should get rid of this shit bc its dead code but yolo...soon!
			#context = { 'validity' : validity }
			return render(request, 'jam/modals/modal_add_company.html', context)
		
		company_name = form_data.get('name')

		
		''' see whether a company with the same name already exists
			if it does, re-render the form with an appropriate error.
			if it doesn't, go ahead with business as usual, creating the company DB record
		'''
		if request.user.company_set.filter(name=company_name).exists():
			#request.user.company_set.get(name=company_name)
			msg = "I'm sorry, you've already added that company. Please add a different one!"

			response={}
			response["error"] = msg
			print "got here"
			return HttpResponseBadRequest(json.dumps(response),content_type="application/json")
		else: 
			'''company = Company(name=company_name,
						  application_deadline=form_data.get('deadline'),
						  notes=form_data.get('company_notes'),
						  user=request.user)
			'''
			
			#event_types = swingmodel.EventType.objects.filter(abbr='due', label='Application Deadline')
			
			#if len(event_types) == 0:
			#	swingmodel.EventType.objects.create(abbr='due', label='Application Deadline')
			#	swingmodel.EventType.objects.filter(abbr='due', label='Application Deadline')
			if (application_deadline != "" and len(application_deadline) != 0):
				year = int(application_deadline[0:4])
				month = int(application_deadline[5:7])
				day = int(application_deadline[8:10])

				title = str(company_name) + ' Deadline'
			
				evt = jam_event(
					name=title,
					event_type='Application Deadline',
					description='',
					companies=company_name,
					start_time='12:00',
					end_time='13:00',
					event_date=application_deadline,
					creator=request.user
				)
				evt.save()

				request.user.events.add(evt)
				request.user.owned_events.add(evt)
			if application_deadline == '':
				company = Company(name=company_name,notes=form_data.get('company_notes'),user=request.user, link=form_data.get('app_link'))
			else:
				company = Company(name=company_name,application_deadline=application_deadline,notes=form_data.get('company_notes'),user=request.user, link=form_data.get('app_link'))

			company.save()

			if (application_deadline != "" and len(application_deadline) != 0):
				company.events.add(evt)
			context = {'username': request.user.username}



			return render(request, 'jam/index/index_landing_home.html', context)
Esempio n. 7
0
def new_company(request):
    #START OF CODE RELEVANT TO IMPORT
    if request.method == "POST" and request.FILES:
        print "in new company upload multiple"
        form = UploadFileForm(request.FILES)
        read_from_file(request.user, request.FILES['filep'])
        context = {'username': request.user.username}

        #return render(request, 'jam/companies/companies.html', context)
        return companies(request, 'all')
    elif request.method == "POST":
        form_data = request.POST

        # check whether we've got a valid date. if invalid, we need them to fix their form errors!
        application_deadline = form_data.get('deadline')
        validity = is_valid_date(application_deadline)
        if (validity != None):
            # return bad request if the deadline is still invalid somehow (but very unlikely!)
            response = {}
            response["error"] = validity
            print "got here"
            return HttpResponseBadRequest(json.dumps(response),
                                          content_type="application/json")

            #probs should get rid of this shit bc its dead code but yolo...soon!
            #context = { 'validity' : validity }
            return render(request, 'jam/modals/modal_add_company.html',
                          context)

        company_name = form_data.get('name')
        ''' see whether a company with the same name already exists
			if it does, re-render the form with an appropriate error.
			if it doesn't, go ahead with business as usual, creating the company DB record
		'''
        if request.user.company_set.filter(name=company_name).exists():
            #request.user.company_set.get(name=company_name)
            msg = "I'm sorry, you've already added that company. Please add a different one!"

            response = {}
            response["error"] = msg
            print "got here"
            return HttpResponseBadRequest(json.dumps(response),
                                          content_type="application/json")
        else:
            '''company = Company(name=company_name,
						  application_deadline=form_data.get('deadline'),
						  notes=form_data.get('company_notes'),
						  user=request.user)
			'''

            #event_types = swingmodel.EventType.objects.filter(abbr='due', label='Application Deadline')

            #if len(event_types) == 0:
            #	swingmodel.EventType.objects.create(abbr='due', label='Application Deadline')
            #	swingmodel.EventType.objects.filter(abbr='due', label='Application Deadline')
            if (application_deadline != "" and len(application_deadline) != 0):
                year = int(application_deadline[0:4])
                month = int(application_deadline[5:7])
                day = int(application_deadline[8:10])

                title = str(company_name) + ' Deadline'

                evt = jam_event(name=title,
                                event_type='Application Deadline',
                                description='',
                                companies=company_name,
                                start_time='12:00',
                                end_time='13:00',
                                event_date=application_deadline,
                                creator=request.user)
                evt.save()

                request.user.events.add(evt)
                request.user.owned_events.add(evt)
            if application_deadline == '':
                company = Company(name=company_name,
                                  notes=form_data.get('company_notes'),
                                  user=request.user,
                                  link=form_data.get('app_link'))
            else:
                company = Company(name=company_name,
                                  application_deadline=application_deadline,
                                  notes=form_data.get('company_notes'),
                                  user=request.user,
                                  link=form_data.get('app_link'))

            company.save()

            if (application_deadline != "" and len(application_deadline) != 0):
                company.events.add(evt)
            context = {'username': request.user.username}

            return render(request, 'jam/index/index_landing_home.html',
                          context)
Esempio n. 8
0
def edit_company(request, company_name):
    print 'edit company view'
    form_data = request.POST

    user = User.objects.get(username=request.user.username)
    company = request.user.company_set.filter(name=company_name).first()

    if form_data:
        if user and company:
            if company.application_deadline != form_data.get('app_deadline'):

                title = str(company.name) + ' Deadline'
                if company.application_deadline:
                    old_evt = request.user.events.filter(name=title).first()
                    request.user.events.delete(old_evt)
                    request.user.owned_events.delete(old_evt)
                    old_evt.delete()

                evt = jam_event(name=title,
                                event_type='Application Deadline',
                                description='',
                                companies=company_name,
                                start_time='12:00',
                                end_time='13:00',
                                event_date=form_data.get('app_deadline'),
                                creator=request.user)
                evt.save()

                request.user.events.add(evt)
                request.user.owned_events.add(evt)

            company.name = form_data.get('company_name')
            company.application_deadline = form_data.get('app_deadline')
            company.notes = form_data.get('notes')

            company.save()
            redirect_link = '../../../companies/' + company.name

            return HttpResponseRedirect(redirect_link)

        else:
            company = Company(
                user=request.user.username,
                company_name=form_data.get('company_name'),
                application_deadline=form_data.get('app_deadline'),
                notes=form_data.get('notes'))
            company.save()
            redirect_link = '../../../companies/' + company.name
            return HttpResponseRedirect(redirect_link)

    app_deadline = company.application_deadline
    app_deadline = str(app_deadline)
    datetime.strptime(app_deadline, "%Y-%m-%d")

    context = {
        'company_name': company_name,
        'application_deadline': app_deadline,
        'notes': company.notes,
        "controlled_channels": request.user.controlledChannels
    }

    return render(request, 'jam/companies/company_page_edit.html', context)