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 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 #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)