コード例 #1
0
ファイル: views.py プロジェクト: Ishayahu/hasadim
def claim_edit(request,id):
    try:
        claim = Claim.objects.get(id=id)
    except Claim.DoesNotExist:
        add_error(u"Заявка с номером %s не найдена!" % id,request)
        # return (False,(HttpResponseRedirect("/assets_by_type/"+type_id+"/")))
        return (False,(HttpResponseRedirect("/")))
    if request.method == 'POST':
        open_date = datetime.datetime.now()
        form = get_localized_form('NewClaimForm',app,request)(request.POST)
        lang,user,fio,method = get_info(request)
        if form.is_valid():
            data = form.cleaned_data
            claim.name =data['name']
            claim.description = data['description']
            claim.save()
            a = request.FILES
            if request.FILES:
                for filed in ('file','file1','file2','file3'):
                    if filed in request.FILES:
                        print request.FILES[filed]
                        claim.file.add(save_file(request.FILES[filed],claim.id,request))
                        claim.save()
            return (False,HttpResponseRedirect('/claim/show/'+str(id)))
        return (False,HttpResponseRedirect('/claim/edit/'+str(id)))
    # тут надо блокировать возможность загрузить новые картинки, больше чем 4-уже_есть
    files = claim.file.all()
    count_of_files = len(files)
    return (True,('claim_add.html',{'NewClaimForm':{'name':claim.name, 'description':claim.description,
                                                    'count_of_files':count_of_files},
                                    },
                  {'title':'GMAH.RU - добавить заявку','files':files},request,app))
コード例 #2
0
ファイル: api.py プロジェクト: Ishayahu/MJCC-tasks
def save_new_model(request,asset_type_id):
    lang=select_language(request)
    user = request.user.username
    try:
        fio = Person.objects.get(login=user)
    except Person.DoesNotExist:
        fio = FioError()
    method = request.method
    asset_type = Asset_type.objects.get(id=asset_type_id)
    form_name = 'NewModel_'+asset_type.catalogue_name
##    print form_name
    aaa = request.method
    #raise NotImplementedError('ERROR')
    if request.method == 'POST':
        # f = ArticleForm(request.POST)
        f = get_localized_form(form_name,app,request)(request.POST)
        aaa = f.is_valid()
        if f.is_valid():
            # Save a new object from the form's data.
##            print form_name
##            print f
            new_model=f.save()
            return (True,('OK.html', {},{'html':u'Модель '+new_model.model_name+u' успешно добавлена в базу'},request,app))
        else:
            raise NotImplementedError(f.errors)
            pass
    return (True,('OK.html', {},{'html':u'Случилась неведомая фигня в функции api.save_new_model'},request,app))
コード例 #3
0
ファイル: views.py プロジェクト: Ishayahu/hasadim
def claim_add(request):
    if request.method == 'POST':
        open_date = datetime.datetime.now()
        form = get_localized_form('NewClaimForm',app,request)(request.POST)
        lang,user,fio,method = get_info(request)
        if form.is_valid():
            data = form.cleaned_data
            # a = datetime.datetime.now()
            open_date = make_aware(open_date,get_current_timezone())

            new_claim=Claim(name=data['name'],
                        description = data['description'],
                        open_date = open_date,
                        owner = fio)
            new_claim.save()
            a = request.FILES
            if request.FILES:
                for filed in ('file','file1','file2','file3'):
                    if filed in request.FILES:
                        print request.FILES[filed]
                        new_claim.file.add(save_file(request.FILES[filed],new_claim.id,request))
                        new_claim.save()
            return (False,HttpResponseRedirect('/'))
        return (False,HttpResponseRedirect('/'))
    return (True,('claim_add.html',{'NewClaimForm':{}},{'title':'GMAH.RU - добавить заявку',},request,app))
コード例 #4
0
ファイル: views.py プロジェクト: Ishayahu/hasadim
def profile_edit(request,id):
    lang=select_language(request)
    user = request.user.username
    try:
        profile_owner = Person.objects.get(id=id)
    except Person.DoesNotExist:
        add_error(u"Пользователь с логином %s не найден!" % user,request)
        return (False,(HttpResponseRedirect("/")))
    who_can_edit=[]
    who_can_edit.extend(admins)
    who_can_edit.append(profile_owner.login)
    if user not in who_can_edit:
        add_error(u"Вы не имеете права редактировать этот профиль!",request)
        return (False,(HttpResponseRedirect("/")))
    if request.method == 'POST':
        # form = UserCreationFormMY(request.POST)
        form = get_localized_form('UserEditForm',app,request)(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            # new_user = form.save()
            profile_owner.fio = data['fio']
            profile_owner.tel = data['tel']
            profile_owner.mail = data['mail']
            profile_owner.save()
            return (False,(HttpResponseRedirect("/accounts/profile/show/%s/" % profile_owner.id)))

    return (True,('register.html',{'UserEditForm':{'fio':profile_owner.fio,'mail':profile_owner.mail,'tel':profile_owner.tel}},{'title':'GMAH.RU','target':u'Редактируем профиль %s' % user},request,app))
コード例 #5
0
ファイル: views.py プロジェクト: Ishayahu/hasadim
def register(request):
    lang=select_language(request)
    if request.method == 'POST':
        # form = UserCreationFormMY(request.POST)
        form = get_localized_form('UserCreationFormMY',app,request)(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            new_user = form.save()
            new_person = Person(
                fio = data['fio'],
                tel = data['tel'],
                mail = data['mail'],
                login = data['username']
            )
            new_person.save()
            return (False,(HttpResponseRedirect("/")))
    # else:
        # form = l_forms[lang]['UserCreationFormMY']()
    # return render_to_response(languages[lang]+"registration/register.html",{'form':form},RequestContext(request))
    return (True,('register.html',{'UserCreationFormMY':{}},{'title':'GMAH.RU','target':'Создать новый профиль',},request,app))
コード例 #6
0
ファイル: api.py プロジェクト: Ishayahu/MJCC-tasks
def get_new_asset_type_save(request):
    lang=select_language(request)
    user = request.user.username
    try:
        fio = Person.objects.get(login=user)
    except Person.DoesNotExist:
        fio = FioError()
    method = request.method
    if request.method == 'POST':
        form = get_localized_form('NewAssetTypeForm',app,request)(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            at=Asset_type(asset_type = data['asset_type'],
                        catalogue_name = data['catalogue_name'],
                        )
            at.save()
            # html='<input type="hidden" id="c_id" value="%s" /><input type="hidden" id="c_name" value="%s" />' % (c.id, c.name)
            # return (True,('OK.html', {},{},request,app))
            # return render_to_response(languages[lang]+'OK.html', {'c':c,'html':html},RequestContext(request))
            return (False,(HttpResponseRedirect("/assets_by_type/"+str(at.id)+"/")))
    raise IOError("Произошла какая-то ошибка, но не могу представить какая. Надо выяснить и записать для диагностики")
コード例 #7
0
ファイル: api.py プロジェクト: Ishayahu/MJCC-tasks
def save_new_contractor(request):
    lang=select_language(request)
    user = request.user.username
    try:
        fio = Person.objects.get(login=user)
    except Person.DoesNotExist:
        fio = FioError()
    method = request.method
    if request.method == 'POST':
        form = get_localized_form('NewContractorForm',app,request)(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            c=Contractor(name = data['name'],
                        tel = data['tel'],
                        email = data['email'],
                        tel_of_support = data['tel_of_support'],
                        contact_name = data['contact_name'],)
            c.save()
            html=u'<input type="hidden" id="c_id" value="%s" /><input type="hidden" id="c_name" value="%s" />' % (c.id, c.name)
            return (True,('OK.html', {},{'html':html},request,app))
            # return render_to_response(languages[lang]+'OK.html', {'c':c,'html':html},RequestContext(request))
    raise IOError("Произошла какая-то ошибка, но не могу представить какая. Надо выяснить и записать для диагностики")