<commit_before>from django.db import models
from django.contrib.sites.models import Site
from django.utils.safestring import mark_safe
 

# Create your models here.
class ComicSite(Site):
    """ A collection of HTML pages using a certain skin. Pages can be browsed and edited."""
    
    # TODO: Sjoerd - Is it correct to define the params below as class params, or should these be in an init method? 
    
    short_name = models.CharField(max_length = 50, default="", help_text = "short name used in url, specific css, files etc. No spaces allowed")
    skin = models.CharField(max_length = 225)    
        
    comment = models.CharField(max_length = 1024, default="", blank=True)
        

class Page(models.Model):
    """ A single editable page containing html and maybe special output plugins """
    
    order = models.IntegerField(editable=False, default=1) #for determining order in which pages appear on site    
    ComicSite = models.ForeignKey("ComicSite")
    
    title = models.CharField(max_length = 255)
    html = models.TextField()
    
    def rawHTML(self):
        """Display html of this page as html. This uses the mark_safe django method to allow direct html rendering"""
        #TODO : do checking for scripts and hacks here? 
        return mark_safe(self.html)
    
    def move(self, move):
        if move == 'UP':
            mm = Page.objects.get(ComicSite=self.ComicSite,order=self.order-1)
            mm.order += 1<commit_msg>Now sets order param correctly when creating new page. Order will be highest found for this site + 1. So new pages are put last in order<commit_after>from django.db import models
from django.contrib.sites.models import Site
from django.utils.safestring import mark_safe
from django.db.models import Max

# Create your models here.
class ComicSite(Site):
    """ A collection of HTML pages using a certain skin. Pages can be browsed and edited."""
    
    # TODO: Sjoerd - Is it correct to define the params below as class params, or should these be in an init method? 
    
    short_name = models.CharField(max_length = 50, default="", help_text = "short name used in url, specific css, files etc. No spaces allowed")
    skin = models.CharField(max_length = 225)    
        
    comment = models.CharField(max_length = 1024, default="", blank=True)
        

class Page(models.Model):
    """ A single editable page containing html and maybe special output plugins """
    
    order = models.IntegerField(editable=False, default=1, help_text = "Determines order in which pages appear on site")     
    ComicSite = models.ForeignKey("ComicSite")
    
    title = models.CharField(max_length = 255)
    html = models.TextField()
    
    def clean(self):
        """ clean method is called automatically for each save in admin"""
        
        #when saving for the first time only, put this page last in oder 
        if not self.id:
            # get max value of order for current pages.
            max_order = Page.objects.filter(ComicSite__pk=self.ComicSite.pk).aggregate(Max('order'))                
            self.order = max_order["order__max"] + 1
        
            
    
    def rawHTML(self):
        """Display html of this page as html. This uses the mark_safe django method to allow direct html rendering"""
        #TODO : do checking for scripts and hacks here? 
        return mark_safe(self.html)
    
    def move(self, move):
        if move == 'UP':
            mm = Page.objects.get(ComicSite=self.ComicSite,order=self.order-1)
            mm.order += 1
{'fraction_non_alphanumeric': 0.08633295838020247, 'fraction_numerical': 0.008998875140607425, 'mean_word_length': 2.800213675213675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5869594', 'n_tokens_mistral': 1008, 'n_tokens_neox': 964, 'n_words': 371}