main/views.py
def clone_xlsform(request, username):
    """
    Copy a public/Shared form to a users list of forms.
    Eliminates the need to download Excel File and upload again.
    """
    to_username = request.user.username
    context = RequestContext(request)
    context.message = {'type': None, 'text': '....'}

    def set_form():
        form_owner = request.POST.get('username')
        id_string = request.POST.get('id_string')
        xform = XForm.objects.get(user__username=form_owner,
                                  id_string=id_string)
        if len(id_string) > 0 and id_string[0].isdigit():
            id_string = '_' + id_string
        path = xform.xls.name
        if default_storage.exists(path):
            xls_file = upload_to(None, '%s%s.xls' % (
                                 id_string, XForm.CLONED_SUFFIX), to_username)
            xls_data = default_storage.open(path)
            xls_file = default_storage.save(xls_file, xls_data)
            context.message = u'%s-%s' % (form_owner, xls_file)
            survey = DataDictionary.objects.create(
                user=request.user,
                xls=xls_file
            ).survey
            # log to cloner's account
            audit = {}
            audit_log(
                Actions.FORM_CLONED, request.user, request.user,
                _("Cloned form '%(id_string)s'.") %
                {
                    'id_string': survey.id_string,
                }, audit, request)
            clone_form_url = reverse(
                show, kwargs={
                    'username': to_username,
                    'id_string': xform.id_string + XForm.CLONED_SUFFIX})
            return {
                'type': 'alert-success',
                'text': _(u'Successfully cloned to %(form_url)s into your '
                          u'%(profile_url)s') %
                {'form_url': u'<a href="%(url)s">%(id_string)s</a> ' % {
                 'id_string': survey.id_string,
                 'url': clone_form_url
                 },
                    'profile_url': u'<a href="%s">profile</a>.' %
                    reverse(profile, kwargs={'username': to_username})}
            }
    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
    if request.is_ajax():
        res = loader.render_to_string(
            'message.html',
            context_instance=context).replace("'", r"\'").replace('\n', '')
        return HttpResponse(
            "$('#mfeedback').html('%s').show();" % res)
    else:
        return HttpResponse(context.message['text'])

    Copy a public/Shared form to a users list of forms.
    Eliminates the need to download Excel File and upload again.
    
Copy a public/Shared form to a users list of forms.
Eliminates the need to download Excel File and upload again.
Copy a public / Shared form to a users list of forms . Eliminates the need to download Excel File and upload again .
def clone_xlsform(request, username):
    to_username = request.user.username
    context = RequestContext(request)
    context.message = {'type': None, 'text': '....'}
    def set_form():
        form_owner = request.POST.get('username')
        id_string = request.POST.get('id_string')
        xform = XForm.objects.get(user__username=form_owner,
                                  id_string=id_string)
        if len(id_string) > 0 and id_string[0].isdigit():
            id_string = '_' + id_string
        path = xform.xls.name
        if default_storage.exists(path):
            xls_file = upload_to(None, '%s%s.xls' % (
                                 id_string, XForm.CLONED_SUFFIX), to_username)
            xls_data = default_storage.open(path)
            xls_file = default_storage.save(xls_file, xls_data)
            context.message = u'%s-%s' % (form_owner, xls_file)
            survey = DataDictionary.objects.create(
                user=request.user,
                xls=xls_file
            ).survey
            audit = {}
            audit_log(
                Actions.FORM_CLONED, request.user, request.user,
                _("Cloned form '%(id_string)s'.") %
                {
                    'id_string': survey.id_string,
                }, audit, request)
            clone_form_url = reverse(
                show, kwargs={
                    'username': to_username,
                    'id_string': xform.id_string + XForm.CLONED_SUFFIX})
            return {
                'type': 'alert-success',
                'text': _(u'Successfully cloned to %(form_url)s into your '
                          u'%(profile_url)s') %
                {'form_url': u'<a href="%(url)s">%(id_string)s</a> ' % {
                 'id_string': survey.id_string,
                 'url': clone_form_url
                 },
                    'profile_url': u'<a href="%s">profile</a>.' %
                    reverse(profile, kwargs={'username': to_username})}
            }
    form_result = publish_form(set_form)
    if form_result['type'] == 'alert-success':
        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
    if request.is_ajax():
        res = loader.render_to_string(
            'message.html',
            context_instance=context).replace("'", r"\'").replace('\n', '')
        return HttpResponse(
            "$('#mfeedback').html('%s').show();" % res)
    else:
        return HttpResponse(context.message['text'])
def clone_xlsform ( request , username ) : to_username = request . user . username context = RequestContext ( request ) context . message = { 'type' : None , 'text' : '....' } def set_form ( ) : form_owner = request . POST . get ( 'username' ) id_string = request . POST . get ( 'id_string' ) xform = XForm . objects . get ( user__username = form_owner , id_string = id_string ) if len ( id_string ) > 0 and id_string [ 0 ] . isdigit ( ) : id_string = '_' + id_string path = xform . xls . name if default_storage . exists ( path ) : xls_file = upload_to ( None , '%s%s.xls' % ( id_string , XForm . CLONED_SUFFIX ) , to_username ) xls_data = default_storage . open ( path ) xls_file = default_storage . save ( xls_file , xls_data ) context . message = u'%s-%s' % ( form_owner , xls_file ) survey = DataDictionary . objects . create ( user = request . user , xls = xls_file ) . survey audit = { } audit_log ( Actions . FORM_CLONED , request . user , request . user , _ ( "Cloned form '%(id_string)s'." ) % { 'id_string' : survey . id_string , } , audit , request ) clone_form_url = reverse ( show , kwargs = { 'username' : to_username , 'id_string' : xform . id_string + XForm . CLONED_SUFFIX } ) return { 'type' : 'alert-success' , 'text' : _ ( u'Successfully cloned to %(form_url)s into your ' u'%(profile_url)s' ) % { 'form_url' : u'<a href="%(url)s">%(id_string)s</a> ' % { 'id_string' : survey . id_string , 'url' : clone_form_url } , 'profile_url' : u'<a href="%s">profile</a>.' % reverse ( profile , kwargs = { 'username' : to_username } ) } } form_result = publish_form ( set_form ) if form_result [ 'type' ] == 'alert-success' : 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 if request . is_ajax ( ) : res = loader . render_to_string ( 'message.html' , context_instance = context ) . replace ( "'" , r"\'" ) . replace ( '\n' , '' ) return HttpResponse ( "$('#mfeedback').html('%s').show();" % res ) else : return HttpResponse ( context . message [ 'text' ] )
Copy a public/Shared form to a users list of forms.
Copy a public / Shared form to a users list of forms .
"""
    Copy a public/Shared form to a users list of forms.
    Eliminates the need to download Excel File and upload again.
    """ # log to cloner's account # 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
request
username