Example #1
0
def home(request):
    if request.method == 'POST' and request.is_ajax:
        form = EventForm(request.POST)
        status = {'status' : 'success'}

        if form.is_valid():
            title = form.cleaned_data['title']
            start = form.cleaned_data['start']
            end = form.cleaned_data['end']
            allDay = form.cleaned_data['allDay']

            event = CalendarEvents(title=title, start=start, end=end, allDay=allDay)
            event.save()

            status['message'] = 'Success!  Your event has been added to the calendar'

        else:
            status['status'] = 'fail'
            status['errors'] = dict(form.errors.items())
            status['message'] = 'Oops! Looks like the tubes got clogged'

        json_response = simplejson.dumps(status)
        return HttpResponse(json_response, mimetype='application/json')

    else:
        form = EventForm
    return render_to_response('core/home.html', {'form': form}, context_instance=RequestContext(request))
  def handle(self, *args, **options):
    events = []
    url    = environ.get('EVENT_DOC_URL', '')

    if url == '':
      print 'no event doc url detected, exiting.'
      return

    csvfile = requests.get(url)

    text    = csvfile.text.encode('ISO-8859-1')
    reader  = csv.reader(text.splitlines(True), delimiter=',')
    user_id = User.objects.first().id

    # ignore first row as it only contains column names
    reader.next()

    for row in reader:
      if Event.objects.filter(name=row[1]).exists():
        return

      if row[9]:
        response = requests.get(row[9])
        uri = (
          "data:" + response.headers['Content-Type'] + ";" +
          "base64," + base64.b64encode(response.content))

      event = {
        'name'       : row[1],
        'description': row[2],
        'start'      : self._format_datestring(row[3]),
        'end'        : self._format_datestring(row[4]),
        'frequency'  : 1,
        'location'   : row[6],
        'contact'    : user_id,
        'url'        : row[7] or None,
        'image'      : uri or None
      }
      events.append(event)

    for e in events:
      event_form = EventForm(e)
      event_form.is_valid()
      with transaction.atomic():
        Event.objects.create(**event_form.cleaned_data)
Example #3
0
    def handle(self, *args, **options):
        events = []
        url = environ.get('EVENT_DOC_URL', '')

        if url == '':
            print 'no event doc url detected, exiting.'
            return

        csvfile = requests.get(url)

        text = csvfile.text.encode('ISO-8859-1')
        reader = csv.reader(text.splitlines(True), delimiter=',')
        user_id = User.objects.first().id

        # ignore first row as it only contains column names
        reader.next()

        for row in reader:
            if Event.objects.filter(name=row[1]).exists():
                return

            if row[9]:
                response = requests.get(row[9])
                uri = ("data:" + response.headers['Content-Type'] + ";" +
                       "base64," + base64.b64encode(response.content))

            event = {
                'name': row[1],
                'description': row[2],
                'start': self._format_datestring(row[3]),
                'end': self._format_datestring(row[4]),
                'frequency': 1,
                'location': row[6],
                'contact': user_id,
                'url': row[7] or None,
                'image': uri or None
            }
            events.append(event)

        for e in events:
            event_form = EventForm(e)
            event_form.is_valid()
            with transaction.atomic():
                Event.objects.create(**event_form.cleaned_data)
Example #4
0
    def load_feature_to_form(self, onefry):
        with self.testapp.application.app_context():
            form = FishFryForm()
            # shortcut to the returned fish fry's properties
            p = onefry['properties']
            # map the fish fry data to the form fields
            form.ffid.data = onefry['id']
            form.alcohol.data = prebool(p['alcohol'])
            form.email.data = p['email']
            form.etc.data = p['etc']
            form.handicap.data = prebool(p['handicap'])
            form.homemade_pierogies.data = prebool(p['homemade_pierogies'])
            form.lunch.data = prebool(p['lunch'])
            form.menu_txt.data = p['menu']['text']
            form.menu_url.data = p['menu']['url']
            form.phone.data = p['phone']
            form.publish.data = p['publish']
            form.take_out.data = prebool(p['take_out'])
            form.validated.data = ['validated']
            form.venue_address.data = p['venue_address']
            form.venue_name.data = p['venue_name']
            form.venue_notes.data = p['venue_notes']
            form.venue_type.data = p['venue_type']
            form.website.data = p['website']
            try:
                form.lng.data = onefry['geometry']['coordinates'][0]
                form.lat.data = onefry['geometry']['coordinates'][1]
            except:
                form.lng.data = None
                form.lat.data = None

            if p['events']:
                events = sort_records(p['events'], 'dt_start')
                for event in events:
                    event_form = EventForm()
                    event_form.dt_start = parse(event['dt_start'])
                    event_form.dt_end = parse(event['dt_end'])
                    form.events.append_entry(event_form)

            print(dir(form))
            print(form.__dict__)
            return form.to_dict()
Example #5
0
def organization_event_create(request, slug):
    c = {}
    org = get_object_or_404(Organization, urlslug=slug)
    c['organization'] = org

    if not org.user_is_owner(request.user):
        raise PermissionDenied

    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            form.save(org=org)
            messages.add_message(request, messages.SUCCESS,
                                 _('Created event!'))
            return redirect(org)
        else:
            form = EventForm(request.POST)
    else:
        form = EventForm()

    c['form'] = form
    return render(request, 'organization/event_create.html', c)
Example #6
0
def organization_event_create (request, slug):
	c = {}
	org = get_object_or_404(Organization, urlslug=slug)
	c['organization'] = org

	if not org.user_is_owner(request.user):
		raise PermissionDenied
	
	if request.method == 'POST':
		form = EventForm (request.POST)
		if form.is_valid ():
			form.save (org=org)
			messages.add_message (request, messages.SUCCESS, _('Created event!'))
			return redirect(org)
		else:
			form = EventForm (request.POST)
	else:
		form = EventForm ()
	
	c['form'] = form
	return render(request, 'organization/event_create.html', c)