Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Requirements #1905

Merged
merged 6 commits into from
Oct 16, 2020
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
12 changes: 6 additions & 6 deletions onadata/apps/api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys
from builtins import str

from celery import task
from celery.result import AsyncResult
from django.conf import settings
from django.core.files.uploadedfile import TemporaryUploadedFile
Expand All @@ -14,6 +13,7 @@

from onadata.apps.api import tools
from onadata.apps.logger.models.xform import XForm
from onadata.celery import app


def recreate_tmp_file(name, path, mime_type):
Expand All @@ -23,7 +23,7 @@ def recreate_tmp_file(name, path, mime_type):
return tmp_file


@task(bind=True)
@app.task(bind=True)
def publish_xlsform_async(self, user_id, post_data, owner_id, file_data):
try:
files = MultiValueDict()
Expand Down Expand Up @@ -56,15 +56,15 @@ def publish_xlsform_async(self, user_id, post_data, owner_id, file_data):
return {u'error': error_message}


@task()
@app.task()
def delete_xform_async(xform_id, user_id):
"""Soft delete an XForm asynchrounous task"""
xform = XForm.objects.get(pk=xform_id)
user = User.objects.get(pk=user_id)
xform.soft_delete(user)


@task()
@app.task()
def delete_user_async():
"""Delete inactive user accounts"""
users = User.objects.filter(active=False,
Expand Down Expand Up @@ -105,14 +105,14 @@ def send_generic_email(email, message_txt, subject):
email_message.send()


@task()
@app.task()
def send_verification_email(email, message_txt, subject):
"""
Sends a verification email
"""
send_generic_email(email, message_txt, subject)


@task()
@app.task()
def send_account_lockout_email(email, message_txt, subject):
send_generic_email(email, message_txt, subject)
4 changes: 2 additions & 2 deletions onadata/apps/logger/import_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import zipfile
from builtins import open

from celery import task
from django.core.files.uploadedfile import InMemoryUploadedFile

from onadata.apps.logger.xform_fs import XFormInstanceFS
from onadata.celery import app
from onadata.libs.utils.logger_tools import create_instance

# odk
Expand Down Expand Up @@ -74,7 +74,7 @@ def import_instance(username, xform_path, photos, osm_files, status,
return 0


@task(ignore_result=True)
@app.task(ignore_result=True)
def import_instance_async(username, xform_path, photos, osm_files, status):
import_instance(username, xform_path, photos, osm_files, status, False)

Expand Down
8 changes: 4 additions & 4 deletions onadata/apps/logger/models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import math
from datetime import datetime

from celery import task
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.gis.db import models
Expand All @@ -27,6 +26,7 @@
from onadata.apps.logger.xform_instance_parser import (XFormInstanceParser,
clean_and_parse_xml,
get_uuid_from_xml)
from onadata.celery import app
from onadata.libs.data.query import get_numeric_fields
from onadata.libs.utils.cache_tools import (DATAVIEW_COUNT, IS_ORG,
PROJ_NUM_DATASET_CACHE,
Expand Down Expand Up @@ -143,7 +143,7 @@ def submission_time():
return timezone.now()


@task
@app.task
@transaction.atomic()
def update_xform_submission_count(instance_id, created):
if created:
Expand Down Expand Up @@ -215,7 +215,7 @@ def update_xform_submission_count_delete(sender, instance, **kwargs):
xform.save()


@task
@app.task
def save_full_json(instance_id, created):
"""set json data, ensure the primary key is part of the json data"""
if created:
Expand All @@ -228,7 +228,7 @@ def save_full_json(instance_id, created):
instance.save(update_fields=['json'])


@task
@app.task
def update_project_date_modified(instance_id, created):
# update the date modified field of the project which will change
# the etag value of the projects endpoint
Expand Down
8 changes: 5 additions & 3 deletions onadata/apps/main/models/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ def query_data(cls, username, query=None, fields=None, sort=None, start=0,
or_params = []
if '$or' in list(query):
or_dict = query.pop('$or')
for l in or_dict:
or_where.extend([u"json->>%s = %s" for i in l.items()])
[or_params.extend(i) for i in l.items()]
for or_query in or_dict:
or_where.extend(
[u"json->>%s = %s" for i in or_query.items()])
[ # pylint: disable=expression-not-assigned
or_params.extend(i) for i in or_query.items()]

or_where = [u"".join([u"(", u" OR ".join(or_where), u")"])]

Expand Down
Loading