<commit_before>from django.db import models
from django.db.models import DateField, TimeField, CharField, PositiveSmallIntegerField
from django.db.models import ManyToManyField, ForeignKey

from agenda.models import Event

from band.models import Band
from venue.models import Venue
from bargain.models import Terms
from bargain.signals import contract_concluded

#from agenda.models import EventManager

class Gig(Event):
    """
    A gig related to a Venue and one or more Bands
    """
    # objects = EventManager()

    venue = ForeignKey(Venue, related_name='gigs')
    bands = ManyToManyField(Band, related_name='gigs')

    @models.permalink                                               
    def get_absolute_url(self):
        return ('event:gig-detail', 
                (),
                {'year'  : self.event_date.year, 
                 'month' : self.event_date.month, 
                 'day'   : self.event_date.day, 
                 'slug'  : self.slug }
                )
    
#-- Bargain

class GigBargain(Terms):
    """
    Terms of a bargain between one or more Bands and a Venue.
    """
    date = DateField()
    opens_at = TimeField()
    closes_at = TimeField()

    bands = ManyToManyField(Band, through='GigBargainBand')
    venue = ForeignKey(Venue)

    ACCESS_CHOICES = (
        ('FREE', 'Free Access'),
        ('FEES', 'Entrance Fee'),
        ('DRNK', 'Drink'),
        ('TICK', 'Ticket'),
        )
    access = CharField(max_length=4, choices=ACCESS_CHOICES)

    fee_amount = PositiveSmallIntegerField(null=True, blank=True)
    
    @staticmethod
    def getForm(extra_inline=0):
        from django.forms.models import formset_factory
        from .forms import GigBargainForm, GigBargainBandForm
        
        GigBargainBandFormSet = formset_factory(GigBargainBandForm, extra=extra_inline)

        return GigBargainForm, ['bargain', GigBargainBandFormSet]

    def getParticipants(self):
        parties = [b for b in self.bands.all()] + [self.venue]
        return parties

    def __unicode__(self):
        return u'Gig bargain at [%s] with [%s]' % (self.venue,
                                                   [b.name for b in self.bands.all()])

    @models.permalink
    def get_absolute_url(self):
        return ('event:bargain-detail', (self.id,))
    
class GigBargainBand(models.Model):
    """
    Data related to a gig bargain for a given band 
    """
    band = ForeignKey(Band)
    bargain = ForeignKey(GigBargain)

    starts_at = TimeField()
    ends_at = TimeField()

    eq_starts_at = TimeField()
    
    REMUNERATION_CHOICES = (
        ('NONE', 'No remuneration'),
        ('FIXE', 'Fixed Amount'),
        ('PERC', 'Percentage'),
        )

    remuneration = CharField(max_length=4, choices=REMUNERATION_CHOICES)

    percentage = PositiveSmallIntegerField(blank=True, null=True, default=None)
    amount = PositiveSmallIntegerField(blank=True, null=True, default=None)
    
    def __unicode__(self):
        return u'%s' % self.band
    

## Signals
from bargain.signals import contract_new, contract_approved, contract_disapproved, contract_amended

def gigbargain_concluded_callback(sender, aContract, aUser, **kwargs):
    """
    Callback when a gig bargain has been concluded
    """
    gigbargain = aContract.terms.gigbargain<commit_msg>equalizer time no more required<commit_after>from django.db import models
from django.db.models import DateField, TimeField, CharField, PositiveSmallIntegerField
from django.db.models import ManyToManyField, ForeignKey

from agenda.models import Event

from band.models import Band
from venue.models import Venue
from bargain.models import Terms
from bargain.signals import contract_concluded

#from agenda.models import EventManager

class Gig(Event):
    """
    A gig related to a Venue and one or more Bands
    """
    # objects = EventManager()

    venue = ForeignKey(Venue, related_name='gigs')
    bands = ManyToManyField(Band, related_name='gigs')

    @models.permalink                                               
    def get_absolute_url(self):
        return ('event:gig-detail', 
                (),
                {'year'  : self.event_date.year, 
                 'month' : self.event_date.month, 
                 'day'   : self.event_date.day, 
                 'slug'  : self.slug }
                )
    
#-- Bargain

class GigBargain(Terms):
    """
    Terms of a bargain between one or more Bands and a Venue.
    """
    date = DateField()
    opens_at = TimeField()
    closes_at = TimeField()

    bands = ManyToManyField(Band, through='GigBargainBand')
    venue = ForeignKey(Venue)

    ACCESS_CHOICES = (
        ('FREE', 'Free Access'),
        ('FEES', 'Entrance Fee'),
        ('DRNK', 'Drink'),
        ('TICK', 'Ticket'),
        )
    access = CharField(max_length=4, choices=ACCESS_CHOICES)

    fee_amount = PositiveSmallIntegerField(null=True, blank=True)
    
    @staticmethod
    def getForm(extra_inline=0):
        from django.forms.models import formset_factory
        from .forms import GigBargainForm, GigBargainBandForm
        
        GigBargainBandFormSet = formset_factory(GigBargainBandForm, extra=extra_inline)

        return GigBargainForm, ['bargain', GigBargainBandFormSet]

    def getParticipants(self):
        parties = [b for b in self.bands.all()] + [self.venue]
        return parties

    def __unicode__(self):
        return u'Gig bargain at [%s] with [%s]' % (self.venue,
                                                   [b.name for b in self.bands.all()])

    @models.permalink
    def get_absolute_url(self):
        return ('event:bargain-detail', (self.id,))
    
class GigBargainBand(models.Model):
    """
    Data related to a gig bargain for a given band 
    """
    band = ForeignKey(Band)
    bargain = ForeignKey(GigBargain)

    starts_at = TimeField()
    ends_at = TimeField()

    eq_starts_at = TimeField(blank=True, null=True)
    
    REMUNERATION_CHOICES = (
        ('NONE', 'No remuneration'),
        ('FIXE', 'Fixed Amount'),
        ('PERC', 'Percentage'),
        )

    remuneration = CharField(max_length=4, choices=REMUNERATION_CHOICES)

    percentage = PositiveSmallIntegerField(blank=True, null=True, default=None)
    amount = PositiveSmallIntegerField(blank=True, null=True, default=None)
    
    def __unicode__(self):
        return u'%s' % self.band
    

## Signals
from bargain.signals import contract_new, contract_approved, contract_disapproved, contract_amended

def gigbargain_concluded_callback(sender, aContract, aUser, **kwargs):
    """
    Callback when a gig bargain has been concluded
    """
    gigbargain = aContract.terms.gigbargain
{'fraction_non_alphanumeric': 0.10273665320771647, 'fraction_numerical': 0.0008972633467922835, 'mean_word_length': 2.658643326039387, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1161136', 'n_tokens_mistral': 2104, 'n_tokens_neox': 2003, 'n_words': 480}