o
    g+                     @   s:  d dl Z d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlZd dlmZ d	ed
fdedfgZd	edfdedfgZd	edfdedfgZG dd dejZG dd dejZG dd dejZdd ZG dd dejZG dd dejZG dd dejZdZG d d! d!ejZdS )"    N)models)gettext_lazy)Development)slugify)	WEBPField)BeautifulSoup)MasterT	submittedFignoredactivedeactiveyesnoc                       s   e Zd ZejdeddejdZejeddddZ	ej
ed	dddddd
ZejdedddZejedddZejedddZ fddZdd ZG dd dZ  ZS )Keywordmain.LanguageLanguagekeywordsverbose_namerelated_name	on_deleteTitle  T
max_lengthdb_indexslugr   r   allow_unicodenullblankselfrelatedr   r    
created atauto_now_add
updated atauto_nowc                    ,   | j rt| j dd| _t j|i | d S NTr   titler   r   supersaver!   argskwargs	__class__ ,/var/www/Entralon-Web-Backend/blog/models.pyr0   %      zKeyword.savec                 C      | j  S Nr.   r!   r6   r6   r7   __str__)      zKeyword.__str__c                   @   "   e Zd ZedZedZdgZdS )zKeyword.Metar   Keywords-idN__name__
__module____qualname___r   verbose_name_pluralorderingr6   r6   r6   r7   Meta,       
rI   )rC   rD   rE   r   
ForeignKeyrF   CASCADElanguage	CharFieldr.   	SlugFieldr   ManyToManyFieldr"   DateTimeField
created_at
updated_atr0   r=   rI   __classcell__r6   r6   r4   r7   r      s    r   c                	       s   e Zd ZejeddddZejeddddddddZej	deddd	Z
ejed
ddZejedddZejedddZ fddZdd ZG dd dZ  ZS )Categoryr   r   Tr   r   r   r   uniquer   r   r    r!   r"   r#   r   defaultr$   r%   r'   r(   c                    r*   r+   r-   r1   r4   r6   r7   r0   ;   r8   zCategory.savec                 C   r9   r:   r;   r<   r6   r6   r7   r=   ?   r>   zCategory.__str__c                   @   r?   )zCategory.MetarU   
CategoriesrA   NrB   r6   r6   r6   r7   rI   B   rJ   rI   )rC   rD   rE   r   rN   rF   r.   rO   r   rP   r"   BooleanFieldis_activaterQ   rR   rS   r0   r=   rI   rT   r6   r6   r4   r7   rU   3   s    rU   c                       s   e Zd ZejdeddejdZejeeddejdZ	ej
eddd	d
Zejeddd	d	d	d	dZejedd	dZejedd	dZ fddZdd ZG dd dZ  ZS )CategoryTranslater   r   category_translater   rU   
translatesr   r   Tr   r   r   r$   r%   r'   r(   c                    s(   t | jjdd| _t j|i | d S r+   )r   categoryr.   r   r/   r0   r1   r4   r6   r7   r0   O   s   zCategoryTranslate.savec                 C   r9   r:   r;   r<   r6   r6   r7   r=   S   r>   zCategoryTranslate.__str__c                   @   s"   e Zd ZedZedZdgZdS )zCategoryTranslate.MetazCategory TranslaterA   NrB   r6   r6   r6   r7   rI   V   rJ   rI   )rC   rD   rE   r   rK   rF   rL   rM   rU   r`   rN   r.   rO   r   rQ   rR   rS   r0   r=   rI   rT   r6   r6   r4   r7   r]   G   s    r]   c                 C   s   d| j  dS )Nznews/z.webp)r   )instancefilenamer6   r6   r7   image_news_folder\   s   rc   c                	       sP  e Zd ZejeeddejdddZej	eddddZ
ejedddddddd	Zeed
eddddZejeeddddZejeeddejdddZejeddedZejedddZejedddZejedddZejeeddejdddZejedddZejedddZ dd Z! fd d!Z"G d"d# d#Z#  Z$S )$Newsr   newsTr   r   r   r   r    r   r   r   r   rV   Image)	upload_tor   r    r   r@   keyword_newsr   r   r    rU   category_newsFeaturedFrY   choicesPublishrX   Deleted
TranslatedWriternews_writersr$   r%   r'   r(   c                 C   r9   r:   r;   r<   r6   r6   r7   r=   p   r>   zNews.__str__c                    r*   r+   r-   r1   r4   r6   r7   r0   s   r8   z	News.savec                   @   s4   e Zd ZedZedZdgZejg ddgZ	dS )z	News.Metard   rA   )r   r.   is_featured)fieldsN)
rC   rD   rE   rF   r   rG   rH   r   Indexindexesr6   r6   r6   r7   rI   w   s    rI   )%rC   rD   rE   r   rK   r   rF   rL   developmentrN   r.   rO   r   r   rc   imagerP   r   r   rU   r`   r[   QUESTION_BOOLEANrt   
is_publish
is_deletedis_translatedr   SET_NULLwriterrQ   rR   rS   r=   r0   rI   rT   r6   r6   r4   r7   rd   _   s"    rd   c                       s$  e Zd ZejdeddejdZejeeddejdZ	ej
eddd	d
Zejeddd	d	d	d	dZejeeddd	dZejeeddejd	d	dZejedd	d	d	dZejedd	d	dZejedddZejedd	d	dZejedd	dZdd Z fd d!ZG d"d# d#Z  ZS )$NewsTranslater   r   news_languager   rd   r_   r   r   Tr   r   r   r@   news_translate_keywordsrj   rU   category_news_translaterf   Summary)r   r   r    Descriptionr   r    z	Read Timer   rX   r$   )r   r&   r'   r(   c                 C   r9   r:   r;   r<   r6   r6   r7   r=      r>   zNewsTranslate.__str__c                    s   t | jjdd| _| jd u s| jdkr'zt| jddd j| _W n   Y | j	d u r@z| jj	j
j| jd | _	W n   Y | jd urOt| j}|j| _t j|i | d S )NTr,    zhtml.parserpr   )rM   )r   re   r.   r   summaryr   descriptionfind_alltextr`   r_   filterrM   firstreadtimeof_htmlminutes	read_timer/   r0   )r!   r2   r3   r   r4   r6   r7   r0      s    
 
zNewsTranslate.savec                   @   s6   e Zd ZedZedZdgZejddgddgZ	dS )zNewsTranslate.MetazNews TranslaterA   rM   re    repeated_language_news_translateru   nameN
rC   rD   rE   rF   r   rG   rH   r   UniqueConstraintconstraintsr6   r6   r6   r7   rI          rI   )rC   rD   rE   r   rK   rF   rL   rM   rd   re   rN   r.   rO   r   rP   r   r   r]   r`   	TextFieldr   r   PositiveIntegerFieldr   rQ   rR   rS   r=   r0   rI   rT   r6   r6   r4   r7   r      s    r   c                       s   e Zd ZdZejeejedddZ	e
edZejeddddZejed	dddZejed
dddZejedddZejedddZ fddZG dd dZ  ZS )Visitora  
    Represents a visitor to a news article.
    
    The Visitor model represents a visitor to a news article in the system. It has the following fields:
    
    - `news`: A foreign key to the `News` model, representing the news article the visitor is associated with.
    - `ip`: The IP address of the visitor.
    - `user_agent`: The user agent information of the visitor (nullable).
    - `visit_time`: The time the visitor spent on the news article (nullable).
    - `unique_time`: A unique identifier for the visitor's visit (nullable).
    - `created_at`: The datetime when the visitor record was created.
    - `updated_at`: The datetime when the visitor record was last updated.
    
    The `save` method automatically sets the `visit_time` and `unique_time` fields if they are not provided.
    
    The model has a unique constraint on the `news`, `unique_time`, and `user_agent` fields to prevent repeated visits by the same user to the same news article.
    rd   visitors)r   r   r   IPz
User AgentTr   z
visit timezunique timer$   r%   r'   r(   c                    s8   | j d u rt | _ tt d | _t j|i |S )Ni  )
visit_timetimeintunique_timer/   r0   r1   r4   r6   r7   r0      s   

zVisitor.savec                   @   s6   e Zd ZedZedZdgZejg dddgZ	dS )zVisitor.Metar   VisitorsrA   )re   r   
user_agentrepeated_user_news_visitr   Nr   r6   r6   r6   r7   rI      r   rI   )rC   rD   rE   __doc__r   rK   rd   rL   rF   re   GenericIPAddressFieldipr   r   
FloatFieldr   IntegerFieldr   rQ   rR   rS   r0   rI   rT   r6   r6   r4   r7   r      s    r   a  Give me an concise and clear article about the following subject with html tags in {language} language, only the relevant part and without html, head, body and heading tags between h2-h6 and not contain title, which is related to real estate consulting, and if possible, the name Entralon (by https://entralon.com link) will be mentioned as a real estate consultant website.
    {text}
    c                   @   s   e Zd ZdZejedddZejede	dZ
ejeeddejd	d	d
ZejeddedZejedd	dZejedd	dZdd ZG dd dZdS )TitleOfBloga  
    Represents the title of a blog post.

    The TitleOfBlog model represents the title of a blog post in the system. It has the following fields:

    - `title`: The title of the blog post.
    - `description`: The description or content of the blog post.
    - `created_at`: The datetime when the blog post title was created.
    - `updated_at`: The datetime when the blog post title was last updated.

    The `__str__` method returns the title of the blog post.
    r      )r   PromptrX   rU   titlesTrf   CreatedFrm   r$   r%   r'   r(   c                 C   r9   r:   r;   r<   r6   r6   r7   r=      r>   zTitleOfBlog.__str__c                   @   r?   )zTitleOfBlog.MetazTitle of BlogzTitles of BlogrA   NrB   r6   r6   r6   r7   rI      rJ   rI   N)rC   rD   rE   r   r   rN   rF   r.   r   BLOG_PROMPTpromptrK   rU   rL   r`   r[   rz   
is_createdrQ   rR   rS   r=   rI   r6   r6   r6   r7   r      s    r   )r   	django.dbr   django.utils.translationr   rF   development.modelsr   django.utils.textr   main.fieldsr   bs4r   r   user.modelsr   CHECK_BOOLEANACTIVE_BOOLEANrz   Modelr   rU   r]   rc   rd   r   r   r   r   r6   r6   r6   r7   <module>   s6    





 '-