def post_document(title): req = request.get_json() document = Document.query.filter_by(title=title).first() if document is None: document = Document(title=title) if req.get('title'): req.pop('title') document.update_attributes(req) document.save() return make_response(json.dumps(document.to_dict()))
def add_document(self, title, manager_page_id): manager_page = self.page(page_id=manager_page_id) if manager_page is not None and self.user and self.user.has_perm( APP_NAME + '.add_link'): profile = ProfileRepo(user=self.user).me if profile is not None: document = Document(title=title, icon_material='get_app', profile=profile) document.save() manager_page.documents.add(document) return True return False
def fcmat(request): if not request.POST: from app.models import Document from app.forms import DocumentForm form = DocumentForm() # A empty, unbound form # Render list page with the documents and the form return render_to_response('app/inp_fcmat.html', { 'title': 'Displaying Functional Connectivity Matrix', 'form': form }, context_instance=RequestContext(request)) else: from app.models import Document from app.forms import DocumentForm from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse from django.conf import settings #or from my_project import settings import os import pyFitMR.fcmat_lib as fcmat_lib from django.conf import settings #or from my_project import settings uploadedfile = False form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() matfile = os.path.join(settings.MEDIA_ROOT, newdoc.docfile.name) uploadedfile = True else: FILE_ROOT = os.path.abspath(os.path.dirname(__file__)) matfile = os.path.join(FILE_ROOT, 'CC_testfile.mat') import scipy.io #import matplotlib.pyplot as plt mat = scipy.io.loadmat(matfile) FC = mat['connectome'] #FC=mat.items()[0][1] #plt.imshow(FC) #print FC script, div = fcmat_lib.plot(FC) if uploadedfile: newdoc.docfile.delete() return render(request, 'app/fcmat_result.html', { "the_script": script, "the_div": div })
def test_model_document(self): """Test to make sure that Document is working properly. """ d1 = Document(title="test") d1.save() assert d1.type == "document" u1 = Unit() u1.save() d1.children.append(u1) d1.save() assert d1.children == [u1] assert u1.parent == d1
def fcmat(request): if not request.POST: from app.models import Document from app.forms import DocumentForm form = DocumentForm() # A empty, unbound form # Render list page with the documents and the form return render_to_response( 'app/inp_fcmat.html', {'title':'Displaying Functional Connectivity Matrix','form': form}, context_instance=RequestContext(request) ) else: from app.models import Document from app.forms import DocumentForm from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse from django.conf import settings #or from my_project import settings import os import pyFitMR.fcmat_lib as fcmat_lib from django.conf import settings #or from my_project import settings uploadedfile = False form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile = request.FILES['docfile']) newdoc.save() matfile = os.path.join(settings.MEDIA_ROOT,newdoc.docfile.name) uploadedfile = True else: FILE_ROOT = os.path.abspath(os.path.dirname(__file__)) matfile = os.path.join(FILE_ROOT,'CC_testfile.mat') import scipy.io #import matplotlib.pyplot as plt mat = scipy.io.loadmat(matfile) FC=mat['connectome'] #FC=mat.items()[0][1] #plt.imshow(FC) #print FC script, div = fcmat_lib.plot(FC) if uploadedfile: newdoc.docfile.delete() return render(request, 'app/fcmat_result.html', {"the_script":script, "the_div":div})
def test_document_belongs_to(self): """Check if ``belongs_to()`` on ``Document`` is working properly. """ user = User() project = Project() document_file = DocumentFile() document = Document() project.document_files = [document_file] document_file.documents = [document] user.projects = [project] user.save() project.save() document.save() document_file.save() assert document.belongs_to(user)
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile = request.FILES['docfile']) newdoc.save() # Redirect to the document list after POST print '**********************************' #print newdoc dir_name= str(newdoc).split('/') name_file= str(dir_name[1]) #print settings.MEDIA_ROOT filepath = str(settings.MEDIA_ROOT) +'/' + str(dir_name[0]) + '/' #functions.xlsx2geojson(filepath,name_file) request.session['name_file'] = name_file request.session['filepath'] = filepath # return HttpResponseRedirect(reverse('app.views.listdetails')) array_headers= functions.readheader_xlsx(filepath,name_file) print array_headers variable = {'array_headers':simplejson.dumps(array_headers)} return render_to_response('listdetails.html',variable,context_instance=RequestContext(request)) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render_to_response( 'list.html', {'documents': documents, 'form': form}, context_instance=RequestContext(request) )
def save(self): super(TextFile, self).save() lexer = None content = self.f.value.decode('utf-8') plain_ext = '.txt', '.log', if self.ext in plain_ext: lexer = TextLexer else: try: lexer = get_lexer_for_filename(self.filename) except ClassNotFound: try: lexer = get_lexer_for_mimetype(self.mimetype) except ClassNotFound: try: lexer = guess_lexer(content) except ClassNotFound: lexer = TextLexer html = highlight( content, lexer, HtmlFormatter(linenos=True, lineanchors='line', anchorlinenos=True)) txt = Document() txt.file_id = self.id txt.html = html txt.content = content txt.save() return self.base
def new_project(request): if request.method == "GET": return render(request, "new_project.html") title = request.POST.get('title') or None file = request.POST.get('file') or None copies = request.POST.get('copies') or None brief = request.POST.get('brief') or None try: """ Creating and saving a new User. """ doc = Document() doc.brief = brief doc.title = title doc.file = file print(doc.file) doc.save() printjob = PrintJob() printjob.charged_to = request.user printjob.copies = copies printjob.status = "Pending" printjob.document = doc printjob.save() # send_mail(request.user,) add_message( request, messages.INFO, "Your Document has been saved sucessfully, and has been sent to the admin for approval" ) return render(request, "new_project.html") except Exception as e: print(e) add_message(request, messages.WARNING, "An error occured, please try again") return render(request, "new_project.html")
class BaseTestCase(TestCase): def setUp(self): self.d = Document() self.d.title="My new doc" self.d.brief = "this doc" self.d.save() # Testing the URLs def test_user_can_register(self): respose = self.client.get('/signup/') self.response_200(respose) def test_homepage_loads_without_errors(self): respose = self.client.get('/') self.response_200(respose) def test_pricing_is_fecthed_correctly(self): response = self.client.get('/pricing/') self.response_200(response) def test_document_can_be_created(self): self.assertIn(self.d,Document.objects.all()) def test_print_job_can_be_created(self): # printjob = PrintJob() # printjob.document = self.d # printjob.copies = 3 # printjob.cost = 40 # printjob.save() # self.assertIsNotNone(printjob) pass
def save(self): super(TextFile, self).save() lexer = None content = self.f.value.decode('utf-8') plain_ext = '.txt', '.log', if self.ext in plain_ext: lexer = TextLexer else: try: lexer = get_lexer_for_filename(self.filename) except ClassNotFound: try: lexer = get_lexer_for_mimetype(self.mimetype) except ClassNotFound: try: lexer = guess_lexer(content) except ClassNotFound: lexer = TextLexer html = highlight(content, lexer, HtmlFormatter(linenos=True, lineanchors='line', anchorlinenos = True)) txt = Document() txt.file_id = self.id txt.html = html txt.content = content txt.save() return self.base