Ejemplo n.º 1
0
    def get_or_create_from_user(cls, user, notify=True):
        if isinstance(user, UserAuth):
            user = user.get_user()
        profile = ProfileByEmailView(user.email()).get()
        created = False
        if not profile:
            source = getattr(user, 'source', 'local')
            nickname = user.nickname()
            at_index = nickname.find('@')
            if at_index >= 0:
                nickname = nickname[:at_index]

            adder = 1
            orig_nick = nickname
            
            for p in Profile.all():
                logging.info(p.nickname)
            logging.info("profiles above")
            
            for i in xrange(1000):
                logging.info('finding nickname %s' % nickname)
                #if not Profile.gql('WHERE nickname=:1', nickname).get():
                if not ProfileByNickView(nickname).get():
                    logging.info('not found break')
                    break
                nickname = '%s_%s' % (orig_nick, adder)
                adder += 1

            profile = Profile(user_email=user.email(), nickname=nickname,
                              source=getattr(user, 'source', None),
                              fullname=nickname)
            created = True
            profile.put()

        if created and notify:
            p = ProfileByEmailView(settings.NEWS_USER).get()
            if p:
                Blip.new(p.get_user(), '@%s joined.' % profile.nickname)
        return created, profile
Ejemplo n.º 2
0
    def post(self, meeting_key=None):
        from models.blip import Blip
        login_user = self.get_current_user()
        m = Meeting.get(meeting_key)
        if m is None:
            return self.error(404)
        if not m.has_member(login_user):
            return self.error(401)

        content = self.request.get('text', '').strip()
        attachment = self.request.get('attachment', '').strip()
        blip = Blip.new(login_user, content,
                        attachment=attachment, meeting=m)
        return self.redirect(m.href())
Ejemplo n.º 3
0
    def post(self):
        errors = []
        title = self.request.get('title', '').strip()
        if not title:
            errors.append('Title cannot be empty')

        content = self.request.get('content', '').strip()
        if not content:
            errors.append('Content cannot be empty')

        if errors:
            return self.render('article_add.html', locals())

        user = self.get_current_user()
        article = Article.new(user, title, content)
        full_article_url = urlparse.urljoin(self.request.uri, article.href())
        blip = Blip.new(user, u'added article %s %s' % (article.title,
                                                        full_article_url))

        return self.redirect(article.href())
Ejemplo n.º 4
0
    def post(self, article_key=None):
        article = Article.get(article_key)
        if article is None or not article.is_active:
            return self.error(404)

        errors = []
        content = self.request.get('content', '').strip()
        if not content:
            errors.append('Content cannot be empty')

        if errors:
            return self.render('revision_add.html', locals())

        user = self.get_current_user()
        rev = ArticleRevision(user=user, article=article,
                              content=content)
        rev.put()
        if user == article.creator:
            article.current_rev_key = str(rev.key())
        article.put()
        full_rev_url = urlparse.urljoin(self.request.uri, rev.href())
        blip = Blip.new(user, u'edited article %s %s' % (article.title,
                                                         full_rev_url))
        return self.redirect(article.href())
Ejemplo n.º 5
0
 def post(self):
     content = self.request.get('text', '').strip()
     attachment = self.request.get('attachment', '').strip()
     blip = Blip.new(self.get_current_user(), content, attachment)
     return self.redirect('/home')