Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
from app.api.admin_sales.fees import AdminSalesFeesList
from app.api.admin_sales.invoices import AdminSalesInvoicesList
from app.api.full_text_search.events import EventSearchResultList
from app.api.import_jobs import ImportJobList, ImportJobDetail

# users
api.route(UserList, 'user_list', '/users')
Expand Down Expand Up @@ -623,3 +624,7 @@

# Full text search w/ Elastic Search
api.route(EventSearchResultList, 'event_search_results', '/search/events')

# Import Jobs
api.route(ImportJobList, 'import_job_list', '/import-jobs')
api.route(ImportJobDetail, 'import_job_detail', '/import-jobs/<int:id>')
11 changes: 9 additions & 2 deletions app/api/helpers/import_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from app.models import db
from app.models.custom_form import CustomForms
from app.models.event import Event
from app.models.users_events_role import UsersEventsRoles
from app.models.role import Role
from app.models.import_job import ImportJob
from app.models.microlocation import Microlocation
from app.models.session import Session
Expand All @@ -27,6 +29,7 @@
from app.models.speaker import Speaker
from app.models.sponsor import Sponsor
from app.models.track import Track
from app.models.user import User, ORGANIZER

IMPORT_SERIES = [
('social_links', SocialLink),
Expand Down Expand Up @@ -328,7 +331,7 @@ def create_service_from_json(task_handle, data, srv, event_id, service_ids=None)
return ids


def import_event_json(task_handle, zip_path):
def import_event_json(task_handle, zip_path, creator_id):
"""
Imports and creates event from json zip
"""
Expand All @@ -353,9 +356,13 @@ def import_event_json(task_handle, zip_path):
data = _delete_fields(srv, data)
new_event = Event(**data)
save_to_db(new_event)
role = Role.query.filter_by(name=ORGANIZER).first()
user = User.query.filter_by(id=creator_id).first()
uer = UsersEventsRoles(user_id=user.id, event_id=new_event.id, role_id=role.id)
save_to_db(uer, 'Event Saved')
write_file(
path + '/social_links',
json.dumps(data.get('social_links', []))
json.dumps(data.get('social_links', [])).encode('utf-8')
) # save social_links
_upload_media_queue(srv, new_event)
except Exception as e:
Expand Down
35 changes: 35 additions & 0 deletions app/api/import_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from flask_rest_jsonapi import ResourceList, ResourceDetail

from app.api.schema.import_jobs import ImportJobSchema
from app.models import db
from app.models.import_job import ImportJob
from app.api.helpers.permissions import jwt_required
from flask_jwt import current_identity


class ImportJobList(ResourceList):
"""
List ImportJob
"""
def query(self, kwargs):
query_ = self.session.query(ImportJob)
query_ = query_.filter_by(user_id=current_identity.id)
return query_

decorators = (jwt_required,)
schema = ImportJobSchema
data_layer = {'session': db.session,
'model': ImportJob,
'methods': {
'query': query,
}}


class ImportJobDetail(ResourceDetail):
"""
ImportJob Detail by id
"""
decorators = (jwt_required, )
schema = ImportJobSchema
data_layer = {'session': db.session,
'model': ImportJob}
2 changes: 1 addition & 1 deletion app/api/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def import_event(source_type):
def import_event_task_base(task_handle, file_path, source_type='json', creator_id=None):
new_event = None
if source_type == 'json':
new_event = import_event_json(task_handle, file_path)
new_event = import_event_json(task_handle, file_path, creator_id)
if new_event:
url = make_frontend_url(path='/events/{identifier}'.format(identifier=new_event.identifier))
return {'url': url,
Expand Down
25 changes: 25 additions & 0 deletions app/api/schema/import_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from marshmallow_jsonapi import fields

from app.api.helpers.utilities import dasherize
from marshmallow_jsonapi.flask import Schema


class ImportJobSchema(Schema):
"""
Api schema for ImportJob Model
"""

class Meta:
"""
Meta class for ImportJob Api Schema
"""
type_ = 'import-job'
self_view = 'v1.import_job_detail'
self_view_kwargs = {'id': '<id>'}
inflect = dasherize

id = fields.Str(dump_only=True)
task = fields.Str(allow_none=False)
starts_at = fields.DateTime(required=True, timezone=True)
result = fields.Str(allow_none=True)
result_status = fields.Str(allow_none=True)
2 changes: 2 additions & 0 deletions app/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def __init__(self,
privacy=None,
event_topic_id=None,
event_sub_topic_id=None,
events_orga_id=None,
ticket_url=None,
copyright=None,
code_of_conduct=None,
Expand Down Expand Up @@ -250,6 +251,7 @@ def __init__(self,
self.event_topic_id = event_topic_id
self.copyright = copyright
self.event_sub_topic_id = event_sub_topic_id
self.events_orga_id = events_orga_id
self.ticket_url = ticket_url
self.code_of_conduct = code_of_conduct
self.schedule_published_on = schedule_published_on
Expand Down
61 changes: 61 additions & 0 deletions docs/api/api_blueprint.apib
Original file line number Diff line number Diff line change
Expand Up @@ -25336,6 +25336,7 @@ Get the details of the panel permission.
}
}


# Group Favourite Events

This Group's APIs can be used for adding a particular event to the favourite list of the user.
Expand Down Expand Up @@ -25515,3 +25516,63 @@ This Group's APIs can be used for adding a particular event to the favourite lis
"version": "1.0"
}
}


# Group Import Jobs

This Group's APIs are used for getting info of import jobs

## Import Jobs Collection [/v1/import-jobs{?page%5bsize%5d,page%5bnumber%5d,sort,filter}]

### List All Import Jobs [GET]
Get a list of all import jobs

+ Request

+ Headers

Accept: application/vnd.api+json

Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

{
"data": [
{
"type": "import-job",
"attributes": {
"starts-at": "2019-03-26T07:34:23.061153+00:00",
"result": "1",
"task": "a8e8b899-7537-4d09-bcd5-fd250a3efc06",
"result-status": "SUCCESS"
},
"id": "1",
"links": {
"self": "/v1/import-jobs/1"
}
},
{
"type": "import-job",
"attributes": {
"starts-at": "2019-03-26T07:47:31.285576+00:00",
"result": "2",
"task": "788ae813-1fcf-4c47-ab4a-80ff33abd097",
"result-status": "SUCCESS"
},
"id": "2",
"links": {
"self": "/v1/import-jobs/2"
}
}
],
"links": {
"self": "/v1/import-jobs"
},
"meta": {
"count": 2
},
"jsonapi": {
"version": "1.0"
}
}