Skip to content

Commit e942a88

Browse files
YogeshSharma0201iamareebjamal
authored andcommitted
fix: event import (#5514)
1 parent e005530 commit e942a88

File tree

7 files changed

+138
-3
lines changed

7 files changed

+138
-3
lines changed

app/api/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
from app.api.admin_sales.fees import AdminSalesFeesList
8585
from app.api.admin_sales.invoices import AdminSalesInvoicesList
8686
from app.api.full_text_search.events import EventSearchResultList
87+
from app.api.import_jobs import ImportJobList, ImportJobDetail
8788

8889
# users
8990
api.route(UserList, 'user_list', '/users')
@@ -623,3 +624,7 @@
623624

624625
# Full text search w/ Elastic Search
625626
api.route(EventSearchResultList, 'event_search_results', '/search/events')
627+
628+
# Import Jobs
629+
api.route(ImportJobList, 'import_job_list', '/import-jobs')
630+
api.route(ImportJobDetail, 'import_job_detail', '/import-jobs/<int:id>')

app/api/helpers/import_helpers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from app.models import db
2020
from app.models.custom_form import CustomForms
2121
from app.models.event import Event
22+
from app.models.users_events_role import UsersEventsRoles
23+
from app.models.role import Role
2224
from app.models.import_job import ImportJob
2325
from app.models.microlocation import Microlocation
2426
from app.models.session import Session
@@ -27,6 +29,7 @@
2729
from app.models.speaker import Speaker
2830
from app.models.sponsor import Sponsor
2931
from app.models.track import Track
32+
from app.models.user import User, ORGANIZER
3033

3134
IMPORT_SERIES = [
3235
('social_links', SocialLink),
@@ -328,7 +331,7 @@ def create_service_from_json(task_handle, data, srv, event_id, service_ids=None)
328331
return ids
329332

330333

331-
def import_event_json(task_handle, zip_path):
334+
def import_event_json(task_handle, zip_path, creator_id):
332335
"""
333336
Imports and creates event from json zip
334337
"""
@@ -353,9 +356,13 @@ def import_event_json(task_handle, zip_path):
353356
data = _delete_fields(srv, data)
354357
new_event = Event(**data)
355358
save_to_db(new_event)
359+
role = Role.query.filter_by(name=ORGANIZER).first()
360+
user = User.query.filter_by(id=creator_id).first()
361+
uer = UsersEventsRoles(user_id=user.id, event_id=new_event.id, role_id=role.id)
362+
save_to_db(uer, 'Event Saved')
356363
write_file(
357364
path + '/social_links',
358-
json.dumps(data.get('social_links', []))
365+
json.dumps(data.get('social_links', [])).encode('utf-8')
359366
) # save social_links
360367
_upload_media_queue(srv, new_event)
361368
except Exception as e:

app/api/import_jobs.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from flask_rest_jsonapi import ResourceList, ResourceDetail
2+
3+
from app.api.schema.import_jobs import ImportJobSchema
4+
from app.models import db
5+
from app.models.import_job import ImportJob
6+
from app.api.helpers.permissions import jwt_required
7+
from flask_jwt import current_identity
8+
9+
10+
class ImportJobList(ResourceList):
11+
"""
12+
List ImportJob
13+
"""
14+
def query(self, kwargs):
15+
query_ = self.session.query(ImportJob)
16+
query_ = query_.filter_by(user_id=current_identity.id)
17+
return query_
18+
19+
decorators = (jwt_required,)
20+
schema = ImportJobSchema
21+
data_layer = {'session': db.session,
22+
'model': ImportJob,
23+
'methods': {
24+
'query': query,
25+
}}
26+
27+
28+
class ImportJobDetail(ResourceDetail):
29+
"""
30+
ImportJob Detail by id
31+
"""
32+
decorators = (jwt_required, )
33+
schema = ImportJobSchema
34+
data_layer = {'session': db.session,
35+
'model': ImportJob}

app/api/imports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def import_event(source_type):
3636
def import_event_task_base(task_handle, file_path, source_type='json', creator_id=None):
3737
new_event = None
3838
if source_type == 'json':
39-
new_event = import_event_json(task_handle, file_path)
39+
new_event = import_event_json(task_handle, file_path, creator_id)
4040
if new_event:
4141
url = make_frontend_url(path='/events/{identifier}'.format(identifier=new_event.identifier))
4242
return {'url': url,

app/api/schema/import_jobs.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from marshmallow_jsonapi import fields
2+
3+
from app.api.helpers.utilities import dasherize
4+
from marshmallow_jsonapi.flask import Schema
5+
6+
7+
class ImportJobSchema(Schema):
8+
"""
9+
Api schema for ImportJob Model
10+
"""
11+
12+
class Meta:
13+
"""
14+
Meta class for ImportJob Api Schema
15+
"""
16+
type_ = 'import-job'
17+
self_view = 'v1.import_job_detail'
18+
self_view_kwargs = {'id': '<id>'}
19+
inflect = dasherize
20+
21+
id = fields.Str(dump_only=True)
22+
task = fields.Str(allow_none=False)
23+
starts_at = fields.DateTime(required=True, timezone=True)
24+
result = fields.Str(allow_none=True)
25+
result_status = fields.Str(allow_none=True)

app/models/event.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def __init__(self,
189189
privacy=None,
190190
event_topic_id=None,
191191
event_sub_topic_id=None,
192+
events_orga_id=None,
192193
ticket_url=None,
193194
copyright=None,
194195
code_of_conduct=None,
@@ -254,6 +255,7 @@ def __init__(self,
254255
self.event_topic_id = event_topic_id
255256
self.copyright = copyright
256257
self.event_sub_topic_id = event_sub_topic_id
258+
self.events_orga_id = events_orga_id
257259
self.ticket_url = ticket_url
258260
self.code_of_conduct = code_of_conduct
259261
self.schedule_published_on = schedule_published_on

docs/api/api_blueprint.apib

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25420,6 +25420,7 @@ Get the details of the panel permission.
2542025420
}
2542125421
}
2542225422

25423+
2542325424
# Group Favourite Events
2542425425

2542525426
This Group's APIs can be used for adding a particular event to the favourite list of the user.
@@ -25599,3 +25600,63 @@ This Group's APIs can be used for adding a particular event to the favourite lis
2559925600
"version": "1.0"
2560025601
}
2560125602
}
25603+
25604+
25605+
# Group Import Jobs
25606+
25607+
This Group's APIs are used for getting info of import jobs
25608+
25609+
## Import Jobs Collection [/v1/import-jobs{?page%5bsize%5d,page%5bnumber%5d,sort,filter}]
25610+
25611+
### List All Import Jobs [GET]
25612+
Get a list of all import jobs
25613+
25614+
+ Request
25615+
25616+
+ Headers
25617+
25618+
Accept: application/vnd.api+json
25619+
25620+
Authorization: JWT <Auth Key>
25621+
25622+
+ Response 200 (application/vnd.api+json)
25623+
25624+
{
25625+
"data": [
25626+
{
25627+
"type": "import-job",
25628+
"attributes": {
25629+
"starts-at": "2019-03-26T07:34:23.061153+00:00",
25630+
"result": "1",
25631+
"task": "a8e8b899-7537-4d09-bcd5-fd250a3efc06",
25632+
"result-status": "SUCCESS"
25633+
},
25634+
"id": "1",
25635+
"links": {
25636+
"self": "/v1/import-jobs/1"
25637+
}
25638+
},
25639+
{
25640+
"type": "import-job",
25641+
"attributes": {
25642+
"starts-at": "2019-03-26T07:47:31.285576+00:00",
25643+
"result": "2",
25644+
"task": "788ae813-1fcf-4c47-ab4a-80ff33abd097",
25645+
"result-status": "SUCCESS"
25646+
},
25647+
"id": "2",
25648+
"links": {
25649+
"self": "/v1/import-jobs/2"
25650+
}
25651+
}
25652+
],
25653+
"links": {
25654+
"self": "/v1/import-jobs"
25655+
},
25656+
"meta": {
25657+
"count": 2
25658+
},
25659+
"jsonapi": {
25660+
"version": "1.0"
25661+
}
25662+
}

0 commit comments

Comments
 (0)