Example #1
0
 def set_form():
     form = QuickConverter(request.POST, request.FILES)
     survey = form.publish(request.user, id_string).survey
     enketo_webform_url = reverse(
         enter_data,
         kwargs={'username': username, 'id_string': survey.id_string}
     )
     audit = {
         'xform': xform.id_string
     }
     audit_log(
         Actions.FORM_XLS_UPDATED, request.user, owner,
         _("XLS for '%(id_string)s' updated.") %
         {
             'id_string': xform.id_string,
         }, audit, request)
     return {
         'type': 'alert-success',
         'text': _(u'Successfully published %(form_id)s.'
                   u' <a href="%(form_url)s">Enter Web Form</a>'
                   u' or <a href="#preview-modal" data-toggle="modal">'
                   u'Preview Web Form</a>')
                 % {'form_id': survey.id_string,
                    'form_url': enketo_webform_url}
     }
Example #2
0
 def set_form():
     form = QuickConverter(request.POST, request.FILES)
     survey = form.publish(request.user).survey
     audit = {}
     audit_log(
         Actions.FORM_PUBLISHED,
         request.user,
         content_user,
         _("Published form '%(id_string)s'.") % {"id_string": survey.id_string},
         audit,
         request,
     )
     enketo_webform_url = reverse(enter_data, kwargs={"username": username, "id_string": survey.id_string})
     return {
         "type": "alert-success",
         "preview_url": reverse(enketo_preview, kwargs={"username": username, "id_string": survey.id_string}),
         "text": _(
             u"Successfully published %(form_id)s."
             u' <a href="%(form_url)s">Enter Web Form</a>'
             u' or <a href="#preview-modal" data-toggle="modal">'
             u"Preview Web Form</a>"
         )
         % {"form_id": survey.id_string, "form_url": enketo_webform_url},
         "form_o": survey,
     }
Example #3
0
 def set_form():
     form = QuickConverter(request.POST, request.FILES)
     survey = form.publish(request.user).survey
     audit = {}
     audit_log(
         Actions.FORM_PUBLISHED, request.user, content_user,
         _("Published form '%(id_string)s'.") %
         {
             'id_string': survey.id_string,
         }, audit, request)
     enketo_webform_url = reverse(
         enter_data,
         kwargs={'username': username, 'id_string': survey.id_string}
     )
     return {
         'type': 'alert-success',
         'preview_url': reverse(enketo_preview, kwargs={
             'username': username,
             'id_string': survey.id_string
         }),
         'text': _(u'Successfully published %(form_id)s.'
                   u' <a href="%(form_url)s">Enter Web Form</a>'
                   u' or <a href="#preview-modal" data-toggle="modal">'
                   u'Preview Web Form</a>')
         % {'form_id': survey.id_string,
             'form_url': enketo_webform_url},
         'form_o': survey
     }
Example #4
0
    def set_form():

        if project:
            args = dict({'project': project.pk}.items() + post.items())
        else:
            args = post
        form = QuickConverter(args,  files)

        return form.publish(owner, id_string=id_string, created_by=user)
Example #5
0
    def set_form():

        if project:
            args = dict({'project': project.pk}.items() + post.items())
        else:
            args = post
        form = QuickConverter(args, files)

        return form.publish(owner, id_string=id_string, created_by=user)
Example #6
0
    def set_form():
        props = {
            'project': project.pk,
            'dropbox_xls_url': request.DATA.get('dropbox_xls_url'),
            'xls_url': request.DATA.get('xls_url'),
            'csv_url': request.DATA.get('csv_url')
        }

        form = QuickConverter(props, request.FILES)

        return form.publish(project.organization, created_by=request.user)
Example #7
0
    def set_form():
        props = {
            'project': project.pk,
            'dropbox_xls_url': request.DATA.get('dropbox_xls_url'),
            'xls_url': request.DATA.get('xls_url'),
            'csv_url': request.DATA.get('csv_url')
        }

        form = QuickConverter(props, request.FILES)

        return form.publish(project.organization, created_by=request.user)
Example #8
0
    def set_form():
        """
        Instantiates QuickConverter form to publish a form.
        """

        if project:
            args = (post and dict(listitems(post))) or {}
            args['project'] = project.pk
        else:
            args = post

        form = QuickConverter(args, files)

        return form.publish(owner, id_string=id_string, created_by=user)
Example #9
0
    def set_form():
        """
        Instantiates QuickConverter form to publish a form.
        """

        if project:
            args = (post and dict(listitems(post))) or {}
            args['project'] = project.pk
        else:
            args = post

        form = QuickConverter(args, files)

        return form.publish(owner, id_string=id_string, created_by=user)
Example #10
0
    def set_form():
        """
        Instantiates QuickConverter form to publish a form.
        """
        props = {
            'project': project.pk,
            'dropbox_xls_url': request.data.get('dropbox_xls_url'),
            'xls_url': request.data.get('xls_url'),
            'csv_url': request.data.get('csv_url'),
            'text_xls_form': request.data.get('text_xls_form')
        }

        form = QuickConverter(props, request.FILES)

        return form.publish(project.organization, created_by=request.user)
Example #11
0
    def set_form():
        """
        Instantiates QuickConverter form to publish a form.
        """
        props = {
            'project': project.pk,
            'dropbox_xls_url': request.data.get('dropbox_xls_url'),
            'xls_url': request.data.get('xls_url'),
            'csv_url': request.data.get('csv_url'),
            'text_xls_form': request.data.get('text_xls_form')
        }

        form = QuickConverter(props, request.FILES)

        return form.publish(project.organization, created_by=request.user)
Example #12
0
def dashboard(request):
    context = RequestContext(request)
    context.form = QuickConverter()
    content_user = request.user
    set_profile_data(context, content_user)
    context.url = request.build_absolute_uri("/%s" % request.user.username)
    return render_to_response("dashboard.html", context_instance=context)
Example #13
0
 def set_form():
     form = QuickConverter(request.POST, request.FILES)
     survey = form.publish(request.user, id_string).survey
     enketo_webform_url = reverse(enter_data, kwargs={"username": username, "id_string": survey.id_string})
     audit = {"xform": xform.id_string}
     audit_log(
         Actions.FORM_XLS_UPDATED,
         request.user,
         owner,
         _("XLS for '%(id_string)s' updated.") % {"id_string": xform.id_string},
         audit,
         request,
     )
     return {
         "type": "alert-success",
         "text": _(
             u"Successfully published %(form_id)s."
             u' <a href="%(form_url)s">Enter Web Form</a>'
             u' or <a href="#preview-modal" data-toggle="modal">'
             u"Preview Web Form</a>"
         )
         % {"form_id": survey.id_string, "form_url": enketo_webform_url},
     }
Example #14
0
def get_viewable_projects(request):
    """
    Returns the list of projects/forms 
    which are created or shared to the currently
    logged in user.
    """
    content_user = get_object_or_404(User,
                                     username__iexact=request.user.username)
    form = QuickConverter()
    data = {'form': form}
    content_user = request.user
    all_forms = content_user.xforms.count()
    xforms = XForm.objects.filter(user=content_user)\
        .select_related('user', 'instances')
    user_xforms = xforms
    xfct = ContentType.objects.get(app_label='logger', model='xform')
    xfs = content_user.userobjectpermission_set.filter(content_type=xfct)
    shared_forms_pks = list(set([xf.object_pk for xf in xfs]))
    forms_shared_with = XForm.objects.filter(
        pk__in=shared_forms_pks).exclude(user=content_user)\
        .select_related('user')
    published_or_shared = XForm.objects.filter(
        pk__in=shared_forms_pks).select_related('user')
    xforms_list = [{
        'id': 'published',
        'xforms': user_xforms,
        'title': _(u"Published Forms"),
        'small': _("Export, map, and view submissions.")
    }, {
        'id': 'shared',
        'xforms': forms_shared_with,
        'title': _(u"Shared Forms"),
        'small': _("List of forms shared with you.")
    }, {
        'id': 'published_or_shared',
        'xforms': published_or_shared,
        'title': _(u"Published Forms"),
        'small': _("Export, map, and view submissions.")
    }]

    new_list = []
    for xform_list in xforms_list:
        if xform_list['xforms'] not in new_list:
            new_list.extend(xform_list['xforms'])
    xforms_list = list(set(new_list))

    return xforms_list
Example #15
0
 def set_form():
     form = QuickConverter(request.POST, request.FILES)
     return form.publish(user)
Example #16
0
 def set_form():
     form = QuickConverter(request.POST, request.FILES)
     if existing_xform:
         return form.publish(user, existing_xform.id_string)
     else:
         return form.publish(user)
Example #17
0
def profile(request, username):
    context = RequestContext(request)
    content_user = get_object_or_404(User, username=username)
    context.form = QuickConverter()

    # xlsform submission...
    if request.method == 'POST' and request.user.is_authenticated():
        def set_form():
            form = QuickConverter(request.POST, request.FILES)
            survey = form.publish(request.user).survey
            audit = {}
            audit_log(
                Actions.FORM_PUBLISHED, request.user, content_user,
                _("Published form '%(id_string)s'.") %
                {
                    'id_string': survey.id_string,
                }, audit, request)
            enketo_webform_url = reverse(
                enter_data,
                kwargs={'username': username, 'id_string': survey.id_string}
            )
            return {
                'type': 'alert-success',
                'preview_url': reverse(enketo_preview, kwargs={
                    'username': username,
                    'id_string': survey.id_string
                }),
                'text': _(u'Successfully published %(form_id)s.'
                          u' <a href="%(form_url)s">Enter Web Form</a>'
                          u' or <a href="#preview-modal" data-toggle="modal">'
                          u'Preview Web Form</a>')
                % {'form_id': survey.id_string,
                    'form_url': enketo_webform_url},
                'form_o': survey
            }
        form_result = publish_form(set_form)
        if form_result['type'] == 'alert-success':
            # comment the following condition (and else)
            # when we want to enable sms check for all.
            # until then, it checks if form barely related to sms
            if is_sms_related(form_result.get('form_o')):
                form_result_sms = check_form_sms_compatibility(form_result)
                context.message_list = [form_result, form_result_sms]
            else:
                context.message = form_result
        else:
            context.message = form_result

    # profile view...
    # for the same user -> dashboard
    if content_user == request.user:
        context.show_dashboard = True
        context.all_forms = content_user.xforms.count()
        context.form = QuickConverterFile()
        context.form_url = QuickConverterURL()

        request_url = request.build_absolute_uri(
            "/%s" % request.user.username)
        context.url = request_url.replace('http://', 'https://')
        xforms = XForm.objects.filter(user=content_user)\
            .select_related('user', 'instances')
        context.user_xforms = xforms
        # forms shared with user
        xfct = ContentType.objects.get(app_label='logger', model='xform')
        xfs = content_user.userobjectpermission_set.filter(content_type=xfct)
        shared_forms_pks = list(set([xf.object_pk for xf in xfs]))
        context.forms_shared_with = XForm.objects.filter(
            pk__in=shared_forms_pks).exclude(user=content_user)\
            .select_related('user')
        context.xforms_list = [
            {
                'id': 'published',
                'xforms': context.user_xforms,
                'title': _(u"Published Forms"),
                'small': _("Export, map, and view submissions.")
            },
            {
                'id': 'shared',
                'xforms': context.forms_shared_with,
                'title': _(u"Shared Forms"),
                'small': _("List of forms shared with you.")
            }
        ]
    # for any other user -> profile
    set_profile_data(context, content_user)
    return render_to_response("profile.html", context_instance=context)
Example #18
0
    def set_form():
        form = QuickConverter(request.POST, request.FILES)

        return form.publish(project.organization)
Example #19
0
 def set_form():
     form = QuickConverter(request.POST, request.FILES)
     return form.publish(user)
Example #20
0
    def set_form():
        form = QuickConverter({'project': project.pk}, request.FILES)

        return form.publish(project.organization, created_by=request.user)
Example #21
0
    def set_form():
        form = QuickConverter(request.POST, request.FILES)

        return form.publish(user, id_string=id_string, created_by=request.user)
Example #22
0
    def set_form():
        form = QuickConverter(request.POST, request.FILES)

        return form.publish(project.organization)
Example #23
0
 def set_form():
     form = QuickConverter(request.POST, request.FILES)
     if existing_xform:
         return form.publish(user, existing_xform.id_string)
     else:
         return form.publish(user)