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)
Example #2
0
def add_recurring_events(request, event, occurrence):
    start_date = datetime.strptime(event.event_date, "%Y-%m-%d")
    end_date = datetime.strptime(occurrence.end_date, "%Y-%m-%d")
    year = int(occurrence.start_year) + 1

    #if occurrence.start_year <= start_date.year && occurrence.start_month <= start_date.month && occurrence.start_day <= start_date.day:
    if occurrence.frequency == "Annually":
        while year <= int(end_date.year):
            date = str(year) + "-" + start_date.strftime(
                "%m") + "-" + start_date.strftime("%d")
            date_datetime = datetime.strptime(date, "%Y-%m-%d")

            if date_datetime < end_date:
                newer_event = jam_event(name=event.name,
                                        event_type=event.event_type,
                                        description=event.description,
                                        companies=event.companies,
                                        event_date=date,
                                        start_time=event.start_time,
                                        end_time=event.end_time,
                                        occurrence_id=occurrence.id,
                                        creator=event.creator)

                newer_event.save()
                request.user.events.add(newer_event)
                request.user.owned_events.add(newer_event)
            year += 1
        return

    if occurrence.frequency == "Monthly":
        increment = 1

        date_datetime = start_date + relativedelta(months=increment)
        while date_datetime <= end_date:
            newer_event = jam_event(name=event.name,
                                    event_type=event.event_type,
                                    description=event.description,
                                    companies=event.companies,
                                    event_date=date_datetime,
                                    start_time=event.start_time,
                                    end_time=event.end_time,
                                    occurrence_id=occurrence.id,
                                    creator=event.creator)

            newer_event.save()
            request.user.events.add(newer_event)
            request.user.owned_events.add(newer_event)

            increment += 1
            date_datetime = start_date + relativedelta(months=increment)
        return

    if occurrence.frequency == "Weekly":
        incr = 7
    if occurrence.frequency == "Daily":
        incr = 1

    increment = incr
    date_datetime = start_date + relativedelta(days=increment)
    while date_datetime <= end_date:
        newer_event = jam_event(name=event.name,
                                event_type=event.event_type,
                                description=event.description,
                                companies=event.companies,
                                event_date=date_datetime,
                                start_time=event.start_time,
                                end_time=event.end_time,
                                occurrence_id=occurrence.id,
                                creator=event.creator)

        newer_event.save()
        request.user.events.add(newer_event)
        request.user.owned_events.add(newer_event)

        increment += incr
        date_datetime = start_date + relativedelta(days=increment)
Example #3
0
def edit_event(request, event_id):
    form_data = request.POST

    user = User.objects.get(username=request.user.username)
    event = request.user.events.get(id=event_id)

    if form_data:
        startTime, endTime = startEndTimeValidation(
            form_data.get('start_time'), form_data.get('end_time'))

        if "Save_All" in form_data:
            if request.POST.get("occurrence_id"):
                occurrence_id = int(request.POST.get("occurrence_id"))

                delete_recurring_events(request, occurrence_id,
                                        event.event_date)
                new_event(request)

                datetime_obj = event.event_date
                redirect_link = '../../../calendar/' + datetime_obj.strftime(
                    '%Y') + '/' + datetime_obj.strftime('%m')
                return HttpResponseRedirect(redirect_link)

        if user and event:
            event.name = form_data.get('name')
            event.event_type = form_data.get('event_type')
            event.description = form_data.get('description')
            event.companies = form_data.get('companies')
            event.event_date = form_data.get('event_date')
            event.start_time = startTime
            event.end_time = endTime
            event.save()

            datetime_obj = datetime.strptime(event.event_date, "%Y-%m-%d")
            redirect_link = '../../../calendar/' + datetime_obj.strftime(
                '%Y') + '/' + datetime_obj.strftime('%m')
            return HttpResponseRedirect(redirect_link)

        else:
            event = jam_event(name=form_data.get('name'),
                              event_type=form_data.get('event_type'),
                              description=form_data.get('description'),
                              companies=form_data.get('companies'),
                              event_date=form_data.get('event_date'),
                              start_time=startTime,
                              end_time=endTime,
                              creator=request.user)
            event.save()
            request.user.events.add(event)
            request.user.owned_events.add(event)

            datetime_obj = datetime.strptime(event.event_date, "%Y-%m-%d")
            redirect_link = '../../../calendar/' + datetime_obj.strftime(
                '%Y') + '/' + datetime_obj.strftime('%m')
            return HttpResponseRedirect(redirect_link)

    event_date = event.event_date
    event_date = str(event_date)
    datetime.strptime(event_date, "%Y-%m-%d")

    if event.occurrence_id:
        delete_button = True
        recurrence_object = EventOccurrence.objects.filter(
            id=event.occurrence_id).first()
        recurrence = recurrence_object.frequency

        end_date = recurrence_object.end_date
        end_date = str(end_date)
        datetime.strptime(end_date, "%Y-%m-%d")
    else:
        delete_button = False
        recurrence = None
        end_date = None

    context = {
        'event': event,
        'event_name': event.name,
        'description': event.description,
        'event_date': event_date,
        'start_time': event.start_time.strftime("%I:%M %p"),
        'end_time': event.end_time.strftime("%I:%M %p"),
        'creator': event.creator,
        'event_type': event.event_type,
        'companies': event.companies,
        "delete_button": delete_button,
        'recurrence': recurrence,
        'end_date': end_date,
        'occurrence_id': event.occurrence_id
    }

    return render(request, 'events/event_edit.html', context)
Example #4
0
def new_event(request):
    if request.method == "POST":
        form_data = request.POST

        event_date = form_data.get('event_date')
        validity = is_valid_date(event_date)

        end_date = form_data.get('end_date')
        end_validity = ''
        if (end_date):
            end_validity = is_valid_date(end_date)

        if (validity != '' and end_validity != ''):

            # return bad request if the date is still invalid somehow (but very unlikely!)
            response = {}
            response["error"] = validity
            return HttpResponseBadRequest(json.dumps(response),
                                          content_type="application/json")

        event_name = form_data.get('name')

        startTime, endTime = startEndTimeValidation(
            form_data.get('start_time'), form_data.get('end_time'))
        #print "start time" + startTime + "end time" + endTime
        if (form_data.get('recurrence') != 'None'):
            date_obj = datetime.strptime(str(form_data.get('event_date')),
                                         "%Y-%m-%d")

            occurrence = EventOccurrence(
                name=event_name,
                frequency=form_data.get('recurrence'),
                start_month=form_data.get('event_date')[5:7],
                start_year=form_data.get('event_date')[0:4],
                start_day=form_data.get('event_date')[8:10],
                day_of_the_week=date_obj.strftime('%A'),
                end_date=form_data.get('end_date'))

            print occurrence

            occurrence.save()

            occurrence_id = occurrence.id
            event = jam_event(name=event_name,
                              event_type=form_data.get('event_type'),
                              description=form_data.get('description'),
                              companies=form_data.get('companies'),
                              event_date=form_data.get('event_date'),
                              start_time=startTime,
                              end_time=endTime,
                              occurrence_id=occurrence_id,
                              creator=request.user)

            add_recurring_events(request, event, occurrence)
        else:
            event = jam_event(name=event_name,
                              event_type=form_data.get('event_type'),
                              description=form_data.get('description'),
                              companies=form_data.get('companies'),
                              event_date=form_data.get('event_date'),
                              start_time=startTime,
                              end_time=endTime,
                              creator=request.user)

        event.save()
        request.user.events.add(event)
        request.user.owned_events.add(event)

        if request.user.controlledChannels.filter(
                name=form_data.get("channel")).exists():
            channel = request.user.controlledChannels.filter(
                name=form_data.get("channel")).first()
            if form_data.get("channel") != "None":
                event.channel_set.add(channel)

        company_field = form_data.get('companies')
        if company_field != '':
            company_field = company_field.replace(" ", "")
            companies = company_field.split(',')
            for c in companies:
                if len(request.user.company_set.filter(name=c)) > 0:
                    company = request.user.company_set.filter(name=c)
                    company = company[0]
                    company.events.add(event)

        context = {'username': request.user.username}

        return render(request, 'jam/index/index_landing_home.html', context)
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)
def companies(request, company_name):
	companies = request.user.company_set.all()
	companies = sorted(companies, key=lambda company: company.name)
	data = request.POST
	show_company = True
	user = User.objects.get(username = request.user.username)

	#first_company = companies.first()

	if len(companies) == 0:
		context = {'companies': companies, 'username': request.user.username, 'upload_form': upload_form, "controlled_channels": request.user.controlledChannels}
	else:
		if company_name == 'all':
			company_name = companies[0]
		
		context = company_info(company_name,request,None)
	
	if(data):
		company_edit = False
		app_deadline = ''
		
		#import pdb;pdb.set_trace()
		go_home = data.get('back_home')

		if("export" in data):
			print "got to export"
			user = request.META['LOGNAME']
			path_name = "/Users/%s/Downloads/" % user
			f = open(os.path.join(path_name, "jam_companies.txt"), "w")
			for company in companies:
				f.write(str(company) + ", " + str(company.application_deadline) + "\n")
			f.close() 

		elif('save' in data):
			company_name = data.get('name')

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

			if user and company: 
				application_deadline = data.get('application_deadline')
				error = is_valid_date(application_deadline)

				if error == None and application_deadline != "" and company.application_deadline != datetime.strptime(data.get('application_deadline'),"%Y-%m-%d"):

					title = str(company.name) + ' Deadline'
					if company.application_deadline:
						old_evt = request.user.events.filter(name=title).first()
						old_owned_evt = request.user.owned_events.filter(name=title).first()
						
						old_evt.delete()
						old_owned_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=data.get('application_deadline'),
						creator=request.user
					)
					evt.save()

					request.user.events.add(evt)
					request.user.owned_events.add(evt)
					company.events.add(evt)
					
			company.name = data.get('name')
			company.notes=data.get('notes')
			company.link = data.get('app_link')
			if error == None and len(application_deadline) > 0:
				company.application_deadline = application_deadline
			elif len(application_deadline) == 0: 
				company.application_deadline = None

			company.save()

			context = company_info(company_name,request,error)

		elif('delete' in data):
			company_name = data.get('delete')
			event_title = str(company_name) + ' Deadline'
			company = request.user.company_set.filter(name=company_name)
			company.delete()
			
			event = request.user.events.filter(name=event_title)
			owned_event = request.user.owned_events.filter(name=event_title)
			event.delete()
			owned_event.delete()
			
			companies = request.user.company_set.all()
			companies = sorted(companies, key=lambda company: company.name)

			if(len(companies) > 0):
				company_name = companies[0]
				context = company_info(company_name,request,None)
			else:
				context = {'companies': companies, 'username': request.user.username, 'upload_form': upload_form, "controlled_channels": request.user.controlledChannels}


		elif(go_home == ("Back")):
			show_company = False
			context = {'companies': companies, 'show': show_company,'upload_form': upload_form, 'username': request.user.username, "controlled_channels": request.user.controlledChannels}

		elif('company_update' in data):
			
			#c_name = data.get('app_status')
			if ('company_edit' in data): 
				company_edit = True 
				show_company = False 
			company_list = data.getlist('app_status[]')
			
			for company in companies: 
				if company.name in company_list: 
					company = request.user.company_set.get(name=company.name)
					company.application_status = True
					company.save()
				else:
					company.application_status = False
					company.save()
			#companies = request.user.company_set.all()

			context = company_info(company_name,request,None)

			#context = {'companies': companies, 'username': request.user.username, 'upload_form': upload_form, "controlled_channels": request.user.controlledChannels}
		elif('company_name' in data or 'company_edit' in data):
			if('company_edit' in data): 
				company_edit = True 
				show_company = False
				c_name = data.get('company_edit')
				company = request.user.company_set.get(name=c_name)
				if company.application_deadline != "" and company.application_deadline != None:
					app_deadline = company.application_deadline.strftime('%Y-%m-%d')
				# print "company edit"
			else:
				# print "company name in data"
				c_name = data.get('company_name')
				company = request.user.company_set.get(name=c_name)
				if company.application_deadline != "" and company.application_deadline != None:
					app_deadline = company.application_deadline.strftime('%Y-%m-%d')
				
			contacts = Contact.objects.filter(user=request.user, employer=c_name)
			
			for e in request.user.events.all():
				for c in e.companies.split(','):
					if c.strip() == company.name:
						company.events.add(e)
			
			
			
			events = company.events.all()
			notes = company.notes

			link = company.link
			has_link = False
			if link != '':
				has_link = True

			context = {'company_edit': company_edit, 'companies': companies, 'company_name': company.name, 
			'application_deadline': app_deadline, 'status': company.application_status, 'show': show_company,
			'contacts': contacts, 'company_notes': company.notes, 'upload_form': upload_form, 'username': request.user.username, 
			'events': events, 'link': link, 'has_link': has_link, "controlled_channels": request.user.controlledChannels}

		else:
			print "got to the else"
			context = {'companies': companies, 'username': request.user.username, 'upload_form': upload_form, "controlled_channels": request.user.controlledChannels}
	
	return render(request, 'jam/companies/companies.html', context)
Example #7
0
def add_recurring_events(request, event, occurrence):
	start_date = datetime.strptime(event.event_date, "%Y-%m-%d")
	end_date = datetime.strptime(occurrence.end_date, "%Y-%m-%d")
	year = int(occurrence.start_year) + 1

	#if occurrence.start_year <= start_date.year && occurrence.start_month <= start_date.month && occurrence.start_day <= start_date.day:
	if occurrence.frequency == "Annually":
		while year <= int(end_date.year):
			date = str(year) + "-" + start_date.strftime("%m") + "-" + start_date.strftime("%d")
			date_datetime = datetime.strptime(date, "%Y-%m-%d")

			if date_datetime < end_date:
				newer_event = jam_event(
					name=event.name,
					event_type=event.event_type,
					description=event.description,
					companies=event.companies,
					event_date=date,
					start_time=event.start_time,
					end_time=event.end_time,
					occurrence_id = occurrence.id,
					creator=event.creator)

				newer_event.save()
				request.user.events.add(newer_event)
				request.user.owned_events.add(newer_event)
			year += 1
		return

	if occurrence.frequency == "Monthly":
		increment = 1

		date_datetime = start_date + relativedelta(months=increment)
		while date_datetime <= end_date:
			newer_event = jam_event(
					name=event.name,
					event_type=event.event_type,
					description=event.description,
					companies=event.companies,
					event_date=date_datetime,
					start_time=event.start_time,
					end_time=event.end_time,
					occurrence_id = occurrence.id,
					creator=event.creator)

			newer_event.save()
			request.user.events.add(newer_event)
			request.user.owned_events.add(newer_event)

			increment += 1
			date_datetime = start_date + relativedelta(months=increment)
		return

	if occurrence.frequency == "Weekly":
		incr = 7
	if occurrence.frequency == "Daily":
		incr = 1

	increment = incr
	date_datetime = start_date + relativedelta(days=increment)
	while date_datetime <= end_date:
		newer_event = jam_event(
					name=event.name,
					event_type=event.event_type,
					description=event.description,
					companies=event.companies,
					event_date=date_datetime,
					start_time=event.start_time,
					end_time=event.end_time,
					occurrence_id = occurrence.id,
					creator=event.creator)

		newer_event.save()
		request.user.events.add(newer_event)
		request.user.owned_events.add(newer_event)

		increment += incr
		date_datetime = start_date + relativedelta(days=increment)
Example #8
0
def edit_event(request, event_id):
	form_data = request.POST

	user = User.objects.get(username=request.user.username)
	event = request.user.events.get(id=event_id)

	if form_data:
		startTime, endTime = startEndTimeValidation(form_data.get('start_time'),form_data.get('end_time'))

		if "Save_All" in form_data:
			if request.POST.get("occurrence_id"):
				occurrence_id = int(request.POST.get("occurrence_id"))

				delete_recurring_events(request, occurrence_id, event.event_date)
				new_event(request)

				datetime_obj = event.event_date
				redirect_link = '../../../calendar/' +  datetime_obj.strftime('%Y') + '/' + datetime_obj.strftime('%m')
				return HttpResponseRedirect(redirect_link)

		if user and event:
			event.name=form_data.get('name')
			event.event_type=form_data.get('event_type')
			event.description=form_data.get('description')
			event.companies=form_data.get('companies')
			event.event_date=form_data.get('event_date')
			event.start_time=startTime
			event.end_time=endTime
			event.save()

			datetime_obj = datetime.strptime(event.event_date, "%Y-%m-%d")
			redirect_link = '../../../calendar/' +  datetime_obj.strftime('%Y') + '/' + datetime_obj.strftime('%m')
			return HttpResponseRedirect(redirect_link)

		else:
			event = jam_event(name=form_data.get('name'),
						  event_type=form_data.get('event_type'),
						  description=form_data.get('description'),
						  companies=form_data.get('companies'),
						  event_date=form_data.get('event_date'),
						  start_time=startTime,
						  end_time=endTime,
						  creator=request.user)
			event.save()
			request.user.events.add(event)
			request.user.owned_events.add(event)

			datetime_obj = datetime.strptime(event.event_date, "%Y-%m-%d")
			redirect_link = '../../../calendar/' +  datetime_obj.strftime('%Y') + '/' + datetime_obj.strftime('%m')
			return HttpResponseRedirect(redirect_link)

	event_date = event.event_date
	event_date = str(event_date)
	datetime.strptime(event_date, "%Y-%m-%d")

	if event.occurrence_id:
		delete_button = True
		recurrence_object = EventOccurrence.objects.filter(id=event.occurrence_id).first()
		recurrence = recurrence_object.frequency
		
		end_date = recurrence_object.end_date
		end_date = str(end_date)
		datetime.strptime(end_date, "%Y-%m-%d")
	else:
		delete_button = False
		recurrence = None
		end_date = None

	context = {'event': event, 'event_name': event.name, 'description': event.description, 'event_date': event_date,
	'start_time': event.start_time.strftime("%I:%M %p"), 'end_time': event.end_time.strftime("%I:%M %p"), 'creator': event.creator, 'event_type': event.event_type, 
	'companies': event.companies, "delete_button": delete_button, 'recurrence': recurrence, 'end_date': end_date,
	'occurrence_id': event.occurrence_id}

	return render(request, 'events/event_edit.html', context)
Example #9
0
def new_event(request):
	if request.method == "POST":
		form_data = request.POST

		event_date = form_data.get('event_date')
		validity = is_valid_date(event_date)

		end_date = form_data.get('end_date')
		end_validity = ''
		if (end_date):
			end_validity = is_valid_date(end_date)

		if(validity!='' and end_validity !=''):
	
			# return bad request if the date is still invalid somehow (but very unlikely!)
			response={}
			response["error"] = validity
			return HttpResponseBadRequest(json.dumps(response),content_type="application/json")
		
		event_name = form_data.get('name')

		startTime, endTime = startEndTimeValidation(form_data.get('start_time'),form_data.get('end_time'))
		#print "start time" + startTime + "end time" + endTime
		if (form_data.get('recurrence') != 'None'):
			date_obj = datetime.strptime(str(form_data.get('event_date')), "%Y-%m-%d")

			occurrence = EventOccurrence(
				name=event_name,
				frequency=form_data.get('recurrence'),
				start_month=form_data.get('event_date')[5:7],
				start_year=form_data.get('event_date')[0:4],
				start_day=form_data.get('event_date')[8:10],
				day_of_the_week=date_obj.strftime('%A'),
				end_date=form_data.get('end_date'))

			print occurrence

			occurrence.save()

			occurrence_id = occurrence.id
			event = jam_event(name=event_name,
						  event_type=form_data.get('event_type'),
						  description=form_data.get('description'),
						  companies=form_data.get('companies'),
						  event_date=form_data.get('event_date'),
						  start_time=startTime,
						  end_time=endTime,
						  occurrence_id = occurrence_id,
						  creator=request.user)

			add_recurring_events(request, event, occurrence)
		else:
			event = jam_event(name=event_name,
							  event_type=form_data.get('event_type'),
							  description=form_data.get('description'),
							  companies=form_data.get('companies'),
							  event_date=form_data.get('event_date'),
							  start_time=startTime,
							  end_time=endTime,
							  creator=request.user)

		event.save()
		request.user.events.add(event)
		request.user.owned_events.add(event)

		if request.user.controlledChannels.filter(name=form_data.get("channel")).exists():
			channel = request.user.controlledChannels.filter(name=form_data.get("channel")).first()
			if form_data.get("channel") != "None":
				event.channel_set.add(channel)
		
		company_field = form_data.get('companies')
		if company_field != '':
			company_field = company_field.replace(" ", "")
			companies = company_field.split(',')
			for c in companies:
				if len(request.user.company_set.filter(name=c)) > 0:
					company = request.user.company_set.filter(name=c)
					company = company[0]
					company.events.add(event)
		
		context = {'username': request.user.username}

		return render(request, 'jam/index/index_landing_home.html', context)
Example #10
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)
Example #11
0
def companies(request, company_name):
    companies = request.user.company_set.all()
    companies = sorted(companies, key=lambda company: company.name)
    data = request.POST
    show_company = True
    user = User.objects.get(username=request.user.username)

    #first_company = companies.first()

    if len(companies) == 0:
        context = {
            'companies': companies,
            'username': request.user.username,
            'upload_form': upload_form,
            "controlled_channels": request.user.controlledChannels
        }
    else:
        if company_name == 'all':
            company_name = companies[0]

        context = company_info(company_name, request, None)

    if (data):
        company_edit = False
        app_deadline = ''

        #import pdb;pdb.set_trace()
        go_home = data.get('back_home')

        if ("export" in data):
            print "got to export"
            user = request.META['LOGNAME']
            path_name = "/Users/%s/Downloads/" % user
            f = open(os.path.join(path_name, "jam_companies.txt"), "w")
            for company in companies:
                f.write(
                    str(company) + ", " + str(company.application_deadline) +
                    "\n")
            f.close()

        elif ('save' in data):
            company_name = data.get('name')

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

            if user and company:
                application_deadline = data.get('application_deadline')
                error = is_valid_date(application_deadline)

                if error == None and application_deadline != "" and company.application_deadline != datetime.strptime(
                        data.get('application_deadline'), "%Y-%m-%d"):

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

                        old_evt.delete()
                        old_owned_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=data.get('application_deadline'),
                        creator=request.user)
                    evt.save()

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

            company.name = data.get('name')
            company.notes = data.get('notes')
            company.link = data.get('app_link')
            if error == None and len(application_deadline) > 0:
                company.application_deadline = application_deadline
            elif len(application_deadline) == 0:
                company.application_deadline = None

            company.save()

            context = company_info(company_name, request, error)

        elif ('delete' in data):
            company_name = data.get('delete')
            event_title = str(company_name) + ' Deadline'
            company = request.user.company_set.filter(name=company_name)
            company.delete()

            event = request.user.events.filter(name=event_title)
            owned_event = request.user.owned_events.filter(name=event_title)
            event.delete()
            owned_event.delete()

            companies = request.user.company_set.all()
            companies = sorted(companies, key=lambda company: company.name)

            if (len(companies) > 0):
                company_name = companies[0]
                context = company_info(company_name, request, None)
            else:
                context = {
                    'companies': companies,
                    'username': request.user.username,
                    'upload_form': upload_form,
                    "controlled_channels": request.user.controlledChannels
                }

        elif (go_home == ("Back")):
            show_company = False
            context = {
                'companies': companies,
                'show': show_company,
                'upload_form': upload_form,
                'username': request.user.username,
                "controlled_channels": request.user.controlledChannels
            }

        elif ('company_update' in data):

            #c_name = data.get('app_status')
            if ('company_edit' in data):
                company_edit = True
                show_company = False
            company_list = data.getlist('app_status[]')

            for company in companies:
                if company.name in company_list:
                    company = request.user.company_set.get(name=company.name)
                    company.application_status = True
                    company.save()
                else:
                    company.application_status = False
                    company.save()
            #companies = request.user.company_set.all()

            context = company_info(company_name, request, None)

            #context = {'companies': companies, 'username': request.user.username, 'upload_form': upload_form, "controlled_channels": request.user.controlledChannels}
        elif ('company_name' in data or 'company_edit' in data):
            if ('company_edit' in data):
                company_edit = True
                show_company = False
                c_name = data.get('company_edit')
                company = request.user.company_set.get(name=c_name)
                if company.application_deadline != "" and company.application_deadline != None:
                    app_deadline = company.application_deadline.strftime(
                        '%Y-%m-%d')
                # print "company edit"
            else:
                # print "company name in data"
                c_name = data.get('company_name')
                company = request.user.company_set.get(name=c_name)
                if company.application_deadline != "" and company.application_deadline != None:
                    app_deadline = company.application_deadline.strftime(
                        '%Y-%m-%d')

            contacts = Contact.objects.filter(user=request.user,
                                              employer=c_name)

            for e in request.user.events.all():
                for c in e.companies.split(','):
                    if c.strip() == company.name:
                        company.events.add(e)

            events = company.events.all()
            notes = company.notes

            link = company.link
            has_link = False
            if link != '':
                has_link = True

            context = {
                'company_edit': company_edit,
                'companies': companies,
                'company_name': company.name,
                'application_deadline': app_deadline,
                'status': company.application_status,
                'show': show_company,
                'contacts': contacts,
                'company_notes': company.notes,
                'upload_form': upload_form,
                'username': request.user.username,
                'events': events,
                'link': link,
                'has_link': has_link,
                "controlled_channels": request.user.controlledChannels
            }

        else:
            print "got to the else"
            context = {
                'companies': companies,
                'username': request.user.username,
                'upload_form': upload_form,
                "controlled_channels": request.user.controlledChannels
            }

    return render(request, 'jam/companies/companies.html', context)
Example #12
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)