Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7bf1a79
Add greenvars script and sprites, works for previewing on somebot web
MercuryRising Dec 2, 2014
7644ed3
Add username to database, allow deleting of maps
MercuryRising Dec 2, 2014
f8c5e1c
Add link to delete maps from single map page
MercuryRising Dec 2, 2014
ec1863a
Add user map list
MercuryRising Dec 2, 2014
8b94494
remove unnecessary print
MercuryRising Dec 2, 2014
3554439
Searching and pagination now work together
MercuryRising Dec 3, 2014
c1d1bd2
Remove sprites
MercuryRising Dec 3, 2014
3a85115
Move to new 45 degree previewer with texture pack support
MercuryRising Dec 3, 2014
0532d57
Start on commenting system
MercuryRising Dec 3, 2014
fe526cc
Initial messaging system works, might be database intensive though
MercuryRising Dec 3, 2014
91218ba
45 preview works, user selectable textures and test locations, userna…
MercuryRising Dec 3, 2014
a30710d
Delete button now hidden until hovered
MercuryRising Dec 3, 2014
abd427b
Add voting
MercuryRising Dec 3, 2014
8440cb1
indicator for new comments
MercuryRising Dec 3, 2014
76bd477
Add feedback toggle, move from json map data to map class
MercuryRising Dec 4, 2014
7e13af3
Autoupvote on load, versioning, primary status, proper deletes (remov…
MercuryRising Dec 4, 2014
b23129e
Make messages work a little nicer, allow url linking in text
MercuryRising Dec 4, 2014
7516f1f
Add all texture packs that worked with scripts, including sprites
MercuryRising Dec 4, 2014
ba02c08
Add changelog
MercuryRising Dec 4, 2014
bd743d6
Remove first textures
MercuryRising Dec 4, 2014
5bcbfd0
Update CHANGELOG.md
MercuryRising Dec 4, 2014
33dfa5b
Update CHANGELOG.md
MercuryRising Dec 4, 2014
6cbd1a6
Update CHANGELOG.md
MercuryRising Dec 4, 2014
88fa6a2
Update CHANGELOG.md
MercuryRising Dec 4, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# CHANGELOG December, 2014

### ADDITIONS

* Login functionality to database (email only used for uniqueness)
* Uses google (need gmail account) to handle authentication
* Set username by clicking the dude next to the login button
* Logging in gives uploaded maps "ownership"
* When submitting maps and logged in, the map's author will change to your username

* Ability to delete maps that you uploaded when logged in
* Ability to pick texture pack that your maps are rendered in
* Ability to pick default test server (when set, clicking 'test' will use your default)
* Added all texture packs that worked easily from wiki
* 45 degree tile preview (thanks GreenVars!)
* Commenting system for maps (need to be logged in to add comment)
* Ability to allow / disallow feedback on map
* Map Voting
* Versioning - when you submit a map with the same map name, it will be added as a version to your map
* This lets you upload 10 maps with the same name, making minors changes, and not clog up the recent page
* If you go to your profile, you will see all the maps that you've submitted
* Primary map: pick which version is displayed
* Added link to /r/tagpromapsharing


### BUG FIXES
* When searching, pagination now works properly (bringing you to page 2 with query, rather than new maps)
* Altered the 'showmap' page - before the image link would take up too much space
..* The image link doesn't show, but clicking a map image will bring you to the full size preview
4 changes: 2 additions & 2 deletions somebotweb/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
from collections import OrderedDict
DEBUG = False
DEBUG = True
SQLALCHEMY_DATABASE_URI = "postgres:///{}".format(os.environ.get("SOMEBOT_DB", "somebot"))
MAX_CONTENT_LENGTH = 512 * 1024 # 512KB
TEST_SERVERS = OrderedDict([
('us', {
'url': 'http://tagpro-maptest.koalabeast.com/',
'desc': 'Los Angeles',
'desc': 'Los Angeles (US)',
}),
('ca', {
'url': 'http://maptest2.newcompte.fr/',
Expand Down
194 changes: 152 additions & 42 deletions somebotweb/models.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,73 @@
import time
import datetime

from flask import url_for

from somebotweb import db

from sqlalchemy.orm import relationship, backref

class Vote(db.Model):
__tablename__ = 'votes'
id = db.Column('id', db.Integer, primary_key=True)
mapid = db.Column('mapid', db.ForeignKey('maps.id'))
userid = db.Column('userid', db.ForeignKey('users.id'))

def __init__(self, mapid, userid):
self.mapid = mapid
self.userid = userid

class User(db.Model):
__tablename__ = 'users' # 'user' is special in postgres
id = db.Column(db.Integer, primary_key=True)
# TODO: Reconsider using Text and instead use String? Probably some performance differences and ability to index blah blah blah
name = db.Column(db.Text)
id = db.Column('id', db.Integer, primary_key=True)
username = db.Column(db.Text, unique=True)
email = db.Column(db.Text)
texture_pack = db.Column(db.Text, default="Vanilla")
test_server = db.Column(db.Text, default="us")

def __init__(self, name, email):
self.name = name
def __init__(self, username, email):
self.username = username
self.email = email

def is_authenticated(self):
return True

def is_active(self):
return True

def is_anonymous(self):
return False

def get_id(self):
return unicode(self.id)

def __repr__(self):
return '<User %r>' % (self.username)

class Comment(db.Model):
__tablename__ = 'comments'

id = db.Column('id', db.Integer, primary_key=True)
mapid = db.Column(db.Integer, db.ForeignKey('maps.id'))
userid = db.Column(db.Integer, db.ForeignKey('users.id'))
username = db.Column(db.Text)
text = db.Column(db.Text)
time = db.Column(db.DateTime, default=datetime.datetime.utcnow)

def __init__(self, mapid, userid, username, text):
self.mapid = mapid
self.userid = userid
self.username = username
self.text = text

def alert_map(self):
m = Map.query.filter_by(id=self.mapid).first()
m.newcomments = 1
db.session.add(m)
db.session.commit()

class Map(db.Model):
# TODO: package instead of module
# TODO: nicer docstrings
__tablename__ = 'maps'
'''
The map schema
To make a map, we need a mapname, and author, and a description
Expand All @@ -32,54 +81,115 @@ class Map(db.Model):
mapname = db.Column(db.Text)
author = db.Column(db.Text)
description = db.Column(db.Text)
upload_time = db.Column(db.Float)
upload_time = db.Column(db.DateTime, default=datetime.datetime.utcnow)
# TODO: sql alchemdy doesn't have some date type?
last_tested = db.Column(db.Float)
times_tested = db.Column(db.Integer)
status = db.Column(db.Text)
userid = db.Column(db.Integer, db.ForeignKey('users.id'))
votes = db.Column(db.Integer, default=0)
newcomments = db.Column(db.Integer, default=0)
feedback_allowed = db.Column(db.Integer, default=1)
is_primary_version = db.Column(db.Integer, default=1)
remixes = relationship("Map")
parent_id = db.Column(db.Integer, db.ForeignKey('maps.id'))
version = db.Column(db.Integer, default=1)

def __init__(self, mapname, author, description, status=None, upload_time=None):
def __init__(self, mapname, author, description, userid=-1, status=None, upload_time=None):
self.mapname = mapname
self.author = author
self.description = description
self.upload_time = upload_time or time.time()
self.last_tested = 0
self.times_tested = 0
self.status = status
if userid > 0:
self.userid = userid
self.is_primary_version = 1
if(author != "Anonymous" and mapname != "Untitled" and userid>0):
query = Map.query.filter_by(mapname=mapname, author=author, userid=self.userid)
if query.count() > 0:
print query.all()
parent = query.order_by("upload_time desc").first()
print "There are previous versions of this"
print "Pv: ", parent.version
print "parent id: ", parent.parent_id

self.version = parent.version+1
parent.is_primary_version = 0
self.parent_id = parent.id

maps = query.all()
for m in maps:
if m.is_primary_version:
m.is_primary_version = 0
db.session.add(m)
if len(maps) > 0:
db.session.commit()
self.is_primary_version = 1

def __repr__(self):
return "<Map [%s] %s - %s>" %(str(self.id), self.mapname, self.author)

def get_json(self):
# TODO: this just returns a python dict, not json :/
'''
Input: map from database - given by Map class from sqlalchemy
Output: Map formatted in JSON
'''
strid = str(self.id)

map_data = {
'mapid': self.id,
'mapname': self.mapname,
'author': self.author,
'description': self.description,
'status': self.status,
'jsonurl': "/static/maps/"+strid+'.json',
'uploaddate': time.strftime('%Y-%m-%d', time.localtime(self.upload_time)),
'pngurl': "/static/maps/"+strid+'.png',
'previewurl': "/static/previews/"+strid+'.png',
'thumburl': "/static/thumbs/"+strid+'.png',
'times_tested': self.times_tested,
"mapurl": "/show/"+strid,
"authorurl": url_for('return_maps_by_author', author=self.author),
# TODO: why mapname in here?
# TODO: it's to name the downloaded file; we should move to
# storing the files in directories (with name id) and then
# keeping nice names inside.
"pngdownload": u"/download?mapname={mapname}&type=png&mapid={mapid}".format(mapname=self.mapname, mapid=strid),
"jsondownload": u"/download?mapname={mapname}&type=json&mapid={mapid}".format(mapname=self.mapname, mapid=strid),
}
return map_data
return "<Map [%s] %s - %s - userid: %s>" %(str(self.id), self.mapname, self.author, self.userid)

def has_voted(self, userid):
voted = Vote.query.filter_by(userid=userid, mapid=self.id).count()
return False if not voted else True

def vote(self, userid):
already_voted = self.has_voted(userid)
vote_status = None
if self.votes is None: self.votes = 0
if not already_voted:
v = Vote(self.id, userid)
db.session.add(v)
self.votes = self.votes + 1
vote_status = True
else:
v = Vote.query.filter_by(userid=userid, mapid=self.id).first()
db.session.delete(v)
self.votes = self.votes - 1
vote_status = False
db.session.commit() # for the vote count
return vote_status

def color_helper(self, userid):
if has_voted(userid):
return "#d43f3a"
else:
return "#428bca"

def clear_comment(self):
self.newcomments = 0

def versions(self):
if(self.mapname != "Untitled" and self.author != "Anonymous"):
versions = Map.query.filter_by(mapname=self.mapname, author=self.author, userid=self.userid).order_by("upload_time asc").all()
return reversed(zip(range(1,100), versions))
else:
return []

def set_primary(self):
if self.is_primary_version:
return True
else:
maps = Map.query.filter_by(userid=self.userid, mapname=self.mapname, author=self.author, is_primary_version=1).all()
for m in maps:
print m, m.version, m.is_primary_version
m.is_primary_version = 0
db.session.add(m)
self.is_primary_version = 1
db.session.add(self)
db.session.commit()
return True

def toggle_feedback(self):
status = None
if self.feedback_allowed:
self.feedback_allowed = 0
status = False
else:
self.feedback_allowed = 1
status = True
return status


db.Index('mapname_idx', db.func.lower(Map.mapname))
Expand Down
Loading