Esempio n. 1
0
func (u *University) FacultyCreate(title, shortname string) (Faculty, error) {
	f := Faculty{}
	f.Title = title
	f.ShortName = shortname
	f.Slug = chpu.Chpu(shortname)
	err := u.db.Insert(&f)
	return f, err
}
Esempio n. 2
0
func getSlug(db *gorp.DbMap, title string) string {
	title = chpu.Chpu(title)
	for {
		id, _ := db.SelectInt("select Id from New where Slug = ?", title)
		if id != 0 {
			title = strinc.Inc(title)
		} else {
			break
		}
	}
	return title
}
Esempio n. 3
0
func (u *University) GroupCreate(g Group) (Group, error) {
	g.Created = time.Now().UTC().UnixNano()
	g.Slug = chpu.Chpu(fmt.Sprintf("%s-%d-%d", g.Title, g.Start, g.End))
	if g.Parent != 0 {
		gp, err := u.GroupGet(g.Parent)
		if err != nil {
			return g, err
		}
		g.Start = gp.Start
		g.End = gp.End
		g.Code = gp.Code
		g.Faculty = gp.Faculty
		g.TrainingDirection = gp.TrainingDirection
	}
	err := u.db.Insert(&g)
	return g, err
}
Esempio n. 4
0
func Create(db *gorp.DbMap, c ChangeLog) (ChangeLog, error) {
	c.Slug = chpu.Chpu(c.Title)
	for {
		id, _ := db.SelectInt("select Id from ChangeLog where Slug = ?", c.Slug)
		if id != 0 {
			c.Slug = strinc.Inc(c.Slug)
		} else {
			break
		}
	}
	r := rate.Rate{}

	t := time.Now().UTC()
	c.Created = t.UnixNano()
	err := db.Insert(&c)
	r.Create(db, 6, c.Id)
	return c, err
}
Esempio n. 5
0
func (u *University) GroupUpdate(g Group) error {
	g.Updated = time.Now().UTC().UnixNano()
	g.Slug = chpu.Chpu(fmt.Sprintf("%s-%d-%d", g.Title, g.Start, g.End))
	_, err := u.db.Update(&g)
	return err
}
Esempio n. 6
0
func (u *University) FacultyUpdate(f Faculty) error {
	f.Slug = chpu.Chpu(f.ShortName)
	_, err := u.db.Update(&f)
	return err
}
Esempio n. 7
0
func (a *Api) Create(data []byte, name, descr, imgtype string, lon, lat float64) (Img, error) {
	bts := bytes.NewReader(data)
	img, _, err := image.Decode(bts)
	if err != nil {
		return Img{}, err
	}

	tm := time.Now()

	if name == "" {
		name = randName()
	}

	name = chpu.Chpu(name)

	title := name

	if len(name) <= int(a.nesting) {
		name = randName()
	}

	//TODO bad code
	for {
		found, err := a.ExistName(name)
		if err != nil {
			return Img{}, err
		}
		if found {
			name = randName()
		}
		if !found {
			break
		}
	}

	path := a.getPath(name)

	os.MkdirAll(path, 0777)

	out, err := os.Create(path + "/" + name + ".jpg")
	if err != nil {
		return Img{}, err
	}
	defer out.Close()
	jpeg.Encode(out, img, nil)

	//todo remove this(fly generated)
	if a.WebpAddr != "" {
		cmd := exec.Command(a.WebpAddr, path+"/"+name+".jpg", "-o",
			path+"/"+name+".webp")
		err := cmd.Run()
		if err != nil {
			fmt.Println(err)
			return Img{}, errors.New("Webp Not Working")
		}
	}

	im := Img{
		Name:        title,
		Slug:        name,
		Description: descr,
		Created:     tm.UnixNano(),
		Updated:     tm.UnixNano(),
		Width:       img.Bounds().Dx(),
		Height:      img.Bounds().Dy(),
		Hash:        int64(imghash.Average(img)),
		Type:        imgtype,
	}

	err = a.Db.Insert(&im)
	if err != nil {
		fmt.Println(err)
		return Img{}, err
	}
	return im, nil
}
Esempio n. 8
0
func (o Object) Slug() string {
	return chpu.Chpu(o.Title) + "_" + fmt.Sprint(o.Id)
}