def edit_theme(request, theme_id=None): """ allows requester to edit their theme args: theme_id: The theme to fill the form with """ if not theme_id: try: theme = request.user.theme except Theme.DoesNotExist: theme = Theme(user=request.user) else: theme = get_object_or_404(Theme, pk=theme_id) if request.method == 'POST': if request.POST['submit'] == 'Save': form = ThemeForm(request.POST, instance=theme) if form.is_valid(): form.save() else: # preview feature form = ThemeForm(request.POST, instance=theme) theme = form.save(commit=False) else: form = ThemeForm(instance=theme) return render_to_response( "themes/edit_theme.html", { 'form': form, 'theme': theme, 'extra_themes': Theme.objects.exclude(name="").all(), }, context_instance=RequestContext(request))
def form_valid(self, form): name = form.cleaned_data['name'] theme_color = form.cleaned_data['theme_color'] background_image = form.cleaned_data['background_image'] theme = Theme(name=name, theme_color=theme_color, background_image=background_image) theme.save()
def create_theme(course_id): theme = Theme(name=request.form.get('name')) parent_id = request.form.get('parent_id') if parent_id: theme.parent_id = parent_id else: theme.course_id = course_id db.session.add(theme) db.session.commit() return redirect(url_for('courses.show', course_id=course_id))
def process_theme(lst): if lst[0]: new_theme = Theme(name=lst[0], player_id=PlayerDict.id_dict[lst[1]], date=datetime.datetime.strptime( lst[2], "%d. %m. %Y")) db.session.add(new_theme) db.session.flush() db.session.refresh(new_theme) else: new_theme = Theme.query.order_by(desc(Theme.id)).first() return new_theme.id
def theme_save_as(request, name): theme = get_object_or_404(Theme, name=name) if request.method == 'POST': # Theme new_theme = Theme() new_theme.verbose_name = request.POST['name'] new_name = slugify(new_theme.verbose_name) counter = 0 while Theme.objects.filter(name=new_name).exclude(pk=theme.pk).count(): counter += 1 new_name = '%s-%s'%(slugify(theme.verbose_name), counter) new_theme.name = new_name new_theme.save() # Templates for tpl in theme.templates.all(): new_tpl, new = new_theme.templates.get_or_create(name=tpl.name) new_tpl.notes = tpl.notes new_tpl.content = tpl.content new_tpl.engine = tpl.engine new_tpl.save() # Static files for sf in theme.static_files.all(): try: new_sf, new = new_theme.static_files.get_or_create(name=sf.name) new_sf.url = sf.url new_sf.mime_type = sf.mime_type new_sf.save() if sf.file: # Finds a name for the new file root = sf.file.path.replace(sf.file.name, '') name, ext = os.path.splitext(sf.file.name) while os.path.exists(root + name + ext): name += '_' # Reads the old file to make a ContentFile instance fp = file(sf.file.path) content = ContentFile(fp.read()) fp.close() # Saves the new file for the new static file object new_sf.file.save(name+ext, content) except Exception, e: print (sf, e.__class__, e) raise ret = {'new_url': reverse('themes_theme', args=(new_theme.name,))}
def post(self): theme = Theme() name = self.request.get('name') description = self.request.get('description') theme.name = name theme.description = description email = self.request.get('email') url = self.request.get('url') token = self.request.get('token') imageUrl = url + '&token=' + token correctUrl = imageUrl.replace("images/", "images%2F") theme.image_url = correctUrl theme.created_user_email = email theme.put() self.response.write('Got post request: ' + name + ' ' + description)
def post(self): user = users.get_current_user() if user: theme = Theme() name = self.request.get('themeName') description = self.request.get('themeDescription') theme.name = name theme.description = description uploaded_file = self.request.POST.get("themeImage") url = writeToGCBucket(uploaded_file) theme.image_url = url theme.created_user_email = user.email() theme.put() self.redirect('/viewThemes')
def put_theme(plateid): #向主题界面发布问答主题 if request.method == 'GET': return render_template('question.html') else: title = request.form.get('title') content = request.form.get('content') plate_id = plateid # plate_id=request.form.get('plate_id') theme = Theme(title=title, content=content) theme.author = g.user plate = Plate.query.filter(Plate.id == plate_id).first() theme.plate = plate m = 0 for x in Theme.query.all(): # 迭代器, if x.plate_id == theme.plate_id: m = m + 1 plate.post_num = m db.session.add(theme) db.session.commit() return redirect(url_for('theme', plate_id=plate.id))
def home(): display_message = None if request.method == 'POST': theme_name = request.form['theme_name'] video_title = request.form['video_title'] if theme_name and video_title: if Theme.objects(name=theme_name).count() > 0: theme = Theme.objects(name=theme_name).first() else: theme = Theme(name=theme_name) theme.save() Video(title=video_title, theme=theme).save() display_message = 'Video added successfully!' else: display_message = 'An error occurred while adding a video!' return render_template('homepage.html', videos=Video.objects(), message=display_message)
def insert_theme(): last_theme = Theme.query.order_by(desc(Theme.date)).limit(1).all()[0] next_monday = time_calc.get_next_monday(last_theme.date) players = Player.query.all() head = ["id", "name"] players = [row2dict(p, head) for p in players] new_theme = None if request.method == 'POST': name = request.form.get('name') player_id = int(request.form.get('player')) print(player_id) date = request.form.get('date') try: new_theme = Theme(name=name, player_id=player_id, date=date) db.session.add(new_theme) db.session.commit() except Exception as e: return str(e) print(db.engine.pool.status()) return render_template("insert_theme.html", insert_theme_page=True, players=players, inserted=new_theme, default_date=next_monday)
(u"Bootstrap", u'bootstrap.min.css'), (u"Amelia", u'amelia.min.css'), (u"Cyborg", u'cyborg.min.css'), (u"Readable", u'readable.min.css'), (u"Slate", u'slate.min.css'), (u"Spruce", u'spruce.min.css'), (u"United", u'united.min.css'), (u"Cerulean", u'cerulean.min.css'), (u"Journal", u'journal.min.css'), (u"Simplex", u'simplex.min.css'), (u"Spacelab", u'spacelab.min.css'), (u"Superhero", u'superhero.min.css'), ] for css in css_files: theme = Theme( name=css[0], cssfile=css[1], ) dbsession.add(theme) dbsession.flush() # Market Items item = MarketItem( name=u"Source Code Market", price=5000, description=u"Buy leaked source code.", ) dbsession.add(item) dbsession.flush() item = MarketItem( name=u"Password Security",
post_save.connect(invalidate_theme, sender=Theme) default_cache_control = cache_control( max_age=604800, must_revalidate=False, ) urlpatterns = patterns( '', url(r"^(?P<object_id>\d+)/$", default_cache_control(theme_css), { 'queryset': Theme.objects, 'template_name': 'themes/theme.css', 'mimetype': 'text/css', }, name='theme-css'), url(r"^default/$", default_cache_control(cache_page(direct_to_template, 600)), { 'template': 'themes/theme.css', 'mimetype': 'text/css', 'extra_context': { 'object': Theme(), }, }, name='default-theme-css'), url(r"^edit/$", edit_theme, name="edit-theme"), url(r"^edit/(?P<theme_id>\d+)/$", edit_theme, name="edit-existing-theme"), )
def save_theme(): error = False errormessage = None themename = request.form.get("name") submitter = request.form.get("submitter", None) template = request.form.get("template", None) data = request.form.get("data", None) email = request.form.get("email", None) rendered = request.form.get("rendered", None) if (not error): if (themename == None): error = True errormessage = "You must enter a theme name" if (not error): recaptchallange = request.form.get("recaptcha_challenge_field") if (not error): recaptresponse = request.form.get("recaptcha_response_field") if (not error): if (submitter == None or submitter == ""): error = True errormessage = "Please enter your name" if (not error): if (email == None or email == ""): error = True errormessage = "Please enter your email" if (not error and not re.match(r"[^@]+@[^@]+\.[^@]+", email)): error = True errormessage = "Please enter a valid email address" if (not error): if (data == None or data == ""): error = True errormessage = "The no data found" if (not error): themedata = Theme.get_by_key_name(themename) if (themedata): error = True errormessage = "A theme with the same name already exist" if (not DEBUG): validation = recaptcha.submit(recaptchallange, recaptresponse, RECAPTCHA_KEY, request.remote_addr) if (not validation.is_valid): error = True errormessage = "Please reenter the recaptcha." if ((DEBUG or validation.is_valid) and not error): newtheme = Theme() newtheme.name = themename newtheme.submitter = submitter newtheme.email = email newtheme.data = data newtheme.counter = 0 newtheme.rendered = rendered newtheme.generate_photo() newtheme.put() return 'success', 200 elif (not error): return 'Something went wrong', 400 else: return JSON.dumps({"error": errormessage}), 400