def zrodlo(request, case_id, event_id): template = loader.get_template("edycja_zrodla.html") class RefForm (forms.Form): art_title = forms.CharField(label=u'Tytul artykulu', required=False) pub_title = forms.CharField(label=u'Tytul publikacji', required=False) url = forms.CharField(label=u'URL', required=False) pub_date = forms.DateField(label='Data publikacji', widget=SelectDateWidget(years=range(1989, 2020)),required=False) access_date = forms.DateField(label='Data dostepu', widget=SelectDateWidget(years=range(1989, 2020))) if request.method == 'GET': ref_form=RefForm() elif request.method == 'POST': ref_form = RefForm(request.POST) if ref_form.is_valid(): data = [ ref_form.cleaned_data[item] for item in ('art_title', 'pub_title', 'url', 'pub_date', 'access_date') ] try: event_refs=list(orm.query('event_refs', event_id)[0][0][0]) except (TypeError, IndexError): event_refs=[] ref_id=orm.query('create_ref', data)[0] event_refs.append(ref_id) orm.query('update_event_refs', (event_refs, event_id)) return HTTPResponseRedirect(reverse('edytor.views.wydarzenie', kwargs=dict(event_id=event_id, case_id=case_id))) return HTTPResponse(template.render(RequestContext(request, dict(form=ref_form))))
def actor (request, object_id): actor = orm.query('actor', object_id)[0] roles_rows = orm.query('actor_roles', object_id) roles_dict = {} for row in roles_rows: role = row[1] case = row[3] role_dict = roles_dict.get(role,dict(id=row[0])) case_list = role_dict.get(case, []) case_list.append(row[2]) role_dict[case] = case_list roles_dict[role] = role_dict roles = [ ( role, [ ((case, roles_dict[role]['id']), roles_dict[role][case]) for case in roles_dict[role].keys() if not case=='id' ] ) for role in roles_dict.keys() ] human = actor[2] if human: related = [] else: related = orm.query('related_human_actors', object_id) result = dict(actor=actor, roles=roles, tab=2 if human else 3, human=human, related=related) template = loader.get_template("aktor.html") return HTTPResponse (template.render(Context(result)))
def atrybut(request, case_id=None, event_id=None, actor_id=None): case_attributes = {'scandal_types':'Typ', 'scandal_field': 'Sfera dotknięta korupcją'} class CaseForm(forms.Form): attribute = forms.ChoiceField(choices=[(key, case_attributes[key]) for key in case_attributes.keys()], label="Wybierz atrybut") name = forms.CharField(label="Nazwa") event_attributes = {'event_types': 'Typ wydarzenia'} class EventForm(forms.Form): attribute = forms.ChoiceField(choices=[(key, event_attributes[key]) for key in event_attributes.keys()],label="Wybierz atrybut") name = forms.CharField(label="Nazwa") actor_attributes = {'secondary_affiliations': 'Afiliacja drugorzędna', 'actor_affiliations': 'Afiliacja','actor_roles':'Rola', 'actor_types': 'Typ'} class ActorForm(forms.Form): attribute = forms.ChoiceField(choices=[(key, actor_attributes[key]) for key in actor_attributes.keys()],label="Wybierz atrybut") name = forms.CharField(label="Nazwa") human = forms.BooleanField(label="Osoba", required=False) if actor_id: form=ActorForm if actor_id=='0': back = reverse('edytor.views.wydarzenie', kwargs=dict(case_id=case_id, event_id=event_id) ) else: back = reverse('edytor.views.aktor', kwargs=dict(case_id=case_id, event_id=event_id, actor_id=actor_id)) elif event_id: form=EventForm back = reverse('edytor.views.wydarzenie', kwargs=dict(case_id=case_id, event_id=event_id) ) elif case_id: form=CaseForm back = reverse('edytor.views.afera', kwargs=dict(case_id=case_id)) template=loader.get_template("atrybut.html") if request.method=='GET': attribute_form = form() elif request.method == 'POST': attribute_form = form(request.POST) if attribute_form.is_valid(): table = attribute_form.cleaned_data['attribute'] name = attribute_form.cleaned_data['name'] if isinstance(attribute_form, ActorForm): data = (table, name, attribute_form.cleaned_data['human']) orm.query('create_attribute_human', data, special=True) else: data = (table, name) orm.query('create_attribute', data, special=True) return HTTPResponseRedirect(back) return HTTPResponse(template.render(RequestContext(request, dict(form=attribute_form, event_id=event_id, actor_id=actor_id, case_id=case_id))))
def api_case_json(request, object_id, major=False): import json case = get_scandal(object_id) events = orm.query('case_events', (object_id, True if major else False)) result = {} result['timeline'] = { 'headline': case[0][0][0], 'type': 'default', 'start_zoom_adjust': 40, 'start_at_slide': 1, 'text': case[0][1], 'startDate': events[0][1].strftime('%Y,%m,%d') if events else '1970,01,01' } dates = [] if events: for event in events: actors = orm.query('event_actors', event[0]) refs = orm.query('full_event_refs', event[0]) text = '' for t in event[2].split('\n'): text = text + '<p>' + t + '</p>' if actors: text = text + '<p class="timeline-aktorzy">Aktorzy wydarzenia:<ul>' for actor in actors: text = text + '<li><a href="/podmiot/%s/">%s</a></li>' % (actor[0], actor[1]) text = text + '</ul>' if refs: text = text + '<p class="timeline-refs">Bibliografia:<ul>' for ref in refs: if ref[4]: if ref[2]: text = text + '<li><a href="%s" target="_blank">%s %s.%s.%s: %s</a></li>' % (ref[4], ref[1], ref[2].day, ref[2].month, ref[2].year, ref[0]) else: text = text + '<li><a href="%s" target="_blank">%s: %s</a></li>' % (ref[4], ref[1], ref[0]) else: if ref[2]: text = text + '<li>%s %s.%s.%s: %s</li>' % (ref[1], ref[2].day, ref[2].month, ref[2].year, ref[0]) else: text = text + '<li>%s: %s</li>' % (ref[1], ref[0]) text = text + '</ul>' dates.append({'startDate': event[1].strftime('%Y,%m,%d'), 'endDate': event[1].strftime('%Y,%m,%d'), 'headline':event[6], 'text': text, 'start_at_slide': 1, 'start_zoom_adjust': -15}) result['timeline']['date']=dates return HTTPResponse(json.dumps(result))
def event (request, object_id): actors = orm.query('event_actors', object_id) template = loader.get_template("aktorzy_wydarzenuia.inc") return HTTPRequest (template.render(Context(dict(event=[None, actors]))))
def aktorzy(request): template = loader.get_template('aktorzy.html') actors = orm.query('all_actors') return HTTPResponse(template.render(RequestContext(request, dict(actors=actors))))
def case_actors (request, object_id): 'returns HTML <ul> for case actors' result = {} result['actors'] = orm.query('case_actors', object_id) template = loader.get_template("aktorzy.inc") return HTTPResponse (template.render(Context(dict(case=result))))
def timeline(request, object_id): 'single scandal timeline view' result = {} scandal = get_scandal(object_id) result['name'] = scandal [0][0][0] result['names'] = scandal [0][0][1:] result['description'] = scandal [0][1] result['background'] = scandal[0][2] result['case'] = object_id result['all_actors'] = orm.query('case_actors', object_id) result['fields'] = orm.query('scandal_fields', object_id) result['types'] = orm.query('scandal_types', object_id) result['case_id'] = object_id result['num_events'] = len(scandal[0][3]) result['tab'] = 1 template = loader.get_template ('linia.html') return HTTPResponse (template.render(Context(result)) )
def case (request, object_id): 'single scandal view' scandal = get_scandal(object_id) events = orm.query('case_events', object_id) if events: ujawnienie_actors = orm.query('event_actors',events[0][0]) ujawnienie = (events[0], ujawnienie_actors[:5],len(ujawnienie_actors)) else: ujawnienie = (None, None, None) result = {} result['name'] = scandal [0][0][0] result['names'] = scandal [0][0][1:] result['description'] = scandal [0][1] result['background'] = scandal[0][2] result['num_events'] = len(events) result['event_leak'] = ujawnienie result['events'] = [ (e, orm.query('event_actors', e[0])[:6] ) for e in events[1:]] result['javascripts'] = ['actors'] result['all_actors'] = orm.query('case_actors', object_id) result['tab'] = '1' result['fields'] = orm.query('scandal_fields', object_id) result['types'] = orm.query('scandal_types', object_id) template = loader.get_template ('afera.html') return HTTPResponse (template.render(Context(result)) )
def event (request, object_id): 'single event view' scandal_title = None event = list(orm.query('event', object_id)[0]) actors = orm.query('event_actors', object_id) event[2] = event[2].split('\n') scandal_title = orm.query('event_case_title', event[0])[0][0][0] try: if event: refs = orm.query('refs','{'+','.join([str(i) for i in event[5]])+'}') except (IndexError, TypeError): refs = [] try: prev_e = orm.query('prev_event', (object_id, object_id))[0] except IndexError: prev_e = None try: next_e = orm.query('next_event', (object_id,object_id))[0] except IndexError: next_e = None result = dict(refs=refs, event=event, prev=prev_e, next=next_e, actors=actors,tab=1) result['tab'] = 1 result['scandal_title'] = scandal_title if isinstance(scandal_title, unicode) else scandal_title.decode('utf-8') template = loader.get_template("wydarzenie.html") return HTTPResponse (template.render(Context(result)))
def szukaj (request): result = dict(form=SearchForm()) if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): term = form.cleaned_data.get('term', '').strip() if term: t = '%' + term + '%' result['cases'] = orm.query('search_cases', (t, t)) result['events'] = orm.query('search_events', (t, t)) result['actors'] = orm.query('search_actors', t) result['form'] = form template = loader.get_template("wyniki.html") return HTTPResponse(template.render(RequestContext(request, result)))
def actors (request, human=True): 'Actors index.' result = [] if human: letters = [ l if isinstance(l, unicode) else l.decode('utf-8') for l in orm.query('letters')[0][0]] for l in letters: result.append((l, orm.query('actors_human_like', (l.lower()+'%', l.upper()+'%')))) template = loader.get_template("indeks.html") else: actors = orm.query('nonhuman_actor_list') actors_dict = {} for row in actors: group = actors_dict.get(row[2], []) group.append(row[:2]) actors_dict[row[2]] = group # print actors_dict keys = actors_dict.keys() keys.sort() for k in keys: actors = actors_dict[k] actors.sort(key=lambda a:a[1].lower()) result.append((k, actors)) template = loader.get_template("instytucje.html") return HTTPResponse (template.render(Context(dict(letters=result,tab=2 if human else 3))))
def wydarzenie (request, case_id, event_id=None): locations = orm.query('locations') class EventForm (forms.Form): types = forms.ChoiceField(orm.query('events_types')) title = forms.CharField(label=u'Tytul') description = forms.CharField(label='Opis', widget=forms.Textarea()) # publication_date = forms.DateField(label='Data publikacji', widget=SelectDateWidget(years=range(1989, 2014)), required=False) event_date = forms.DateField(label='Data wydarzenia', widget=SelectDateWidget(years=range(1989,2020))) major = forms.BooleanField(label="Wazne", required=False) descriptive_date = forms.CharField(label='Data opisowa', required=False) if request.method == "GET": if event_id: event = orm.query('event',event_id) try: if event[0][0]: event=event[0] initial = dict(title=event[6], description=event[2], event_date=event[1], descriptive_date=event[8], types=event[9]) event_form = EventForm (initial=initial) else: event_form = EventForm() except IndexError: event_form = EventForm() else: event_form = EventForm() template = loader.get_template('edycja_wydarzenia.html') return HTTPResponse(template.render(RequestContext(request, dict(form=event_form, event_id=event_id, case_id=case_id)))) elif request.method =="POST": event_form = EventForm(request.POST) if event_form.is_valid(): data = [ [int(event_form.cleaned_data[index])] if index=='types' else event_form.cleaned_data[index] for index in ('title', 'types', 'description', 'event_date', 'major', 'descriptive_date')] if event_id: data.append(str(event_id)) result = orm.query('update_event', data) else: event_id = orm.query('create_event', data)[0][0] events = orm.query('case_events_list',int(case_id))[0][0] if not events: events = [] events.append(int(event_id)) status = orm.query('case_update_events', (events, case_id)) return HTTPResponseRedirect('/edit/%s/event/%s' % ( case_id, event_id)) else: template = loader.get_template('edycja_wydarzenia.html') return HTTPResponse(template.render(RequestContext(request, dict(form=event_form))))
def powiazane (request,actor_id=None): template = loader.get_template ("powiazane.html") class RelatedForm(forms.Form): actor = forms.ChoiceField(choices=[ list(i) for i in orm.query('all_actors') ], label="Nazwa", widget=forms.RadioSelect()) affiliation = forms.ChoiceField(choices=[ list(i) for i in orm.query('all_actor_affiliations')], label="Afiliacje",widget=forms.RadioSelect(attrs={'size': 24}), required=False) secondary_affiliations = forms.ChoiceField(choices=[ list(i) for i in orm.query('all_actor_secondary_affiliations')], label="Afiliacje drugorzedne",widget=forms.RadioSelect(attrs={'size': 24}), required=False) if request.method == "GET": return HTTPResponse (template.render(RequestContext(request, dict(form=RelatedForm())))) elif request.method == "POST": form = RelatedForm(request.POST) if form.is_valid(): affiliation = form.cleaned_data.get("affiliation", None) secondary = form.cleaned_data.get("secondary_affiliations", None) orm.query('create_related', (form.cleaned_data["actor"], int(affiliation) if affiliation else None, int(secondary) if secondary else None)) return HTTPResponseRedirect(redirect_to=reverse('edytor.views.powiazane')) else: return HTTPResponse(template.render(RequestContext(request, dict(form=actor_form))))
def edycja_aktora(request, object_id): template = loader.get_template('edycja_aktora.html') class ActorForm(forms.Form): id = forms.IntegerField(label='id', widget=forms.HiddenInput) name = forms.CharField(label='Nazwa/nazwisko', widget=forms.TextInput(attrs=dict(size='64'))) human = forms.BooleanField(label="Osoba", required=False) if request.method == 'POST': actor_form=ActorForm(request.POST) if actor_form.is_valid(): orm.query('update_actor', (actor_form.cleaned_data['name'], actor_form.cleaned_data['human'], object_id)) return HTTPResponseRedirect(redirect_to=reverse('edytor.views.aktorzy')) else: return HTTPResponse(template.render(RequestContext(request, dict(form=actor_form, object_id=object_id)))) elif request.method == 'GET': actor = orm.query('actor', object_id)[0] initial = dict(id=actor[0], name=actor[1], human=actor[2]) form = ActorForm(initial=initial) return HTTPResponse (template.render(RequestContext(request, dict(form=form))))
def afera(request, case_id=None): template = loader.get_template('edycja_afery.html') fields = orm.query('case_types') types = orm.query('case_fields') class ScandalForm(forms.Form): name = forms.CharField(label=u'Tytuly (oddzielone przecinkami)') description = forms.CharField(label='Opis', widget=forms.Textarea()) background = forms.CharField(label='Tło', widget=forms.Textarea()) types = forms.MultipleChoiceField(orm.query('case_types'), widget=forms.CheckboxSelectMultiple(attrs={'size': len(orm.query('case_types'))}),label="Typ") fields = forms.MultipleChoiceField(orm.query('case_fields'), widget=forms.CheckboxSelectMultiple(attrs={'size': len(orm.query('case_fields'))}), label="Sfera") if request.method == "GET": if case_id: case = orm.query('get_case', case_id) try: if case[0][0]: #jest id case=case[0] case_form = ScandalForm(initial=dict(titles=','.join(case[1]), description=case[2], background=case[3])) else: case_form=ScandalForm() except IndexError: case_form=ScandalForm() else: case_form=ScandalForm() return HTTPResponse(template.render(RequestContext(request, dict(form=case_form, case_id=case_id)))) elif request.method == "POST": case_form = ScandalForm(request.POST) if case_form.is_valid(): data = [ [ int(i) for i in case_form.cleaned_data[index] ] if index in ['types','fields'] else case_form.cleaned_data[index] for index in ('name', 'description', 'background', 'types', 'fields')] data = [data[0].split(',')] + data[1:] if case_id: data.append(str(case_id)) orm.query('update_case', data) else: result=orm.query('create_case', data)[0][0] return HTTPResponseRedirect('/edit/%s' % result) else: return HTTPResponse(template.render(RequestContext(request, dict(form=case_form))))
def cases (request, type_id=None, field_id=None, intro=False): 'all cases view' if type_id and field_id: cases = orm.query('cases_type_field', (type_id, field_id)) elif type_id: cases = orm.query('cases_type', type_id) elif field_id: cases = orm.query('cases_field', field_id) else: cases = orm.query('cases') types = [ (typ[0], [ t for t in typ[1].split('/') if t]) for typ in orm.query('case_types') ] fields = [ (field[0], [ t for t in field[1].split('/') if t]) for field in orm.query('case_fields') ] result = [] ## TODO ustawianie id=active dla wybranych fieldow i typow for c in cases: case = dict(id=c[0],title=c[1], description=c[2]) actors = orm.query('case_actors', c[0]) case['events'] = orm.query('event_count', c[0])[0][0] case['actors'] = actors[:5] if actors: case['num_actors'] = len(actors) else: case['num_actors'] = 0 try: case['num_events'] = len(c[7]) except (TypeError, IndexError): case['num_events'] = 0 result.append(case) template = loader.get_template ('afery.html') return HTTPResponse (template.render(Context(dict(cases=result,intro=intro, tab=1, javascripts=['actors', 'jquery-1.9.1.min', 'hide'], jquery=True, types=types, fields=fields, type_id=type_id, field_id=field_id))))
def aktor(request, case_id, event_id, actor_id=None, add=False): template = loader.get_template('edycja_aktora.html') class ActorForm(forms.Form): actor = forms.ChoiceField(choices=[ list(i) for i in orm.query('all_actors') ], label="Nazwa", widget=forms.RadioSelect()) class AddActorForm(forms.Form): name = forms.CharField(label='Nazwa/nazwisko') human = forms.BooleanField(label="Osoba", required=False) class EventActorForm(forms.Form): types = forms.MultipleChoiceField(choices=[ list(i) for i in orm.query('all_actor_types') ], widget=forms.CheckboxSelectMultiple(attrs={'size': 24}), label="Typy", required=False) roles = forms.ChoiceField(choices=orm.query('all_actor_roles'), label="Role", required=False) primary = forms.BooleanField(default=True) affiliations = forms.MultipleChoiceField(choices=[ list(i) for i in orm.query('all_actor_affiliations')], label="Afiliacje",widget=forms.CheckboxSelectMultiple(attrs={'size': 24}), required=False) secondary = forms.BooleanField(default=True) secondary_affiliations = forms.MultipleChoiceField(choices=[ list(i) for i in orm.query('all_actor_secondary_affiliations')], label="Afiliacje drugorzedne",widget=forms.CheckboxSelectMultiple(attrs={'size': 24}), required=False) if request.method == "GET": if actor_id: # mamy wybranego aktora # todo uzupelnianie zaznaczen TODO metadata = orm.query('case_actor_events_metadata', (case_id, actor_id)) if metadata: line = metadata[-1] cols = ('types','roles', 'affiliations', 'secondary_affiliations') metadata_dict = {} # for line in metadata: for item in cols: workset = metadata_dict.get(item,set()) l = line[cols.index(item)] if l: workset = workset.union(tuple(l)) metadata_dict[item] = workset output = {} for item in cols: workdict = {} workset = metadata_dict.get(item,set()) for val in workset: if item == 'roles': output[item] = str(val) else: workdict[val] = 'checked' output[item] = workdict # 'abc'[10] actor_form = EventActorForm(initial=output) else: actor_form = EventActorForm() return HTTPResponse(template.render(RequestContext(request, dict(form=actor_form, event_id=event_id, case_id=case_id)))) else: if add: # dodajemy aktora return HTTPResponse(template.render(RequestContext(request, dict(form=AddActorForm(), event_id=event_id, case_id=case_id)))) else: # wybieramy aktora return HTTPResponse(template.render(RequestContext(request, dict(form=ActorForm(), event_id=event_id, case_id=case_id)))) elif request.method == "POST": if actor_id: # wybralismy aktora i albo pokazujemy formatke albo go przypisujemy actor_form = EventActorForm(request.POST) if actor_form.is_valid(): data = [ [int(i) for i in actor_form.cleaned_data[index]] if index in ['types', 'roles', 'affiliations', 'secondary_affiliations'] else actor_form.cleaned_data[index] for index in ('types', 'roles', 'affiliations', 'secondary_affiliations', 'primary', 'secondary')] data = [event_id, actor_id] + data orm.query('assign_actor', data) return HTTPResponseRedirect(redirect_to=reverse('edytor.views.wydarzenie', kwargs=dict(event_id=event_id, case_id=case_id))) else: #cos nie pasuje, pokazujemy form jeszcze raz TODO return HTTPResponse(template.render(RequestContext(request, dict(form=actor_form, event_id=event_id, case_id=case_id, actor_id=actor_id)))) else: if add == True: add_actor_form=AddActorForm(request.POST) if add_actor_form.is_valid(): actor_id = orm.query('create_actor', (add_actor_form.cleaned_data['name'], add_actor_form.cleaned_data['human']))[0][0] return HTTPResponseRedirect(redirect_to=reverse('edytor.views.aktor', kwargs=dict(event_id=event_id, case_id=case_id, actor_id=actor_id))) else: return HTTPResponse(template.render(RequestContext(request, dict(form=add_actor_form, event_id=event_id, case_id=case_id)))) else: actor_form = ActorForm(request.POST) if actor_form.is_valid(): # nie mamy actor_id, albo pokazujemy formatke, albo przekierowujemy do actor_id actor_id = actor_form.cleaned_data["actor"] return HTTPResponseRedirect(redirect_to=reverse('edytor.views.aktor', kwargs=dict(event_id=event_id, case_id=case_id, actor_id=actor_id))) else: return HTTPResponse(template.render(RequestContext(request, dict(form=actor_form))))
def lista(request): template=loader.get_template("lista_afer.html") cases = orm.query("cases") return HTTPResponse(template.render(RequestContext(request, dict(cases=cases))))