-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can now access events from the home page. Page gives detailed info (host, creator, description, times/date, location).
- Loading branch information
Showing
5 changed files
with
255 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,146 +1,146 @@ | ||
from datetime import datetime | ||
from datetime import timedelta | ||
|
||
import urllib | ||
|
||
from google.appengine.ext import db | ||
from google.appengine.api import users | ||
from google.appengine.api import mail | ||
|
||
class AppUser(db.Model): | ||
"""Stores extra User data for validation of events and features""" | ||
id = db.UserProperty(auto_current_user=True) | ||
verified = db.BooleanProperty(indexed=False) | ||
banned = db.BooleanProperty(indexed=False) | ||
premium = db.BooleanProperty(indexed=False) | ||
goodEventsCount = db.IntegerProperty(indexed=False) | ||
badEventsCount = db.IntegerProperty(indexed=False) | ||
|
||
@staticmethod | ||
def registerUser(): | ||
"""Constructor for the AppUser class""" | ||
id=users.get_current_user() | ||
key=id.email().split('@')[0] | ||
user = AppUser(key_name=key) | ||
user.id = id | ||
user.verified=False | ||
user.banned=False | ||
user.premium=False | ||
user.goodEventsCount=0 | ||
user.badEventsCount=0 | ||
user.put() | ||
return user | ||
|
||
@staticmethod | ||
def getUser(): | ||
"""Gets the AppUser object of the current user. If they're not registered, this registers them""" | ||
user = users.get_current_user() | ||
userList = db.GqlQuery("SELECT * FROM AppUser WHERE id = :1 LIMIT 1", | ||
user).fetch(1) | ||
if userList == []: # Wasn't found | ||
return AppUser.registerUser() | ||
return userList[0] | ||
|
||
@property | ||
def getUserLink(self): | ||
return """/User/"""+str(self.key().name()) | ||
|
||
@staticmethod | ||
def getUserFromKey(key): | ||
""" Retrieves an AppUser object from the """ | ||
#get(Key(key)) | ||
#return None if no user found | ||
|
||
def banUser(self): | ||
"""Initiates the banhammer""" | ||
#ensure they're supposed to be here | ||
if self.badEventsCount >= 3 and not self.banned: | ||
self.banned=True | ||
self.put() | ||
message = mail.EmailMessage( | ||
sender="Friends with Food Admin <[email protected]>", | ||
subject="Your account has been flagged to be banned") | ||
|
||
message.to = self.id.email() | ||
message.cc = "[email protected]" | ||
message.body = """ | ||
Dear %s: | ||
Your account on Friends with Food has been flagged for | ||
banning after being reported for several consecutive fake | ||
events. Your account has been banned from creating new events. | ||
If you feel that this is in error, please reply-all to this | ||
message with an explanation. | ||
Thanks, | ||
The Friends with Food Team | ||
""" % self.id.nickname() | ||
message.send() | ||
|
||
|
||
def promoteUser(self): | ||
"""Users are rewarded with verified user status whenever they pay up or | ||
make 3 good Events""" | ||
#ensure they're supposed to be here and haven't been here before | ||
if self.goodEventsCount >= 3 and not self.verified: | ||
self.verifiedUser=True | ||
self.put() | ||
message = mail.EmailMessage( | ||
sender="Friends with Food Admin <[email protected]>", | ||
subject="Your account has been verified!") | ||
|
||
message.to = self.id.email() | ||
message.cc = "[email protected]" | ||
message.body = """ | ||
Dear %s: | ||
Your account on Friends with Food has been verified! Because you've | ||
shown us so many good events, we've upgraded your account. Now, you'll | ||
get notified of free food on campus ASAP! You'll also be able to verify | ||
events so that everyone knows they're legit. | ||
*With great power comes great responsibility* | ||
Thanks, | ||
The Friends with Food Team | ||
""" % self.id.nickname() | ||
message.send() | ||
|
||
|
||
|
||
class Event(db.Model): | ||
"""Models an individual Event item, describing the entirety of the event.""" | ||
creator = db.ReferenceProperty(AppUser, required=True) | ||
host = db.StringProperty(indexed=False) | ||
name = db.StringProperty(indexed=False, required=True) | ||
location = db.StringProperty(indexed=False, required=True) | ||
description = db.StringProperty(multiline=True) | ||
dateStart = db.DateTimeProperty(required=True) | ||
dateEnd = db.DateTimeProperty() | ||
lastUpdated = db.DateTimeProperty(auto_now=True) | ||
verified = db.BooleanProperty() | ||
attending = db.IntegerProperty(indexed=False) | ||
|
||
def verify(self): | ||
if self.verified: | ||
return | ||
self.verified=True | ||
#push | ||
|
||
def getXMLFormat(self): | ||
return """<Event name='""" + self.name + """'> | ||
<location>""" + self.location + """</location> | ||
<start>""" + self.startTime.isoformat()[:16] + """</start> | ||
<end>""" + (self.dateEnd.isoformat()[:16] if dateEnd is not None else "") + """</end> | ||
<host>""" + self.host + """</host> | ||
<creator>""" + self.creator.id.nickname() + """</creator> | ||
<attending>""" + (str)(self.attending) + """</attending> | ||
<description>""" + self.description + """</description> | ||
<verified>""" + ("1" if self.verified else "0") + """</verified> | ||
<key>""" + self.key() + """</key> | ||
</Event>""" | ||
|
||
def getEventLink(self): | ||
return '/?' + urllib.urlencode({'message':'''Event pages coming soon'''}) #Update to actual page. | ||
from datetime import datetime | ||
from datetime import timedelta | ||
|
||
import urllib | ||
|
||
from google.appengine.ext import db | ||
from google.appengine.api import users | ||
from google.appengine.api import mail | ||
|
||
class AppUser(db.Model): | ||
"""Stores extra User data for validation of events and features""" | ||
id = db.UserProperty(auto_current_user=True) | ||
verified = db.BooleanProperty(indexed=False) | ||
banned = db.BooleanProperty(indexed=False) | ||
premium = db.BooleanProperty(indexed=False) | ||
goodEventsCount = db.IntegerProperty(indexed=False) | ||
badEventsCount = db.IntegerProperty(indexed=False) | ||
|
||
@staticmethod | ||
def registerUser(): | ||
"""Constructor for the AppUser class""" | ||
id=users.get_current_user() | ||
key=id.email().split('@')[0] | ||
user = AppUser(key_name=key) | ||
user.id = id | ||
user.verified=False | ||
user.banned=False | ||
user.premium=False | ||
user.goodEventsCount=0 | ||
user.badEventsCount=0 | ||
user.put() | ||
return user | ||
|
||
@staticmethod | ||
def getUser(): | ||
"""Gets the AppUser object of the current user. If they're not registered, this registers them""" | ||
user = users.get_current_user() | ||
userList = db.GqlQuery("SELECT * FROM AppUser WHERE id = :1 LIMIT 1", | ||
user).fetch(1) | ||
if userList == []: # Wasn't found | ||
return AppUser.registerUser() | ||
return userList[0] | ||
|
||
@property | ||
def getUserLink(self): | ||
return """/User/"""+str(self.key().name()) | ||
|
||
@staticmethod | ||
def getUserFromKey(key): | ||
""" Retrieves an AppUser object from the """ | ||
#get(Key(key)) | ||
#return None if no user found | ||
|
||
def banUser(self): | ||
"""Initiates the banhammer""" | ||
#ensure they're supposed to be here | ||
if self.badEventsCount >= 3 and not self.banned: | ||
self.banned=True | ||
self.put() | ||
message = mail.EmailMessage( | ||
sender="Friends with Food Admin <[email protected]>", | ||
subject="Your account has been flagged to be banned") | ||
|
||
message.to = self.id.email() | ||
message.cc = "[email protected]" | ||
message.body = """ | ||
Dear %s: | ||
Your account on Friends with Food has been flagged for | ||
banning after being reported for several consecutive fake | ||
events. Your account has been banned from creating new events. | ||
If you feel that this is in error, please reply-all to this | ||
message with an explanation. | ||
Thanks, | ||
The Friends with Food Team | ||
""" % self.id.nickname() | ||
message.send() | ||
|
||
|
||
def promoteUser(self): | ||
"""Users are rewarded with verified user status whenever they pay up or | ||
make 3 good Events""" | ||
#ensure they're supposed to be here and haven't been here before | ||
if self.goodEventsCount >= 3 and not self.verified: | ||
self.verifiedUser=True | ||
self.put() | ||
message = mail.EmailMessage( | ||
sender="Friends with Food Admin <[email protected]>", | ||
subject="Your account has been verified!") | ||
|
||
message.to = self.id.email() | ||
message.cc = "[email protected]" | ||
message.body = """ | ||
Dear %s: | ||
Your account on Friends with Food has been verified! Because you've | ||
shown us so many good events, we've upgraded your account. Now, you'll | ||
get notified of free food on campus ASAP! You'll also be able to verify | ||
events so that everyone knows they're legit. | ||
*With great power comes great responsibility* | ||
Thanks, | ||
The Friends with Food Team | ||
""" % self.id.nickname() | ||
message.send() | ||
|
||
|
||
|
||
class Event(db.Model): | ||
"""Models an individual Event item, describing the entirety of the event.""" | ||
creator = db.ReferenceProperty(AppUser, required=True) | ||
host = db.StringProperty(indexed=False) | ||
name = db.StringProperty(indexed=False, required=True) | ||
location = db.StringProperty(indexed=False, required=True) | ||
description = db.StringProperty(multiline=True) | ||
dateStart = db.DateTimeProperty(required=True) | ||
dateEnd = db.DateTimeProperty() | ||
lastUpdated = db.DateTimeProperty(auto_now=True) | ||
verified = db.BooleanProperty() | ||
attending = db.IntegerProperty(indexed=False) | ||
|
||
def verify(self): | ||
if self.verified: | ||
return | ||
self.verified=True | ||
#push | ||
|
||
def getXMLFormat(self): | ||
return """<Event name='""" + self.name + """'> | ||
<location>""" + self.location + """</location> | ||
<start>""" + self.startTime.isoformat()[:16] + """</start> | ||
<end>""" + (self.dateEnd.isoformat()[:16] if dateEnd is not None else "") + """</end> | ||
<host>""" + self.host + """</host> | ||
<creator>""" + self.creator.id.nickname() + """</creator> | ||
<attending>""" + (str)(self.attending) + """</attending> | ||
<description>""" + self.description + """</description> | ||
<verified>""" + ("1" if self.verified else "0") + """</verified> | ||
<key>""" + self.key() + """</key> | ||
</Event>""" | ||
|
||
def getEventLink(self): | ||
return """/Event/"""+str(self.key()) #Update to actual page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.