Esempio n. 1
0
def root():
  lietotajs = ""
  #Attēli ir linki uz pixabay attēliem; attēlu saraksts atrodas static/pictures.bin
  #Ja tiek pievienots jauns attēls
  if request.method == 'POST':
    newPicture = request.form['newPicture']
    pictureExistsAlready = picmethods.checkIfPictureExists(newPicture)
    if pictureExistsAlready:
      print('Duplicate picture error.')
    else:
      picmethods.addNewPicture(newPicture)
    pictures = picmethods.loadAllPictures()
    return render_template("bildes.html", pictures=pictures,comments=commethods.findCommentCount,lietotajs=lietotajs)
  #Ja lapa tiek vienkārši ielādēta
  else:
    #Skatāmies, vai eksistē cepums ar nosaukumu "lietotajs"
    #Ja neeksistē, uztaisām cepumu uz 24 stundām un ieliekam random lietotājvārdu
    if not request.cookies.get('lietotajs'):
      res = make_response('Uzstadam lietotajvardu')
      lietotajs = namemethods.generateRandomNickname()
      res.set_cookie('lietotajs', lietotajs)#cepuma iestatīšana nestrādā, btw
    #Ja cepums jau eksistē, nolasām un ieliekam mainīgajā lietotajs
    else:
      res = make_response('Lietotajvards ir {}'.format(request.cookies.get('lietotajs')))
      lietotajs = request.cookies.get('lietotajs')

    #Ielādējam visus attēlus un izsaucam šablonu, padodot attēlu sarakstu, komentāru sarakstu un lietotājvārdu
    pictures = picmethods.loadAllPictures()
    return render_template("bildes.html", pictures=pictures,comments=commethods.findCommentCount,lietotajs=lietotajs)
Esempio n. 2
0
def visasBildes():
    #Ja tiek pievienots jauns attēls
    if request.method == 'POST':
        newPicture = request.form['newPicture']
        pictureExistsAlready = picmethods.checkIfPictureExists(newPicture)
        if pictureExistsAlready:
            print('Duplicate picture error.')
        else:
            picmethods.addNewPicture(newPicture)
        pictures = picmethods.loadAllPictures()
        return render_template("bildes.html", pictures=pictures)
    #Ja lapa tiek vienkārši ielādēta
    else:
        pictures = picmethods.loadAllPictures()
        return render_template("bildes.html", pictures=pictures)
Esempio n. 3
0
def root():
    #Attēli ir linki uz pixabay attēliem; attēlu saraksts atrodas static/pictures.bin
    #Ja tiek pievienots jauns attēls
    if request.method == 'POST':
        newPicture = request.form['newPicture']
        pictureExistsAlready = picmethods.checkIfPictureExists(newPicture)
        if pictureExistsAlready:
            print('Duplicate picture error.')
        else:
            picmethods.addNewPicture(newPicture)
        pictures = picmethods.loadAllPictures()
        return render_template("bildes.html", pictures=pictures)
    #Ja lapa tiek vienkārši ielādēta
    else:
        pictures = picmethods.loadAllPictures()
        return render_template("bildes.html",
                               pictures=pictures,
                               comments=commethods.findCommentCount)