def add_spud_from_fan(self, spud): spud_text = ' '.join([s.encode('ascii', 'ignore') for s in spud.expanded_data['text']]) tagged_entities = [] tags = FanFollowingEntityTag.objects.filter(fan=self.role.entity) logging.debug("SpudsController add_spud_from_fan: Found %s tags for fan: %s" % ( len(tags or []), self.role.entity.id)) for tag in tags: if tag.tag and tag.tag in spud_text: mention = "@%s%s" % (tag.entity_type, tag.entity_id) logging.debug("SpudsController add_spud_from_fan: Adding mention: %s" % mention) tagged_entities.append(mention) if tag.entity_type == 'Team': try: team = TeamPage.objects.get(id=tag.entity_id) except TeamPage.DoesNotExist: logging.error("SpudsController add_spud_from_fan: No Team with id: %s" % tag.entity_id) continue # Check if there are Student points that need awarding try: admin = TeamAdministrator.objects.get(team_page=team) if admin.entity_type == 'student': stu = Student.objects.get(id=admin.entity_id) team_tagged_in_spud(stu) except Exception as e: logging.error("%s" % e) # Also mention any associated venues for association in TeamVenueAssociation.objects.filter(team_page=team): mention = "@%s%s" % (EntityController.ENTITY_VENUE, association.venue.id) logging.debug( "SpudsController add_spud_from_fan: Adding associated venue mention: %s" % mention) tagged_entities.append(mention) user_text = '@%s%s %s' % (RoleController.ENTITY_FAN, self.role.entity.id, ' '.join(tagged_entities)) logging.debug("SpudsController add_spud_from_fan: Adding spud with user_text: %s" % user_text) data = { 'type': 'image', 'url': spud.expanded_data['image']['standard_resolution']['url'], 'title': spud_text, 'usertext': user_text, 'extra': spud.data} krowd_io_storage = KrowdIOStorage.GetOrCreateForCurrentUserRole(self.role) post_spud(krowd_io_storage, data) spud.state = SpudFromSocialMedia.STATE_ACCEPTED spud.save()
def approve_spuds(self, spud_ids, venue_id): """ Sends SPUD off to Krowd.io tagged with the venue in this case :param spud_ids: The ids of the spuds to accept :param venue_id: The id of the venue the spuds are tied to :return: None """ for spud_id in spud_ids: spud = SpudFromSocialMedia.objects.get(id=spud_id) spud.state = SpudFromSocialMedia.STATE_ACCEPTED spud.save() post_spud( KrowdIOStorage.GetOrCreateForVenue(venue_id), { 'type': 'image', 'url': spud.expanded_data['image']['standard_resolution']['url'], 'title': ' '.join([s.encode('ascii', 'ignore') for s in spud.expanded_data['text']]), 'usertext': '@Venue%s' % venue_id, 'extra': spud.data })