class Show(models.Model): info = models.ForeignKey('schedule.Info', verbose_name=_("Info"), related_name='show') date = models.ForeignKey(DateRange, verbose_name=_("date"), related_name='show') thread = models.OneToOneField(Thread, verbose_name=_("messages"), related_name='show', null=True, blank=True) approved = models.NullBooleanField(_('approved'), default=None) visible = models.BooleanField(_('visible'), default=False) turnout = models.IntegerField(blank=True, null=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) objects = models.GeoManager() class Meta: verbose_name = _('show') verbose_name_plural = _('shows') app_label = 'schedule' def get_absolute_url(self): return ('show', [self.id]) get_absolute_url = models.permalink(get_absolute_url)
class Profile(UserenaBaseProfile): user = models.OneToOneField(User, unique=True, primary_key=True, verbose_name=_('user'), related_name='profile') genre = models.ManyToManyField(Genre, verbose_name=_("genre"), related_name='genre_artist', blank=True) contact_info = models.OneToOneField(ContactInfo, unique=True, blank=True, null=True, verbose_name=_('contactInfo'), related_name='contactInfo') has_owner = models.BooleanField(default=True) profile_type = models.CharField(_('profile type'), max_length=1, choices=PROFILE_TYPE_CHOICES, default=PROFILE_TYPE_CHOICES[1][0]) weight = models.IntegerField(default=0) objects = models.GeoManager() def __unicode__(self): profileType = self.profile_type if profileType == 'f': return u'%s %s' % (self.user.first_name, self.user.last_name) elif profileType == 'm': return '%s' % self.artist_profile.name elif profileType == 'v': return '%s' % self.venueProfile.name return '%s' % self.user.username def get_absolute_url(self): profileType = self.profile_type if profileType == 'f': return ('fan:home', [self.user.username]) elif profileType == 'm': return ('artist:home', [self.user.username]) elif profileType == 'v': return ('venue:home', [self.user.username]) return ('home') get_absolute_url = models.permalink(get_absolute_url)
class UserProfile(models.Model): user = models.ForeignKey(User, unique=True, verbose_name=_('Username')) # not going to use volunteer, comment at a good moment... volunteer = models.BooleanField("Volunteer Opportunities", choices=BOOLEAN_CHOICES, default=False) updates = models.BooleanField( 'I would like to receive occasional email updates and newsletters', choices=BOOLEAN_CHOICES, default=False) zip_code = models.CharField(max_length=6, null=True, blank=True) photo = models.ImageField(upload_to='photos', height_field=None, width_field=None, max_length=200, null=True, blank=True) site_edits = models.IntegerField(_('Site Edits (to track activity)'), default=0, editable=False) uid = models.IntegerField(_('Random User ID'), null=True, blank=True, editable=False) active = models.BooleanField(choices=BOOLEAN_CHOICES, default=True) def __unicode__(self): name = self.user.get_full_name() if name: return unicode("%s" % self.user.get_full_name()) else: return unicode("%s" % self.user.username) class Meta: verbose_name = _('Profile') verbose_name_plural = _('Profiles') def recently_edited_trees(self): trees = Tree.history.filter( last_updated_by=self.user, present=True).exclude(_audit_change_type="U", _audit_diff="").order_by('-last_updated')[:7] print trees recent_edits = [] for t in trees: recent_edits.append( (t.species, t.date_planted, t.last_updated, t.id)) return sorted(recent_edits, key=itemgetter(2), reverse=True)[:7] def recently_added_photos(self): return TreePhoto.objects.filter( reported_by=self.user, tree__present=True).order_by('-reported_by')[:7] def recently_changed_reputation(self): return UserReputationAction.objects.filter( user=self.user).order_by('-date_created')[:7] def recently_added_pends(self): return TreePending.objects.filter( submitted_by=self.user).order_by('-submitted')[:7] def badges(self): return BadgeToUser.objects.filter(user=self) def badges_in_progress(self): return_badges = [] for b in Badge.objects.all(): if b.meta_badge.get_progress( self.user) > b.meta_badge.progress_start: if b.meta_badge.get_progress( self.user) < b.meta_badge.progress_finish: return_badges.append( (b, b.meta_badge.get_progress(self.user))) return return_badges def made_edit(self): self.site_edits += 1 self.save() def username(self): return u"%s" % self.user.username def first_name(self): return u"%s" % self.user.first_name def last_name(self): return u"%s" % self.user.last_name def full_name(self): return u"%s %s" % (self.user.first_name, self.user.last_name) def email(self): return u"%s" % self.user.email def remove(self): return '<input type="button" value="Remove" onclick="location.href=\'%s/delete/\'" />' % ( self.pk) remove.short_description = '' remove.allow_tags = True def get_absolute_url(self): return ('profiles_profile_detail', (), { 'username': self.user.username }) get_absolute_url = models.permalink(get_absolute_url) def get_random_id(self): return random.randint(100000, 999999) def account_activated(self): return self.user.is_active account_activated.boolean = True def account_diff(self): if self.user.is_active: return (self.user.date_joined - datetime.datetime.now()) def save(self, force_insert=False, force_update=False, using='default'): if not self.id: self.uid = self.get_random_id() super(UserProfile, self).save()