1+ import urllib .parse
12from collections .abc import Callable
2- from typing import cast
3+ from typing import Literal , cast
34
45from pydantic import BaseModel , Field
56
89from app .gen .client import adminapi
910from app .sources .vizier import VizierSource
1011from app .upload import upload_for_web
11- from server .forms .upload_base import UploadBaseForm
1212
1313
14- class UploadVizierForm (UploadBaseForm ):
14+ class UploadVizierForm (BaseModel ):
1515 catalog_name : str = Field (..., title = "VizieR catalog name" )
1616 source_table_name : str = Field (..., title = "VizieR table name" )
1717 cache_path : str = Field (default = ".vizier_cache/" , title = "Cache path" )
1818 batch_size : int = Field (default = 100 , title = "Batch size" , ge = 1 )
19+ table_name : str = Field (
20+ default = "" ,
21+ title = "Table name" ,
22+ description = "Machine-readable HyperLEDA table id; leave empty to derive from VizieR." ,
23+ )
24+ table_description : str = Field (
25+ default = "" ,
26+ title = "Table description" ,
27+ description = "Human-readable description; leave empty to take from VizieR metadata." ,
28+ )
29+ bibcode : str = Field (
30+ default = "" ,
31+ title = "Bibcode" ,
32+ description = "NASA ADS bibcode; leave empty to read from VizieR." ,
33+ )
34+ table_type : Literal ["regular" , "compilation" ] = Field (
35+ default = "regular" ,
36+ title = "Table type" ,
37+ description = "Type of data that table represents." ,
38+ )
39+ dry_run : bool = Field (
40+ default = False ,
41+ title = "Dry run" ,
42+ description = "Show schema and process rows without actually uploading any data. Useful for validation." ,
43+ )
44+ endpoint : Literal ["dev" , "test" , "prod" ] = Field (
45+ default = "prod" ,
46+ title = "API endpoint" ,
47+ description = "Where to upload. Leave unchanged if https://leda.sao.ru is needed." ,
48+ )
1949
2050
2151def handle_upload_vizier (form : BaseModel , report_func : Callable [[report .Event ], None ]) -> None :
@@ -24,22 +54,55 @@ def handle_upload_vizier(form: BaseModel, report_func: Callable[[report.Event],
2454 base_url = env_map [f .endpoint ],
2555 token = "fake" ,
2656 )
27- source = VizierSource (f .catalog_name , f .source_table_name , cache_path = f .cache_path , batch_size = f .batch_size )
28- bibcode = f .bibcode .strip () if f .has_bibcode else ""
29- pub_name = f .pub_name .strip ()
30- pub_authors = list (f .pub_authors )
31- pub_year = f .pub_year
57+ source = VizierSource (
58+ f .catalog_name ,
59+ f .source_table_name ,
60+ cache_path = f .cache_path ,
61+ batch_size = f .batch_size ,
62+ )
63+
64+ table_name_in = f .table_name .strip ()
65+ if table_name_in :
66+ resolved_table_name = table_name_in
67+ else :
68+ resolved_table_name = source .get_table_name ()
69+
70+ table_description_in = f .table_description .strip ()
71+ if table_description_in :
72+ resolved_description = table_description_in
73+ else :
74+ resolved_description = source .get_description ()
75+
76+ bibcode_in = f .bibcode .strip ()
77+ if bibcode_in :
78+ resolved_bibcode = bibcode_in
79+ else :
80+ resolved_bibcode = source .get_bibcode ()
81+
82+ if not resolved_bibcode :
83+ msg = "bibcode is empty: provide one or ensure VizieR metadata includes it"
84+ raise ValueError (msg )
85+
86+ report_func (report .LogEvent (message = f"Table name: { resolved_table_name } " ))
87+ report_func (report .LogEvent (message = f"Description: { resolved_description } " ))
88+ ads_url = "https://ui.adsabs.harvard.edu/abs/" + urllib .parse .quote (resolved_bibcode , safe = "" )
89+ report_func (
90+ report .LogEvent (
91+ message = f"Paper: { ads_url } " ,
92+ ),
93+ )
94+
3295 table_type = (f .table_type or "regular" ).upper ()
3396
3497 upload_for_web (
3598 source ,
3699 client ,
37- f . table_name . strip () ,
38- f . table_description . strip () ,
39- bibcode ,
40- pub_name ,
41- pub_authors ,
42- pub_year ,
100+ resolved_table_name ,
101+ resolved_description ,
102+ resolved_bibcode ,
103+ "" ,
104+ [] ,
105+ 0 ,
43106 table_type ,
44107 dry_run = f .dry_run ,
45108 report_func = report_func ,
0 commit comments