Skip to content

Commit 6a12a6d

Browse files
authored
Add files via upload
1 parent ba5d57e commit 6a12a6d

3 files changed

Lines changed: 72 additions & 37 deletions

File tree

qualcoder/manage_files.py

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from .html_parser import *
5959
from .memo import DialogMemo
6060
from .report_codes import DialogReportCodes # for isInstance()
61+
from .ris import Ris
6162
from .select_items import DialogSelectItems
6263
from .view_av import DialogViewAV, DialogCodeAV # for isinstance update files
6364
from .view_image import DialogViewImage, DialogCodeImage # for isinstance update files
@@ -306,6 +307,7 @@ def table_menu(self, position):
306307
item_text = self.ui.tableWidget.item(row, col).text()
307308
# Use these next few lines to use for moving a linked file into or an internal file out of the project folder
308309
mediapath = None
310+
risid = None
309311
try:
310312
id_ = int(self.ui.tableWidget.item(row, self.ID_COLUMN).text())
311313
except AttributeError:
@@ -314,6 +316,7 @@ def table_menu(self, position):
314316
for s in self.source:
315317
if s['id'] == id_:
316318
mediapath = s['mediapath']
319+
risid = s['risid']
317320
# Action cannot be None otherwise may default to one of the actions below depending on column clicked
318321
menu = QtWidgets.QMenu()
319322
menu.setStyleSheet("QMenu {font-size:" + str(self.app.settings['fontsize']) + "pt} ")
@@ -343,6 +346,8 @@ def table_menu(self, position):
343346
action_order_by_value_asc = None
344347
action_order_by_value_desc = None
345348
action_date_picker = None
349+
action_ref_apa = None
350+
action_ref_vancouver = None
346351
if col > self.CASE_COLUMN:
347352
action_order_by_value_asc = menu.addAction(_("Order ascending"))
348353
action_order_by_value_desc = menu.addAction(_("Order descending"))
@@ -355,6 +360,9 @@ def table_menu(self, position):
355360
result = cur.fetchone()
356361
if result is not None and result[0] == "character":
357362
action_date_picker = menu.addAction(_("Enter date"))
363+
if self.header_labels[col] in ("Ref_Authors", "Ref_Title", "Ref_Journal", "Ref_Type", "Ref_Year"):
364+
action_ref_apa = menu.addAction(_("Copy reference to clipboard. APA"))
365+
action_ref_vancouver = menu.addAction(_("Copy reference to clipboard. Vancouver"))
358366
action_rename = None
359367
action_export = None
360368
action_delete = None
@@ -438,15 +446,31 @@ def table_menu(self, position):
438446
if action == action_url:
439447
webbrowser.open(item_text)
440448
if action == action_date_picker:
441-
ui = DialogMemo(self.app, "Date selector", "", "hide")
442-
ui.ui.textEdit.hide()
449+
ui_memo = DialogMemo(self.app, "Date selector", "", "hide")
450+
ui_memo.ui.textEdit.hide()
443451
calendar = QtWidgets.QCalendarWidget()
444-
ui.ui.gridLayout.addWidget(calendar, 0, 0, 1, 1)
445-
ok = ui.exec()
452+
ui_memo.ui.gridLayout.addWidget(calendar, 0, 0, 1, 1)
453+
ok = ui_memo.exec()
446454
if ok:
447455
selected_date = calendar.selectedDate().toString("yyyy-MM-dd")
448456
self.ui.tableWidget.setItem(row, col, QtWidgets.QTableWidgetItem(selected_date))
449457
return
458+
if action == action_ref_apa:
459+
ris_obj = Ris(self.app)
460+
ris_obj.get_references(selected_ris=risid)
461+
apa = ris_obj.refs
462+
if not apa:
463+
return
464+
cb = QtWidgets.QApplication.clipboard()
465+
cb.setText(apa[0]['apa'].replace("\n", " "))
466+
if action == action_ref_vancouver:
467+
ris_obj = Ris(self.app)
468+
ris_obj.get_references(selected_ris=risid)
469+
vancouver = ris_obj.refs
470+
if not vancouver:
471+
return
472+
cb = QtWidgets.QApplication.clipboard()
473+
cb.setText(vancouver[0]['vancouver'].replace("\n", " "))
450474

451475
def view_original_text_file(self, mediapath):
452476
""" View original text file.
@@ -773,14 +797,14 @@ def load_file_data(self, order_by=""):
773797
self.source = []
774798
cur = self.app.conn.cursor()
775799
placeholders = None
776-
# default alphabetic order
777-
sql = "select name, id, fulltext, mediapath, ifnull(memo,''), owner, date, av_text_id from source order by upper(name)"
800+
# Default alphabetic order
801+
sql = "select name, id, fulltext, mediapath, ifnull(memo,''), owner, date, av_text_id, risid from source order by upper(name)"
778802
if order_by == "filename desc":
779803
sql += " desc"
780804
if order_by == "date":
781-
sql = "select name, id, fulltext, mediapath, ifnull(memo,''), owner, date, av_text_id from source order by date, upper(name)"
805+
sql = "select name, id, fulltext, mediapath, ifnull(memo,''), owner, date, av_text_id, risid from source order by date, upper(name)"
782806
if order_by == "filetype":
783-
sql = "select name, id, fulltext, mediapath, ifnull(memo,''), owner, date, av_text_id from source order by mediapath"
807+
sql = "select name, id, fulltext, mediapath, ifnull(memo,''), owner, date, av_text_id, risid from source order by mediapath"
784808
if order_by == "casename":
785809
sql = "select distinct source.name, source.id, source.fulltext, source.mediapath, ifnull(source.memo,''), "
786810
sql += "source.owner, source.date, av_text_id "
@@ -790,11 +814,11 @@ def load_file_data(self, order_by=""):
790814

791815
if order_by[:14] == "attribute asc:":
792816
attribute_name = order_by[14:]
793-
# two types of ordering character or numeric
817+
# Two types of ordering character or numeric
794818
cur.execute("select valuetype from attribute_type where name=?", [attribute_name])
795819
attr_type = cur.fetchone()[0]
796820
sql = "select source.name, source.id, fulltext, mediapath, ifnull(source.memo,''), source.owner, "
797-
sql += "source.date, av_text_id from source join attribute on attribute.id = source.id "
821+
sql += "source.date, av_text_id, risid from source join attribute on attribute.id = source.id "
798822
sql += " where attribute.attr_type = 'file' and attribute.name=? "
799823
if attr_type == "character":
800824
sql += "order by lower(attribute.value) asc "
@@ -808,7 +832,7 @@ def load_file_data(self, order_by=""):
808832
cur.execute("select valuetype from attribute_type where name=?", [attribute_name])
809833
attr_type = cur.fetchone()[0]
810834
sql = "select source.name, source.id, fulltext, mediapath, ifnull(source.memo,''), source.owner, "
811-
sql += "source.date, av_text_id from source join attribute on attribute.id = source.id "
835+
sql += "source.date, av_text_id, risid from source join attribute on attribute.id = source.id "
812836
sql += " where attribute.attr_type = 'file' and attribute.name=? "
813837
if attr_type == "character":
814838
sql += "order by lower(attribute.value) desc "
@@ -825,7 +849,7 @@ def load_file_data(self, order_by=""):
825849
icon, metadata = self.get_icon_and_metadata(row[1])
826850
self.source.append({'name': row[0], 'id': row[1], 'fulltext': row[2],
827851
'mediapath': row[3], 'memo': row[4], 'owner': row[5], 'date': row[6],
828-
'av_text_id': row[7], 'metadata': metadata, 'icon': icon,
852+
'av_text_id': row[7], 'risid': row[8], 'metadata': metadata, 'icon': icon,
829853
'case': self.get_cases_by_filename(row[0]),
830854
'attributes': []})
831855

@@ -852,6 +876,9 @@ def load_file_data(self, order_by=""):
852876
if att_name == "Ref_authors":
853877
tmp = tmp.replace(";", "\n")
854878
s['attributes'].append(tmp)
879+
# Get reference for file, Vancouver and APA style
880+
# TODO
881+
855882
self.fill_table()
856883

857884
def get_icon_and_metadata(self, id_):
@@ -998,18 +1025,17 @@ def add_attribute(self):
9981025
Then get the attribute type through a dialog.
9991026
AddAttribute dialog checks for duplicate attribute name.
10001027
New attribute is added to the model and database.
1001-
Reserved attribute words - usef for imported references:
1028+
Reserved attribute words - used for imported references:
10021029
Ref_Type (Type of Reference) – character variable
10031030
Ref_Author (authors list) – character
10041031
Ref_Title – character
10051032
Ref_Year (of publication) – numeric
1033+
Ref_Journal - character
10061034
"""
10071035

10081036
if self.av_dialog_open is not None:
10091037
self.av_dialog_open.mediaplayer.stop()
10101038
self.av_dialog_open = None
1011-
'''check_names = self.attribute_names + [{'name': 'Ref_Type'}, {'name': 'Ref_Author'}, {'name': 'Ref_Title'},
1012-
{'name':'Ref_Year'}]'''
10131039
ui = DialogAddAttribute(self.app)
10141040
ok = ui.exec()
10151041
if not ok:
@@ -2049,7 +2075,7 @@ def fill_table(self):
20492075
for offset, attribute in enumerate(data['attributes']):
20502076
item = QtWidgets.QTableWidgetItem(attribute)
20512077
self.ui.tableWidget.setItem(row, self.ATTRIBUTE_START_COLUMN + offset, item)
2052-
if self.attribute_labels_ordered[offset] in ("Ref_Authors", "Ref_Title", "Ref_Type", "Ref_Year"):
2078+
if self.attribute_labels_ordered[offset] in ("Ref_Authors", "Ref_Title", "Ref_Type", "Ref_Year", "Ref_Journal"):
20532079
item.setFlags(item.flags() ^ QtCore.Qt.ItemFlag.ItemIsEditable)
20542080
# Resize columns and rows
20552081
self.ui.tableWidget.hideColumn(self.ID_COLUMN)

qualcoder/manage_references.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,14 +505,14 @@ def table_refs_menu(self, position):
505505
if action == action_copy_to_clipboard:
506506
reference_text = self.ui.tableWidget_refs.item(row, 1).text()
507507
cb = QtWidgets.QApplication.clipboard()
508-
cb.setText(reference_text)
508+
cb.setText(reference_text.replace("\n", " "))
509509
if action == action_copy_apa_to_clipboard:
510510
#reference_text = self.ui.tableWidget_refs.item(row, 1).text()
511511
ref_id = self.ui.tableWidget_refs.item(row, REF_ID).text()
512512
for ref in self.refs:
513513
if int(ref_id) == ref['risid']:
514514
cb = QtWidgets.QApplication.clipboard()
515-
cb.setText(ref['apa'])
515+
cb.setText(ref['apa'].replace("\n", " "))
516516

517517
def import_references(self):
518518
""" Import RIS formatted references from .ris or .txt files """

qualcoder/ris.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def exception_handler(exception_type, value, tb_obj):
5454

5555
class Ris:
5656
""" Load ris list of dictionaries.
57-
Format RIS to short display.
57+
Format RIS to Vancouver or APA for display.
5858
References in RIS can be poorly created often due to how the researcher created them. """
5959

6060
app = None
@@ -64,13 +64,20 @@ def __init__(self, app):
6464
sys.excepthook = exception_handler
6565
self.app = app
6666

67-
def get_references(self):
68-
""" As list of dictionaries with risid and summary
67+
def get_references(self, selected_ris=None):
68+
""" As list of dictionaries with risid and summary.
69+
6970
"""
70-
cur = self.app.conn.cursor()
71+
7172
self.refs = []
72-
cur.execute("select distinct risid from ris order by risid")
73+
cur = self.app.conn.cursor()
74+
if not selected_ris:
75+
cur.execute("select distinct risid from ris order by risid")
76+
else:
77+
cur.execute("select distinct risid from ris where risid=?", [selected_ris])
7378
ris_ids_res = cur.fetchall()
79+
if not ris_ids_res: # May be empty if selected_ris is incorrect or no references present
80+
return
7481
for ris_id in ris_ids_res:
7582
ref = {'risid': ris_id[0]}
7683
details = str(ris_id[0]) + " "
@@ -142,13 +149,13 @@ def format_vancouver_and_apa(self, ref):
142149
issn = None
143150
url = None
144151
doi = None
145-
vancouver = ""
146-
apa = "" # American Psychological Association refernce style
152+
vancouver = "" # Vancouver reference style, approximately
153+
apa = "" # American Psychological Association reference style
147154

148155
# Get the first title based on this order
149156
for tag in ("TI", "T1", "ST", "TT"):
150157
try:
151-
title = ref[tag] + "\n"
158+
title = f"{ref[tag]}.\n"
152159
break
153160
except KeyError:
154161
pass
@@ -162,7 +169,7 @@ def format_vancouver_and_apa(self, ref):
162169
authors = authors[1:] + "\n"
163170
# Editor
164171
if 'ED' in ref:
165-
editor = "Editor: " + ref['ED'] + "\n"
172+
editor = f"Editor: {ref['ED']} \n"
166173
# Publication year
167174
if 'PY' in ref:
168175
published_year = ref['PY']
@@ -172,15 +179,15 @@ def format_vancouver_and_apa(self, ref):
172179
if 'PB' in ref:
173180
publisher = ref['PB']
174181
if 'PP' in ref:
175-
publisher += " " + ref['PP']
182+
publisher += f" {ref['PP']}"
176183
# ISSN
177184
if 'SN' in ref:
178-
issn = "ISSN: " + ref['SN']
185+
issn = f"ISSN: {ref['SN']}"
179186
# Journal name, T2 tag is often used for this
180187
for tag in ("JO", "JF", "T2", "JA", "J1", "J2"):
181188
try:
182189
if periodical_name == "":
183-
periodical_name = ref[tag] + " "
190+
periodical_name = f"{ref[tag]} "
184191
continue
185192
except KeyError:
186193
pass
@@ -189,14 +196,14 @@ def format_vancouver_and_apa(self, ref):
189196
edition = ref['ET']
190197
# Volume and issue
191198
if 'VL' in ref:
192-
volume = " Vol." + ref['VL']
199+
volume = f" Vol.{ref['VL']}"
193200
if volume is None and 'VO' in ref:
194201
volume = " Vol." + ref['VO']
195202
if 'IS' in ref:
196203
issue = ref['IS']
197204
volume_and_or_issue = ""
198205
if volume and issue:
199-
volume_and_or_issue = volume + "(" + issue + ") "
206+
volume_and_or_issue = volume + f"({issue}) "
200207
if volume is None and issue:
201208
volume_and_or_issue += " " + issue + " "
202209
if volume_and_or_issue == "" and edition:
@@ -215,9 +222,9 @@ def format_vancouver_and_apa(self, ref):
215222
if 'UR' in ref:
216223
url = ref['UR']
217224
if 'Y2' in ref:
218-
url += " Accessed: " + ref['Y2']
225+
url += f" Accessed: {ref['Y2']}"
219226
if 'DO' in ref:
220-
doi = "doi: " + ref['DO']
227+
doi = f"doi: {ref['DO']}"
221228

222229
# Wrap up Vancouver style reference
223230
vancouver = title + authors
@@ -252,9 +259,11 @@ def format_vancouver_and_apa(self, ref):
252259
if published_year != "":
253260
apa += f"({published_year}). "
254261
if title != "":
255-
apa += f"{title}."
256-
apa += f"{periodical_name}, "
257-
apa += f"{volume_and_or_issue}. "
262+
apa += f"{title}"
263+
if periodical_name != "":
264+
apa += f"{periodical_name}, "
265+
if volume_and_or_issue != "":
266+
apa += f"{volume_and_or_issue}. "
258267
if pages:
259268
apa += f"({pages})"
260269
if url is not None:

0 commit comments

Comments
 (0)