- added to FunctionBase: bool register_default_models (default true)

if true then winix will add default models for ezc templates such as "request", "item", etc.
- some methods from templates/item.cpp moved to Item
This commit is contained in:
2021-06-20 18:04:50 +02:00
parent e7c7324058
commit 79eda7abb0
21 changed files with 271 additions and 83 deletions

View File

@@ -344,6 +344,7 @@ bool App::Init()
model_connector.set_winix_locale(&TemplatesFunctions::locale);
model_connector.set_winix_session_manager(&session_manager);
model_connector.set_winix_time_zones(&system.time_zones);
model_connector.set_winix_pattern_cacher(&TemplatesFunctions::pattern_cacher);
if( !TryToMakeDatabaseMigration() )
return false;
@@ -846,6 +847,24 @@ void App::CheckPostRedirect()
}
void App::AddDefaultModels()
{
if( !cur.request->send_bin_stream && !cur.request->return_json )
{
if( cur.request->function && cur.request->function->register_default_models )
{
cur.request->models.Add(L"request", cur.request);
if( cur.request->is_item )
{
cur.request->models.Add(L"item", cur.request->item);
}
}
}
}
// !! IMPROVE ME change to a better name
// may ProcessRequest()? but probably it is already defined...
// this method needs some refactoring
@@ -886,6 +905,8 @@ void App::Make()
if( !cur.request->redirect_to.empty() )
return;
AddDefaultModels();
if( cur.request->status == WINIX_ERR_OK )
functions.MakeFunction();

View File

@@ -194,6 +194,7 @@ private:
void SetLocale();
void CheckPostRedirect();
void MakePage();
void AddDefaultModels();
void Make();
void SaveSessionsIfNeeded(); // !! IMPROVE ME wywalic do menagera sesji??
void LogAccess();

View File

@@ -1389,7 +1389,7 @@ using namespace misc_private;
tmp_qencode.clear();
QEncode(in, tmp_qencode);
tmp_qencode.to_string(out, clear);
tmp_qencode.to_str(out, clear);
tmp_qencode.clear();
}

View File

@@ -771,7 +771,7 @@ void UrlEncode(char c, StringType & out, bool clear_out = true)
static pt::TextStream tmp;
UrlEncode(c, tmp);
tmp.to_string(out, clear_out);
tmp.to_str(out, clear_out);
}
@@ -882,6 +882,7 @@ void QEncode(const std::wstring & in, pt::TextStreamBase<char_type, stack_size,
}
// no thread safe
void QEncode(const std::wstring & in, std::string & out, bool clear = true);

View File

@@ -94,6 +94,11 @@ public:
void Str(const StringType & str);
void Str(const StringType && str);
void to_str(std::string & str, bool clear_string = true) const;
void to_str(std::wstring & str, bool clear_string = true) const;
void to_string(std::string & str, bool clear_string = true) const;
void to_string(std::wstring & str, bool clear_string = true) const;
CharType operator[](size_t index);
TextStream & operator<<(const char * str);
@@ -115,6 +120,8 @@ public:
TextStream & operator<<(const pt::Space & space);
TextStream & operator<<(const pt::Date & date);
TextStream & operator<<(const TextStream & stream);
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
TextStream & operator<<(const pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
@@ -233,10 +240,59 @@ void TextStream<StringType>::Str(const StringType & str)
template<class StringType>
void TextStream<StringType>::Str(const StringType && str)
{
buffer = str;
buffer = std::move(str);
}
template<class StringType>
void TextStream<StringType>::to_str(std::string & str, bool clear_string) const
{
return to_string(str, clear_string);
}
template<class StringType>
void TextStream<StringType>::to_str(std::wstring & str, bool clear_string) const
{
return to_string(str, clear_string);
}
template<class StringType>
void TextStream<StringType>::to_string(std::string & str, bool clear_string) const
{
if( clear_string )
str.clear();
if constexpr (sizeof(typename StringType::value_type) == sizeof(char))
{
str.append(buffer);
}
else
{
pt::wide_to_utf8(buffer, str, false);
}
}
template<class StringType>
void TextStream<StringType>::to_string(std::wstring & str, bool clear_string) const
{
if( clear_string )
str.clear();
if constexpr (sizeof(typename StringType::value_type) == sizeof(wchar_t))
{
str.append(buffer);
}
else
{
pt::utf8_to_wide(buffer, str, false);
}
}
template<class StringType>
typename TextStream<StringType>::CharType TextStream<StringType>::operator[](size_t index)
@@ -455,6 +511,19 @@ return *this;
}
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const TextStream<StringType> & stream)
{
buffer.append(stream.buffer);
return *this;
}
template<class StringType>
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
TextStream<StringType> & TextStream<StringType>::operator<<(

View File

@@ -107,7 +107,8 @@ void ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
data.model_connector.set_winix_session(nullptr);
data.model_connector.set_winix_locale(nullptr); // null for a moment, may will be changed
data.model_connector.set_winix_session_manager(nullptr);// null for a moment, may will be changed
data.model_connector.set_winix_time_zones(nullptr);// null for a moment, may will be changed
data.model_connector.set_winix_time_zones(nullptr); // null for a moment, may will be changed
data.model_connector.set_winix_pattern_cacher(nullptr); // null for a moment, may will be changed
item.object->set_model_connector(&data.model_connector);