def DeleteClass(self, *args): from google.appengine.ext import db from models import Task, Class, Book, Chapter from google.appengine.api import users user = users.get_current_user() classname = args[0].replace('%20', ' ') #Deleting all Tasks for this Module q = Task.all().filter('user ==',user).filter('classname ==',classname) results = q.fetch(10) for result in results: result.delete() #Deleting all the Scripts and Chapters from this Module qq = Book.all().filter('user ==',user).filter('classname ==',classname) books = qq.fetch(10) for book in books: qqq = Chapter.all().filter('book ==', book.title).filter('user ==',user) for chapter in qqq: chapter.delete() book.delete() #Deleting the Module itself qqqq = Class.all().filter('user ==',user).filter('name ==',classname) results = qqqq.fetch(10) for result in results: result.delete() return self.RefreshClasses()
def cacheAllUserClasses(self, user_key): all_user_classes = memcache.get(str(user_key) + "all") if type(all_user_classes) is list: return all_user_classes else: all_user_classes = Class.all().filter( 'other_users ==', str(user_key)).order("last_updated") memcache.set(str(user_key) + "all", all_user_classes) return all_user_classes
def cacheClass(self, user_key, class_name): class_obj = memcache.get(str(user_key) + class_name) if type(class_obj) is Class: return class_obj else: class_obj = Class.all().filter('name =', class_name).filter( 'other_users ==', str(user_key)).get() memcache.set(str(user_key) + class_name, class_obj) return class_obj
def get(self): user = self.getCookieCacheUser() if user: the_classes = Class.all().filter("user_creator !=", user) user_classes = self.cacheAllUserClasses(user.key().id()) page_title = "Welcome " + user.username self.render('index.html', current_user=user, the_classes=the_classes, page_title=page_title, user_classes=user_classes) else: the_classes = Class.all() page_title = "Welcome To Sparquiz" self.render('index.html', current_user=None, the_classes=the_classes, page_title=page_title)
def AddTask(self, *args): from datetime import date from models import Class user = users.get_current_user() classes = Class.all().order("exam").filter('user ==',user).filter('exam >', date.today()) path = os.path.join(os.path.dirname(__file__), "templates","addtask.html") template_values = { 'classes': classes } code = template.render(path, template_values).decode('utf-8') return code
def RefreshClasses(self): from models import Class, Task, Book from datetime import date user = users.get_current_user() books = Book.all().filter('user ==',user) classes = Class.all().order("exam").filter('user ==',user).filter('exam >', date.today()) template_values = { 'books' : books, 'classes': classes } path = os.path.join(os.path.dirname(__file__), "templates", "listmoduls.html") code = template.render(path, template_values).decode('utf-8') return code
def get(self, username=""): user = self.getCookieCacheUser() if user: if user.username == username: classes = Class.all().filter( "other_users ==", str(user.key().id())).order("last_updated") page_title = "List of Classes" self.render('edituserprofile.html', page_title=page_title, current_user=user, classes=classes, class_active="active") else: user_profile = self.get_user_by_name(username) self.render('userprofile.html', user_profile=user_profile)
def get(self): #imports from models import Class, Task, Book from datetime import date #get current User user = users.get_current_user() #Check if user wants to change the language cookie_django_language = self.request.get('language', '') if cookie_django_language: if cookie_django_language == 'unset': del self.request.COOKIES['django_language'] else: self.request.COOKIES['django_language'] = cookie_django_language self.reset_language() if user: classes = Class.all().order("exam").filter('user ==',user).filter('exam >', date.today()) logoutlink = users.create_logout_url(self.request.uri) books = Book.all().filter('user ==',user) inline = Task.all().order("enddate").filter('state ==','Offen').filter('user ==',user).filter('enddate >', date.today()) urgent = Task.all().order("enddate").filter('state ==','Offen').filter('user ==',user).filter('enddate <=', date.today()) template_values = { 'books' : books, 'title':'Task Management', 'user' : user.email(), 'tasks': inline, 'urgent': urgent, 'logout' : logoutlink, 'classes': classes } path = os.path.join(os.path.dirname(__file__), 'templates', "index.html") self.response.out.write(template.render(path, template_values).decode('utf-8')) else: providers = [] for p in openIdProviders: p_name = p.split('.')[0].lower() p_url = p.lower() providers.append([users.create_login_url(federated_identity=p_url), p_name]) template_values = { 'providers' : providers, } path = os.path.join(os.path.dirname(__file__), 'templates', "login.html") self.response.out.write(template.render(path, template_values).decode('utf-8'))
def post(self, username="", class_name=""): user = self.getCookieCacheUser() user_creator = self.get_user_by_name(username) class_obj = Class.all().filter('name =', class_name).filter( 'user_creator =', user_creator).get() if user and user_creator and class_obj: if str(user.key().id()) not in class_obj.requests and str( user.key().id()) not in class_obj.other_users: class_obj.requests.append(str(user.key().id())) class_obj.put() memcache.delete(str(user_creator.key().id()) + class_name) my_response = {'msg': 'success'} json_response = json.dumps(my_response) self.response.headers.add_header('content-type', 'text/json', charset='utf-8') self.response.out.write(json_response) else: self.write("We cannot process your request")
async def read(current_user: User = Depends(getTokenUser)): classes = Class.all().select_related("level", "section", "a_s") return await ClassBaseOut.from_queryset(classes)
def post(self): from datetime import datetime, date from models import Task, Book, Class user = users.get_current_user() from cgi import escape type = escape(self.request.get('type')) if type == 'task': if self.request.get('description'): beschreibung = self.request.get('description') else: beschreibung = _("Keine Beschreibung vorhanden") classname = escape(self.request.get('class')) if classname == "": color = 'gray' classname = 'None' else: colors = Class.all().filter('user ==',user).filter('name ==',self.request.get('class')) for c in colors: color = c.color if self.request.get('homework') == "checked": home = True else: home = False try: enddate = datetime.strptime(self.request.get('enddate'),"%d.%m.%Y %H:%M") except: try: enddate = datetime.strptime(self.request.get('enddate'),"%d.%m.%Y") except: enddate = datetime.strptime("1.1.1970","%d.%m.%Y") entry = Task( title = escape(self.request.get('name').replace('/','-')), classname = classname, color = color, homework = home, state = "Offen", user = user, text = beschreibung, enddate = enddate ) entry.put() self.redirect('/') if type == 'class': if escape(self.request.get('preexam')) == "checked": preexam = True else: preexam = False try: examdate = datetime.strptime(escape(self.request.get('exam')),"%d.%m.%Y") except: try: examdate = datetime.strptime(escape(self.request.get('exam')),"%d.%m.%Y %H:%M") except: self.redirect('/') #better solution needed! entry = Class( name = escape(self.request.get('name')), color = escape(self.request.get('color')), semester = int(escape(self.request.get('semester'))), preexam = preexam, user = user, exam = examdate ) entry.put() self.redirect('/') if type == 'book': import re from models import Book, Chapter skentry = Book( title = self.request.get('name'), classname = self.request.get('class'), user = user ) skentry.put() index = escape(self.request.get('index')) pfound = re.compile('(\d*(\.\d*)*)\s(.+?)(\.{2,}|\s|(\.\s)+)(\d+)') for line in index.split('\n'): found = pfound.search(line) try: name = found.group(3) number = found.group(1) entry = Chapter( title = name, number = number, user = user, book = self.request.get('name'), state = "offen" ) entry.put() except: pass self.redirect('/') self.redirect('/')