def _create_note(self, user, file_name, file_path):
        note = Note(parent=ndb.Key("User", user.nickname()),
                    title=self.request.get('title'),
                    content=self.request.get('content'))

        #note.put()

        item_titles = self.request.get('checklist_items').split(',')
        for item_title in item_titles:
            if not item_title:
                continue
            item = CheckListItem(title=item_title)
            #item.put()
            #note.checklist_items.append(item.key)

            note.checklist_items.append(item)

            #item = CheckListItemObject(title=item_title)
            #note.checklist_items.append(item)

        if file_name and file_path:
            url, thumbnail_url = self._get_urls_for(file_name)

            f = NoteFile(parent=note.key, name=file_name,
                         url=url, thumbnail_url=thumbnail_url,
                         full_path=file_path)
            f.put()
            note.files.append(f.key)

        note.put()
Exemple #2
0
def index(request):
    if request.GET:
        new_data = ''
        data = request.GET.get('text')
        if 'shifr' == request.GET.get('command'):
            step = int(request.GET.get('code'))
        else:
            step = -int(request.GET.get('code'))
        capital_letters = [chr(letter) for letter in range(65, 91)]
        capital_letters_step = [capital_letters[(i+step+26) % 26] for i in range(0, 26)]
        low_letters = [chr(letter) for letter in range(97, 123)]
        low_letters_step = [low_letters[(i+step+26) % 26] for i in range(0, 26)]
        for letter in data:
            if letter in capital_letters:
                new_data += capital_letters_step[(ord(letter)-65) % 26]
            elif letter in low_letters:
                new_data += low_letters_step[(ord(letter)-97) % 26]
            else:
                new_data += letter
        note = Note(shifr=request.GET.get('text'), ROT=int(request.GET.get('code')), label=request.GET.get('label'))
        note.save()

        return HttpResponse(JsonResponse({'text': new_data }))
    else:
        form = ShifrForm()
        context = {
            'form': form,
        }
        return render(request, 'content.html', context)
Exemple #3
0
def delete_checked():
    try:
        Note.objects(checked=True).delete()
    except:
        return jsonify({"success": False, "message": "cannot delete"})

    return jsonify({"success": "true"})
Exemple #4
0
    def _create_note(self, user, file_name, file_path):

        note = Note(parent=ndb.Key("User", user.nickname()),
                    title=self.request.get('title'),
                    content=self.request.get('content'))
        note.put()

        # Retrieve csv representing checklist items
        item_titles = self.request.get('checklist_items').split(',')

        for item_title in item_titles:
            if not item_title:
                continue
            # create a checklist instance
            item = CheckListItem(parent = note.key, title = item_title)
            # store each checklist
            item.put()
            # after storing it, we can access the key to append it to the note
            note.checklist_items.append(item.key)

        if file_name and file_path:
            url, thumbnail_url = self._get_urls_for(file_name)

            f = NoteFile(parent=note.key, name=file_name,
                         url=url, thumbnail_url=thumbnail_url,
                         full_path=file_path)
            f.put()
            note.files.append(f.key)

            # update the note entity with the checklist items
            note.put()  
Exemple #5
0
def publish_note(request):

    if request.POST['flag'] == 'index':

        id = request.POST['userid']
        pub = Publisher.objects.filter(id=id)[0]
        return render(request, 'edit.html', {'pub': pub})
    else:

        username = request.POST['id']
        title = request.POST['title']
        content = request.POST['content']
        flag = request.POST['flag']
        timer = time.strftime("%Y-%m-%d %X", time.localtime())

        note = Note(title=title,
                    time=timer,
                    content=content,
                    publisher_id=username)
        note.save()
        #待修改
        #增刷新个人主页帖子window.location.reload;
        return HttpResponse(
            '<script type="text/javascript">alert("发布成功");window.history.go(-2);</script>'
        )
Exemple #6
0
    def _create_note(self, user, file_name, file_path):
        note = Note(parent=ndb.Key("User", user.nickname()),
                    title=self.request.get('title'),
                    content=self.request.get('content'))

        #note.put()

        item_titles = self.request.get('checklist_items').split(',')
        for item_title in item_titles:
            if not item_title:
                continue
            item = CheckListItem(title=item_title)
            #item.put()
            #note.checklist_items.append(item.key)

            note.checklist_items.append(item)

            #item = CheckListItemObject(title=item_title)
            #note.checklist_items.append(item)

        if file_name and file_path:
            url, thumbnail_url = self._get_urls_for(file_name)

            f = NoteFile(parent=note.key, name=file_name,
                         url=url, thumbnail_url=thumbnail_url,
                         full_path=file_path)
            f.put()
            note.files.append(f.key)

        note.put()
Exemple #7
0
def insert_initial_data():
    try:
        admin = User(
            username='******',
            password=app.config.get('ADMIN_PASSWORD')
        )
        db.session.add(admin)
        db.session.commit()
    except IntegrityError:
        db.session.rollback()
        return

    admin_note = Note(
        title='Hello world',
        content=('Lorem ipsum dolor sit amet, consectetur '
        'adipiscing elit, sed do eiusmod tempor incididunt...'),
        owner=admin
    )
    db.session.add(admin_note)

    admin_note = Note(
        title='flag',
        content=app.config.get('FLAG'),
        owner=admin
    )
    db.session.add(admin_note)
    db.session.commit()
def delete_quote(id):
    note = Note.objects(id=id).first()

    deleteNote = deleteQuoteForm(request.form)
    if request.method == 'POST':
        deleteNote = deleteQuoteForm(request.form)

        if deleteNote.validate == False:
            flash('Faliure', 'danger')
            return redirect(url_for('profile') + ('/' + current_user.slug))

        if deleteNote.validate_on_submit():
            note = Note.objects(id=id).first()

            current_user.notes.remove(note)
            current_user.save()

            note.delete()

            flash('Successfully deleted', 'warning')

    return render_template("delete.html",
                           title="delete",
                           delete_note=deleteNote,
                           note=note)
Exemple #9
0
def handle_add_notes(username):
    """ Display form to add notes for the logged in user.
        Add new note and redirect to user detail.
    """

    if session.get('user_id') != username:
        flash("You are not authorized to add notes to this user!")
        return redirect('/')

    form = NoteForm()

    if form.validate_on_submit():

        new_note = Note()
        form.populate_obj(new_note)
        new_note.owner = username

        db.session.add(new_note)
        db.session.commit()

        flash("Note has been added")

        return redirect(f"/users/{username}")
    else:
        return render_template("add_notes.html", form=form)
Exemple #10
0
def post_note():
    note = Note()
    note.message = bottle.request.forms.get("message")
    note.hashtags = extract_hashtags(note.message)
    persistence.insert_note(note)
    
    bottle.redirect("")
Exemple #11
0
    def _create_note(self, user, title, content, attachments):

        note = Note(parent=ndb.Key("User", user.nickname()),
                    title=title,
                    content=content)
        note.put()

        if attachments:
            bucket_name = app_identity.get_default_gcs_bucket_name()
            for file_name, file_content in attachments:
                content_t = mimetypes.guess_type(file_name)[0]
                real_path = os.path.join('/', bucket_name, user.user_id(), file_name)

                with cloudstorage.open(real_path, 'w', content_type=content_t,
                                       options={'x-goog-acl': 'public-read'}) as f:
                    f.write(file_content.decode())

                key = blobstore.create_gs_key('/gs' + real_path)
                try:
                    url = images.get_serving_url(key, size=0)
                    thumbnail_url = images.get_serving_url(key, size=150, crop=True)
                except images.TransformationError, images.NotImageError:
                    url = "http://storage.googleapis.com{}".format(real_path)
                    thumbnail_url = None

                f = NoteFile(parent=note.key, name=file_name,
                             url=url, thumbnail_url=thumbnail_url,
                             full_path=real_path)
                f.put()
                note.files.append(f.key)

            note.put()
Exemple #12
0
    def create(user_first_name, user_last_name, movie, note):
        """ Create a new note """
        notation = Note(user_first_name=user_first_name,
                        user_last_name=user_last_name,
                        movie=movie,
                        note=note)

        return notation.save()
Exemple #13
0
def index():
    if request.method == 'POST' and request.form.get('content'):
        note = Note(content=request.form['content'])
        Note.save(note)
        return redirect(url_for('index'))

    notes = Note.list_public()
    return render_template('index.html', notes=notes)
Exemple #14
0
def handle_uploaded_json_file(f, user):
    
    def convert_date(str_date):
        new_str = str_date.replace('+00:00','')
        try:
            new_dt = datetime.strptime(new_str, '%Y-%m-%d %H:%M:%S.%f')
        except ValueError:
            new_dt = datetime.strptime(new_str, '%Y-%m-%d %H:%M:%S')
        return new_dt
    
    with open('notes.json', 'wb+') as destination:
        for chunk in f.chunks():
            destination.write(chunk)
        f.close()
    with open('notes.json', 'r') as fh:
        json_data = json.load(fh)
        fh.close()
    
    version, notes = json_data
    
    # for user in User.objects.all():
        # if not Folder.)objects.filter(user = user, name = "Main").exists():
            # folder = Folder(name="Main", user = user)
            # folder.save()
        # if not Folder.objects.filter(user = user, name = ")Trash").exists():
            # folder = Folder(name="Trash", user = u)ser)
            # folder.save()  
          
    for note in notes:
        created_at = convert_date(note['created_at'])
        title = note['title']
        username = note['user']

        # TODO: If user is blank we need to assign to a default user.  For now just skip.
        # Its technically a database integrity violation anyway.
        if username is None: continue

        user = User.objects.get(username = username)        

        if not Note.objects.filter(title = title, 
                               created_at = created_at).exists():
            new_note = Note()
            new_note.title =  title
            new_note.created_at = created_at
            new_note.modified_at = convert_date(note['modified_at'])
            new_note.note_type = note['post_type'] 
            new_note.note = note['note']
            foldr = note['folder']
            
            
            try:
                folder = Folder.objects.get(name = foldr, user = user)
            except Folder.DoesNotExist:
                folder = Folder(name = foldr, user = user)
                folder.save()
            new_note.folder = folder
            new_note.user = user
            new_note.save()
Exemple #15
0
def homepage():
	if request.method == 'POST':
		if request.form.get('content'):
			note = Note.create(content=request.form['content'])
			rendered = render_template('note.html', note=note)
			return jsonify({'note': rendered, 'success': True})

		notes = Note.public().limit(50)
		return jsonify({'success': False})
 def note_insert(self, note):
     if note.from_datastore:
         note_with_parent = note
     else:
         note_with_parent = Note(parent=main.get_parent_key(endpoints.get_current_user()),
                                 note = note.note, company_entity_key = note.company_entity_key)
          
     note_with_parent.put()
     return note_with_parent
Exemple #17
0
 def create(self):
     if request.method == 'POST':
         if request.form.get('message'):
             Note.create(
                 user=auth.get_logged_in_user(),
                 message=request.form['message'],
             )
     next = request.form.get('next') or self.dashboard_url()
     return redirect(next)
Exemple #18
0
def note_add(request, event_id):
    event = get_object_or_404(Event, pk=event_id)
    if request.method == 'POST': # If the form has been submitted...
        form = NoteForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            note = Note(event=event, user=request.user, note = form.cleaned_data['note'])
            note.save()
            messages.success(request, _("Saved note"))
    return HttpResponseRedirect(reverse('event', args=[event.id]))
def create():
    title = request.get_json().get('title')
    content = request.get_json().get('content')
    if content:
        note = Note()
        result = note.create_note(title, content)
        return jsonify(result), 201
    else:
        return "", 204
Exemple #20
0
def create_tables():
    from models import User, Message, Note, Relationship, City, Pinche

    # User.create_table()
    Relationship.create_table()
    Note.create_table()
    Message.create_table()
    City.create_table()
    Pinche.create_table()
Exemple #21
0
 def create(self):
     if request.method == 'POST':
         if request.form.get('message'):
             Note.create(
                 user=auth.get_logged_in_user(),
                 message=request.form['message'],
             )
     next = request.form.get('next') or self.dashboard_url()
     return redirect(next)
Exemple #22
0
def create_tables():
    from models import User, Message, Note, Relationship, City, Pinche
    
    # User.create_table()
    Relationship.create_table()
    Note.create_table()
    Message.create_table()
    City.create_table()
    Pinche.create_table()
Exemple #23
0
def index(request):

    if request.method == 'POST':
        title = request.POST['title']
        text = request.POST['text']
        note = Note(title=title, text=text)
        note.save()
    else:
        return render(request, 'webApp/index.html')
def homepage():
    notes = Note.select()
    if request.method == 'POST':
        if request.form.get('content'):
            note = Note.create(content=request.form['content'])
            rendered = render_template('note.html', note=note)
            return render_template('homepage.html', notes=notes)

    return render_template('homepage.html', notes=notes)
Exemple #25
0
def homepage():
    if request.method == 'POST':
        if request.form.get('content'):
            note = Note.create(content=request.form['content'])

            rendered = render_template('note.html', note=note)
            return redirect(url_for('homepage'))
        return jsonify({'success': False})
    notes = Note.public().limit(50)
    return render_template('homepage.html', notes=notes)
Exemple #26
0
def hour_notification():
    while True:
        now = datetime.now()
        offset = 60 - (now.second + (now.microsecond / 1000000))
        dt = int(now.timestamp() + offset)
        sleep(offset)
        [
            notification(Note(*note))
            for note in Note().select(f'datetime={dt + 3600}')
        ]
Exemple #27
0
 def create(self):
     if not users.get_current_user():
         webapp2.abort(401)
     form = NoteForm(self.get_locale(), self.request.POST, None)
     if self.request.POST and form.validate():
         note = Note(author=users.get_current_user(), **form.data)
         note.date = datetime.now()
         note.put()
         return self.redirect('/note/list')
     self.render_template('form.html', {'title': _('Note'), 'form': form, 'name': 'note'})
Exemple #28
0
def hello():
    form = InputForm()
    if form.validate_on_submit():
        message = request.form["message"]
        name = request.form["name"]
        note = Note(message=message, name=name)
        note.add()
        #return redirect(url_for("success", message=message, name=name, lookupId = note.lookupId))
        return render_template("success.html", message=message, name=name, lookupId = note.lookupId)
    return render_template("index.html", form=form)
Exemple #29
0
 def save(self, account):
     cd = self.cleaned_data
     note = Note(amount=cd['amount'],
                 timestamp=cd['timestamp'],
                 description=cd['description'],
                 category=cd['category'],
                 account=account)
     note.save()
     account.balance = account.balance + cd['amount']
     account.save()
Exemple #30
0
def finish_plan_api():
    pk = flask.request.form.get('pk')
    user_id = flask.session['user_id']
    plan = Plan.fetchone(pk=pk)
    if not plan:
        raise error.PlanNoteFound()

    plan_log = PlanLog()
    plan_log.user_id = user_id
    plan_log.plan_id = plan.pk
    plan_log.create_at = datetime.now()
    plan_log.update_at = datetime.now()
    plan_log.is_enable = 1
    plan_log.save(commit=False)

    for item in plan.plan_items:
        note = Note()
        note.kind_id = item.kind.pk
        note.user_id = user_id
        note.quantity = item.quantity
        note.plan_log_id = plan_log.pk
        note.create_at = datetime.now()
        note.update_at = datetime.now()
        note.save()

    return {'pk': pk}
Exemple #31
0
 def on_note_delete(self, note_id):
     res = self.list_panel.delete_note(note_id)
     Note.find(note_id).delete_instance()
     if res:
         self.show_note(res)
     else:
         self.todo_panel.empty()
         self.detail_panel.remove_note()
         if self.detail_panel.IsShown():
             self.detail_panel.Hide()
     self.nav_panel.note_tree.update_selected_notebook_count(-1)
Exemple #32
0
def homepage():
    if not session.get('logged_in'):
        return redirect(url_for('login'))
    if request.method == 'POST':
        if request.form.get('content'):
            note = Note.create(content=request.form['content'])
            flash('New entry posted')
            return redirect(url_for('homepage'))

    notes = Note.public().paginate(get_page(), 50)
    return render_template('homepage.html', notes=notes)
 def add_note(self, message, user):
     if message:
         note = Note(activity=self.object)
         note.message = message
         note.user = user
         note.save()
         messages.success(self.request, 'Note added successfully.')
         return True
     else:
         messages.error(self.request, 'Message cannot be empty.')
         return False
 def get(self):
     if 'X-AppEngine-Cron' not in self.request.headers:
         self.error(403)
     przedszkole = iPrzedszkole('<nazwa przedszkola>', '<uzytkownik>', '<haslo>')
     menu = przedszkole.jadlospis()
     if menu is None:
         menu = "Weekend :)"
     note = Note(id='jadlospis')
     note.kindergartenMenu = menu
     note.put()
     memcache.set(key='jadlospis', value=note.kindergartenMenu, time=expirationTime)
    def note_insert(self, note):
        if note.from_datastore:
            note_with_parent = note
        else:
            note_with_parent = Note(parent=main.get_parent_key(
                endpoints.get_current_user()),
                                    note=note.note,
                                    company_entity_key=note.company_entity_key)

        note_with_parent.put()
        return note_with_parent
Exemple #36
0
def create():
    user = auth.get_logged_in_user()
    if request.method == 'POST' and request.form["content"]:
        Note.create(
            user=user,
            content=request.form["content"],
        )
        flash('Your note has been created')
        return redirect(url_for('getNotes'))

    return render_template('create.html')
Exemple #37
0
 def save(self, account):
     cd = self.cleaned_data
     note = Note(
         amount=cd['amount'],
         timestamp=cd['timestamp'],
         description=cd['description'],
         category=cd['category'],
         account=account
     )
     note.save()
     account.balance = account.balance + cd['amount']
     account.save()
Exemple #38
0
 def insert(self, note):
     logging.debug('inserting note: %s' % str(note))
     note_model = NoteModel(name=note.name,
                            type=note.type,
                            meeting_id=note.meeting_id,
                            time=note.time,
                            start_time_delta=note.start_time_delta,
                            assignee=note.assignee,
                            description=note.description)
     note_key = note_model.put()
     logging.debug('successfully inserted note, id %d' % note_key.id())
     return note_key.id()
Exemple #39
0
 def _create_note(self,user):
     
     note = Note(parent=ndb.Key("User",user.nickname()),
                 title=self.request.get('title'),
                 content=self.request.get('content'))
     note.put()
     item_titles = self.request.get('checklist_items').split(',')
     for item_title in item_titles:
         item = CheckListItem(parent=note.key,title=item_title)
         item.put()
         note.checklist_items.append(item.key)
     note.put()
Exemple #40
0
def createNote(request):

    username = request.POST['username']
    note = request.POST['note']

    date_time = helpers.get_datetime(note)

    newNote = Note(user=username, text_body=note, time=date_time)# TODO: START and EXPIRATION date objects
    newNote.save()

    # SHOULD REDIRECT TO LOGIN PAGE
    return redirect("index")
 def test_book_autodelete(self):
     note1 = Note(text='text')
     note1.save()
     note2 = Note(text='text')
     note2.save()
     book = Book(title='title')
     book.save()
     book.notes.add(*[note1, note2])
     note1.delete()
     self.assertTrue(Book.objects.all())
     note2.delete()
     self.assertFalse(Book.objects.all())
 def post_notes(permission):
     title = request.json.get('title')
     description = request.json.get('description')
     category_id = request.json.get('category_id')
     if not title or not description:
         abort(400)
     description_string = str(description).replace("\'", "\"")
     new_note = Note(title=title,
                     description=description_string,
                     category_id=category_id)
     new_note.insert()
     return jsonify({'success': True}), 200
Exemple #43
0
    def post(self):
        print("Done.")

        note = Note(
                img = self.request.get('img'), 
                describe = self.request.get('desc'),
                )

        note.put()
        
        template = jinja_env.get_template('./templates/map.html')
        self.response.out.write(template.render())
Exemple #44
0
def write_note(request):
    try:
        note = request.POST.get('note')
        email = request.user.email
        location = request.POST.get('location')
        artboard = ArtBoard.objects.get(location=location)
        new_note = Note(email=email, note=note, artboard=artboard)
        new_note.save()
        redirection = '/exegesis/svg/?url=' + location
        return redirect(redirection)
    except:
        print sys.exc_info()
        return render(request, 'wrong.html')
Exemple #45
0
def add():
    new_user = User(name=request.form['name'],
                    password=request.form['password'])

    new_note = Note(date=datetime.utcnow(),
                    comment="User " + new_user.name + " was added.")
    LogCount.added = LogCount.added + 1
    LogCount.save()

    sqldb.session.add(new_user)
    sqldb.session.commit()
    new_note.save()
    return redirect(url_for('index'))
    def note_for_company(self, request):
        user = endpoints.get_current_user()
        query = Note.query(ancestor=main.get_parent_key(user)).filter(
            Note.company_entity_key == request.company_entity_key)

        returnNote = Note(note="",
                          company_entity_key=request.company_entity_key)

        for note in query:
            returnNote = note
            break

        return returnNote
Exemple #47
0
def smile():
    form = VoteForm()
    if "randomNote" not in session: #this is temporary; once site gets up and going, will find better way to counter botting
        session["randomNote"] = toJSON(Note.getRandomNote())
    if form.validate_on_submit():
        tempNote = Note.getNote(session["randomNote"]["lookupId"])
        if form.like.data:
            tempNote.update({"numLikes": tempNote.numLikes + 1})
        elif form.dislike.data:
            tempNote.update({"numDislikes": tempNote.numDislikes + 1})
        session.clear()
        return redirect('/smile')
    return render_template("smile.html", notez = Note.getNote(session["randomNote"]["lookupId"]), form=form)
Exemple #48
0
def delete():
    to_delete_id = request.form['del_id']
    to_delete = User.query.filter_by(id=to_delete_id).first()

    new_note = Note(date=datetime.utcnow(),
                    comment="User " + to_delete.name + " was deleted.")
    LogCount.deleted = LogCount.deleted + 1
    LogCount.save()

    sqldb.session.delete(to_delete)
    sqldb.session.commit()
    new_note.save()
    return redirect(url_for('index'))
Exemple #49
0
    def get(self):
        if 'X-AppEngine-Cron' not in self.request.headers:
            self.error(403)
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(),
                                      urllib2.HTTPHandler(debuglevel=1))
        req = urllib2.Request(url)
        req.add_header('User-Agent', userAgent)
        opener.open(req)

        data_stage1 = {'pesel': pesel, 'akcja': 'sprawdzpesel'}

        encoded_data_stage1 = urllib.urlencode(data_stage1)
        req = urllib2.Request(url)
        req.add_data(encoded_data_stage1)
        req.add_header('User-Agent', userAgent)
        opener.open(req)

        data_stage2 = {
            'imie': imie,
            'nazwisko': nazwisko,
            'pesel': pesel,
            'akcja': 'login',
            'pin': pin
        }

        encoded_data_stage2 = urllib.urlencode(data_stage2)
        req = urllib2.Request(url)
        req.add_data(encoded_data_stage2)
        req.add_header('User-Agent', userAgent)
        result = opener.open(req).read().decode('iso-8859-2')
        zlobek1 = re.search(
            r"<li>I  wybor ZLOBEK nr <strong>%s</strong>  --> MIEJSCE: <strong> (\d+)</strong>"
            % nursery_no1, result)
        zlobek1 = zlobek1.group(1)
        zlobek2 = re.search(
            r"<li>II wybor ZLOBEK nr <strong>%s</strong> --> MIEJSCE: <strong> (\d+)</strong>"
            % nursery_no2, result)
        zlobek2 = zlobek2.group(1)
        zlobek3 = re.search(
            r"<li>III wybor ZLOBEK nr <strong>{}</strong> --> MIEJSCE: <strong> (\d+)</strong>"
            .format(nursery_no3), result)
        zlobek3 = zlobek3.group(1)

        id_date = datetime.datetime.now().strftime("%Y-%m-%d")
        note = Note(id=id_date,
                    db_nursery_no1=int(zlobek1),
                    db_nursery_no2=int(zlobek2),
                    db_nursery_no3=int(zlobek3))
        note.put()
        logging.info("!! INFO !! CRON on {} Z1:{} Z2:{} Z3:{}".format(
            id_date, zlobek1, zlobek2, zlobek3))
Exemple #50
0
def homepage():
    if request.method == 'POST':
        #create a new note in the db
        if request.form.get('content'):
            note = Note.create(content=request.form['content'])

            # Render a single note panel and return the HTML.
            rendered = render_template('note.html', note=note)
            return jsonify({'note': rendered, 'success': True})

        return jsonify({'success': False})

    notes = Note.public().paginate(get_page(), 50)
    return render_template('homepage.html', notes=notes)
Exemple #51
0
def homepage():
	if request.method == 'POST':
		if request.form.get('content'):
			# New note
			note = Note.create(content = request.form['content'])
			# Make a note panel and jsonify
			rendered = render_template('note.html', note = note)
			return jsonify({'note': rendered, 'success': True})

		# no content, return failure
		return jsonify({'success': False})

	notes = Note.public().limit(50)
	return render_template('homepage.html', notes = notes)
Exemple #52
0
 def testNote(self):
     Note(author=self.current_user, title='Test 1', public=False).put()
     self.assertEqual(1, Note.all().count(10))
     Note(author=self.current_user, title='Test 2', public=True).put()
     self.assertEqual(2, Note.all().count(10))
     Note(author=self.current_user, title='Test 3', text=u'Treść', url='jkpluta.appspot.com', public=True).put()
     self.assertEqual(3, Note.all().count(10))
     with self.assertRaises(datastore_errors.BadValueError):
         Note().put()
     with self.assertRaises(datastore_errors.BadValueError):
         Note().put(author=self.current_user, title='Test X')
     with self.assertRaises(datastore_errors.BadValueError):
         Note().put(author=self.current_user, public=False)
     self.assertEqual(3, Note.all().count(10))
def update_note(pk):
    if request.method == 'POST':
        if request.form.get('updated_parts'):
            query = Note.update(content=request.form['updated_parts']).where(
                Note.id == pk)
            query.execute()
            return redirect(url_for('homepage'))

    try:
        note = Note.get(Note.id == pk)
    except Note.DoesNotExist:
        abort(404)

    return render_template('update.html', note=note)
Exemple #54
0
def homepage():
    if request.method == 'POST':
        print('/ request method is post')
        if request.form.get('content'):
            print('/ request metho is post,content is ', request.form['content'])

            note = Note.create(content=request.form['content'])

            rendered = render_template('note.html', note=note)
            return jsonify({'note': rendered, 'success': True})

        return jsonify({'success': False})
    print('/ request method is get')
    notes = Note.public().paginate(get_page(), 50)
    return render_template('homepage.html', notes=notes)
Exemple #55
0
def homepage():
    if request.method == 'POST':
        if request.form.get('content'):
            # Create a new note in the db.
            note = Note.create(content=request.form['content'])

            # Render a single note panel and return the HTML.
            rendered = render_template('note.html', note=note)
            return jsonify({'note': rendered, 'success': True})

        # If there's no content, indicate a failure.
        return jsonify({'success': False})

    notes = Note.public().limit(50)
    return render_template('homepage.html', notes=notes)
Exemple #56
0
def view_note_slug(slug, **kwarg):
    note = Note.get_by_slug(slug)
    form = NoteForm()
    if not note:
        flash(u'Note not found.', 'info')
        return redirect(url_for('list_notes'))
    return render_template("view.html", note=note, form=form)
Exemple #57
0
    def POST(self):
        user = users.get_current_user()
        form = form_add_note()
        object = {}
        if form.validates():
            object["success"] = True
            object["response"] = form.d.note
            note = Note(author=user, name=form.d.note, tags=form.d.ntag_list.split(","))

            note.put()
            object["message"] = "New note has been created"
        else:
            object["success"] = False
            object["errors"] = form.get_errors()
            object["message"] = "Note has not been created"
        return simplejson.dumps(object)
Exemple #58
0
def archive_note(pk):
    try:
        note = Note.get(Note.id == pk)
    except Note.DoesNotExist:
        abort(404)
    note.delete_instance()
    return redirect(url_for('homepage'))
def get_note_counter():
    data = memcache.get('note_count')
    if data is None:
        data = Note.query().count()
        memcache.set('note_count', data)

    return data
    def get(self):
        if 'X-AppEngine-Cron' not in self.request.headers:
            self.error(403)

        notes = Note.query().fetch()
        for note in notes:
            self._shrink_note(note)