Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dj-ref Attributes are not converted #5

Open
NiclasWil opened this issue Apr 30, 2024 · 5 comments
Open

dj-ref Attributes are not converted #5

NiclasWil opened this issue Apr 30, 2024 · 5 comments

Comments

@NiclasWil
Copy link

NiclasWil commented Apr 30, 2024

When I'm adding dj-ref Attributes to my HTML in Bootstrap Studio then theses references are never processed.
They remain in HTML Tag as attributes
Input File

<div class="ms-3">
    <h4 class="w-auto" dj-ref="conversationname">$$Conversation Name$$</h4>
    <p dj-ref="conversation.last_message">$$Nullam id dolor id nibh ultricies vehicula ut id elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus.$$</p>
</div>

Output File

<div class="ms-3">
      <h4 class="w-auto" dj-ref="conversationname">
              $$Conversation Name$$
       </h4>
       <p dj-ref="conversation.last_message">
              $$Nullam id dolor id nibh ultricies vehicula ut id elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus.$$
       </p>
</div>

All other tags i used so far instead of dj-ref are working fine. The problem seems to be TagConverter.convert() since replace_ref is never called

def convert(self):
      with open(self._filename, encoding='utf8') as htmlstream:
         self._bs = BeautifulSoup(htmlstream.read(), 'html.parser')
         
      self.remove_for_data()
      self.replace_include_tag()
      
      for tag in self.ENCLOSED_TAG:
         self.extend_tag(tag, before=True, after=True)
   
      for tag in self.REPLACE_TAG:
         self.extend_tag(tag)
   
      for tag in self.TAG_LINK:
         self.replace_links(tag)      

      content = self.replace_background_img(self.beautiful_soup.prettify())
      content = html.unescape(content)
      
      if self._loadStatic:
         content = f"{{% load static %}}\n\n{content}"
         
      self._bs = None
            
      return content

I could check the issue and create a PR for this. But not sure if this is the main issue (not tested yet)

@NiclasWil
Copy link
Author

When I'm adding dj-ref Attributes to my HTML in Bootstrap Studio then theses references are never processed. They remain in HTML Tag as attributes Input File

<div class="ms-3">
    <h4 class="w-auto" dj-ref="conversationname">$$Conversation Name$$</h4>
    <p dj-ref="conversation.last_message">$$Nullam id dolor id nibh ultricies vehicula ut id elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus.$$</p>
</div>

Output File

<div class="ms-3">
      <h4 class="w-auto" dj-ref="conversationname">
              $$Conversation Name$$
       </h4>
       <p dj-ref="conversation.last_message">
              $$Nullam id dolor id nibh ultricies vehicula ut id elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus.$$
       </p>
</div>

All other tags i used so far instead of dj-ref are working fine. The problem seems to be TagConverter.convert() since replace_ref is never called

def convert(self):
      with open(self._filename, encoding='utf8') as htmlstream:
         self._bs = BeautifulSoup(htmlstream.read(), 'html.parser')
         
      self.remove_for_data()
      self.replace_include_tag()
      
      for tag in self.ENCLOSED_TAG:
         self.extend_tag(tag, before=True, after=True)
   
      for tag in self.REPLACE_TAG:
         self.extend_tag(tag)
   
      for tag in self.TAG_LINK:
         self.replace_links(tag)      

      content = self.replace_background_img(self.beautiful_soup.prettify())
      content = html.unescape(content)
      
      if self._loadStatic:
         content = f"{{% load static %}}\n\n{content}"
         
      self._bs = None
            
      return content

I could check the issue and create a PR for this. But not sure if this is the main issue (not tested yet)

def convert(self):
      with open(self._filename, encoding='utf8') as htmlstream:
         self._bs = BeautifulSoup(htmlstream.read(), 'html.parser')
         
      self.remove_for_data()
      self.replace_include_tag()
      ###I expect this line to be the solution
      self.replace_ref()
      
      for tag in self.ENCLOSED_TAG:
         self.extend_tag(tag, before=True, after=True)
   
      for tag in self.REPLACE_TAG:
         self.extend_tag(tag)
   
      for tag in self.TAG_LINK:
         self.replace_links(tag)      

      content = self.replace_background_img(self.beautiful_soup.prettify())
      content = html.unescape(content)
      
      if self._loadStatic:
         content = f"{{% load static %}}\n\n{content}"
         
      self._bs = None
            
      return content

But I'm not used to qork with QT and able to test

@enjoysmath
Copy link
Owner

I see your bug post, I will fix it maybe in a few days. Will post back here. Unless you want to fix it ? It's simple Python / Pyqt5 code.

@NiclasWil
Copy link
Author

I added the line of Code i think would fix this bug. But I'm not able to test it properly. When i use pyinstaller to create a exe File the Path from BSS is not taken as Parameter. Seems to be an issue how i used pyinstaller because the python console is launching in background.

If i want to test manually I'm not able to instantiate the classes correctly since there are QT ExportMapper Objects needed for Fileconverter ect.

So i think I'm not used to QT enough yet to Test. Even if i create a batch that is calling bss_to_django.py from Bootstrap Studio something goes wrong that i can't figure out. So maybe you could provider me some Details how to test or you fix it, whenever there is time.

But great Tool so far helps a lot to migrate to django 😀

@FruitfulApproach
Copy link

@NiclasWil Yes, you are right. It's such a rough tool that you must dev on it to fix things. I just wrote these instructions for stoic here:

#6 (comment)

That will get you up and running as a developer. But let me run some ideas by you:

  • Codegen support:
    1. Automatically creating a URL entry for each page and a basic render view for that template.
    2. If there is a form, automatically generating a basic form in Django. If dj-crispy=1 then use Crispy forms.
    3. It could also even generate the basic error-handling structure of a view that handles the POST request of a form.
    4. AJAX + BSS + Django. Codegen on both JS and Python side for handling modern web design (AJAX methods).
    5. Automatic creation of the default Django login system given that you put in an accounts-related widget in BSS.

BTW, to debug on this, there should be a requirements.txt as part of the project. Then you'd do:

pip install -r requirements.txt from within BootstrapStudioToDjango folder.

If not, then you'll at least need to do pip install pyqt5 and see that it goes through successfully.

@FruitfulApproach
Copy link

@NiclasWil Do you need any more guidance on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants