Beispiel #1
0
def settings_email(request):
    """
    """
    resp_dict     = dict()
    form = SMTPsettings(request.POST)
    if form.is_valid():
        data_in_post = form.cleaned_data
        mconf = SevercartConfigs()
        mconf.smtp_server   = data_in_post['smtp_server']
        mconf.smtp_port     = data_in_post['smtp_port']
        mconf.email_sender  = data_in_post['email_sender']
        mconf.smtp_login    = data_in_post['smtp_login']
        mconf.smtp_password = data_in_post['smtp_password']
        mconf.use_ssl       = data_in_post['use_ssl']
        mconf.use_tls       = data_in_post['use_tls']
        mconf.commit()
        resp_dict['errors'] = ''
        resp_dict['text']   = _('Settings successfully saved.')
    else:
        error_message = dict([(key, [error for error in value]) for key, value in form.errors.items()])
        resp_dict['errors'] = error_message
    
    return JsonResponse(resp_dict)
Beispiel #2
0
def general_settings(request):
    """Вывод формы настройки отрисовки наклеек.
    """
    context = {}
    conf = SevercartConfigs()

    if request.method == 'POST':
        form = StickFormat(request.POST)
        if form.is_valid():
            data_in_post = form.cleaned_data
            choice = data_in_post.get('choice', 'A4')
            print_qr_code = data_in_post.get('print_qr_code')
            time_zone = data_in_post.get('time_zone')
            show_time = data_in_post.get('show_time')
            conf.page_format = choice
            conf.print_bar_code = print_qr_code
            conf.time_zone = time_zone
            conf.show_time = show_time
            conf.commit()
            context['form'] = form
            messages.success(request, _('Settings success saved.'))
        else:
            context['form'] = form
    else:
        print_qr_code = 1 if conf.print_bar_code else 2
        show_time = 1 if conf.show_time else 2
        form = StickFormat(
            initial={
                'choice': conf.page_format,
                'print_qr_code':
                print_qr_code,  # Внимание! Есть соблазнзаменить на self.print_qr_code
                'time_zone': conf.time_zone,
                'show_time': show_time,
            })
        context['form'] = form
    return render(request, 'service/general_settings.html', context)