def create_test_event(u=None, o=None):
    if not o: # pragma: no cover
        o = create_test_organization(u)
    e = Event(name='do stuff', organizer=o.admin, organization=o, description='yeah', date_start=timezone.now(),
        date_end=timezone.now() + timezone.timedelta(hours=1), location='New York City, NY', hour_type='SRV')
    e.save()
    return e
Example #2
0
File: views.py Project: 13901/to_do
def home(request):
    if request.method == "POST":
        #import pdb; pdb.set_trace() 
        title = request.POST["title"]
        description = request.POST["description"]
        venue = request.POST["venue"]
        date = request.POST["date"].split("-")
        event = Event(
                title=title,
                description=description,
                venue=venue,
                date=datetime.date(int(date[0]), int(date[1]), int(date[2]))
                )
        event.save()
        return HttpResponseRedirect("/list")
        #import pdb; pdb.set_trace()

    return render_to_response("create.html", {}, context_instance=RequestContext(request))
Example #3
0
def event_add(request, id):
    dance = Dance.objects.get(pk=id)

    if request.method == "POST":
        form = EventForm(request.POST)
        if form.is_valid():
            # figure out band
            band, band_created = Band.objects.get_or_create(name=form.cleaned_data['band'])
            # figure out caller
            caller, caller_created = Person.objects.get_or_create(name=form.cleaned_data['caller'])

            event = Event(date=form.cleaned_data['date'],band=band,caller=caller,dance=dance)
            event.save()
            return HttpResponseRedirect( reverse( 'main.views.dance', args=(event.dance.id,) ) )
        
    else:
        form = EventForm()

    return render_to_response('main/event_add.html', {'form':form,'dance':dance})
Example #4
0
def events(request):
    context = {}
    user = user_to_fingr(request.user)
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():

            currTime = datetime.datetime.now()

            good = True
            #we need to do some hacky stuff and set the year, because otherwise it might do 1889 which is an error
            startTime = form.cleaned_data['timeStart']
            endTime = form.cleaned_data['timeEnd']
            startTime = startTime.replace(year=currTime.year)
            endTime = endTime.replace(year=currTime.year)

            #HOW DO I VALIDATE PROPERLY?
            if endTime <= startTime:
                errors = form._errors.setdefault("timeEnd", ErrorList())
                errors.append(u"End time must be after Start time")
                good = False
            if form.cleaned_data['date'] < currTime.date():
                errors = form._errors.setdefault("date", ErrorList())
                errors.append(u"Day must be today or in the future")
                good = False

            if good:
                event = Event(title=form.cleaned_data['title'], owner=user, date=form.cleaned_data['date'],
                              timeStart=startTime, timeEnd=endTime, description=form.cleaned_data['description']
                )
                event.save()
                notify_all_friends(user, "You have been invited to " + user.full_name + "'s event: " + event.title)

    else:
        form = EventForm()

    context['form'] = form

    context['userEvents'] = Event.objects.filter(owner=user)
    context['friendEvents'] = Event.objects.filter(owner__in=user.friends_list)

    return render(request, 'events.html', context)
Example #5
0
def submit(request):
	if ('name' not in request.POST):
		context = {'message1':'Error', 'message2':'Please enter an event name'}
		return render(request, 'add_event/message.html', context)
	else:
		name = request.POST['name']

	if ('fee' not in request.POST):
		context = {'message1':'Error', 'message2':'Please enter the event registration fee'}
		return render(request, 'add_event/message.html', context)
	else:
		fee = request.POST['fee'];

	tf = None
	if ('teamFee' in request.POST):
		teamFee = request.POST['teamFee']
		if teamFee == 'true':
			tf = True
		else:
			tf = False
	else:
		teamFee = None

	if ('minimum' in request.POST):
		minimum = request.POST['minimum']
	else:
		minimum = None

	if ('maximum' in request.POST):
		maximum = request.POST['maximum']
	else:
		maximum = None

	if maximum is None and minimum is None:
		data = Event(name=name, minimum=minimum, maximum=maximum, fee=fee, team=False, teamCollect=tf, registration_active=True)
	else:
		data = Event(name=name, minimum=minimum, maximum=maximum, fee=fee, team=True, teamCollect=tf, registration_active=True)
	data.save()

	context = {'redirect':'true'}
	return render(request, 'add_event/event.html', context)
Example #6
0
 def getEvents(url, house, message):
     try:
         r = requests.get(url)
     except:
         r = False
         message += 'request failed. '
     if r:
         data = r.text
         soup = BeautifulSoup(data, 'html.parser')
         tds = soup.findAll('td')
         dupes = 0
         for td in tds:
             title = td.find('p',
                             {'class': 'parl-calendar-event-title'})
             if title:
                 title = str(title)
                 description = td.find(
                     'p', {'class': 'parl-calendar-event-description'})
                 description = str(description)
                 location = td.findParents(
                     'table')[0]['data-specflow-id']
                 location = str(location)
                 date = today
                 event = Event(date=date,
                               location=location,
                               house=house,
                               title=title,
                               description=description)
                 if Event.objects.filter(date=date,
                                         title=title,
                                         house=house).exists():
                     dupes += 1
                     message += 'duplicates %s' % str(dupes)
                 else:
                     event.save()
                     message += 'added event: %s' % title
             else:
                 message += 'no events. '
Example #7
0
    def process_item(self, item, spider):
        if not Event.objects.filter(title=item['title']).exists():
            event = Event()
            event.title = item['title']
        else:
            event = Event.objects.get(title=item['title'])

        event.url = item['url']
        event.image = item['image']
        event.body = item['body']
        event.date = item['date'].replace('/', '-')
        event.time = item['time']
        event.price = item['price']

        if Venue.objects.filter(name=item['venue']).exists():
            venue = Venue.objects.get(name=item['venue'])
        else:
            venue = Venue()
            venue.name = item['venue']
            venue.save()

        venue.address = item['address']
        event.venue = venue

        event.save()
        artists = item['artists']
        for artist_name in artists:
            if Artist.objects.filter(name=artist_name).exists():
                artist = Artist.objects.get(name=artist_name)
            else:
                artist = Artist()
                artist.name = artist_name
                artist.save()
            event.artists.add(artist)

        event.save()
Example #8
0
def create(request):
    if request.POST:
        start_date = request.POST['start_date']
        end_date = request.POST['end_date']
        name = request.POST['event_name']
        url = request.POST['event_url']
        length = request.POST['length']

        REQUIRED_FIELDS = {
            "Start date": start_date,
            "End date": end_date,
            "Name": name,
            "Length": length
        }

        error = []
        for key, value in REQUIRED_FIELDS.items():
            if not value:
                error.append(key + " is a required field")
        if error:
            for e in error:
                messages.warning(request, e)
            return render(request, "main/create.html")
        try:
            length = float(length)
        except:
            messages.warning(request, "length must be a string")
            return render(request, "main/create.html")

        if length < .5 or length > 24:
            messages.warning(
                request,
                "length cannot be less than .5 or greater than 24 hours")
            return render(request, "main/create.html")
        if length % .5:
            messages.warning(request,
                             "length must be in interval of 30 minutes")
            return render(request, "main/create.html")
        if end_date < start_date:
            temp = start_date
            start_date = end_date
            end_date = temp
        try:
            start_date = datetime.strptime(start_date, "%m/%d/%Y %H:%M:%S")
            end_date = datetime.strptime(end_date, "%m/%d/%Y %H:%M:%S")
        except:
            messages.warning(
                request, "start_date or end_date are incorrectly formatted")
            return render(request, "main/create.html")
        if not url:
            while True:
                url = randomSentence(30, 50)
                if Event.objects.filter(code_name=url).count() == 0:
                    break

        else:
            if Event.objects.filter(code_name=url).count() > 0:
                message.warning(request,
                                "url '{}' is already taken".format(url))
                return render(request, "main/create.html")

        Event.deleteOutOfDate()
        event = Event(start_date=start_date,
                      end_date=end_date,
                      title=name,
                      code_name=url,
                      length=length)
        event.creator = request.user.profile
        event.save()
        request.user.profile.events.add(event)
        messages.success(request, "Event '{}' created".format(url))
        return redirect("event", code_name=event.code_name)

        # try:

        # except:
        #     messages.warning(request, "start_date, end_date, event_name, and event_url are required arguments")
        #     return render(request, "main/create.html")
        # try:
        #     start_date = datetime.strptime(start_date, "%m/%d/%Y %H:%M:%S")
        #     end_date = datetime.strptime(end_date, "%m/%d/%Y %H:%M:%S")
        # except:
        #     if not start_date or end_date:
        #         messages.warning(request, "start_date and end_date are required fields")
        #         return HttpResponse("location.reload()")
        #     return HttpResponse("date is in bad format, must be m/d/Y H:M:S")

        # if not name:
        #     messages.warning(request, "name is a required field")
        #     return HttpResponse("location.reload()")
        # try:
        #     Event.objects.get(code_name=url)
        #     messages.warning(request, "url '{}' already exists".format(url))
        #     return HttpResponse("location.reload()")
        # except:
        #     pass
        # try:

        #     return HttpResponse("window.replace(" + url + ")")
        # except Exception as e:
        #     messages.warning(request, str(e))
        #     return HttpResponse("location.reload()")

        # return event.code_name

    return render(request, "main/create.html")