def create_event(request): if request.method == 'POST': # If the form has been submitted... form = EventForm(request.POST) # A form bound to the POST data if form.is_valid(): name = form.cleaned_data['title'] name = Event.normalize_name(name) key_words = form.cleaned_data['key_words'] list_keywords = Keyword.normalize_keywords(key_words) keyobjs = [] for key in list_keywords: try: fkeyword = Keyword.objects.get(key_word=key) except Keyword.DoesNotExist: fkeyword = Keyword(key_word=key) fkeyword.save() keyobjs.append(fkeyword) e = Event(name=name, start_date=None, end_date=None) try: e.start_date = form.cleaned_data['start_date'] except: pass try: e.end_date = form.cleaned_data['end_date'] except: pass e.save() e.keywords = keyobjs try: parent = form.cleaned_data['parent_id'] parent_event = Event.objects.get(id=parent) parent_event.children.add(e) cache.delete("graph" + str(parent)) # clear parent view to include child except Event.DoesNotExist: pass return HttpResponseRedirect('detail/%d' % (e.id)) # Redirect after POST else: # initialize the form with a set of values that are passed in as data. If there are no initial values,initialize an empty form. try: parent_id = request.GET["parent_id"] keywords = request.GET["keywords"] sd = request.GET["start_date"] ed = request.GET["end_date"] data = { 'start_date': sd, 'end_date': ed, 'key_words': keywords, 'parent_id': parent_id, 'title': " " } form = EventForm(data) except: form = EventForm() return render_to_response('twitinfo/create_event.html', {'form': form}, context_instance=RequestContext(request))
def search_results(request): search = Event.normalize_name(request.GET['query']) events = Event.objects.filter(name = search) events_from_keywords = Event.objects.filter(keywords__key_word=search) total_events=itertools.chain(events,events_from_keywords) total_events=list(total_events) if len(total_events)==0: return render_to_response('twitinfo/results.html', {'error':'Sorry, the keyword you searched for does not exist.'}, context_instance=RequestContext(request)) else: return render_to_response('twitinfo/results.html', {'events':total_events}, context_instance=RequestContext(request))
def search_results(request): search = Event.normalize_name(request.GET['query']) events = Event.objects.filter(name=search) events_from_keywords = Event.objects.filter(keywords__key_word=search) total_events = itertools.chain(events, events_from_keywords) total_events = list(total_events) if len(total_events) == 0: return render_to_response( 'twitinfo/results.html', {'error': 'Sorry, the keyword you searched for does not exist.'}, context_instance=RequestContext(request)) else: return render_to_response('twitinfo/results.html', {'events': total_events}, context_instance=RequestContext(request))
def create_event(request): if request.method == 'POST': # If the form has been submitted... form = EventForm(request.POST) # A form bound to the POST data if form.is_valid(): name = form.cleaned_data['title'] name = Event.normalize_name(name) key_words = form.cleaned_data['key_words'] list_keywords = Keyword.normalize_keywords(key_words) keyobjs=[] for key in list_keywords: try: fkeyword = Keyword.objects.get(key_word = key) except Keyword.DoesNotExist: fkeyword = Keyword(key_word = key) fkeyword.save() keyobjs.append(fkeyword) e = Event(name = name,start_date = None,end_date = None) try: e.start_date = form.cleaned_data['start_date'] except: pass try: e.end_date = form.cleaned_data['end_date'] except: pass e.save() e.keywords = keyobjs try: parent = form.cleaned_data['parent_id'] parent_event = Event.objects.get(id=parent) parent_event.children.add(e) cache.delete("graph" + str(parent)) # clear parent view to include child except Event.DoesNotExist: pass return HttpResponseRedirect('detail/%d' % (e.id)) # Redirect after POST else: # initialize the form with a set of values that are passed in as data. If there are no initial values,initialize an empty form. try: parent_id=request.GET["parent_id"] keywords=request.GET["keywords"] sd=request.GET["start_date"] ed=request.GET["end_date"] data={'start_date':sd,'end_date':ed,'key_words':keywords,'parent_id':parent_id,'title':" "} form = EventForm(data) except: form = EventForm() return render_to_response('twitinfo/create_event.html', {'form': form}, context_instance=RequestContext(request))